Bug 1369107 - 4. Remove GeckoAppShell.ContextGetter; r=snorp
authorJim Chen <nchen@mozilla.com>
Fri, 02 Jun 2017 16:13:42 -0400
changeset 410278 49051e18e2760f6a34658b178f52f63fb0e8396e
parent 410277 5c6b25ec2b198c6f8b75ca9c930dfc75a5286529
child 410279 6065144fe5b32eab26374fd7ad67930d0c6d9403
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1369107
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 1369107 - 4. Remove GeckoAppShell.ContextGetter; r=snorp Remove ContextGetter and all implementations now that it's no longer being used. MozReview-Commit-ID: G5jWFsQPfWw
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/ContextGetter.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -123,17 +123,16 @@ import static org.mozilla.gecko.Tabs.INT
 import static org.mozilla.gecko.Tabs.INTENT_EXTRA_TAB_ID;
 import static org.mozilla.gecko.Tabs.INVALID_TAB_ID;
 import static org.mozilla.gecko.mma.MmaDelegate.DOWNLOAD_VIDEOS_OR_ANY_OTHER_MEDIA;
 import static org.mozilla.gecko.mma.MmaDelegate.LOADS_ARTICLES;
 
 public abstract class GeckoApp extends GeckoActivity
                                implements AnchoredPopup.OnVisibilityChangeListener,
                                           BundleEventListener,
-                                          ContextGetter,
                                           GeckoMenu.Callback,
                                           GeckoMenu.MenuPresenter,
                                           GeckoView.ContentListener,
                                           ScreenOrientationDelegate,
                                           Tabs.OnTabsChangedListener,
                                           ViewTreeObserver.OnGlobalLayoutListener {
 
     private static final String LOGTAG = "GeckoApp";
@@ -388,22 +387,16 @@ public abstract class GeckoApp extends G
             super(message);
         }
     }
 
     void toggleChrome(final boolean aShow) { }
 
     void focusChrome() { }
 
-    @Override
-    public Context getContext() {
-        return this;
-    }
-
-    @Override
     public SharedPreferences getSharedPreferences() {
         return GeckoSharedPrefs.forApp(this);
     }
 
     public SharedPreferences getSharedPreferencesForProfile() {
         return GeckoSharedPrefs.forProfile(this);
     }
 
@@ -1279,23 +1272,16 @@ public abstract class GeckoApp extends G
         // business later and dispose of the reference.
         GeckoLoader.setLastIntent(intent);
 
         // Workaround for <http://code.google.com/p/android/issues/detail?id=20915>.
         try {
             Class.forName("android.os.AsyncTask");
         } catch (ClassNotFoundException e) { }
 
-        // 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.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)
         );
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApplication.java
@@ -3,17 +3,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import android.app.Application;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
-import android.content.SharedPreferences;
 import android.content.res.Configuration;
 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;
@@ -51,18 +50,17 @@ import org.mozilla.gecko.util.HardwareUt
 import org.mozilla.gecko.util.PRNGFixes;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.UUIDUtil;
 
 import java.io.File;
 import java.lang.reflect.Method;
 import java.util.UUID;
 
-public class GeckoApplication extends Application
-    implements ContextGetter {
+public class GeckoApplication extends Application {
     private static final String LOG_TAG = "GeckoApplication";
     private static final String MEDIA_DECODING_PROCESS_CRASH = "MEDIA_DECODING_PROCESS_CRASH";
 
     private boolean mInBackground;
     private boolean mPausedGecko;
     private boolean mIsInitialResume;
 
     private LightweightTheme mLightweightTheme;
@@ -131,26 +129,16 @@ public class GeckoApplication extends Ap
         final Context context = GeckoAppShell.getApplicationContext();
         final Intent intent = new Intent();
         intent.setClass(context, Restarter.class)
               .putExtra("pid", Process.myPid())
               .putExtra(Intent.EXTRA_INTENT, restartIntent);
         context.startService(intent);
     }
 
-    @Override
-    public Context getContext() {
-        return this;
-    }
-
-    @Override
-    public SharedPreferences getSharedPreferences() {
-        return GeckoSharedPrefs.forApp(this);
-    }
-
     /**
      * We need to do locale work here, because we need to intercept
      * each hit to onConfigurationChanged.
      */
     @Override
     public void onConfigurationChanged(Configuration config) {
         Log.d(LOG_TAG, "onConfigurationChanged: " + config.locale +
                        ", background: " + mInBackground);
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -363,17 +363,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',
     'Clipboard.java',
-    'ContextGetter.java',
     'CrashHandler.java',
     'EventDispatcher.java',
     'GeckoAccessibility.java',
     'GeckoAppShell.java',
     'GeckoBatteryManager.java',
     'GeckoEditable.java',
     'GeckoEditableChild.java',
     'GeckoEditableClient.java',
deleted file mode 100644
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/ContextGetter.java
+++ /dev/null
@@ -1,15 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; 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 android.content.Context;
-import android.content.SharedPreferences;
-
-public interface ContextGetter {
-    Context getContext();
-    SharedPreferences getSharedPreferences();
-}
-
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -110,17 +110,17 @@ public class GeckoAppShell
     private static final CrashHandler CRASH_HANDLER = new CrashHandler() {
         @Override
         protected String getAppPackageName() {
             return AppConstants.ANDROID_PACKAGE_NAME;
         }
 
         @Override
         protected Context getAppContext() {
-            return sContextGetter != null ? getApplicationContext() : null;
+            return getApplicationContext();
         }
 
         @Override
         protected Bundle getCrashExtras(final Thread thread, final Throwable exc) {
             final Bundle extras = super.getCrashExtras(thread, exc);
 
             extras.putString("ProductName", AppConstants.MOZ_APP_BASENAME);
             extras.putString("ProductID", AppConstants.MOZ_APP_ID);
@@ -142,18 +142,19 @@ public class GeckoAppShell
 
             super.uncaughtException(thread, exc);
         }
 
         @Override
         public boolean reportException(final Thread thread, final Throwable exc) {
             try {
                 if (exc instanceof OutOfMemoryError) {
-                    SharedPreferences prefs = getSharedPreferences();
-                    SharedPreferences.Editor editor = prefs.edit();
+                    final SharedPreferences prefs =
+                            GeckoSharedPrefs.forApp(getApplicationContext());
+                    final SharedPreferences.Editor editor = prefs.edit();
                     editor.putBoolean(PREFS_OOM_EXCEPTION, true);
 
                     // Synchronously write to disk so we know it's done before we
                     // shutdown
                     editor.commit();
                 }
 
                 reportJavaCrash(exc, getExceptionStackTrace(exc));
@@ -1625,44 +1626,26 @@ public class GeckoAppShell
             return null;
         } catch (android.content.pm.PackageManager.NameNotFoundException nnfe) {
             Log.w(LOGTAG, "Couldn't find package.", nnfe);
             return null;
         }
     }
 
     private static Context sApplicationContext;
-    private static ContextGetter sContextGetter;
-
-    @Deprecated
-    @WrapForJNI
-    public static Context getContext() {
-        return sContextGetter.getContext();
-    }
-
-    public static void setContextGetter(ContextGetter cg) {
-        sContextGetter = cg;
-    }
 
     @WrapForJNI
     public static Context getApplicationContext() {
         return sApplicationContext;
     }
 
     public static void setApplicationContext(final Context context) {
         sApplicationContext = context;
     }
 
-    public static SharedPreferences getSharedPreferences() {
-        if (sContextGetter == null) {
-            throw new IllegalStateException("No ContextGetter; cannot fetch prefs.");
-        }
-        return sContextGetter.getSharedPreferences();
-    }
-
     public interface GeckoInterface {
         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;
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoView.java
@@ -38,18 +38,17 @@ import android.os.SystemClock;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.View;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputConnection;
 
-public class GeckoView extends LayerView
-    implements ContextGetter {
+public class GeckoView extends LayerView {
 
     private static final String DEFAULT_SHARED_PREFERENCES_FILE = "GeckoView";
     private static final String LOGTAG = "GeckoView";
 
     private static final boolean DEBUG = false;
 
     /* package */ enum State implements NativeQueue.State {
         @WrapForJNI INITIAL(0),
@@ -313,22 +312,16 @@ public class GeckoView extends LayerView
         if (GeckoThread.initMainProcess(GeckoProfile.get(appContext),
                                         geckoArgs,
                                         /* 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 && GeckoAppShell.getGeckoInterface() == null) {
-            GeckoAppShell.setContextGetter(this);
-        }
-
         preload(context);
 
         // Perform common initialization for Fennec/GeckoView.
         GeckoAppShell.setLayerView(this);
 
         initializeView();
         mListener.registerListeners();
 
@@ -1053,25 +1046,16 @@ public class GeckoView extends LayerView
             }
             default: {
                 callback.sendError("Invalid type");
                 break;
             }
         }
     }
 
-    protected String getSharedPreferencesFile() {
-        return DEFAULT_SHARED_PREFERENCES_FILE;
-    }
-
-    @Override
-    public SharedPreferences getSharedPreferences() {
-        return getContext().getSharedPreferences(getSharedPreferencesFile(), 0);
-    }
-
     public EventDispatcher getEventDispatcher() {
         return mEventDispatcher;
     }
 
     public interface ProgressListener {
         static final int STATE_IS_BROKEN = 1;
         static final int STATE_IS_SECURE = 2;
         static final int STATE_IS_INSECURE = 4;
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -236,24 +236,16 @@ auto GeckoAppShell::GetApplicationContex
 constexpr char GeckoAppShell::GetConnection_t::name[];
 constexpr char GeckoAppShell::GetConnection_t::signature[];
 
 auto GeckoAppShell::GetConnection(mozilla::jni::String::Param a0) -> mozilla::jni::Object::LocalRef
 {
     return mozilla::jni::Method<GetConnection_t>::Call(GeckoAppShell::Context(), nullptr, a0);
 }
 
-constexpr char GeckoAppShell::GetContext_t::name[];
-constexpr char GeckoAppShell::GetContext_t::signature[];
-
-auto GeckoAppShell::GetContext() -> mozilla::jni::Object::LocalRef
-{
-    return mozilla::jni::Method<GetContext_t>::Call(GeckoAppShell::Context(), nullptr);
-}
-
 constexpr char GeckoAppShell::GetCurrentBatteryInformation_t::name[];
 constexpr char GeckoAppShell::GetCurrentBatteryInformation_t::signature[];
 
 auto GeckoAppShell::GetCurrentBatteryInformation() -> mozilla::jni::DoubleArray::LocalRef
 {
     return mozilla::jni::Method<GetCurrentBatteryInformation_t>::Call(GeckoAppShell::Context(), nullptr);
 }
 
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -701,35 +701,16 @@ public:
         static const mozilla::jni::CallingThread callingThread =
                 mozilla::jni::CallingThread::ANY;
         static const mozilla::jni::DispatchTarget dispatchTarget =
                 mozilla::jni::DispatchTarget::CURRENT;
     };
 
     static auto GetConnection(mozilla::jni::String::Param) -> mozilla::jni::Object::LocalRef;
 
-    struct GetContext_t {
-        typedef GeckoAppShell Owner;
-        typedef mozilla::jni::Object::LocalRef ReturnType;
-        typedef mozilla::jni::Object::Param SetterType;
-        typedef mozilla::jni::Args<> Args;
-        static constexpr char name[] = "getContext";
-        static constexpr char signature[] =
-                "()Landroid/content/Context;";
-        static const bool isStatic = true;
-        static const mozilla::jni::ExceptionMode exceptionMode =
-                mozilla::jni::ExceptionMode::ABORT;
-        static const mozilla::jni::CallingThread callingThread =
-                mozilla::jni::CallingThread::ANY;
-        static const mozilla::jni::DispatchTarget dispatchTarget =
-                mozilla::jni::DispatchTarget::CURRENT;
-    };
-
-    static auto GetContext() -> mozilla::jni::Object::LocalRef;
-
     struct GetCurrentBatteryInformation_t {
         typedef GeckoAppShell Owner;
         typedef mozilla::jni::DoubleArray::LocalRef ReturnType;
         typedef mozilla::jni::DoubleArray::Param SetterType;
         typedef mozilla::jni::Args<> Args;
         static constexpr char name[] = "getCurrentBatteryInformation";
         static constexpr char signature[] =
                 "()[D";