Bug 1437869 - [1.0] Pass and handle session settings in the content process. r=jchen
authorEugen Sawin <esawin@mozilla.com>
Wed, 07 Mar 2018 22:41:22 +0100
changeset 462421 c59f42a79b5a3c74d7d5d2279b5dc52ba3564034
parent 462420 525be9fb39bd676e406a89116eb55d8638a7b39d
child 462422 a2a51018aa5f04013f6772306d8154389082c0ff
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1437869
milestone60.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 1437869 - [1.0] Pass and handle session settings in the content process. r=jchen
mobile/android/chrome/geckoview/GeckoViewContentSettings.js
mobile/android/chrome/geckoview/jar.mn
mobile/android/modules/geckoview/GeckoViewContentModule.jsm
mobile/android/modules/geckoview/GeckoViewModule.jsm
mobile/android/modules/geckoview/GeckoViewSettings.jsm
new file mode 100644
--- /dev/null
+++ b/mobile/android/chrome/geckoview/GeckoViewContentSettings.js
@@ -0,0 +1,43 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+ChromeUtils.import("resource://gre/modules/GeckoViewContentModule.jsm");
+ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyGetter(this, "dump", () =>
+    ChromeUtils.import("resource://gre/modules/AndroidLog.jsm",
+                       {}).AndroidLog.d.bind(null, "ViewSettings[C]"));
+
+function debug(aMsg) {
+  // dump(aMsg);
+}
+
+// Handles GeckoView content settings including:
+// * tracking protection
+// * desktop mode
+class GeckoViewContentSettings extends GeckoViewContentModule {
+  init() {
+    debug("init");
+    this._useTrackingProtection = false;
+  }
+
+  onSettingsUpdate() {
+    debug("onSettingsUpdate");
+    this.useTrackingProtection = !!this.settings.useTrackingProtection;
+  }
+
+  get useTrackingProtection() {
+    return this._useTrackingProtection;
+  }
+
+  set useTrackingProtection(aUse) {
+    if (aUse != this._useTrackingProtection) {
+      docShell.useTrackingProtection = aUse;
+      this._useTrackingProtection = aUse;
+    }
+  }
+}
+
+var settings = new GeckoViewContentSettings("GeckoViewSettings", this);
--- a/mobile/android/chrome/geckoview/jar.mn
+++ b/mobile/android/chrome/geckoview/jar.mn
@@ -4,10 +4,11 @@
 
 geckoview.jar:
 % content geckoview %content/
 
   content/ErrorPageEventHandler.js
   content/geckoview.xul
   content/geckoview.js
   content/GeckoViewContent.js
+  content/GeckoViewContentSettings.js
   content/GeckoViewNavigationContent.js
   content/GeckoViewScrollContent.js
--- a/mobile/android/modules/geckoview/GeckoViewContentModule.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewContentModule.jsm
@@ -21,19 +21,27 @@ XPCOMUtils.defineLazyGetter(this, "dump"
 
 class GeckoViewContentModule {
   constructor(aModuleName, aMessageManager) {
     this.moduleName = aModuleName;
     this.messageManager = aMessageManager;
     this.eventDispatcher = EventDispatcher.forMessageManager(aMessageManager);
 
     this.messageManager.addMessageListener(
+      "GeckoView:UpdateSettings",
+      aMsg => {
+        this.settings = aMsg.data;
+        this.onSettingsUpdate();
+      }
+    );
+    this.messageManager.addMessageListener(
       "GeckoView:Register",
       aMsg => {
         if (aMsg.data.module == this.moduleName) {
+          this.settings = aMsg.data.settings;
           this.register();
         }
       }
     );
     this.messageManager.addMessageListener(
       "GeckoView:Unregister",
       aMsg => {
         if (aMsg.data.module == this.moduleName) {
@@ -43,9 +51,10 @@ class GeckoViewContentModule {
     );
 
     this.init();
   }
 
   init() {}
   register() {}
   unregister() {}
+  onSettingsUpdate() {}
 }
--- a/mobile/android/modules/geckoview/GeckoViewModule.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewModule.jsm
@@ -20,23 +20,28 @@ class GeckoViewModule {
   constructor(aModuleName, aWindow, aBrowser, aEventDispatcher) {
     this.isRegistered = false;
     this.window = aWindow;
     this.browser = aBrowser;
     this.eventDispatcher = aEventDispatcher;
     this.moduleName = aModuleName;
 
     this.eventDispatcher.registerListener(
-      () => this.onSettingsUpdate(), "GeckoView:UpdateSettings"
+      (aEvent, aData, aCallback) => {
+        this.messageManager.sendAsyncMessage("GeckoView:UpdateSettings",
+                                             this.settings);
+        this.onSettingsUpdate();
+      }, "GeckoView:UpdateSettings"
     );
 
     this.eventDispatcher.registerListener(
       (aEvent, aData, aCallback) => {
         if (aData.module == this.moduleName) {
           this._register();
+          aData.settings = this.settings;
           this.messageManager.sendAsyncMessage("GeckoView:Register", aData);
         }
       }, "GeckoView:Register"
     );
 
     this.eventDispatcher.registerListener(
       (aEvent, aData, aCallback) => {
         if (aData.module == this.moduleName) {
--- a/mobile/android/modules/geckoview/GeckoViewSettings.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewSettings.jsm
@@ -4,64 +4,50 @@
 
 "use strict";
 
 var EXPORTED_SYMBOLS = ["GeckoViewSettings"];
 
 ChromeUtils.import("resource://gre/modules/GeckoViewModule.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
-ChromeUtils.defineModuleGetter(this, "SafeBrowsing",
-  "resource://gre/modules/SafeBrowsing.jsm");
+XPCOMUtils.defineLazyModuleGetters(this, {
+  SafeBrowsing: "resource://gre/modules/SafeBrowsing.jsm",
+  UserAgentOverrides: "resource://gre/modules/UserAgentOverrides.jsm",
+});
 
 XPCOMUtils.defineLazyGetter(this, "dump", () =>
     ChromeUtils.import("resource://gre/modules/AndroidLog.jsm",
                        {}).AndroidLog.d.bind(null, "ViewSettings"));
 
 function debug(aMsg) {
   // dump(aMsg);
 }
 
 // Handles GeckoView settings including:
-// * tracking protection
 // * multiprocess
+// * user agent override
 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;
     this._displayMode = Ci.nsIDocShell.DISPLAY_MODE_BROWSER;
+
+    this.messageManager.loadFrameScript(
+      "chrome://geckoview/content/GeckoViewContentSettings.js", true);
   }
 
   onSettingsUpdate() {
     debug("onSettingsUpdate: " + JSON.stringify(this.settings));
 
+    this.displayMode = this.settings.displayMode;
     this.useTrackingProtection = !!this.settings.useTrackingProtection;
-    this.displayMode = this.settings.displayMode;
-  }
-
-  get useTrackingProtection() {
-    return this._useTrackingProtection;
-  }
-
-  set useTrackingProtection(aUse) {
-    if (aUse && !this._isSafeBrowsingInit) {
-      SafeBrowsing.init();
-      this._isSafeBrowsingInit = true;
-    }
-    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) {
@@ -73,16 +59,23 @@ class GeckoViewSettings extends GeckoVie
     if (aUse) {
       this.browser.setAttribute("remote", "true");
     } else {
       this.browser.removeAttribute("remote");
     }
     parentNode.appendChild(this.browser);
   }
 
+  set useTrackingProtection(aUse) {
+    if (aUse && !this._isSafeBrowsingInit) {
+      SafeBrowsing.init();
+      this._isSafeBrowsingInit = true;
+    }
+  }
+
   get displayMode() {
     return this._displayMode;
   }
 
   set displayMode(aMode) {
     if (!this.useMultiprocess) {
       this.window.QueryInterface(Ci.nsIInterfaceRequestor)
                    .getInterface(Ci.nsIDocShell)