Bug 1479313: Don't load manifestMessages.js until needed. r=felipe

MozReview-Commit-ID: s2fq6XcgQ7

--HG--
rename : dom/ipc/manifestMessages.js => dom/ipc/ManifestMessages.jsm
extra : source : f5d647fae9733c5a19f53539fc6702de2a7fbbab
This commit is contained in:
Kris Maglione 2018-07-29 13:18:26 -07:00
Родитель bbe0065e6f
Коммит d5418d7fd0
5 изменённых файлов: 62 добавлений и 53 удалений

Просмотреть файл

@ -1320,7 +1320,6 @@ var gBrowserInit = {
mm.loadFrameScript("chrome://browser/content/tab-content.js", true); mm.loadFrameScript("chrome://browser/content/tab-content.js", true);
mm.loadFrameScript("chrome://browser/content/content.js", true); mm.loadFrameScript("chrome://browser/content/content.js", true);
mm.loadFrameScript("chrome://global/content/content-HybridContentTelemetry.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); window.messageManager.addMessageListener("Browser:LoadURI", RedirectLoad);

Просмотреть файл

@ -90,6 +90,12 @@ addMessageListener("MixedContent:ReenableProtection", function() {
XPCOMUtils.defineLazyProxy(this, "LightweightThemeChildHelper", XPCOMUtils.defineLazyProxy(this, "LightweightThemeChildHelper",
"resource:///modules/LightweightThemeChildHelper.jsm"); "resource:///modules/LightweightThemeChildHelper.jsm");
XPCOMUtils.defineLazyProxy(this, "ManifestMessages", () => {
let tmp = {};
ChromeUtils.import("resource://gre/modules/ManifestMessages.jsm", tmp);
return new tmp.ManifestMessages(global);
});
let themeablePagesWhitelist = new Set([ let themeablePagesWhitelist = new Set([
"about:home", "about:home",
"about:newtab", "about:newtab",
@ -517,3 +523,8 @@ addEventListener("MozAfterPaint", function onFirstNonBlankPaint() {
removeEventListener("MozAfterPaint", onFirstNonBlankPaint); removeEventListener("MozAfterPaint", onFirstNonBlankPaint);
sendAsyncMessage("Browser:FirstNonBlankPaint"); sendAsyncMessage("Browser:FirstNonBlankPaint");
}); });
addMessageListener("DOM:WebManifest:hasManifestLink", ManifestMessages);
addMessageListener("DOM:ManifestObtainer:Obtain", ManifestMessages);
addMessageListener("DOM:Manifest:FireAppInstalledEvent", ManifestMessages);
addMessageListener("DOM:WebManifest:fetchIcon", ManifestMessages);

Просмотреть файл

@ -11,54 +11,52 @@
* *
* BUG: https://bugzilla.mozilla.org/show_bug.cgi?id=1083410 * BUG: https://bugzilla.mozilla.org/show_bug.cgi?id=1083410
*/ */
/*globals Task, ManifestObtainer, ManifestFinder, content, sendAsyncMessage, addMessageListener, Components*/
"use strict"; "use strict";
const {
utils: Cu, var EXPORTED_SYMBOLS = ["ManifestMessages"];
} = Components;
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.defineModuleGetter(this, "ManifestObtainer", ChromeUtils.defineModuleGetter(this, "ManifestObtainer",
"resource://gre/modules/ManifestObtainer.jsm"); "resource://gre/modules/ManifestObtainer.jsm");
ChromeUtils.defineModuleGetter(this, "ManifestFinder", ChromeUtils.defineModuleGetter(this, "ManifestFinder",
"resource://gre/modules/ManifestFinder.jsm"); "resource://gre/modules/ManifestFinder.jsm");
ChromeUtils.defineModuleGetter(this, "ManifestIcons", ChromeUtils.defineModuleGetter(this, "ManifestIcons",
"resource://gre/modules/ManifestIcons.jsm"); "resource://gre/modules/ManifestIcons.jsm");
const MessageHandler = { class ManifestMessages {
registerListeners() { constructor(mm) {
addMessageListener( this.mm = mm;
"DOM:WebManifest:hasManifestLink", }
this.hasManifestLink.bind(this)
); receiveMessage(message) {
addMessageListener( switch (message.name) {
"DOM:ManifestObtainer:Obtain", case "DOM:WebManifest:hasManifestLink":
this.obtainManifest.bind(this) return this.hasManifestLink(message);
); case "DOM:ManifestObtainer:Obtain":
addMessageListener( return this.obtainManifest(message);
"DOM:Manifest:FireAppInstalledEvent", case "DOM:Manifest:FireAppInstalledEvent":
this.fireAppInstalledEvent.bind(this) return this.fireAppInstalledEvent(message);
); case "DOM:WebManifest:fetchIcon":
addMessageListener( return this.fetchIcon(message);
"DOM:WebManifest:fetchIcon", }
this.fetchIcon.bind(this) return undefined;
); }
},
/** /**
* Check if the content document includes a link to a web manifest. * Check if the this.mm.content document includes a link to a web manifest.
* @param {Object} aMsg The IPC message, which is destructured to just * @param {Object} aMsg The IPC message, which is destructured to just
* get the id. * get the id.
*/ */
hasManifestLink({data: {id}}) { hasManifestLink({data: {id}}) {
const response = makeMsgResponse(id); const response = makeMsgResponse(id);
response.result = ManifestFinder.contentHasManifestLink(content); response.result = ManifestFinder.contentHasManifestLink(this.mm.content);
response.success = true; response.success = true;
sendAsyncMessage("DOM:WebManifest:hasManifestLink", response); this.mm.sendAsyncMessage("DOM:WebManifest:hasManifestLink", response);
}, }
/** /**
* Asynchronously obtains a web manifest from content by using the * Asynchronously obtains a web manifest from this.mm.content by using the
* ManifestObtainer and messages back the result. * ManifestObtainer and messages back the result.
* @param {Object} aMsg The IPC message, which is destructured to just * @param {Object} aMsg The IPC message, which is destructured to just
* get the id. * get the id.
@ -66,26 +64,26 @@ const MessageHandler = {
async obtainManifest({data: {id}}) { async obtainManifest({data: {id}}) {
const response = makeMsgResponse(id); const response = makeMsgResponse(id);
try { try {
response.result = await ManifestObtainer.contentObtainManifest(content); response.result = await ManifestObtainer.contentObtainManifest(this.mm.content);
response.success = true; response.success = true;
} catch (err) { } catch (err) {
response.result = serializeError(err); response.result = serializeError(err);
} }
sendAsyncMessage("DOM:ManifestObtainer:Obtain", response); this.mm.sendAsyncMessage("DOM:ManifestObtainer:Obtain", response);
}, }
fireAppInstalledEvent({data: {id}}){ fireAppInstalledEvent({data: {id}}) {
const ev = new Event("appinstalled"); const ev = new Event("appinstalled");
const response = makeMsgResponse(id); const response = makeMsgResponse(id);
if (!content || content.top !== content) { if (!this.mm.content || this.mm.content.top !== this.mm.content) {
const msg = "Can only dispatch install event on top-level browsing contexts."; const msg = "Can only dispatch install event on top-level browsing contexts.";
response.result = serializeError(new Error(msg)); response.result = serializeError(new Error(msg));
} else { } else {
response.success = true; response.success = true;
content.dispatchEvent(ev); this.mm.content.dispatchEvent(ev);
} }
sendAsyncMessage("DOM:Manifest:FireAppInstalledEvent", response); this.mm.sendAsyncMessage("DOM:Manifest:FireAppInstalledEvent", response);
}, }
/** /**
* Given a manifest and an expected icon size, ask ManifestIcons * Given a manifest and an expected icon size, ask ManifestIcons
@ -95,15 +93,15 @@ const MessageHandler = {
const response = makeMsgResponse(id); const response = makeMsgResponse(id);
try { try {
response.result = response.result =
await ManifestIcons.contentFetchIcon(content, manifest, iconSize); await ManifestIcons.contentFetchIcon(this.mm.content, manifest, iconSize);
response.success = true; response.success = true;
} catch (err) { } catch (err) {
response.result = serializeError(err); response.result = serializeError(err);
} }
sendAsyncMessage("DOM:WebManifest:fetchIcon", response); this.mm.sendAsyncMessage("DOM:WebManifest:fetchIcon", response);
}, }
}
};
/** /**
* Utility function to Serializes an JS Error, so it can be transferred over * Utility function to Serializes an JS Error, so it can be transferred over
* the message channel. * the message channel.
@ -124,11 +122,9 @@ function serializeError(aError) {
} }
function makeMsgResponse(aId) { function makeMsgResponse(aId) {
return { return {
id: aId, id: aId,
success: false, success: false,
result: undefined result: undefined
}; };
} }
MessageHandler.registerListeners();

Просмотреть файл

@ -8,4 +8,3 @@ toolkit.jar:
content/global/BrowserElementChild.js (../browser-element/BrowserElementChild.js) content/global/BrowserElementChild.js (../browser-element/BrowserElementChild.js)
content/global/BrowserElementChildPreload.js (../browser-element/BrowserElementChildPreload.js) content/global/BrowserElementChildPreload.js (../browser-element/BrowserElementChildPreload.js)
content/global/BrowserElementCopyPaste.js (../browser-element/BrowserElementCopyPaste.js) content/global/BrowserElementCopyPaste.js (../browser-element/BrowserElementCopyPaste.js)
content/global/manifestMessages.js (manifestMessages.js)

Просмотреть файл

@ -13,6 +13,10 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'dom' XPIDL_MODULE = 'dom'
EXTRA_JS_MODULES += [
'ManifestMessages.jsm',
]
EXPORTS.mozilla.dom.ipc += [ EXPORTS.mozilla.dom.ipc += [
'IdType.h', 'IdType.h',
'MemMapSnapshot.h', 'MemMapSnapshot.h',