diff --git a/framework/src/org/apache/cordova/AndroidChromeClient.java b/framework/src/org/apache/cordova/AndroidChromeClient.java index 73e97240..a683ec69 100755 --- a/framework/src/org/apache/cordova/AndroidChromeClient.java +++ b/framework/src/org/apache/cordova/AndroidChromeClient.java @@ -229,11 +229,10 @@ public class AndroidChromeClient extends WebChromeClient implements CordovaChrom } else if (defaultValue != null && defaultValue.startsWith("gap_init:")) { - String startUrl = Config.getStartUrl(); // Protect against random iframes being able to talk through the bridge. // Trust only file URLs and the start URL's domain. // The extra origin.startsWith("http") is to protect against iframes with data: having "" as origin. - if (origin.startsWith("file:") || (origin.startsWith("http") && startUrl.startsWith(origin))) { + if (origin.startsWith("file:") || (origin.startsWith("http") && appView.loadedUrl.startsWith(origin))) { // Enable the bridge int bridgeMode = Integer.parseInt(defaultValue.substring(9)); appView.jsMessageQueue.setBridgeMode(bridgeMode); diff --git a/framework/src/org/apache/cordova/AndroidWebView.java b/framework/src/org/apache/cordova/AndroidWebView.java index c8c3c903..8499caf8 100755 --- a/framework/src/org/apache/cordova/AndroidWebView.java +++ b/framework/src/org/apache/cordova/AndroidWebView.java @@ -26,12 +26,6 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; -import org.apache.cordova.Config; -import org.apache.cordova.CordovaInterface; -import org.apache.cordova.LOG; -import org.apache.cordova.PluginManager; -import org.apache.cordova.PluginResult; - import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.BroadcastReceiver; @@ -80,11 +74,8 @@ public class AndroidWebView extends WebView implements CordovaWebView { /** Activities and other important classes **/ private CordovaInterface cordova; CordovaWebViewClient viewClient; - @SuppressWarnings("unused") private CordovaChromeClient chromeClient; - private String url; - // Flag to track that a loadUrl timeout occurred int loadUrlTimeout = 0; @@ -97,10 +88,12 @@ public class AndroidWebView extends WebView implements CordovaWebView { private View mCustomView; private WebChromeClient.CustomViewCallback mCustomViewCallback; - private ActivityResult mResult = null; - private CordovaResourceApi resourceApi; - + private Whitelist whitelist; + private CordovaPreferences preferences; + // The URL passed to loadUrl(), not necessarily the URL of the current page. + String loadedUrl; + class ActivityResult { int request; @@ -134,13 +127,16 @@ public class AndroidWebView extends WebView implements CordovaWebView { // Use two-phase init so that the control will work with XML layouts. @Override - public void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient, List pluginEntries) { + public void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient, + List pluginEntries, Whitelist whitelist, CordovaPreferences preferences) { if (this.cordova != null) { throw new IllegalStateException(); } this.cordova = cordova; setWebChromeClient(webChromeClient); setWebViewClient(webViewClient); + this.whitelist = whitelist; + this.preferences = preferences; pluginManager = new PluginManager(this, this.cordova, pluginEntries); jsMessageQueue = new NativeToJsMessageQueue(this, cordova); @@ -364,7 +360,7 @@ public class AndroidWebView extends WebView implements CordovaWebView { LOG.d(TAG, ">>> loadUrl(" + url + ")"); if (recreatePlugins) { - this.url = url; + this.loadedUrl = url; this.pluginManager.init(); } @@ -420,7 +416,7 @@ public class AndroidWebView extends WebView implements CordovaWebView { if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) { LOG.d(TAG, ">>> loadUrlNow()"); } - if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)) { + if (url.startsWith("file://") || url.startsWith("javascript:") || whitelist.isUrlWhiteListed(url)) { super.loadUrl(url); } } @@ -541,7 +537,7 @@ public class AndroidWebView extends WebView implements CordovaWebView { if (!openExternal) { // Make sure url is in whitelist - if (url.startsWith("file://") || Config.isUrlWhiteListed(url)) { + if (url.startsWith("file://") || whitelist.isUrlWhiteListed(url)) { // TODO: What about params? // Load new URL this.loadUrl(url); @@ -862,10 +858,6 @@ public class AndroidWebView extends WebView implements CordovaWebView { return myList; } - public void storeResult(int requestCode, int resultCode, Intent intent) { - mResult = new ActivityResult(requestCode, resultCode, intent); - } - public CordovaResourceApi getResourceApi() { return resourceApi; } @@ -926,5 +918,13 @@ public class AndroidWebView extends WebView implements CordovaWebView { return this; } - + @Override + public Whitelist getWhitelist() { + return this.whitelist; + } + + @Override + public CordovaPreferences getPreferences() { + return preferences; + } } diff --git a/framework/src/org/apache/cordova/Config.java b/framework/src/org/apache/cordova/Config.java index dfb039d8..c13d3972 100644 --- a/framework/src/org/apache/cordova/Config.java +++ b/framework/src/org/apache/cordova/Config.java @@ -22,6 +22,7 @@ package org.apache.cordova; import android.app.Activity; import android.util.Log; +@Deprecated // Use Whitelist, CordovaPrefences, etc. directly. public class Config { private static final String TAG = "Config"; @@ -82,4 +83,8 @@ public class Config { public static String getErrorUrl() { return parser.getPreferences().getString("errorurl", null); } + + public static Whitelist getWhitelist() { + return parser.getWhitelist(); + } } diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 059a5523..dbb6fee5 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -162,7 +162,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { } appView = makeWebView(); - appView.init(this, makeWebViewClient(appView), makeChromeClient(appView), pluginEntries); + appView.init(this, makeWebViewClient(appView), makeChromeClient(appView), pluginEntries, whitelist, preferences); // TODO: Have the views set this themselves. if (preferences.getBoolean("DisallowOverscroll", false)) { @@ -175,6 +175,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { setVolumeControlStream(AudioManager.STREAM_MUSIC); } + @SuppressWarnings("deprecation") protected void loadConfig() { ConfigXmlParser parser = new ConfigXmlParser(); parser.parse(this); @@ -581,8 +582,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { // If errorUrl specified, then load it final String errorUrl = preferences.getString("errorUrl", null); - if ((errorUrl != null) && (errorUrl.startsWith("file://") || Config.isUrlWhiteListed(errorUrl)) && (!failingUrl.equals(errorUrl))) { - + if ((errorUrl != null) && (errorUrl.startsWith("file://") || whitelist.isUrlWhiteListed(errorUrl)) && (!failingUrl.equals(errorUrl))) { // Load URL on UI thread me.runOnUiThread(new Runnable() { public void run() { @@ -639,8 +639,9 @@ public class CordovaActivity extends Activity implements CordovaInterface { /** * Determine if URL is in approved list of URLs to load. */ + @Deprecated // Use whitelist object directly. public boolean isUrlWhiteListed(String url) { - return Config.isUrlWhiteListed(url); + return whitelist.isUrlWhiteListed(url); } /* diff --git a/framework/src/org/apache/cordova/CordovaPlugin.java b/framework/src/org/apache/cordova/CordovaPlugin.java index 8111e7b7..2e7a9327 100644 --- a/framework/src/org/apache/cordova/CordovaPlugin.java +++ b/framework/src/org/apache/cordova/CordovaPlugin.java @@ -32,20 +32,29 @@ import android.net.Uri; * Plugins must extend this class and override one of the execute methods. */ public class CordovaPlugin { - public String id; - public CordovaWebView webView; // WebView object + public CordovaWebView webView; public CordovaInterface cordova; + protected CordovaPreferences preferences; - /** - * @param cordova The context of the main Activity. - * @param webView The associated CordovaWebView. - */ - public void initialize(CordovaInterface cordova, CordovaWebView webView) { + void privateInitialize(CordovaInterface cordova, CordovaWebView webView, CordovaPreferences preferences) { assert this.cordova == null; this.cordova = cordova; this.webView = webView; + this.preferences = preferences; + initialize(cordova, webView); + initialize(); } + @Deprecated // Override initialize() instead. + public void initialize(CordovaInterface cordova, CordovaWebView webView) { + } + + /** + * This is where you can do start-up logic with protected fields set. + */ + protected void initialize() { + } + /** * Executes the request. * diff --git a/framework/src/org/apache/cordova/CordovaUriHelper.java b/framework/src/org/apache/cordova/CordovaUriHelper.java index 0250601a..2d3f3d89 100644 --- a/framework/src/org/apache/cordova/CordovaUriHelper.java +++ b/framework/src/org/apache/cordova/CordovaUriHelper.java @@ -49,7 +49,7 @@ class CordovaUriHelper { if(url.startsWith("http:") || url.startsWith("https:")) { // We only need to whitelist sites on the Internet! - if(Config.isUrlWhiteListed(url)) + if(appView.getWhitelist().isUrlWhiteListed(url)) { return false; } diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index dc871ac8..977ad4db 100644 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -12,7 +12,8 @@ import android.widget.LinearLayout.LayoutParams; public interface CordovaWebView { public static final String CORDOVA_VERSION = "4.0.0-dev"; - void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient, List pluginEntries); + void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient, + List pluginEntries, Whitelist whitelist, CordovaPreferences preferences); View getView(); @@ -132,5 +133,7 @@ public interface CordovaWebView { // Required for test String getUrl(); boolean isPaused(); - + + Whitelist getWhitelist(); + CordovaPreferences getPreferences(); } diff --git a/framework/src/org/apache/cordova/CoreAndroid.java b/framework/src/org/apache/cordova/CoreAndroid.java index 56c7e649..64036733 100755 --- a/framework/src/org/apache/cordova/CoreAndroid.java +++ b/framework/src/org/apache/cordova/CoreAndroid.java @@ -47,16 +47,12 @@ public class CoreAndroid extends CordovaPlugin { /** * Sets the context of the Command. This can then be used to do things like * get file paths associated with the Activity. - * - * @param cordova The context of the main Activity. - * @param webView The CordovaWebView Cordova is running in. */ - public void initialize(CordovaInterface cordova, CordovaWebView webView) { - super.initialize(cordova, webView); + @Override + public void initialize() { this.initTelephonyReceiver(); } - /** * Executes the request and returns PluginResult. * diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java index 1a29510d..4938091d 100644 --- a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java @@ -72,7 +72,7 @@ public class IceCreamCordovaWebViewClient extends AndroidWebViewClient implement } private boolean isUrlHarmful(String url) { - return ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) + return ((url.startsWith("http:") || url.startsWith("https:")) && !appView.getWhitelist().isUrlWhiteListed(url)) || url.contains("app_webview"); } diff --git a/framework/src/org/apache/cordova/PluginEntry.java b/framework/src/org/apache/cordova/PluginEntry.java index 3adffebc..e0acfacf 100755 --- a/framework/src/org/apache/cordova/PluginEntry.java +++ b/framework/src/org/apache/cordova/PluginEntry.java @@ -84,7 +84,7 @@ public class PluginEntry { Class c = getClassByName(this.pluginClass); if (isCordovaPlugin(c)) { this.plugin = (CordovaPlugin) c.newInstance(); - this.plugin.initialize(ctx, webView); + this.plugin.privateInitialize(ctx, webView, webView.getPreferences()); return plugin; } } catch (Exception e) {