diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 0cf90751e9f..0c4579cf9d1 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1280,6 +1280,7 @@ public abstract class GeckoApp // When that's fixed, `this` can change to // `(GeckoApplication) getApplication()` here. GeckoAppShell.setContextGetter(this); + GeckoAppShell.setApplicationContext(getApplicationContext()); GeckoAppShell.setGeckoInterface(this); Tabs.getInstance().attachToContext(this); diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 404b8d4a1dc..1191adfb1c2 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -2045,6 +2045,7 @@ public class GeckoAppShell } } + private static Context sApplicationContext; private static ContextGetter sContextGetter; @WrapForJNI(allowMultithread = true) @@ -2056,6 +2057,14 @@ public class GeckoAppShell sContextGetter = cg; } + 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."); diff --git a/mobile/android/base/GeckoView.java b/mobile/android/base/GeckoView.java index a15db52c820..102d7c74470 100644 --- a/mobile/android/base/GeckoView.java +++ b/mobile/android/base/GeckoView.java @@ -139,6 +139,10 @@ public class GeckoView extends LayerView private void init(Context context, String url, boolean doInit) { + if (GeckoAppShell.getApplicationContext() == null) { + GeckoAppShell.setApplicationContext(context.getApplicationContext()); + } + // Set the GeckoInterface if the context is an activity and the GeckoInterface // has not already been set if (context instanceof Activity && getGeckoInterface() == null) {