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.
This commit is contained in:
Jim Chen 2015-11-11 21:28:59 -05:00
parent 9d879a0145
commit 776204544b
3 changed files with 14 additions and 0 deletions

View File

@ -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);

View File

@ -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.");

View File

@ -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) {