Bug 1365711 - Set GeckoInterface from GeckoApplication; r=snorp
authorJim Chen <nchen@mozilla.com>
Thu, 25 May 2017 18:33:30 -0400
changeset 360704 35d857a41a7b6f269b6b2fa0c64e6f28168110e1
parent 360703 6b91b33444eb0b779bc18da64bb1abc17b5314a6
child 360705 60e0d98a2ae6c03a2f6708deecc1089fe026971f
push id90718
push usernchen@mozilla.com
push dateThu, 25 May 2017 22:34:28 +0000
treeherdermozilla-inbound@35d857a41a7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1365711
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1365711 - Set GeckoInterface from GeckoApplication; r=snorp Now that GeckoInterface only contains openUriExternal and getHandlersFor* methods, we can set GeckoInterface from GeckoApplication only, and not GeckoApp or GeckoView. This also lets us get rid of BaseGeckoInterface. MozReview-Commit-ID: KQloIO6ITlK
mobile/android/base/geckoview.ddf
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
mobile/android/base/moz.build
mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
--- a/mobile/android/base/geckoview.ddf
+++ b/mobile/android/base/geckoview.ddf
@@ -8,17 +8,16 @@ show allResults
 
 [lib] = \
   org.mozilla.gecko.gfx.* \
   org.mozilla.gecko.mozglue.* \
   org.mozilla.gecko.sqlite.* \
   org.mozilla.gecko.util.* \
   org.mozilla.gecko.AndroidGamepadManager \
   org.mozilla.gecko.AppConstants \
-  org.mozilla.gecko.BaseGeckoInterface \
   org.mozilla.gecko.ContextGetter \
   org.mozilla.gecko.CrashHandler \
   org.mozilla.gecko.EventDispatcher \
   org.mozilla.gecko.GeckoAccessibility \
   org.mozilla.gecko.GeckoAppShell \
   org.mozilla.gecko.GeckoBatteryManager \
   org.mozilla.gecko.GeckoEditable \
   org.mozilla.gecko.GeckoEditableClient \
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -121,17 +121,16 @@ import java.util.concurrent.TimeUnit;
 import static org.mozilla.gecko.Tabs.INTENT_EXTRA_SESSION_UUID;
 import static org.mozilla.gecko.Tabs.INTENT_EXTRA_TAB_ID;
 import static org.mozilla.gecko.Tabs.INVALID_TAB_ID;
 
 public abstract class GeckoApp extends GeckoActivity
                                implements AnchoredPopup.OnVisibilityChangeListener,
                                           BundleEventListener,
                                           ContextGetter,
-                                          GeckoAppShell.GeckoInterface,
                                           GeckoMenu.Callback,
                                           GeckoMenu.MenuPresenter,
                                           GeckoView.ContentListener,
                                           ScreenOrientationDelegate,
                                           Tabs.OnTabsChangedListener,
                                           ViewTreeObserver.OnGlobalLayoutListener {
 
     private static final String LOGTAG = "GeckoApp";
@@ -1273,17 +1272,16 @@ public abstract class GeckoApp extends G
 
         // GeckoAppShell is tightly coupled to us, rather than
         // the app context, because various parts of Fennec (e.g.,
         // GeckoScreenOrientation) use GAS to access the Activity in
         // the guise of fetching a Context.
         // When that's fixed, `this` can change to
         // `(GeckoApplication) getApplication()` here.
         GeckoAppShell.setContextGetter(this);
-        GeckoAppShell.setGeckoInterface(this);
         GeckoAppShell.setScreenOrientationDelegate(this);
 
         // Tell Stumbler to register a local broadcast listener to listen for preference intents.
         // We do this via intents since we can't easily access Stumbler directly,
         // as it might be compiled outside of Fennec.
         getApplicationContext().sendBroadcast(
                 new Intent(INTENT_REGISTER_STUMBLER_LISTENER)
         );
@@ -2241,17 +2239,16 @@ public abstract class GeckoApp extends G
         EventDispatcher.getInstance().registerUiThreadListener(this, "Snackbar:Show");
 
         if (mIsAbortingAppLaunch) {
             return;
         }
 
         foregrounded = true;
 
-        GeckoAppShell.setGeckoInterface(this);
         GeckoAppShell.setScreenOrientationDelegate(this);
 
         // If mIgnoreLastSelectedTab is set, we're either the first activity to run, so our startup
         // code will (have) handle(d) tab selection, or else we've received a new intent and want to
         // open and select a new tab as well.
         if (!mIgnoreLastSelectedTab) {
             Tab selectedTab = Tabs.getInstance().getSelectedTab();
 
@@ -2714,22 +2711,16 @@ public abstract class GeckoApp extends G
     public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
         Permissions.onRequestPermissionsResult(this, permissions, grantResults);
     }
 
     private void geckoConnected() {
         mLayerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
     }
 
-    @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);
         }
 
@@ -2926,35 +2917,16 @@ public abstract class GeckoApp extends G
                                                   final SessionInformation previousSession) {
         // GeckoApp does not need to record any health information - return a stub.
         return new StubbedHealthRecorder();
     }
 
     protected void recordStartupActionTelemetry(final String passedURL, final String action) {
     }
 
-    @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);
-    }
-
     public GeckoView getGeckoView() {
         return mLayerView;
     }
 
     @Override
     public boolean setRequestedOrientationForCurrentActivity(int requestedActivityInfoOrientation) {
         // We want to support the Screen Orientation API, and it always makes sense to lock the
         // orientation of a browser Activity, so we support locking.
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -14,16 +14,17 @@ import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
 import android.graphics.Rect;
 import android.graphics.RectF;
 import android.net.Uri;
 import android.os.Process;
 import android.os.SystemClock;
+import android.text.TextUtils;
 import android.util.Log;
 
 import com.squareup.leakcanary.LeakCanary;
 import com.squareup.leakcanary.RefWatcher;
 
 import org.mozilla.gecko.annotation.WrapForJNI;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserDB;
@@ -232,16 +233,48 @@ public class GeckoApplication extends Ap
         mRefWatcher = LeakCanary.install(this);
 
         sSessionUUID = UUID.randomUUID().toString();
 
         GeckoActivityMonitor.getInstance().initialize(this);
 
         final Context context = getApplicationContext();
         GeckoAppShell.setApplicationContext(context);
+        GeckoAppShell.setGeckoInterface(new GeckoAppShell.GeckoInterface() {
+            @Override
+            public boolean openUriExternal(final String targetURI, final String mimeType,
+                                           final String packageName, final String className,
+                                           final String action, final String title) {
+                // Default to showing prompt in private browsing to be safe.
+                return IntentHelper.openUriExternal(targetURI, mimeType, packageName,
+                                                    className, action, title, true);
+            }
+
+            @Override
+            public String[] getHandlersForMimeType(final String mimeType,
+                                                   final String action) {
+                final Intent intent = IntentHelper.getIntentForActionString(action);
+                if (mimeType != null && mimeType.length() > 0) {
+                    intent.setType(mimeType);
+                }
+                return IntentHelper.getHandlersForIntent(intent);
+            }
+
+            @Override
+            public String[] getHandlersForURL(final String url, final String action) {
+                // May contain the whole URL or just the protocol.
+                final Uri uri = url.indexOf(':') >= 0 ? Uri.parse(url)
+                                                      : new Uri.Builder().scheme(url).build();
+                final Intent intent = IntentHelper.getOpenURIIntent(
+                        getApplicationContext(), uri.toString(), "",
+                        TextUtils.isEmpty(action) ? Intent.ACTION_VIEW : action, "");
+                return IntentHelper.getHandlersForIntent(intent);
+            }
+        });
+
         HardwareUtils.init(context);
         FilePicker.init(context);
         DownloadsIntegration.init();
         HomePanelsManager.getInstance().init(context);
 
         GlobalPageMetadata.getInstance().init();
 
         // We need to set the notification client before launching Gecko, since Gecko could start
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -362,17 +362,16 @@ if CONFIG['MOZ_WEBRTC']:
     ]
     wrjar.javac_flags += ['-Xlint:all,-deprecation,-cast']
 
 gvjar = add_java_jar('gecko-view')
 
 gvjar.sources += [geckoview_source_dir + 'java/org/mozilla/gecko/' + x
                   for x in [
     'AndroidGamepadManager.java',
-    'BaseGeckoInterface.java',
     'Clipboard.java',
     'ContextGetter.java',
     'CrashHandler.java',
     'EventDispatcher.java',
     'GeckoAccessibility.java',
     'GeckoAppShell.java',
     'GeckoBatteryManager.java',
     'GeckoEditable.java',
deleted file mode 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-package org.mozilla.gecko;
-
-import org.mozilla.gecko.util.HardwareUtils;
-import org.mozilla.geckoview.BuildConfig;
-
-import android.app.Activity;
-import android.content.Context;
-import android.view.View;
-import android.widget.AbsoluteLayout;
-
-public class BaseGeckoInterface implements GeckoAppShell.GeckoInterface {
-    private final Context mContext;
-
-    public BaseGeckoInterface(Context context) {
-        mContext = context;
-    }
-
-    @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/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -315,18 +315,17 @@ public class GeckoView extends LayerView
                                         /* debugging */ false)) {
             GeckoThread.launch();
         }
     }
 
     private void init(final Context context, final GeckoViewSettings settings) {
         // Set the GeckoInterface if the context is an activity and the
         // GeckoInterface has not already been set
-        if (context instanceof Activity && getGeckoInterface() == null) {
-            setGeckoInterface(new BaseGeckoInterface(context));
+        if (context instanceof Activity && GeckoAppShell.getGeckoInterface() == null) {
             GeckoAppShell.setContextGetter(this);
         }
 
         preload(context);
 
         // Perform common initialization for Fennec/GeckoView.
         GeckoAppShell.setLayerView(this);
 
@@ -1054,24 +1053,16 @@ public class GeckoView extends LayerView
             }
             default: {
                 callback.sendError("Invalid type");
                 break;
             }
         }
     }
 
-    public static void setGeckoInterface(final BaseGeckoInterface geckoInterface) {
-        GeckoAppShell.setGeckoInterface(geckoInterface);
-    }
-
-    public static GeckoAppShell.GeckoInterface getGeckoInterface() {
-        return GeckoAppShell.getGeckoInterface();
-    }
-
     protected String getSharedPreferencesFile() {
         return DEFAULT_SHARED_PREFERENCES_FILE;
     }
 
     @Override
     public SharedPreferences getSharedPreferences() {
         return getContext().getSharedPreferences(getSharedPreferencesFile(), 0);
     }