-
Notifications
You must be signed in to change notification settings - Fork 215
/
SessionUtils.java
80 lines (71 loc) · 4.13 KB
/
SessionUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package org.mozilla.vrbrowser.browser.engine;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.Nullable;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.utils.SystemUtils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
class SessionUtils {
private static final String LOGTAG = SystemUtils.createLogtag(SessionUtils.class);
public static boolean isLocalizedContent(@Nullable String url) {
return url != null && (url.startsWith("about:") || url.startsWith("data:"));
}
public static void vrPrefsWorkAround(Context aContext, Bundle aExtras) {
File path = GeckoProfile.initFromArgs(aContext, null).getDir();
String prefFileName = path.getAbsolutePath() + File.separator + "user.js";
Log.i(LOGTAG, "Creating file: " + prefFileName);
try (FileOutputStream out = new FileOutputStream(prefFileName)) {
out.write("pref(\"dom.vr.enabled\", true);\n".getBytes());
out.write("pref(\"dom.vr.external.enabled\", true);\n".getBytes());
out.write("pref(\"dom.vr.webxr.enabled\", true);\n".getBytes());
out.write("pref(\"webgl.enable-surface-texture\", true);\n".getBytes());
// Enable MultiView draft extension
out.write("pref(\"webgl.enable-draft-extensions\", true);\n".getBytes());
out.write("pref(\"apz.allow_double_tap_zooming\", false);\n".getBytes());
out.write("pref(\"dom.webcomponents.customelements.enabled\", true);\n".getBytes());
out.write("pref(\"javascript.options.ion\", true);\n".getBytes());
out.write("pref(\"media.webspeech.synth.enabled\", false);\n".getBytes());
// Prevent autozoom when giving a form field focus.
out.write("pref(\"formhelper.autozoom\", false);\n".getBytes());
// Disable WebRender until it works with FxR
out.write("pref(\"gfx.webrender.force-disabled\", true);\n".getBytes());
out.write("pref(\"signon.rememberSignons\", false);\n".getBytes());
// Disable web extension process until it is able to restart.
out.write("pref(\"extensions.webextensions.remote\", false);\n".getBytes());
if (BuildConfig.DEBUG) {
int processCount = SettingsStore.getInstance(aContext).isMultiE10s() ? 3 : 1;
out.write(("pref(\"dom.ipc.processCount\", " + processCount + ");\n").getBytes());
}
int msaa = SettingsStore.getInstance(aContext).getMSAALevel();
if (msaa > 0) {
int msaaLevel = msaa == 2 ? 4 : 2;
out.write(("pref(\"gl.msaa-level\"," + msaaLevel + ");\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("pref(\"media.autoplay.enabled.user-gestures-needed\", false);\n".getBytes());
out.write("pref(\"media.autoplay.enabled.ask-permission\", false);\n".getBytes());
out.write("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) {
Log.e(LOGTAG, "Unable to write file: '" + prefFileName + "' got exception: " + e.toString());
}
}
private static void addOptionalPref(FileOutputStream out, String aKey, Bundle aExtras) throws IOException {
if (aExtras != null && aExtras.containsKey(aKey)) {
boolean value = aExtras.getBoolean(aKey);
out.write(String.format("pref(\"%s\", %s);\n", aKey, value ? "true" : "false").getBytes());
}
}
}