Bug 1500906 - Suppress FileUriExposedExceptions when launching helper apps. r=jchen, a=pascalc
authorJan Henning <jh+bitbucket@buttercookie.de>
Wed, 24 Oct 2018 21:02:17 +0200
changeset 492967 b71bed0c6a40
parent 492966 032ed494717a
child 492968 ea5bceb1d4ac
push id1843
push userryanvm@gmail.com
push dateMon, 05 Nov 2018 14:45:45 +0000
treeherdermozilla-release@b71bed0c6a40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen, pascalc
bugs1500906, 1450449
milestone63.0.2
Bug 1500906 - Suppress FileUriExposedExceptions when launching helper apps. r=jchen, a=pascalc Sharing tabs with file:// URIs is not possible, but users can still send them to other apps via the helper app system in the URL bar/context menu. "Intent:Open" and "Intent:OpenForResult" are both sent from Gecko by HelperApps.jsm. The same reasoning as in bug 1450449 applies as to why for publicly accessible files content:// URIs are more trouble than they're worth. Differential Revision: https://phabricator.services.mozilla.com/D9697
mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
--- a/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
@@ -17,16 +17,17 @@ import org.mozilla.gecko.widget.External
 
 import android.app.Activity;
 import android.content.ClipData;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.net.Uri;
+import android.os.StrictMode;
 import android.provider.Browser;
 import android.provider.MediaStore;
 import android.support.annotation.Nullable;
 import android.support.v4.app.FragmentActivity;
 import android.support.v4.content.FileProvider;
 import android.text.TextUtils;
 import android.util.Log;
 import android.webkit.MimeTypeMap;
@@ -429,22 +430,28 @@ public final class IntentHelper implemen
                                                message.getString("url", ""),
                                                message.getString("mime", ""),
                                                message.getString("action", ""),
                                                message.getString("title", ""));
         callback.sendSuccess(getHandlersForIntent(intent));
     }
 
     private void open(final GeckoBundle message) {
-        openUriExternal(message.getString("url", ""),
-                        message.getString("mime", ""),
-                        message.getString("packageName", ""),
-                        message.getString("className", ""),
-                        message.getString("action", ""),
-                        message.getString("title", ""), false);
+        final StrictMode.VmPolicy prevPolicy = StrictMode.getVmPolicy();
+        StrictMode.setVmPolicy(StrictMode.VmPolicy.LAX);
+        try {
+            openUriExternal(message.getString("url", ""),
+                            message.getString("mime", ""),
+                            message.getString("packageName", ""),
+                            message.getString("className", ""),
+                            message.getString("action", ""),
+                            message.getString("title", ""), false);
+        } finally {
+            StrictMode.setVmPolicy(prevPolicy);
+        }
     }
 
     private void openForResult(final GeckoBundle message, final EventCallback callback) {
         Intent intent = getOpenURIIntent(getContext(),
                                          message.getString("url", ""),
                                          message.getString("mime", ""),
                                          message.getString("action", ""),
                                          message.getString("title", ""));
@@ -453,20 +460,24 @@ public final class IntentHelper implemen
         intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 
         final FragmentActivity activity = getActivity();
         if (activity == null) {
             callback.sendError(null);
             return;
         }
         final ResultHandler handler = new ResultHandler(callback);
+        final StrictMode.VmPolicy prevPolicy = StrictMode.getVmPolicy();
+        StrictMode.setVmPolicy(StrictMode.VmPolicy.LAX);
         try {
             ActivityHandlerHelper.startIntentForActivity(activity, intent, handler);
         } catch (SecurityException e) {
             Log.w(LOGTAG, "Forbidden to launch activity.", e);
+        } finally {
+            StrictMode.setVmPolicy(prevPolicy);
         }
     }
 
     /**
      * Opens a URI without any valid handlers on device. In the best case, a package is specified
      * and we can bring the user directly to the application page in an app market. If a package is
      * not specified and there is a fallback url in the intent extras, we open that url. If neither
      * is present, we alert the user that we were unable to open the link.