From 776204544bddfbce3b6c577fc7a7e771bca328ae Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Wed, 11 Nov 2015 21:28:59 -0500 Subject: [PATCH] Bug 1219016 - Store application context in GeckoAppShell; r=snorp This patch adds separate setter and getter for the application context in GeckoAppShell. The existing getContext method is misused for both application and activity context, so new methods are added to improve consistency. --- mobile/android/base/GeckoApp.java | 1 + mobile/android/base/GeckoAppShell.java | 9 +++++++++ mobile/android/base/GeckoView.java | 4 ++++ 3 files changed, 14 insertions(+) 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) {