Bug 1332331 - [1.1] Add multiprocess GeckoView setting. r=snorp DONTBUILD
authorEugen Sawin <esawin@mozilla.com>
Wed, 19 Apr 2017 22:32:32 +0200
changeset 565460 dce8993067a6b98fb46e7a1077a091ccdf343819
parent 565459 24f6ba02de71fc14e50bc3a27800990f39414529
child 565461 cd5b1f72ee4e81d41429fb32216cc470e7cd6c00
child 565468 70debe6d9f951070571152bf144da9d406ca3058
push id54862
push userdtownsend@mozilla.com
push dateWed, 19 Apr 2017 21:37:55 +0000
reviewerssnorp
bugs1332331
milestone55.0a1
Bug 1332331 - [1.1] Add multiprocess GeckoView setting. r=snorp DONTBUILD
mobile/android/chrome/geckoview/geckoview.xul
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoViewSettings.java
mobile/android/modules/geckoview/GeckoViewSettings.jsm
--- a/mobile/android/chrome/geckoview/geckoview.xul
+++ b/mobile/android/chrome/geckoview/geckoview.xul
@@ -5,12 +5,12 @@
 
 <?xml-stylesheet href="chrome://browser/content/browser.css" type="text/css"?>
 
 <window id="main-window"
         onload="startup();"
         windowtype="navigator:browser"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
-  <browser id="content" type="content" primary="true" src="about:blank" flex="1" remote="true"/>
+  <browser id="content" type="content" primary="true" src="about:blank" flex="1"/>
 
   <script type="application/javascript" src="chrome://geckoview/content/geckoview.js"/>
 </window>
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoViewSettings.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoViewSettings.java
@@ -17,34 +17,48 @@ public final class GeckoViewSettings {
     private static class Key<T> {
         private final String text;
 
         public Key(final String text) {
             this.text = text;
         }
     }
 
+    /*
+     * Key to enabled and disable tracking protection.
+     */
     public static final Key<Boolean> USE_TRACKING_PROTECTION =
         new Key<Boolean>("useTrackingProtection");
+    /*
+     * Key to enabled and disable private mode browsing.
+     */
     public static final Key<Boolean> USE_PRIVATE_MODE =
         new Key<Boolean>("usePrivateMode");
+    /*
+     * Key to enabled and disable multiprocess browsing (e10s).
+     * Note: can only be set during GeckoView initialization, changes during an
+     * active GeckoView session will be ignored.
+     */
+    public static final Key<Boolean> USE_MULTIPROCESS =
+        new Key<Boolean>("useMultiprocess");
 
     private final EventDispatcher mEventDispatcher;
     private final GeckoBundle mBundle;
 
     public GeckoViewSettings() {
         this(null);
     }
 
     /* package */ GeckoViewSettings(EventDispatcher eventDispatcher) {
         mEventDispatcher = eventDispatcher;
         mBundle = new GeckoBundle();
 
         setBoolean(USE_TRACKING_PROTECTION, false);
         setBoolean(USE_PRIVATE_MODE, false);
+        setBoolean(USE_MULTIPROCESS, true);
     }
 
     /* package */ GeckoViewSettings(GeckoViewSettings settings, EventDispatcher eventDispatcher) {
         mBundle = new GeckoBundle(settings.mBundle);
         mEventDispatcher = eventDispatcher;
     }
 
     public void setBoolean(final Key<Boolean> key, boolean value) {
--- a/mobile/android/modules/geckoview/GeckoViewSettings.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewSettings.jsm
@@ -18,20 +18,25 @@ var dump = Cu.import("resource://gre/mod
            .AndroidLog.d.bind(null, "ViewSettings");
 
 function debug(aMsg) {
   // dump(aMsg);
 }
 
 // Handles GeckoView settings including:
 // * tracking protection
+// * multiprocess
 class GeckoViewSettings extends GeckoViewModule {
   init() {
     this._isSafeBrowsingInit = false;
     this._useTrackingProtection = false;
+
+    // We only allow to set this setting during initialization, further updates
+    // will be ignored.
+    this.useMultiprocess = !!this.settings.useMultiprocess;
   }
 
   onSettingsUpdate() {
     debug("onSettingsUpdate: " + JSON.stringify(this.settings));
 
     this.useTrackingProtection = !!this.settings.useTrackingProtection;
   }
 
@@ -47,9 +52,28 @@ class GeckoViewSettings extends GeckoVie
     if (aUse != this._useTrackingProtection) {
       this.messageManager.loadFrameScript('data:,' +
         'docShell.useTrackingProtection = ' + aUse,
         true
       );
       this._useTrackingProtection = aUse;
     }
   }
+
+  get useMultiprocess() {
+    return this.browser.getAttribute("remote") == "true";
+  }
+
+  set useMultiprocess(aUse) {
+    if (aUse == this.useMultiprocess) {
+      return;
+    }
+    let parentNode = this.browser.parentNode;
+    parentNode.removeChild(this.browser);
+
+    if (aUse) {
+      this.browser.setAttribute("remote", "true");
+    } else {
+      this.browser.removeAttribute("remote");
+    }
+    parentNode.appendChild(this.browser);
+  }
 }