Bug 1645633, setup RPM pages on the DOMWindowCreated event instead of using the 'xx-document-global-created' observer notification, r=mconley

Differential Revision: https://phabricator.services.mozilla.com/D79611
This commit is contained in:
Neil Deakin 2020-06-17 15:04:39 +00:00
parent 91916ebd33
commit 9843200d33
2 changed files with 24 additions and 34 deletions

View File

@ -6,6 +6,8 @@
var EXPORTED_SYMBOLS = ["BrowserTabChild"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(
this,
"E10SUtils",
@ -31,6 +33,8 @@ class BrowserTabChild extends JSWindowActorChild {
let loadContext = context.docShell.QueryInterface(Ci.nsILoadContext);
let userContextId = loadContext.originAttributes.userContextId;
this.initializeRPM();
this.sendAsyncMessage("Browser:WindowCreated", { userContextId });
break;
}
@ -110,4 +114,24 @@ class BrowserTabChild extends JSWindowActorChild {
break;
}
}
// Creates a new PageListener for this process. This will listen for page loads
// and for those that match URLs provided by the parent process will set up
// a dedicated message port and notify the parent process.
// Note: this is part of the old message-manager based RPM and is only still
// used by newtab and talos tests.
initializeRPM() {
// Strip the hash from the URL, because it's not part of the origin.
let url = this.document.documentURI.replace(/[\#?].*$/, "");
let registeredURLs = Services.cpmm.sharedData.get("RemotePageManager:urls");
if (registeredURLs && registeredURLs.has(url)) {
let { ChildMessagePort } = ChromeUtils.import(
"resource://gre/modules/remotepagemanager/RemotePageManagerChild.jsm"
);
// Set up the child side of the message port
new ChildMessagePort(this.contentWindow);
}
}
}

View File

@ -13,37 +13,3 @@ Services.cpmm.addMessageListener("gmp-plugin-crash", ({ data }) => {
.getService(Ci.mozIGeckoMediaPluginService)
.RunPluginCrashCallbacks(data.pluginID, data.pluginName);
});
let ProcessObserver = {
init() {
Services.obs.addObserver(this, "chrome-document-global-created");
Services.obs.addObserver(this, "content-document-global-created");
},
observe(subject, topic, data) {
switch (topic) {
case "chrome-document-global-created":
case "content-document-global-created": {
// Strip the hash from the URL, because it's not part of the origin.
let window = subject;
let url = window.document.documentURI.replace(/[#?].*$/, "");
let registeredURLs = Services.cpmm.sharedData.get(
"RemotePageManager:urls"
);
if (registeredURLs && registeredURLs.has(url)) {
let { ChildMessagePort } = ChromeUtils.import(
"resource://gre/modules/remotepagemanager/RemotePageManagerChild.jsm"
);
// Set up the child side of the message port
new ChildMessagePort(window);
}
break;
}
}
},
};
ProcessObserver.init();
// Drop the reference so it can be GCed.
ProcessObserver.init = null;