Bug 1485718 - Enable setting of javascript on GeckoView sessions through `GeckoSessionSettings.` r=jchen
authorEmily Toop <etoop@mozilla.com>
Thu, 01 Nov 2018 12:45:37 +0000
changeset 500350 9cfb0bf7cb66ab1b53492550d88832821b74be54
parent 500349 622c92e6c4ba0fe272b638279212263d7e35111e
child 500351 6ae3b85ff64cf43fea831634f36677592ba1453c
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1485718
milestone65.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 1485718 - Enable setting of javascript on GeckoView sessions through `GeckoSessionSettings.` r=jchen This is a resubmission due to issues landing old one. Not sure if this needs a re-review? Old review: https://phabricator.services.mozilla.com/D8093. This has now been closed so I cannot update it. Differential Revision: https://phabricator.services.mozilla.com/D10199
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
@@ -24,16 +24,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;
@@ -59,12 +60,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.ALLOW_JAVASCRIPT, 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("ALLOW_JAVASCRIPT should be set",
+                sessionRule.session.settings.getBoolean(
+                        GeckoSessionSettings.ALLOW_JAVASCRIPT),
+                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> ALLOW_JAVASCRIPT =
+            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(ALLOW_JAVASCRIPT.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);