Bug 1479310: Don't load content-UITour.js until needed. r=Mossop
authorKris Maglione <maglione.k@gmail.com>
Sun, 29 Jul 2018 12:36:45 -0700
changeset 429722 3583823171dea4207f9ea5665060bcb559f5e586
parent 429721 2d46e1fe31214d36d1e11218deb44423baee2c26
child 429723 d403426d1dcdd7b7cd5b51e62b7b71c5d69631a3
push id34372
push usernerli@mozilla.com
push dateThu, 02 Aug 2018 08:55:28 +0000
treeherdermozilla-central@bd79b07f57a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1479310
milestone63.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 1479310: Don't load content-UITour.js until needed. r=Mossop MozReview-Commit-ID: 55EPBxUYv9o
browser/base/content/browser.js
browser/components/uitour/ContentUITour.jsm
browser/components/uitour/content-UITour.js
browser/components/uitour/jar.mn
browser/components/uitour/moz.build
toolkit/content/browser-content.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1315,17 +1315,16 @@ var gBrowserInit = {
     FeedHandler.init();
     TrackingProtection.init();
     CaptivePortalWatcher.init();
     ZoomUI.init(window);
 
     let mm = window.getGroupMessageManager("browsers");
     mm.loadFrameScript("chrome://browser/content/tab-content.js", true);
     mm.loadFrameScript("chrome://browser/content/content.js", true);
-    mm.loadFrameScript("chrome://browser/content/content-UITour.js", true);
     mm.loadFrameScript("chrome://global/content/content-HybridContentTelemetry.js", true);
     mm.loadFrameScript("chrome://global/content/manifestMessages.js", true);
 
     window.messageManager.addMessageListener("Browser:LoadURI", RedirectLoad);
 
     if (!gMultiProcessBrowser) {
       // There is a Content:Click message manually sent from content.
       Services.els.addSystemEventListener(gBrowser.tabpanels, "click",
rename from browser/components/uitour/content-UITour.js
rename to browser/components/uitour/ContentUITour.jsm
--- a/browser/components/uitour/content-UITour.js
+++ b/browser/components/uitour/ContentUITour.jsm
@@ -1,35 +1,39 @@
 /* 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/. */
 
-/* eslint-env mozilla/frame-script */
+var EXPORTED_SYMBOLS = ["UITourListener"];
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const PREF_TEST_WHITELIST = "browser.uitour.testingOrigins";
 const UITOUR_PERMISSION   = "uitour";
 
-var UITourListener = {
+class UITourListener {
+  constructor(mm) {
+    this.mm = mm;
+  }
+
   handleEvent(event) {
     if (!Services.prefs.getBoolPref("browser.uitour.enabled")) {
       return;
     }
     if (!this.ensureTrustedOrigin()) {
       return;
     }
-    addMessageListener("UITour:SendPageCallback", this);
-    addMessageListener("UITour:SendPageNotification", this);
-    sendAsyncMessage("UITour:onPageEvent", {
+    this.mm.addMessageListener("UITour:SendPageCallback", this);
+    this.mm.addMessageListener("UITour:SendPageNotification", this);
+    this.mm.sendAsyncMessage("UITour:onPageEvent", {
       detail: event.detail,
       type: event.type,
-      pageVisibilityState: content.document.visibilityState,
+      pageVisibilityState: this.mm.content.document.visibilityState,
     });
-  },
+  }
 
   isTestingOrigin(aURI) {
     if (Services.prefs.getPrefType(PREF_TEST_WHITELIST) != Services.prefs.PREF_STRING) {
       return false;
     }
 
     // Add any testing origins (comma-seperated) to the whitelist for the session.
     for (let origin of Services.prefs.getCharPref(PREF_TEST_WHITELIST).split(",")) {
@@ -38,68 +42,68 @@ var UITourListener = {
         if (aURI.prePath == testingURI.prePath) {
           return true;
         }
       } catch (ex) {
         Cu.reportError(ex);
       }
     }
     return false;
-  },
+  }
 
   // This function is copied from UITour.jsm.
   isSafeScheme(aURI) {
     let allowedSchemes = new Set(["https", "about"]);
     if (!Services.prefs.getBoolPref("browser.uitour.requireSecure"))
       allowedSchemes.add("http");
 
     if (!allowedSchemes.has(aURI.scheme))
       return false;
 
     return true;
-  },
+  }
 
   ensureTrustedOrigin() {
+    let {content} = this.mm;
+
     if (content.top != content)
       return false;
 
     let uri = content.document.documentURIObject;
 
     if (uri.schemeIs("chrome"))
       return true;
 
     if (!this.isSafeScheme(uri))
       return false;
 
     let permission = Services.perms.testPermission(uri, UITOUR_PERMISSION);
     if (permission == Services.perms.ALLOW_ACTION)
       return true;
 
     return this.isTestingOrigin(uri);
-  },
+  }
 
   receiveMessage(aMessage) {
     switch (aMessage.name) {
       case "UITour:SendPageCallback":
         this.sendPageEvent("Response", aMessage.data);
         break;
       case "UITour:SendPageNotification":
         this.sendPageEvent("Notification", aMessage.data);
         break;
       }
-  },
+  }
 
   sendPageEvent(type, detail) {
     if (!this.ensureTrustedOrigin()) {
       return;
     }
 
-    let doc = content.document;
+    let win = this.mm.content;
     let eventName = "mozUITour" + type;
-    let event = new doc.defaultView.CustomEvent(eventName, {
+    let event = new win.CustomEvent(eventName, {
       bubbles: true,
-      detail: Cu.cloneInto(detail, doc.defaultView)
+      detail: Cu.cloneInto(detail, win),
     });
-    doc.dispatchEvent(event);
+    win.document.dispatchEvent(event);
   }
-};
-
-addEventListener("mozUITour", UITourListener, false, true);
+}
deleted file mode 100644
--- a/browser/components/uitour/jar.mn
+++ /dev/null
@@ -1,6 +0,0 @@
-# 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/.
-
-browser.jar:
-       content/browser/content-UITour.js
--- a/browser/components/uitour/moz.build
+++ b/browser/components/uitour/moz.build
@@ -1,16 +1,15 @@
 # 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/.
 
 EXTRA_JS_MODULES += [
+    'ContentUITour.jsm',
     'UITour.jsm',
 ]
 
-JAR_MANIFESTS += ['jar.mn']
-
 BROWSER_CHROME_MANIFESTS += [
     'test/browser.ini',
 ]
 
 with Files('**'):
     BUG_COMPONENT = ('Firefox', 'Tours')
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -38,16 +38,22 @@ XPCOMUtils.defineLazyProxy(this, "PopupB
 });
 
 XPCOMUtils.defineLazyProxy(this, "ShieldFrameListener", () => {
   let tmp = {};
   ChromeUtils.import("resource://normandy-content/ShieldFrameListener.jsm", tmp);
   return new tmp.ShieldFrameListener(global);
 });
 
+XPCOMUtils.defineLazyProxy(this, "UITourListener", () => {
+  let tmp = {};
+  ChromeUtils.import("resource:///modules/ContentUITour.jsm", tmp);
+  return new tmp.UITourListener(global);
+});
+
 XPCOMUtils.defineLazyProxy(this, "SelectionSourceContent",
   "resource://gre/modules/SelectionSourceContent.jsm");
 
 XPCOMUtils.defineLazyProxy(this, "WebChannelContent",
   "resource://gre/modules/WebChannelContent.jsm");
 
 XPCOMUtils.defineLazyProxy(this, "DateTimePickerContent", () => {
   let tmp = {};
@@ -537,8 +543,10 @@ let ExtFind = {
         break;
     }
   },
 };
 
 ExtFind.init();
 
 addEventListener("ShieldPageEvent", ShieldFrameListener, false, true);
+
+addEventListener("mozUITour", UITourListener, false, true);