Skip to content

Commit

Permalink
Ensure that vrPrefsWorkAround method is called before creating the Ge…
Browse files Browse the repository at this point in the history
…cko Runtime (#3654)
  • Loading branch information
MortimerGoro authored and bluemarvin committed Jul 8, 2020
1 parent 4ca1220 commit e9c03ea
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ protected void attachBaseContext(Context base) {

@Override
protected void onCreate(Bundle savedInstanceState) {
Bundle extras = getIntent() != null ? getIntent().getExtras() : null;
SessionStore.prefOverrides(this, extras);
((VRBrowserApplication)getApplication()).onActivityCreate(this);
SettingsStore.getInstance(getBaseContext()).setPid(Process.myPid());
// Fix for infinite restart on startup crashes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.mozilla.vrbrowser.browser.Places;
import org.mozilla.vrbrowser.browser.Services;
import org.mozilla.vrbrowser.browser.engine.EngineProvider;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.db.AppDatabase;
import org.mozilla.vrbrowser.db.DataRepository;
import org.mozilla.vrbrowser.downloads.DownloadsManager;
Expand Down Expand Up @@ -52,6 +53,7 @@ public void onCreate() {
return;
}

SessionStore.prefOverrides(this);
TelemetryWrapper.init(this, EngineProvider.INSTANCE.getDefaultClient(this));
GleanMetricsService.init(this, EngineProvider.INSTANCE.getDefaultClient(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ object EngineProvider {
return runtime!!
}

@Synchronized
fun isRuntimeCreated(): Boolean {
return runtime != null
}

fun createGeckoWebExecutor(context: Context): GeckoWebExecutor {
return GeckoWebExecutor(getOrCreateRuntime(context))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ private SessionStore() {
mSessions = new ArrayList<>();
}

public static void prefOverrides(Context context, Bundle aExtras) {
public static void prefOverrides(Context context) {
// FIXME: Once GeckoView has a prefs API
SessionUtils.vrPrefsWorkAround(context, aExtras);
SessionUtils.vrPrefsWorkAround(context);
}

public void initialize(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public static boolean isLocalizedContent(@Nullable String url) {
return url != null && (url.startsWith("about:") || url.startsWith("data:"));
}

public static void vrPrefsWorkAround(Context aContext, Bundle aExtras) {
public static void vrPrefsWorkAround(Context aContext) {
if (EngineProvider.INSTANCE.isRuntimeCreated()) {
throw new IllegalStateException("vrPrefsWorkAround must be called before creating the runtime");
}

File path = GeckoProfile.initFromArgs(aContext, null).getDir();
String prefFileName = path.getAbsolutePath() + File.separator + "user.js";
Log.i(LOGTAG, "Creating file: " + prefFileName);
Expand All @@ -52,18 +56,6 @@ public static void vrPrefsWorkAround(Context aContext, Bundle aExtras) {
} else {
out.write("user_pref(\"webgl.msaa-force\", false);\n".getBytes());
}
if (BuildConfig.DEBUG) {
int processCount = SettingsStore.getInstance(aContext).isMultiE10s() ? 3 : 1;
out.write(("user_pref(\"dom.ipc.processCount\", " + processCount + ");\n").getBytes());
addOptionalPref(out, "dom.vr.require-gesture", aExtras);
addOptionalPref(out, "privacy.reduceTimerPrecision", aExtras);
if (aExtras != null && aExtras.getBoolean("media.autoplay.enabled", false)) {
// Enable playing audios without gesture (used for gfx automated testing)
out.write("user_pref(\"media.autoplay.enabled.user-gestures-needed\", false);\n".getBytes());
out.write("user_pref(\"media.autoplay.enabled.ask-permission\", false);\n".getBytes());
out.write("user_pref(\"media.autoplay.default\", 0);\n".getBytes());
}
}
} catch (FileNotFoundException e) {
Log.e(LOGTAG, "Unable to create file: '" + prefFileName + "' got exception: " + e.toString());
} catch (IOException e) {
Expand Down

0 comments on commit e9c03ea

Please sign in to comment.