diff --git a/framework/src/org/apache/cordova/CordovaChromeClient.java b/framework/src/org/apache/cordova/CordovaChromeClient.java index e9f8f93e..49ec1b5d 100755 --- a/framework/src/org/apache/cordova/CordovaChromeClient.java +++ b/framework/src/org/apache/cordova/CordovaChromeClient.java @@ -45,6 +45,7 @@ public class CordovaChromeClient extends WebChromeClient { private String TAG = "CordovaLog"; private long MAX_QUOTA = 100 * 1024 * 1024; private DroidGap ctx; + private CordovaWebView appView; /** * Constructor. @@ -53,6 +54,13 @@ public class CordovaChromeClient extends WebChromeClient { */ public CordovaChromeClient(Context ctx) { this.ctx = (DroidGap) ctx; + appView = this.ctx.appView; + } + + public CordovaChromeClient(Context ctx, CordovaWebView app) + { + this.ctx = (DroidGap) ctx; + appView = app; } /** @@ -182,7 +190,7 @@ public class CordovaChromeClient extends WebChromeClient { String action = array.getString(1); String callbackId = array.getString(2); boolean async = array.getBoolean(3); - String r = ctx.pluginManager.exec(service, action, callbackId, message, async); + String r = appView.pluginManager.exec(service, action, callbackId, message, async); result.confirm(r); } catch (JSONException e) { e.printStackTrace(); diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index c55877f1..aaa11eda 100644 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -9,6 +9,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.cordova.api.LOG; +import org.apache.cordova.api.PluginManager; import org.xmlpull.v1.XmlPullParserException; import android.content.Context; @@ -24,10 +25,16 @@ public class CordovaWebView extends WebView { /** The authorization tokens. */ private Hashtable authenticationTokens = new Hashtable(); - private Context mCtx; + /** The whitelist **/ private ArrayList whiteList = new ArrayList(); private HashMap whiteListCache = new HashMap(); + protected PluginManager pluginManager; + + /** Actvities and other important classes **/ + private Context mCtx; + private CordovaWebViewClient viewClient; + private CordovaChromeClient chromeClient; public CordovaWebView(Context context) { super(context); @@ -73,12 +80,19 @@ public class CordovaWebView extends WebView { settings.setDatabaseEnabled(true); String databasePath = mCtx.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); - + + //Setup the WebChromeClient and WebViewClient + setWebViewClient(new CordovaWebViewClient(mCtx, this)); + setWebChromeClient(new CordovaChromeClient(mCtx, this)); + // Enable DOM storage settings.setDomStorageEnabled(true); // Enable built-in geolocation settings.setGeolocationEnabled(true); + + //Start up the plugin manager + this.pluginManager = new PluginManager(this, (DroidGap) mCtx); } /** diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java index 26516873..1daf7597 100755 --- a/framework/src/org/apache/cordova/CordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java @@ -20,6 +20,7 @@ package org.apache.cordova; import org.apache.cordova.api.LOG; +import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; @@ -41,6 +42,7 @@ public class CordovaWebViewClient extends WebViewClient { private static final String TAG = "Cordova"; DroidGap ctx; + CordovaWebView appView; private boolean doClearHistory = false; /** @@ -50,6 +52,13 @@ public class CordovaWebViewClient extends WebViewClient { */ public CordovaWebViewClient(DroidGap ctx) { this.ctx = ctx; + appView = ctx.appView; + } + + public CordovaWebViewClient(Context ctx, CordovaWebView view) + { + this.ctx = (DroidGap) ctx; + appView = view; } /** @@ -64,7 +73,7 @@ public class CordovaWebViewClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) { // First give any plugins the chance to handle the url themselves - if ((this.ctx.pluginManager != null) && this.ctx.pluginManager.onOverrideUrlLoading(url)) { + if ((appView.pluginManager != null) && appView.pluginManager.onOverrideUrlLoading(url)) { } // If dialing phone (tel:5551212) diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index f5864196..5f9e3bd9 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -156,7 +156,6 @@ public class DroidGap extends Activity implements CordovaInterface { protected LinearLayout root; public boolean bound = false; public CallbackServer callbackServer; - protected PluginManager pluginManager; protected boolean cancelLoadUrl = false; protected ProgressDialog spinnerDialog = null; @@ -285,9 +284,6 @@ public class DroidGap extends Activity implements CordovaInterface { ViewGroup.LayoutParams.FILL_PARENT, 1.0F)); - this.appView.setWebChromeClient(webChromeClient); - this.setWebViewClient(this.appView, webViewClient); - // Add web view but make it invisible while loading URL this.appView.setVisibility(View.INVISIBLE); root.addView(this.appView); @@ -296,21 +292,8 @@ public class DroidGap extends Activity implements CordovaInterface { // Clear cancel flag this.cancelLoadUrl = false; - // Create plugin manager - this.pluginManager = new PluginManager(this.appView, this); } - /** - * Set the WebViewClient. - * - * @param appView - * @param client - */ - protected void setWebViewClient(WebView appView, WebViewClient client) { - this.webViewClient = client; - appView.setWebViewClient(client); - } - /** * Look at activity parameters and process them. * This must be called from the main UI thread. @@ -403,7 +386,7 @@ public class DroidGap extends Activity implements CordovaInterface { else { me.callbackServer.reinit(url); } - me.pluginManager.init(); + appView.pluginManager.init(); // If loadingDialog property, then show the App loading dialog for first page of app String loading = null; @@ -734,9 +717,7 @@ public class DroidGap extends Activity implements CordovaInterface { this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onPause.fire();}catch(e){console.log('exception firing pause event from native');};"); // Forward to plugins - if (this.pluginManager != null) { - this.pluginManager.onPause(this.keepRunning); - } + appView.pluginManager.onPause(this.keepRunning); // If app doesn't want to run in background if (!this.keepRunning) { @@ -754,9 +735,7 @@ public class DroidGap extends Activity implements CordovaInterface { super.onNewIntent(intent); //Forward to plugins - if (this.pluginManager != null) { - this.pluginManager.onNewIntent(intent); - } + appView.pluginManager.onNewIntent(intent); } @Override @@ -779,9 +758,7 @@ public class DroidGap extends Activity implements CordovaInterface { this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onResume.fire();}catch(e){console.log('exception firing resume event from native');};"); // Forward to plugins - if (this.pluginManager != null) { - this.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning); - } + appView.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning); // If app doesn't want to run in background if (!this.keepRunning || this.activityResultKeepRunning) { @@ -814,9 +791,7 @@ public class DroidGap extends Activity implements CordovaInterface { this.appView.loadUrl("about:blank"); // Forward to plugins - if (this.pluginManager != null) { - this.pluginManager.onDestroy(); - } + appView.pluginManager.onDestroy(); } else { this.endActivity(); @@ -832,9 +807,7 @@ public class DroidGap extends Activity implements CordovaInterface { public void postMessage(String id, Object data) { // Forward to plugins - if (this.pluginManager != null) { - this.pluginManager.postMessage(id, data); - } + appView.pluginManager.postMessage(id, data); } /** @@ -848,9 +821,7 @@ public class DroidGap extends Activity implements CordovaInterface { */ @Deprecated public void addService(String serviceType, String className) { - if (this.pluginManager != null) { - this.pluginManager.addService(serviceType, className); - } + appView.pluginManager.addService(serviceType, className); } /**