Bug 1485718 - Enable setting of javascript on GeckoView sessions through `GeckoSessionSettings.` r=jchen
☠☠ backed out by f5f7adca7a89 ☠ ☠
authorEmily Toop <etoop@mozilla.com>
Tue, 23 Oct 2018 15:40:30 +0000
changeset 490956 307ddcb2187bd1a1f95e537d745c7dfc4de11d24
parent 490955 14b5c82201e5ea74962f98b6accc9d9f686c45fe
child 490957 f5f7adca7a89585b6bf4b0a481724bd9aa9b87a7
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjchen
bugs1485718
milestone65.0a1
Bug 1485718 - Enable setting of javascript on GeckoView sessions through `GeckoSessionSettings.` r=jchen Differential Revision: https://phabricator.services.mozilla.com/D8093
mobile/android/chrome/geckoview/GeckoViewContentSettings.js
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
--- a/mobile/android/chrome/geckoview/GeckoViewContentSettings.js
+++ b/mobile/android/chrome/geckoview/GeckoViewContentSettings.js
@@ -23,16 +23,17 @@ class GeckoViewContentSettings extends G
   }
 
   onSettingsUpdate() {
     debug `onSettingsUpdate ${this.settings}`;
 
     this.displayMode = this.settings.displayMode;
     this.useTrackingProtection = !!this.settings.useTrackingProtection;
     this.userAgentMode = this.settings.userAgentMode;
+    this.allowJavascript = this.settings.allowJavascript;
   }
 
   get useTrackingProtection() {
     return docShell.useTrackingProtection;
   }
 
   set useTrackingProtection(aUse) {
     docShell.useTrackingProtection = aUse;
@@ -58,12 +59,20 @@ class GeckoViewContentSettings extends G
   }
 
   set displayMode(aMode) {
     const docShell = content && GeckoViewUtils.getRootDocShell(content);
     if (docShell) {
       docShell.displayMode = aMode;
     }
   }
+
+  get allowJavascript() {
+    return docShell.allowJavascript;
+  }
+
+  set allowJavascript(aAllowJavascript) {
+    docShell.allowJavascript = aAllowJavascript;
+  }
 }
 
 let {debug, warn} = GeckoViewContentSettings.initLogging("GeckoViewSettings");
 let module = GeckoViewContentSettings.create(this);
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
@@ -38,30 +38,35 @@ class GeckoSessionTestRuleTest : BaseSes
     }
 
     @ClosedSessionAtStart
     @Test fun getSession_closedSession() {
         assertThat("Session is closed", sessionRule.session.isOpen, equalTo(false))
     }
 
     @Setting.List(Setting(key = Setting.Key.USE_PRIVATE_MODE, value = "true"),
-                  Setting(key = Setting.Key.DISPLAY_MODE, value = "DISPLAY_MODE_MINIMAL_UI"))
+                  Setting(key = Setting.Key.DISPLAY_MODE, value = "DISPLAY_MODE_MINIMAL_UI"),
+                  Setting(key = Setting.Key.JAVASCRIPT_ALLOWED, value = "false"))
     @Setting(key = Setting.Key.USE_TRACKING_PROTECTION, value = "true")
     @Test fun settingsApplied() {
         assertThat("USE_PRIVATE_MODE should be set",
                    sessionRule.session.settings.getBoolean(
                            GeckoSessionSettings.USE_PRIVATE_MODE),
                    equalTo(true))
         assertThat("DISPLAY_MODE should be set",
                    sessionRule.session.settings.getInt(GeckoSessionSettings.DISPLAY_MODE),
                    equalTo(GeckoSessionSettings.DISPLAY_MODE_MINIMAL_UI))
         assertThat("USE_TRACKING_PROTECTION should be set",
                    sessionRule.session.settings.getBoolean(
                            GeckoSessionSettings.USE_TRACKING_PROTECTION),
                    equalTo(true))
+        assertThat("JAVASCRIPT_ALLOWED should be set",
+                sessionRule.session.settings.getBoolean(
+                        GeckoSessionSettings.JAVASCRIPT_ALLOWED),
+                equalTo(false))
     }
 
     @Test(expected = UiThreadUtils.TimeoutException::class)
     @TimeoutMillis(1000)
     fun noPendingCallbacks() {
         // Make sure we don't have unexpected pending callbacks at the start of a test.
         sessionRule.waitUntilCalled(object : Callbacks.All {})
     }
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
@@ -196,16 +196,17 @@ public class GeckoSessionTestRule implem
      * </pre>
      */
     @Target({ElementType.METHOD, ElementType.TYPE})
     @Retention(RetentionPolicy.RUNTIME)
     public @interface Setting {
         enum Key {
             CHROME_URI,
             DISPLAY_MODE,
+            ALLOW_JAVASCRIPT,
             SCREEN_ID,
             USE_MULTIPROCESS,
             USE_PRIVATE_MODE,
             USE_TRACKING_PROTECTION;
 
             private final GeckoSessionSettings.Key<?> mKey;
             private final Class<?> mType;
 
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSessionSettings.java
@@ -97,16 +97,21 @@ public final class GeckoSessionSettings 
                                        DISPLAY_MODE_STANDALONE, DISPLAY_MODE_FULLSCREEN));
 
     /*
      * Key to specify if media should be suspended when the session is inactive.
      */
     public static final Key<Boolean> SUSPEND_MEDIA_WHEN_INACTIVE =
         new Key<Boolean>("suspendMediaWhenInactive", /* initOnly */ false, /* values */ null);
 
+    /*
+     * Key to specify if JavaScript should be allowed on this session.
+     */
+    public static final Key<Boolean> JAVASCRIPT_ALLOWED =
+            new Key<Boolean>("allowJavascript", /* initOnly */ false, /* values */ null);
 
     private final GeckoSession mSession;
     private final GeckoBundle mBundle;
 
     public GeckoSessionSettings() {
         this(null, null);
     }
 
@@ -125,16 +130,17 @@ public final class GeckoSessionSettings 
 
         mBundle = new GeckoBundle();
         mBundle.putString(CHROME_URI.name, null);
         mBundle.putInt(SCREEN_ID.name, 0);
         mBundle.putBoolean(USE_TRACKING_PROTECTION.name, false);
         mBundle.putBoolean(USE_PRIVATE_MODE.name, false);
         mBundle.putBoolean(USE_MULTIPROCESS.name, true);
         mBundle.putBoolean(SUSPEND_MEDIA_WHEN_INACTIVE.name, false);
+        mBundle.putBoolean(JAVASCRIPT_ALLOWED.name, true);
         mBundle.putInt(USER_AGENT_MODE.name, USER_AGENT_MODE_MOBILE);
         mBundle.putInt(DISPLAY_MODE.name, DISPLAY_MODE_BROWSER);
     }
 
     public void setBoolean(final Key<Boolean> key, final boolean value) {
         synchronized (mBundle) {
             if (valueChangedLocked(key, value)) {
                 mBundle.putBoolean(key.name, value);