Bug 1351980 - Initialize the UserAgentOverrides.jsm module at startup and shut it down at shutdown for all Gecko applications instead of relying on each one to do it on its own; r=schien
☠☠ backed out by b78070b17cca ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 30 Mar 2017 20:58:45 -0400
changeset 350732 1c7c92033bb1bd1317d12d79e6d6e4d0473133ad
parent 350731 a7ac485f20cf144d31f283f059bb22560e752783
child 350733 fbc8e05e5251ad2e3c59a8eb45ccddb00b2cecf1
push id31583
push userkwierso@gmail.com
push dateSat, 01 Apr 2017 00:48:26 +0000
treeherdermozilla-central@00a166a8640d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersschien
bugs1351980
milestone55.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 1351980 - Initialize the UserAgentOverrides.jsm module at startup and shut it down at shutdown for all Gecko applications instead of relying on each one to do it on its own; r=schien
b2g/chrome/content/shell.js
browser/base/content/test/static/browser_all_files_referenced.js
browser/installer/package-manifest.in
mobile/android/chrome/content/browser.js
mobile/android/installer/package-manifest.in
netwerk/protocol/http/UserAgentOverrides.js
netwerk/protocol/http/UserAgentOverrides.manifest
netwerk/protocol/http/moz.build
netwerk/test/mochitests/test_user_agent_overrides.html
netwerk/test/mochitests/test_user_agent_updates.html
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -2,17 +2,16 @@
 /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
 /* 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/. */
 
 window.performance.mark('gecko-shell-loadstart');
 
 Cu.import('resource://gre/modules/NotificationDB.jsm');
-Cu.import('resource://gre/modules/UserAgentOverrides.jsm');
 Cu.import('resource://gre/modules/Keyboard.jsm');
 Cu.import('resource://gre/modules/ErrorPage.jsm');
 Cu.import('resource://gre/modules/AlertsHelper.jsm');
 Cu.import('resource://gre/modules/SystemUpdateService.jsm');
 
 if (isGonk) {
   Cu.import('resource://gre/modules/ResourceStatsService.jsm');
 }
@@ -402,17 +401,16 @@ var shell = {
     window.addEventListener('MozAfterPaint', this);
     window.addEventListener('sizemodechange', this);
     window.addEventListener('unload', this);
     this.contentBrowser.addEventListener('mozbrowserloadstart', this, true);
     this.contentBrowser.addEventListener('mozbrowserscrollviewchange', this, true);
     this.contentBrowser.addEventListener('mozbrowsercaretstatechanged', this);
 
     CustomEventManager.init();
-    UserAgentOverrides.init();
     CaptivePortalLoginHelper.init();
 
     this.contentBrowser.src = homeURL;
 
     this._isEventListenerReady = false;
 
     window.performance.mark('gecko-shell-system-frame-set');
 
@@ -432,18 +430,16 @@ var shell = {
     window.removeEventListener('keydown', this, true);
     window.removeEventListener('keyup', this, true);
     window.removeEventListener('MozApplicationManifest', this);
     window.removeEventListener('sizemodechange', this);
     this.contentBrowser.removeEventListener('mozbrowserloadstart', this, true);
     this.contentBrowser.removeEventListener('mozbrowserscrollviewchange', this, true);
     this.contentBrowser.removeEventListener('mozbrowsercaretstatechanged', this);
     ppmm.removeMessageListener("content-handler", this);
-
-    UserAgentOverrides.uninit();
   },
 
   // If this key event represents a hardware button which needs to be send as
   // a message, broadcasts it with the message set to 'xxx-button-press' or
   // 'xxx-button-release'.
   broadcastHardwareKeys: function shell_broadcastHardwareKeys(evt) {
     let type;
     let message;
--- a/browser/base/content/test/static/browser_all_files_referenced.js
+++ b/browser/base/content/test/static/browser_all_files_referenced.js
@@ -246,18 +246,16 @@ var whitelist = new Set([
   // Bug 1351089
   {file: "resource://gre/modules/PresentationDeviceInfoManager.jsm"},
   // Bug 1351091
   {file: "resource://gre/modules/Profiler.jsm"},
   // Bug 1351658
   {file: "resource://gre/modules/PropertyListUtils.jsm", platforms: ["linux", "win"]},
   // Bug 1351093
   {file: "resource://gre/modules/Sntp.jsm"},
-  // Bug 1351980
-  {file: "resource://gre/modules/UserAgentOverrides.jsm"},
   // Bug 1351097
   {file: "resource://gre/modules/accessibility/AccessFu.jsm"},
   // Bug 1351099
   {file: "resource://gre/modules/addons/AddonLogging.jsm"},
   // Bug 1351604
   {file: "resource://gre/modules/psm/X509.jsm"},
   // Bug 1351637
   {file: "resource://gre/modules/sdk/bootstrap.js"},
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -352,16 +352,18 @@
 
 ; JavaScript components
 @RESPATH@/components/ConsoleAPI.manifest
 @RESPATH@/components/ConsoleAPIStorage.js
 @RESPATH@/components/BrowserElementParent.manifest
 @RESPATH@/components/BrowserElementParent.js
 @RESPATH@/components/FeedProcessor.manifest
 @RESPATH@/components/FeedProcessor.js
+@RESPATH@/components/UserAgentOverrides.js
+@RESPATH@/components/UserAgentOverrides.manifest
 @RESPATH@/components/WellKnownOpportunisticUtils.js
 @RESPATH@/components/WellKnownOpportunisticUtils.manifest
 #ifndef XP_MACOSX
 ; OSX uses native platform impl.  Windows, Linux, and Android uses fallback JS impl.
 @BINPATH@/components/nsDNSServiceDiscovery.manifest
 @BINPATH@/components/nsDNSServiceDiscovery.js
 #endif
 @RESPATH@/browser/components/BrowserFeeds.manifest
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -38,19 +38,16 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/UITelemetry.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
                                   "resource://gre/modules/PluralForm.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
                                   "resource://gre/modules/Downloads.jsm");
 
-XPCOMUtils.defineLazyModuleGetter(this, "UserAgentOverrides",
-                                  "resource://gre/modules/UserAgentOverrides.jsm");
-
 XPCOMUtils.defineLazyModuleGetter(this, "LoginManagerContent",
                                   "resource://gre/modules/LoginManagerContent.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "LoginManagerParent",
                                   "resource://gre/modules/LoginManagerParent.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
@@ -454,17 +451,16 @@ var BrowserApp = {
 
     NativeWindow.init();
     FormAssistant.init();
     IndexedDB.init();
     XPInstallObserver.init();
     CharacterEncoding.init();
     ActivityObserver.init();
     RemoteDebugger.init();
-    UserAgentOverrides.init();
     DesktopUserAgent.init();
     Distribution.init();
     Tabs.init();
     SearchEngines.init();
     Experiments.init();
 
     // XXX maybe we don't do this if the launch was kicked off from external
     Services.io.offline = false;
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -272,16 +272,18 @@
 @BINPATH@/components/Push.js
 @BINPATH@/components/Push.manifest
 @BINPATH@/components/PushComponents.js
 #endif
 @BINPATH@/components/BrowserElementParent.manifest
 @BINPATH@/components/BrowserElementParent.js
 @BINPATH@/components/FeedProcessor.manifest
 @BINPATH@/components/FeedProcessor.js
+@RESPATH@/components/UserAgentOverrides.js
+@RESPATH@/components/UserAgentOverrides.manifest
 @BINPATH@/components/WellKnownOpportunisticUtils.js
 @BINPATH@/components/WellKnownOpportunisticUtils.manifest
 @BINPATH@/components/mozProtocolHandler.js
 @BINPATH@/components/mozProtocolHandler.manifest
 @BINPATH@/components/nsDNSServiceDiscovery.manifest
 @BINPATH@/components/nsDNSServiceDiscovery.js
 @BINPATH@/components/toolkitsearch.manifest
 @BINPATH@/components/nsSearchService.js
new file mode 100644
--- /dev/null
+++ b/netwerk/protocol/http/UserAgentOverrides.js
@@ -0,0 +1,37 @@
+/* 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/. */
+
+"use strict";
+
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/UserAgentOverrides.jsm");
+
+function UserAgentOverridesComponent() {
+}
+
+UserAgentOverridesComponent.prototype = {
+  init: function uaoc_init() {
+    Services.obs.addObserver(this, "xpcom-shutdown", false);
+    UserAgentOverrides.init();
+  },
+
+  observe: function uaoc_observe(aSubject, aTopic, aData) {
+    if (aTopic == "app-startup") {
+      this.init();
+    } else if (aTopic == "xpcom-shutdown") {
+      Services.obs.removeObserver(this, "xpcom-shutdown");
+      UserAgentOverrides.uninit();
+    }
+  },
+
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
+  classID: Components.ID("{965b0ca8-155b-11e7-93ae-92361f002671}")
+};
+
+const components = [UserAgentOverridesComponent];
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
new file mode 100644
--- /dev/null
+++ b/netwerk/protocol/http/UserAgentOverrides.manifest
@@ -0,0 +1,4 @@
+# UserAgentOverrides.js
+component {965b0ca8-155b-11e7-93ae-92361f002671} UserAgentOverrides.js process=main
+contract @mozilla.org/network/useragentoverrides;1 {965b0ca8-155b-11e7-93ae-92361f002671}
+category app-startup UserAgentOverrides service,@mozilla.org/network/useragentoverrides;1
--- a/netwerk/protocol/http/moz.build
+++ b/netwerk/protocol/http/moz.build
@@ -116,11 +116,13 @@ include('/ipc/chromium/chromium-config.m
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '/dom/base',
     '/netwerk/base',
 ]
 
 EXTRA_COMPONENTS += [
+    'UserAgentOverrides.js',
+    'UserAgentOverrides.manifest',
     'WellKnownOpportunisticUtils.js',
     'WellKnownOpportunisticUtils.manifest',
 ]
--- a/netwerk/test/mochitests/test_user_agent_overrides.html
+++ b/netwerk/test/mochitests/test_user_agent_overrides.html
@@ -226,21 +226,16 @@ function testPriority(callback) {
 function testOverrides(callback) {
   SpecialPowers.pushPrefEnv({
     set: [[PREF_OVERRIDES_ENABLED, true]]
   }, function nextTest() {
     testUA(tests.shift(), function() { tests.length ? nextTest() : callback() });
   });
 }
 
-SpecialPowers.loadChromeScript(_ => {
-  Components.utils.import("resource://gre/modules/UserAgentOverrides.jsm");
-  UserAgentOverrides.init();
-});
-
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestCompleteLog();
 SimpleTest.requestLongerTimeout(5);
 
 testOverrides(function() {
   testInactive(function() {
     testPriority(SimpleTest.finish)
   });
--- a/netwerk/test/mochitests/test_user_agent_updates.html
+++ b/netwerk/test/mochitests/test_user_agent_updates.html
@@ -195,41 +195,34 @@ function testBadUpdate(callback) {
 SimpleTest.waitForExplicitFinish();
 SimpleTest.requestFlakyTimeout("Test sets timeouts to wait for updates to happen.");
 
 SpecialPowers.pushPrefEnv({
   set: [
     [PREF_APP_UPDATE_TIMERMINIMUMDELAY, 0]
   ]
 }, function () {
-  chromeScript.sendSyncMessage("UAO-uninit");
-
   // Sets the OVERRIDES var in the chrome script.
   // We do this to avoid code duplication.
   chromeScript.sendSyncMessage("set-overrides", OVERRIDES);
 
   // testProfileLoad, testDownload, and testProfileSave must run in this order
-  //  because testDownload depends on testProfileLoad to call UAO.init()
-  //  and testProfileSave depends on testDownload to save overrides to the profile
+  // because testDownload depends on testProfileLoad and testProfileSave depends
+  // on testDownload to save overrides to the profile
   chromeScript.sendAsyncMessage("testProfileLoad", location.hostname);
 });
 
 
 const chromeScript = SpecialPowers.loadChromeScript(_ => {
   // Enter update timer manager test mode
   Components.classes["@mozilla.org/updates/timer-manager;1"].getService(
     Components.interfaces.nsIObserver).observe(null, "utm-test-init", "");
 
-  Components.utils.import("resource://gre/modules/UserAgentOverrides.jsm");
-
   var _notifyOnUpdate = false;
 
-  var UAO = UserAgentOverrides;
-  UAO.uninit();
-
   Components.utils.import("resource://gre/modules/FileUtils.jsm");
   var FU = FileUtils;
 
   const { TextDecoder, TextEncoder, OS } = Components.utils.import("resource://gre/modules/osfile.jsm");
   var OSF = OS.File;
 
   const KEY_PREFDIR = "PrefD";
   const KEY_APPDIR = "XCurProcD";
@@ -313,29 +306,24 @@ const chromeScript = SpecialPowers.loadC
       }
     );
   }
 
 
   addMessageListener("testProfileSave", testProfileSave);
   addMessageListener("testProfileLoad", testProfileLoad);
   addMessageListener("set-overrides", function(overrides) { OVERRIDES = overrides});
-  addMessageListener("UAO-init", function() { UAO.init(); });
-  addMessageListener("UAO-uninit", function() { UAO.uninit(); });
   addMessageListener("notify-on-update", () => { _notifyOnUpdate = true });
 });
 
 chromeScript.addMessageListener("testProfileSaveDone", SimpleTest.finish);
 chromeScript.addMessageListener("testProfileLoadDone", function() {
   SpecialPowers.pushPrefEnv({
     set: [[PREF_UPDATES_ENABLED, true]]
   }, function () {
-    // initialize UserAgentOverrides.jsm and
-    // UserAgentUpdates.jsm and load saved file
-    chromeScript.sendSyncMessage("UAO-init");
     (function waitForLoad() {
       var ifr = document.createElement('IFRAME');
       ifr.src = location.origin;
 
       ifr.addEventListener('load', function() {
         var nav = ifr.contentWindow.navigator;
         if (nav.userAgent !== UA_ALT_OVERRIDE) {
           setTimeout(waitForLoad, 100);