Bug 1440708 - [1.0] Add GeckoRuntime JavaScript control setting. r=droeh,snorp
authorEugen Sawin <esawin@mozilla.com>
Tue, 10 Apr 2018 23:15:48 +0200
changeset 466849 c84e830f2c9f426b7a3a5bfc44045c86cee58915
parent 466848 88aab44edada90cbf1d4a353a3e74d5ec3a9b6ab
child 466850 475889d2f86964df75fe76e16e9caa8e18e723f8
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdroeh, snorp
bugs1440708
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1440708 - [1.0] Add GeckoRuntime JavaScript control setting. r=droeh,snorp
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoRuntimeSettings.java
@@ -60,16 +60,26 @@ public final class GeckoRuntimeSettings 
          * Set the custom Gecko intent extras.
          *
          * @param extras The Gecko intent extras.
          */
         public @NonNull Builder extras(final @NonNull Bundle extras) {
             mSettings.mExtras = extras;
             return this;
         }
+
+        /**
+         * Set whether JavaScript support should be enabled.
+         *
+         * @param flag A flag determining whether JavaScript should be enabled.
+         */
+        public @NonNull Builder javaScriptEnabled(final boolean flag) {
+            mSettings.mJavaScript.set(flag);
+            return this;
+        }
     }
 
     /* package */ GeckoRuntime runtime;
     /* package */ boolean mUseContentProcess;
     /* package */ String[] mArgs;
     /* package */ Bundle mExtras;
     /* package */ int prefCount;
 
@@ -97,17 +107,22 @@ public final class GeckoRuntimeSettings 
 
         public void flush() {
             if (GeckoRuntimeSettings.this.runtime != null) {
                 GeckoRuntimeSettings.this.runtime.setPref(name, value);
             }
         }
     }
 
-    private final Pref<?>[] mPrefs = new Pref<?>[] {};
+    /* package */ Pref<Boolean> mJavaScript = new Pref<Boolean>(
+        "javascript.enabled", true);
+
+    private final Pref<?>[] mPrefs = new Pref<?>[] {
+        mJavaScript
+    };
 
     /* package */ GeckoRuntimeSettings() {
         this(null);
     }
 
     /* package */ GeckoRuntimeSettings(final @Nullable GeckoRuntimeSettings settings) {
         if (BuildConfig.DEBUG && prefCount != mPrefs.length) {
             throw new AssertionError("Add new pref to prefs list");
@@ -115,16 +130,17 @@ public final class GeckoRuntimeSettings 
 
         if (settings == null) {
             mArgs = new String[0];
             mExtras = new Bundle();
         } else {
             mUseContentProcess = settings.getUseContentProcessHint();
             mArgs = settings.getArguments().clone();
             mExtras = new Bundle(settings.getExtras());
+            mJavaScript.set(settings.mJavaScript.get());
         }
     }
 
     /* package */ void flush() {
         for (final Pref<?> pref: mPrefs) {
             pref.flush();
         }
     }
@@ -151,33 +167,54 @@ public final class GeckoRuntimeSettings 
      * Get the custom Gecko intent extras.
      *
      * @return The Gecko intent extras.
      */
     public Bundle getExtras() {
         return mExtras;
     }
 
+    /**
+     * Get whether JavaScript support is enabled.
+     *
+     * @return Whether JavaScript support is enabled.
+     */
+    public boolean getJavaScriptEnabled() {
+        return mJavaScript.get();
+    }
+
+    /**
+     * Set whether JavaScript support should be enabled.
+     *
+     * @param flag A flag determining whether JavaScript should be enabled.
+     */
+    public @NonNull GeckoRuntimeSettings setJavaScriptEnabled(final boolean flag) {
+        mJavaScript.set(flag);
+        return this;
+    }
+
     @Override // Parcelable
     public int describeContents() {
         return 0;
     }
 
     @Override // Parcelable
     public void writeToParcel(Parcel out, int flags) {
         out.writeByte((byte) (mUseContentProcess ? 1 : 0));
         out.writeStringArray(mArgs);
         mExtras.writeToParcel(out, flags);
+        out.writeByte((byte) (mJavaScript.get() ? 1 : 0));
     }
 
     // AIDL code may call readFromParcel even though it's not part of Parcelable.
     public void readFromParcel(final Parcel source) {
         mUseContentProcess = source.readByte() == 1;
         mArgs = source.createStringArray();
         mExtras.readFromParcel(source);
+        mJavaScript.set(source.readByte() == 1);
     }
 
     public static final Parcelable.Creator<GeckoRuntimeSettings> CREATOR
         = new Parcelable.Creator<GeckoRuntimeSettings>() {
         @Override
         public GeckoRuntimeSettings createFromParcel(final Parcel in) {
             final GeckoRuntimeSettings settings = new GeckoRuntimeSettings();
             settings.readFromParcel(in);