You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2015/03/03 03:40:55 UTC

[1/4] android commit: CB-8588 Add CATEGORY_BROWSABLE to intents from showWebPage openExternal=true

Repository: cordova-android
Updated Branches:
  refs/heads/master 53dba8678 -> eccf48616


CB-8588 Add CATEGORY_BROWSABLE to intents from showWebPage openExternal=true


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/747d2c97
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/747d2c97
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/747d2c97

Branch: refs/heads/master
Commit: 747d2c97cdd3ea3927b6f9ab7e774040f8d9e245
Parents: af2969d
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Mar 2 21:01:06 2015 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Mar 2 21:04:20 2015 -0500

----------------------------------------------------------------------
 framework/src/org/apache/cordova/CordovaWebViewImpl.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/747d2c97/framework/src/org/apache/cordova/CordovaWebViewImpl.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
index a7dd41a..744bd44 100644
--- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
@@ -232,10 +232,12 @@ public class CordovaWebViewImpl implements CordovaWebView {
             return;
         }
         try {
-            // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
-            // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
             Intent intent = new Intent(Intent.ACTION_VIEW);
+            // To send an intent without CATEGORY_BROWSER, a custom plugin should be used.
+            intent.addCategory(Intent.CATEGORY_BROWSABLE);
             Uri uri = Uri.parse(url);
+            // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
+            // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
             if ("file".equals(uri.getScheme())) {
                 intent.setDataAndType(uri, resourceApi.getMimeType(uri));
             } else {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[2/4] android commit: CB-8587 Don't allow webview navigations within showWebPage that are not whitelisted

Posted by ag...@apache.org.
CB-8587 Don't allow webview navigations within showWebPage that are not whitelisted


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/af2969de
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/af2969de
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/af2969de

Branch: refs/heads/master
Commit: af2969dec58ca89150b84b5d57edcf63d4ce1302
Parents: 53dba86
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Mar 2 21:00:22 2015 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Mar 2 21:04:20 2015 -0500

----------------------------------------------------------------------
 framework/src/org/apache/cordova/CordovaWebViewImpl.java | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/af2969de/framework/src/org/apache/cordova/CordovaWebViewImpl.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
index d3f5ec9..a7dd41a 100644
--- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
@@ -209,7 +209,7 @@ public class CordovaWebViewImpl implements CordovaWebView {
 
     @Override
     public void showWebPage(String url, boolean openExternal, boolean clearHistory, Map<String, Object> params) {
-        LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory);
+        LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap)", url, openExternal, clearHistory);
 
         // If clearing history
         if (clearHistory) {
@@ -223,10 +223,13 @@ public class CordovaWebViewImpl implements CordovaWebView {
                 // TODO: What about params?
                 // Load new URL
                 loadUrlIntoView(url, true);
-                return;
+            } else {
+                LOG.w(TAG, "showWebPage: Refusing to load URL into webview since it is not in the <allow-navigation> whitelist. URL=" + url);
             }
-            // Load in default viewer if not
-            LOG.w(TAG, "showWebPage: Cannot load URL into webview since it is not in white list.  Loading into browser instead. (URL=" + url + ")");
+        }
+        if (!pluginManager.shouldOpenExternalUrl(url)) {
+            LOG.w(TAG, "showWebPage: Refusing to send intent for URL since it is not in the <allow-intent> whitelist. URL=" + url);
+            return;
         }
         try {
             // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[4/4] android commit: Add about:blank and data: to default shouldAllowNavigation()

Posted by ag...@apache.org.
Add about:blank and data: to default shouldAllowNavigation()


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/eccf4861
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/eccf4861
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/eccf4861

Branch: refs/heads/master
Commit: eccf486162a75da572b4b6d3eca0c5eb75ad3949
Parents: a6da46a
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Mar 2 21:40:28 2015 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Mar 2 21:40:28 2015 -0500

----------------------------------------------------------------------
 framework/src/org/apache/cordova/PluginManager.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/eccf4861/framework/src/org/apache/cordova/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java
index 4787542..57e5012 100755
--- a/framework/src/org/apache/cordova/PluginManager.java
+++ b/framework/src/org/apache/cordova/PluginManager.java
@@ -325,8 +325,10 @@ public class PluginManager {
         }
 
         // 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:")) {
+        if (url.startsWith("data:") || url.startsWith("about:blank")) {
+            return true;
+        }
+        if (url.startsWith("file://")) {
             //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/");
@@ -362,7 +364,7 @@ public class PluginManager {
         }
 
         // Default policy:
-        return url.startsWith("file://");
+        return url.startsWith("file://") || url.startsWith("about:blank");
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[3/4] android commit: CB-8510 Remove `shouldOverrideUrlLoading` from `CordovaWebViewEngine.Client`.

Posted by ag...@apache.org.
CB-8510 Remove `shouldOverrideUrlLoading` from `CordovaWebViewEngine.Client`.

It's logic that's pretty webview-specific, so it doesn't make sense to
share.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/a6da46a0
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/a6da46a0
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/a6da46a0

Branch: refs/heads/master
Commit: a6da46a00e3f4c5bb334077274e4ac4759295fc2
Parents: 747d2c9
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Mar 2 20:43:45 2015 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Mar 2 21:04:21 2015 -0500

----------------------------------------------------------------------
 .../apache/cordova/CordovaWebViewEngine.java    |  1 -
 .../org/apache/cordova/CordovaWebViewImpl.java  | 31 --------------------
 .../cordova/engine/SystemWebViewClient.java     | 16 ++++++++--
 3 files changed, 14 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a6da46a0/framework/src/org/apache/cordova/CordovaWebViewEngine.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewEngine.java b/framework/src/org/apache/cordova/CordovaWebViewEngine.java
index 8b62b1f..d996a1c 100644
--- a/framework/src/org/apache/cordova/CordovaWebViewEngine.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewEngine.java
@@ -72,7 +72,6 @@ public interface CordovaWebViewEngine {
      */
     public interface Client {
         Boolean onDispatchKeyEvent(KeyEvent event);
-        boolean shouldOverrideUrlLoading(String url);
         void clearLoadTimeoutTimer();
         void onPageStarted(String newUrl);
         void onReceivedError(int errorCode, String description, String failingUrl);

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a6da46a0/framework/src/org/apache/cordova/CordovaWebViewImpl.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
index 744bd44..303f4e8 100644
--- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java
@@ -588,37 +588,6 @@ public class CordovaWebViewImpl implements CordovaWebView {
         }
 
         @Override
-        public boolean shouldOverrideUrlLoading(String url) {
-            // Give plugins the chance to handle the url
-            if (pluginManager.shouldAllowNavigation(url)) {
-                // Allow internal navigation
-                return false;
-            } else if (pluginManager.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
-                // returned true, then we should open the URL here.
-                try {
-                    Intent intent = new Intent(Intent.ACTION_VIEW);
-                    intent.setData(Uri.parse(url));
-                    intent.addCategory(Intent.CATEGORY_BROWSABLE);
-                    intent.setComponent(null);
-                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
-                        intent.setSelector(null);
-                    }
-                    getContext().startActivity(intent);
-                    return true;
-                } catch (android.content.ActivityNotFoundException e) {
-                    Log.e(TAG, "Error loading url " + url, e);
-                }
-                return true;
-            }
-            LOG.w(TAG, "Blocked navigation because URL was not whitelisted: " + url);
-            // Block by default
-            return true;
-        }
-
-        @Override
         public void onScrollChanged(int l, int t, int oldl, int oldt) {
             // TODO: scrolling is perf-sensitive, so we'd probably be better to no use postMessage
             // here, and also not to create any new objects.

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a6da46a0/framework/src/org/apache/cordova/engine/SystemWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java
index 69dc2f2..6aaac75 100755
--- a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java
+++ b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java
@@ -76,9 +76,21 @@ public class SystemWebViewClient extends WebViewClient {
      */
 	@Override
     public boolean shouldOverrideUrlLoading(WebView view, String url) {
-        return parentEngine.client.shouldOverrideUrlLoading(url);
+        // Give plugins the chance to handle the url
+        if (parentEngine.pluginManager.onOverrideUrlLoading(url)) {
+            return true;
+        } else if (parentEngine.pluginManager.shouldOpenExternalUrl(url)) {
+            parentEngine.getCordovaWebView().showWebPage(url, true, false, null);
+            return true;
+        } else if (!parentEngine.pluginManager.shouldAllowNavigation(url)) {
+            // This blocks iframe navigations as well.
+            LOG.w(TAG, "Blocked (possibly sub-frame) navigation to non-allowed URL: " + url);
+            return true;
+        }
+
+        return false;
     }
-    
+
     /**
      * On received http auth request.
      * The method reacts on all registered authentication tokens. There is one and only one authentication token for any host + realm combination


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org