Convert usages of Config.* to use the non-static versions

This commit is contained in:
Andrew Grieve 2014-07-08 14:11:14 -04:00
parent 9b25d45b93
commit d31ee20ba5
6 changed files with 26 additions and 22 deletions

View File

@ -22,6 +22,7 @@ package org.apache.cordova;
import android.app.Activity; import android.app.Activity;
import android.util.Log; import android.util.Log;
@Deprecated // Use Whitelist, CordovaPrefences, etc. directly.
public class Config { public class Config {
private static final String TAG = "Config"; private static final String TAG = "Config";
@ -82,4 +83,8 @@ public class Config {
public static String getErrorUrl() { public static String getErrorUrl() {
return parser.getPreferences().getString("errorurl", null); return parser.getPreferences().getString("errorurl", null);
} }
public static Whitelist getWhitelist() {
return parser.getWhitelist();
}
} }

View File

@ -227,7 +227,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
} }
appView = makeWebView(); appView = makeWebView();
appView.init(this, makeWebViewClient(appView), makeChromeClient(appView), pluginEntries); appView.init(this, makeWebViewClient(appView), makeChromeClient(appView), pluginEntries, whitelist);
// TODO: Have the views set this themselves. // TODO: Have the views set this themselves.
if (preferences.getBoolean("DisallowOverscroll", false)) { if (preferences.getBoolean("DisallowOverscroll", false)) {
@ -844,8 +844,9 @@ public class CordovaActivity extends Activity implements CordovaInterface {
/** /**
* Determine if URL is in approved list of URLs to load. * Determine if URL is in approved list of URLs to load.
*/ */
@Deprecated // Use whitelist object directly.
public boolean isUrlWhiteListed(String url) { public boolean isUrlWhiteListed(String url) {
return Config.isUrlWhiteListed(url); return whitelist.isUrlWhiteListed(url);
} }
/* /*

View File

@ -240,11 +240,10 @@ public class CordovaChromeClient extends WebChromeClient {
} }
else if (defaultValue != null && defaultValue.startsWith("gap_init:")) { else if (defaultValue != null && defaultValue.startsWith("gap_init:")) {
String startUrl = Config.getStartUrl();
// Protect against random iframes being able to talk through the bridge. // Protect against random iframes being able to talk through the bridge.
// Trust only file URLs and the start URL's domain. // 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. // 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 // Enable the bridge
int bridgeMode = Integer.parseInt(defaultValue.substring(9)); int bridgeMode = Integer.parseInt(defaultValue.substring(9));
appView.jsMessageQueue.setBridgeMode(bridgeMode); appView.jsMessageQueue.setBridgeMode(bridgeMode);

View File

@ -49,7 +49,7 @@ class CordovaUriHelper {
if(url.startsWith("http:") || url.startsWith("https:")) if(url.startsWith("http:") || url.startsWith("https:"))
{ {
// We only need to whitelist sites on the Internet! // We only need to whitelist sites on the Internet!
if(Config.isUrlWhiteListed(url)) if(appView.getWhitelist().isUrlWhiteListed(url))
{ {
return false; return false;
} }

View File

@ -26,12 +26,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; 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.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -80,11 +74,8 @@ public class CordovaWebView extends WebView {
/** Activities and other important classes **/ /** Activities and other important classes **/
private CordovaInterface cordova; private CordovaInterface cordova;
CordovaWebViewClient viewClient; CordovaWebViewClient viewClient;
@SuppressWarnings("unused")
private CordovaChromeClient chromeClient; private CordovaChromeClient chromeClient;
private String url;
// Flag to track that a loadUrl timeout occurred // Flag to track that a loadUrl timeout occurred
int loadUrlTimeout = 0; int loadUrlTimeout = 0;
@ -97,9 +88,10 @@ public class CordovaWebView extends WebView {
private View mCustomView; private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback; private WebChromeClient.CustomViewCallback mCustomViewCallback;
private ActivityResult mResult = null;
private CordovaResourceApi resourceApi; private CordovaResourceApi resourceApi;
private Whitelist whitelist;
// The URL passed to loadUrl(), not necessarily the URL of the current page.
String loadedUrl;
class ActivityResult { class ActivityResult {
@ -142,13 +134,15 @@ public class CordovaWebView extends WebView {
} }
// Use two-phase init so that the control will work with XML layouts. // Use two-phase init so that the control will work with XML layouts.
public void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient, List<PluginEntry> pluginEntries) { public void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient,
List<PluginEntry> pluginEntries, Whitelist whitelist) {
if (this.cordova != null) { if (this.cordova != null) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
this.cordova = cordova; this.cordova = cordova;
this.viewClient = webViewClient; this.viewClient = webViewClient;
this.chromeClient = webChromeClient; this.chromeClient = webChromeClient;
this.whitelist = whitelist;
super.setWebChromeClient(webChromeClient); super.setWebChromeClient(webChromeClient);
super.setWebViewClient(webViewClient); super.setWebViewClient(webViewClient);
@ -310,6 +304,11 @@ public class CordovaWebView extends WebView {
return this.chromeClient; return this.chromeClient;
} }
public Whitelist getWhitelist() {
return this.whitelist;
}
/** /**
* Load the url into the webview. * Load the url into the webview.
* *
@ -357,7 +356,7 @@ public class CordovaWebView extends WebView {
LOG.d(TAG, ">>> loadUrl(" + url + ")"); LOG.d(TAG, ">>> loadUrl(" + url + ")");
if (recreatePlugins) { if (recreatePlugins) {
this.url = url; this.loadedUrl = url;
this.pluginManager.init(); this.pluginManager.init();
} }
@ -413,7 +412,7 @@ public class CordovaWebView extends WebView {
if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) { if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
LOG.d(TAG, ">>> loadUrlNow()"); 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); super.loadUrl(url);
} }
} }
@ -549,7 +548,7 @@ public class CordovaWebView extends WebView {
if (!openExternal) { if (!openExternal) {
// Make sure url is in whitelist // Make sure url is in whitelist
if (url.startsWith("file://") || Config.isUrlWhiteListed(url)) { if (url.startsWith("file://") || whitelist.isUrlWhiteListed(url)) {
// TODO: What about params? // TODO: What about params?
// Load new URL // Load new URL
this.loadUrl(url); this.loadUrl(url);
@ -897,8 +896,8 @@ public class CordovaWebView extends WebView {
return myList; return myList;
} }
@Deprecated // This never did anything
public void storeResult(int requestCode, int resultCode, Intent intent) { public void storeResult(int requestCode, int resultCode, Intent intent) {
mResult = new ActivityResult(requestCode, resultCode, intent);
} }
public CordovaResourceApi getResourceApi() { public CordovaResourceApi getResourceApi() {

View File

@ -77,7 +77,7 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
} }
private boolean isUrlHarmful(String url) { 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"); || url.contains("app_webview");
} }