forked from github/cordova-android
Merge branch 'master' into 4.0.x (remove Config.* references)
Conflicts: framework/src/org/apache/cordova/CordovaActivity.java framework/src/org/apache/cordova/CordovaChromeClient.java framework/src/org/apache/cordova/CordovaWebView.java
This commit is contained in:
commit
ac194cd34f
@ -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);
|
||||
|
@ -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<PluginEntry> pluginEntries) {
|
||||
public void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient,
|
||||
List<PluginEntry> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<PluginEntry> pluginEntries);
|
||||
void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient,
|
||||
List<PluginEntry> 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();
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user