Bug 1479310: Don't load content-UITour.js until needed. r?Mossop
MozReview-Commit-ID: 55EPBxUYv9o
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1318,17 +1318,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 = {};
@@ -526,8 +532,10 @@ let ExtFind = {
break;
}
},
};
ExtFind.init();
addEventListener("ShieldPageEvent", ShieldFrameListener, false, true);
+
+addEventListener("mozUITour", UITourListener, false, true);