Move the callback server into the View, preparing to start CordovaWebView testing

This commit is contained in:
Joe Bowser 2012-03-30 13:28:19 -07:00
parent 49b50ce66c
commit 2818e05e71
2 changed files with 36 additions and 8 deletions

View File

@ -15,9 +15,11 @@ import org.xmlpull.v1.XmlPullParserException;
import android.content.Context; import android.content.Context;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm; import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebViewClient;
public class CordovaWebView extends WebView { public class CordovaWebView extends WebView {
@ -30,9 +32,12 @@ public class CordovaWebView extends WebView {
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>(); private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>(); private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>();
protected PluginManager pluginManager; protected PluginManager pluginManager;
public CallbackServer callbackServer;
/** Actvities and other important classes **/ /** Actvities and other important classes **/
private Context mCtx; private Context mCtx;
private CordovaWebViewClient viewClient;
private CordovaChromeClient chromeClient;
public CordovaWebView(Context context) { public CordovaWebView(Context context) {
super(context); super(context);
@ -241,4 +246,28 @@ public class CordovaWebView extends WebView {
return false; return false;
} }
@Override
public void setWebViewClient(WebViewClient client) {
if(client.getClass().equals(CordovaWebView.class)) {
viewClient = (CordovaWebViewClient) client;
super.setWebViewClient(viewClient);
}
else
{
//This should throw an exception!
}
}
@Override
public void setWebChromeClient(WebChromeClient client) {
if(client.getClass().equals(CordovaWebView.class)) {
chromeClient = (CordovaChromeClient) client;
super.setWebChromeClient(chromeClient);
}
else
{
//This should throw an exception!
}
}
} }

View File

@ -155,7 +155,6 @@ public class DroidGap extends Activity implements CordovaInterface {
protected LinearLayout root; protected LinearLayout root;
public boolean bound = false; public boolean bound = false;
public CallbackServer callbackServer;
protected boolean cancelLoadUrl = false; protected boolean cancelLoadUrl = false;
protected ProgressDialog spinnerDialog = null; protected ProgressDialog spinnerDialog = null;
@ -380,12 +379,12 @@ public class DroidGap extends Activity implements CordovaInterface {
me.appView.clearHistory(); me.appView.clearHistory();
// Create callback server and plugin manager // Create callback server and plugin manager
if (me.callbackServer == null) { if (me.appView.callbackServer == null) {
me.callbackServer = new CallbackServer(); me.appView.callbackServer = new CallbackServer();
me.callbackServer.init(url); me.appView.callbackServer.init(url);
} }
else { else {
me.callbackServer.reinit(url); me.appView.callbackServer.reinit(url);
} }
appView.pluginManager.init(); appView.pluginManager.init();
@ -833,8 +832,8 @@ public class DroidGap extends Activity implements CordovaInterface {
*/ */
public void sendJavascript(String statement) { public void sendJavascript(String statement) {
//We need to check for the null case on the Kindle Fire beacuse it changes the width and height on load //We need to check for the null case on the Kindle Fire beacuse it changes the width and height on load
if(this.callbackServer != null) if(this.appView.callbackServer != null)
this.callbackServer.sendJavascript(statement); this.appView.callbackServer.sendJavascript(statement);
} }
/** /**