mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
Move newly added should* methods of CordovaUriHelper into PluginManager
Doing this so that clients won't mistakenly call the wrong one.
This commit is contained in:
parent
204130a598
commit
c12d93e77f
@ -138,7 +138,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
cordova.getActivity().runOnUiThread(r);
|
||||
}
|
||||
}));
|
||||
bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue, this.cordova.getActivity().getPackageName(), helper);
|
||||
bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue, this.cordova.getActivity().getPackageName());
|
||||
initWebViewSettings();
|
||||
pluginManager.addService(CoreAndroid.PLUGIN_NAME, CoreAndroid.class.getCanonicalName());
|
||||
pluginManager.init();
|
||||
@ -383,7 +383,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
|
||||
LOG.d(TAG, ">>> loadUrlNow()");
|
||||
}
|
||||
if (url.startsWith("javascript:") || helper.shouldAllowNavigation(url)) {
|
||||
if (url.startsWith("javascript:") || pluginManager.shouldAllowNavigation(url)) {
|
||||
super.loadUrl(url);
|
||||
}
|
||||
}
|
||||
@ -458,7 +458,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
||||
if (!openExternal) {
|
||||
|
||||
// Make sure url is in whitelist
|
||||
if (helper.shouldAllowNavigation(url)) {
|
||||
if (pluginManager.shouldAllowNavigation(url)) {
|
||||
// TODO: What about params?
|
||||
// Load new URL
|
||||
loadUrlIntoView(url, true);
|
||||
|
@ -38,13 +38,11 @@ public class CordovaBridge {
|
||||
private volatile int expectedBridgeSecret = -1; // written by UI thread, read by JS thread.
|
||||
private String loadedUrl;
|
||||
private String appContentUrlPrefix;
|
||||
protected CordovaUriHelper helper;
|
||||
|
||||
public CordovaBridge(PluginManager pluginManager, NativeToJsMessageQueue jsMessageQueue, String packageName, CordovaUriHelper helper) {
|
||||
public CordovaBridge(PluginManager pluginManager, NativeToJsMessageQueue jsMessageQueue, String packageName) {
|
||||
this.pluginManager = pluginManager;
|
||||
this.jsMessageQueue = jsMessageQueue;
|
||||
this.appContentUrlPrefix = "content://" + packageName + ".";
|
||||
this.helper = helper;
|
||||
}
|
||||
|
||||
public String jsExec(int bridgeSecret, String service, String action, String callbackId, String arguments) throws JSONException, IllegalAccessException {
|
||||
@ -173,7 +171,7 @@ public class CordovaBridge {
|
||||
// to navigate to anyway.
|
||||
if (origin.startsWith("file:") ||
|
||||
origin.startsWith(this.appContentUrlPrefix) ||
|
||||
helper.shouldAllowNavigation(origin)) {
|
||||
pluginManager.shouldAllowNavigation(origin)) {
|
||||
// Enable the bridge
|
||||
int bridgeMode = Integer.parseInt(defaultValue.substring(9));
|
||||
jsMessageQueue.setBridgeMode(bridgeMode);
|
||||
|
@ -39,67 +39,6 @@ public class CordovaUriHelper {
|
||||
cordova = cdv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the webview should be allowed to navigate to a given URL.
|
||||
*
|
||||
* This method implements the default whitelist policy when no plugins override
|
||||
* shouldAllowNavigation
|
||||
*/
|
||||
public boolean shouldAllowNavigation(String url) {
|
||||
Boolean pluginManagerAllowsNavigation = this.appView.getPluginManager().shouldAllowNavigation(url);
|
||||
if (pluginManagerAllowsNavigation == null) {
|
||||
// Default policy:
|
||||
// Internal urls on file:// or data:// that do not contain "/app_webview/" are allowed for navigation
|
||||
if(url.startsWith("file://") || url.startsWith("data:"))
|
||||
{
|
||||
//This directory on WebKit/Blink based webviews contains SQLite databases!
|
||||
//DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||
return !url.contains("/app_webview/");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return pluginManagerAllowsNavigation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the webview should be allowed to launch an intent for a given URL.
|
||||
*
|
||||
* This method implements the default whitelist policy when no plugins override
|
||||
* shouldOpenExternalUrl
|
||||
*/
|
||||
public boolean shouldOpenExternalUrl(String url) {
|
||||
Boolean pluginManagerAllowsExternalUrl = this.appView.getPluginManager().shouldOpenExternalUrl(url);
|
||||
if (pluginManagerAllowsExternalUrl == null) {
|
||||
// Default policy:
|
||||
// External URLs are not allowed
|
||||
return false;
|
||||
}
|
||||
return pluginManagerAllowsExternalUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the webview should be allowed to request a resource from a given URL.
|
||||
*
|
||||
* This method implements the default whitelist policy when no plugins override
|
||||
* shouldAllowRequest
|
||||
*/
|
||||
public boolean shouldAllowRequest(String url) {
|
||||
|
||||
Boolean pluginManagerAllowsRequest = this.appView.getPluginManager().shouldAllowRequest(url);
|
||||
if (pluginManagerAllowsRequest == null) {
|
||||
// Default policy:
|
||||
// Internal urls on file:// or data:// that do not contain "/app_webview/" are allowed for navigation
|
||||
if(url.startsWith("file://") || url.startsWith("data:"))
|
||||
{
|
||||
//This directory on WebKit/Blink based webviews contains SQLite databases!
|
||||
//DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||
return !url.contains("/app_webview/");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return pluginManagerAllowsRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the host application a chance to take over the control when a new url
|
||||
* is about to be loaded in the current WebView.
|
||||
@ -109,18 +48,17 @@ public class CordovaUriHelper {
|
||||
* Internal urls on file:// or data:// that do not contain "app_webview" are allowed for navigation
|
||||
* External urls are not allowed.
|
||||
*
|
||||
* @param view The WebView that is initiating the callback.
|
||||
* @param url The url to be loaded.
|
||||
* @return true to override, false for default behavior
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
|
||||
public boolean shouldOverrideUrlLoading(String url) {
|
||||
// Give plugins the chance to handle the url
|
||||
if (shouldAllowNavigation(url)) {
|
||||
if (appView.getPluginManager().shouldAllowNavigation(url)) {
|
||||
// Allow internal navigation
|
||||
return false;
|
||||
}
|
||||
if (shouldOpenExternalUrl(url)) {
|
||||
if (appView.getPluginManager().shouldOpenExternalUrl(url)) {
|
||||
// Do nothing other than what the plugins wanted.
|
||||
// If any returned false, then the request was either blocked
|
||||
// completely, or handled out-of-band by the plugin. If they all
|
||||
|
@ -45,7 +45,7 @@ public class IceCreamCordovaWebViewClient extends AndroidWebViewClient {
|
||||
try {
|
||||
// Check the against the whitelist and lock out access to the WebView directory
|
||||
// Changing this will cause problems for your application
|
||||
if (!helper.shouldAllowRequest(url)) {
|
||||
if (!appView.getPluginManager().shouldAllowRequest(url)) {
|
||||
LOG.w(TAG, "URL blocked by whitelist: " + url);
|
||||
// Results in a 404.
|
||||
return new WebResourceResponse("text/plain", "UTF-8", null);
|
||||
|
@ -313,22 +313,25 @@ public class PluginManager {
|
||||
* false: At least one plugin returned false (block the
|
||||
* resource)
|
||||
*/
|
||||
public Boolean shouldAllowRequest(String url) {
|
||||
Boolean anyResponded = null;
|
||||
public boolean shouldAllowRequest(String url) {
|
||||
for (PluginEntry entry : this.entryMap.values()) {
|
||||
CordovaPlugin plugin = pluginMap.get(entry.service);
|
||||
if (plugin != null) {
|
||||
Boolean result = plugin.shouldAllowRequest(url);
|
||||
if (result != null) {
|
||||
anyResponded = true;
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
// This will be true if all plugins allow the request, or null if no plugins override the method
|
||||
return anyResponded;
|
||||
|
||||
// Default policy:
|
||||
// Internal urls on file:// or data:// that do not contain "/app_webview/" are allowed for navigation
|
||||
if (url.startsWith("file://") || url.startsWith("data:")) {
|
||||
//This directory on WebKit/Blink based webviews contains SQLite databases!
|
||||
//DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||
return !url.contains("/app_webview/");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -347,22 +350,25 @@ public class PluginManager {
|
||||
* false: At least one plugin returned false (block the
|
||||
* navigation)
|
||||
*/
|
||||
public Boolean shouldAllowNavigation(String url) {
|
||||
Boolean anyResponded = null;
|
||||
public boolean shouldAllowNavigation(String url) {
|
||||
for (PluginEntry entry : this.entryMap.values()) {
|
||||
CordovaPlugin plugin = pluginMap.get(entry.service);
|
||||
if (plugin != null) {
|
||||
Boolean result = plugin.shouldAllowNavigation(url);
|
||||
if (result != null) {
|
||||
anyResponded = true;
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
// This will be true if all plugins allow the request, or null if no plugins override the method
|
||||
return anyResponded;
|
||||
|
||||
// Default policy:
|
||||
// Internal urls on file:// or data:// that do not contain "/app_webview/" are allowed for navigation
|
||||
if (url.startsWith("file://") || url.startsWith("data:")) {
|
||||
// This directory on WebKit/Blink based webviews contains SQLite databases!
|
||||
// DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
|
||||
return !url.contains("/app_webview/");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -384,21 +390,18 @@ public class PluginManager {
|
||||
* intent)
|
||||
*/
|
||||
public Boolean shouldOpenExternalUrl(String url) {
|
||||
Boolean anyResponded = null;
|
||||
for (PluginEntry entry : this.entryMap.values()) {
|
||||
CordovaPlugin plugin = pluginMap.get(entry.service);
|
||||
if (plugin != null) {
|
||||
Boolean result = plugin.shouldOpenExternalUrl(url);
|
||||
if (result != null) {
|
||||
anyResponded = true;
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
// This will be true if all plugins allow the request, or null if no plugins override the method
|
||||
return anyResponded;
|
||||
// Default policy:
|
||||
// External URLs are not allowed
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user