Bug 1258450 - Delegate Intent handling from GeckoAppShell to GeckoInterface. r=snorp,mcomella
☠☠ backed out by 7f7a84327477 ☠ ☠
authorNick Alexander <nalexander@mozilla.com>
Sun, 20 Mar 2016 20:27:52 -0700
changeset 290846 e5ec40672f6ee91471a420e797e653e3e322bba4
parent 290845 462e9e4314eff25e00e65e75359274ec09807eee
child 290847 dcffecae84b741d837295ad77d0dd9e7ece391eb
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, mcomella
bugs1258450
milestone48.0a1
Bug 1258450 - Delegate Intent handling from GeckoAppShell to GeckoInterface. r=snorp,mcomella MozReview-Commit-ID: HoHqZU0Ev5D
mobile/android/base/java/org/mozilla/gecko/BaseGeckoInterface.java
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java
--- a/mobile/android/base/java/org/mozilla/gecko/BaseGeckoInterface.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BaseGeckoInterface.java
@@ -156,9 +156,27 @@ public class BaseGeckoInterface implemen
     public void setUriTitle(final String uri, final String title) {
         // By default, no titles are associated with URIs.
     }
 
     @Override
     public void setAccessibilityEnabled(boolean enabled) {
         // By default, take no action when accessibility is toggled on or off.
     }
+
+    @Override
+    public boolean openUriExternal(String targetURI, String mimeType, String packageName, String className, String action, String title) {
+        // By default, never open external URIs.
+        return false;
+    }
+
+    @Override
+    public String[] getHandlersForMimeType(String mimeType, String action) {
+        // By default, offer no handlers for any MIME type.
+        return new String[] {};
+    }
+
+    @Override
+    public String[] getHandlersForURL(String url, String action) {
+        // By default, offer no handlers for any URL.
+        return new String[] {};
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -2525,19 +2525,26 @@ public abstract class GeckoApp
     public void notifyCheckUpdateResult(String result) {
         GeckoAppShell.notifyObservers("Update:CheckResult", result);
     }
 
     private void geckoConnected() {
         mLayerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
     }
 
+    @Override
     public void setAccessibilityEnabled(boolean enabled) {
     }
 
+    @Override
+    public boolean openUriExternal(String targetURI, String mimeType, String packageName, String className, String action, String title) {
+        // Default to showing prompt in private browsing to be safe.
+        return IntentHelper.openUriExternal(targetURI, mimeType, packageName, className, action, title, true);
+    }
+
     public static class MainLayout extends RelativeLayout {
         private TouchEventInterceptor mTouchEventInterceptor;
         private MotionEventInterceptor mMotionEventInterceptor;
 
         public MainLayout(Context context, AttributeSet attrs) {
             super(context, attrs);
         }
 
@@ -2782,9 +2789,28 @@ public abstract class GeckoApp
         final BrowserDB db = GeckoProfile.get(context).getDB();
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
                 GlobalHistory.getInstance().update(context.getContentResolver(), db, uri, title);
             }
         });
     }
+
+    @Override
+    public String[] getHandlersForMimeType(String mimeType, String action) {
+        Intent intent = IntentHelper.getIntentForActionString(action);
+        if (mimeType != null && mimeType.length() > 0)
+            intent.setType(mimeType);
+        return IntentHelper.getHandlersForIntent(intent);
+    }
+
+    @Override
+    public String[] getHandlersForURL(String url, String action) {
+        // May contain the whole URL or just the protocol.
+        Uri uri = url.indexOf(':') >= 0 ? Uri.parse(url) : new Uri.Builder().scheme(url).build();
+
+        Intent intent = IntentHelper.getOpenURIIntent(getApplicationContext(), uri.toString(), "",
+                TextUtils.isEmpty(action) ? Intent.ACTION_VIEW : action, "");
+
+        return IntentHelper.getHandlersForIntent(intent);
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java
@@ -15,17 +15,16 @@ import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
 import java.net.MalformedURLException;
 import java.net.Proxy;
 import java.net.URLConnection;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.StringTokenizer;
 import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
 
 import android.annotation.SuppressLint;
 import org.mozilla.gecko.annotation.JNITarget;
 import org.mozilla.gecko.annotation.RobocopTarget;
@@ -830,31 +829,30 @@ public class GeckoAppShell
                 default:
                     return 72;
             }
         }
     }
 
     @WrapForJNI(stubName = "GetHandlersForMimeTypeWrapper")
     static String[] getHandlersForMimeType(String aMimeType, String aAction) {
-        Intent intent = IntentHelper.getIntentForActionString(aAction);
-        if (aMimeType != null && aMimeType.length() > 0)
-            intent.setType(aMimeType);
-        return IntentHelper.getHandlersForIntent(intent);
+        final GeckoInterface geckoInterface = getGeckoInterface();
+        if (geckoInterface == null) {
+            return new String[] {};
+        }
+        return geckoInterface.getHandlersForMimeType(aMimeType, aAction);
     }
 
     @WrapForJNI(stubName = "GetHandlersForURLWrapper")
     static String[] getHandlersForURL(String aURL, String aAction) {
-        // aURL may contain the whole URL or just the protocol
-        Uri uri = aURL.indexOf(':') >= 0 ? Uri.parse(aURL) : new Uri.Builder().scheme(aURL).build();
-
-        Intent intent = IntentHelper.getOpenURIIntent(getApplicationContext(), uri.toString(), "",
-            TextUtils.isEmpty(aAction) ? Intent.ACTION_VIEW : aAction, "");
-
-        return IntentHelper.getHandlersForIntent(intent);
+        final GeckoInterface geckoInterface = getGeckoInterface();
+        if (geckoInterface == null) {
+            return new String[] {};
+        }
+        return geckoInterface.getHandlersForURL(aURL, aAction);
     }
 
     @WrapForJNI(stubName = "GetHWEncoderCapability")
     static boolean getHWEncoderCapability() {
       return HardwareCodecCapabilityUtils.getHWEncoderCapability();
     }
 
     @WrapForJNI(stubName = "GetHWDecoderCapability")
@@ -923,19 +921,21 @@ public class GeckoAppShell
 
     @WrapForJNI
     public static boolean openUriExternal(String targetURI,
                                           String mimeType,
                                           String packageName,
                                           String className,
                                           String action,
                                           String title) {
-
-        // Default to showing prompt in private browsing to be safe.
-        return IntentHelper.openUriExternal(targetURI, mimeType, packageName, className, action, title, true);
+        final GeckoInterface geckoInterface = getGeckoInterface();
+        if (geckoInterface == null) {
+            return false;
+        }
+        return geckoInterface.openUriExternal(targetURI, mimeType, packageName, className, action, title);
     }
 
     /**
      * Only called from GeckoApp.
      */
     public static void setNotificationClient(NotificationClient client) {
         if (notificationClient == null) {
             notificationClient = client;
@@ -1810,16 +1810,21 @@ public class GeckoAppShell
          * This method is always invoked on the Gecko thread.
          *
          * @param uri given.
          * @param title to associate with the given URI.
          */
         public void setUriTitle(final String uri, final String title);
 
         public void setAccessibilityEnabled(boolean enabled);
+
+        public boolean openUriExternal(String targetURI, String mimeType, String packageName, String className, String action, String title);
+
+        public String[] getHandlersForMimeType(String mimeType, String action);
+        public String[] getHandlersForURL(String url, String action);
     };
 
     private static GeckoInterface sGeckoInterface;
 
     public static GeckoInterface getGeckoInterface() {
         return sGeckoInterface;
     }