Bug 1369466 - Use Services.ppmm.sharedData instead of initialProcessData on the RemotePageManager. r=Mossop
This is an optimization that reduces the memory usage of the registeredUrls list (as it will use shared data among all processes), and makes the Register/Unregister messages unecessary since the changes in sharedData are automatically propagated to all running processes.
The flush() is unfortunately needed to force the propagation in this case, otherwise it would propagate on the next idle tick, and that is not enough to make sure that the RemotePageManager works for the first about:newtab created when starting Firefox
MozReview-Commit-ID: JG3na0XXWA2
--- a/toolkit/components/remotepagemanager/RemotePageManagerParent.jsm
+++ b/toolkit/components/remotepagemanager/RemotePageManagerParent.jsm
@@ -285,42 +285,38 @@ var RemotePageManagerInternal = {
// Initialises all the needed listeners
init() {
Services.mm.addMessageListener("RemotePage:InitPort", this.initPort.bind(this));
this.updateProcessUrls();
},
updateProcessUrls() {
- Services.ppmm.initialProcessData["RemotePageManager:urls"] = Array.from(this.pages.keys());
+ Services.ppmm.sharedData.set("RemotePageManager:urls", new Set(this.pages.keys()));
+ Services.ppmm.sharedData.flush();
},
// Registers interest in a remote page. A callback is called with a port for
// the new page when loading begins (i.e. the page hasn't actually loaded yet).
// Only one callback can be registered per URL.
addRemotePageListener(url, callback) {
if (this.pages.has(url)) {
throw new Error("Remote page already registered: " + url);
}
this.pages.set(url, callback);
this.updateProcessUrls();
-
- // Notify all the frame scripts of the new registration
- Services.ppmm.broadcastAsyncMessage("RemotePage:Register", { urls: [url] });
},
// Removes any interest in a remote page.
removeRemotePageListener(url) {
if (!this.pages.has(url)) {
throw new Error("Remote page is not registered: " + url);
}
- // Notify all the frame scripts of the removed registration
- Services.ppmm.broadcastAsyncMessage("RemotePage:Unregister", { urls: [url] });
this.pages.delete(url);
this.updateProcessUrls();
},
// A remote page has been created and a port is ready in the content side
initPort({ target: browser, data: { url, portID } }) {
let callback = this.pages.get(url);
if (!callback) {
--- a/toolkit/content/process-content.js
+++ b/toolkit/content/process-content.js
@@ -23,18 +23,16 @@ let TOPICS = [
"content-document-global-created",
];
if (gInContentProcess) {
TOPICS.push("inner-window-destroyed");
TOPICS.push("xpcom-shutdown");
}
-let registeredURLs = new Set(Services.cpmm.initialProcessData["RemotePageManager:urls"]);
-
let ProcessObserver = {
init() {
for (let topic of TOPICS) {
Services.obs.addObserver(this, topic);
}
},
uninit() {
@@ -47,16 +45,18 @@ let ProcessObserver = {
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.has(url))
return;
// Get the frame message manager for this window so we can associate this
// page with a browser element
let messageManager = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsIInterfaceRequestor)
@@ -82,20 +82,8 @@ let ProcessObserver = {
this.uninit();
break;
}
}
},
};
ProcessObserver.init();
-
-// A message from chrome telling us what pages to listen for
-Services.cpmm.addMessageListener("RemotePage:Register", ({ data }) => {
- for (let url of data.urls)
- registeredURLs.add(url);
-});
-
-// A message from chrome telling us what pages to stop listening for
-Services.cpmm.addMessageListener("RemotePage:Unregister", ({ data }) => {
- for (let url of data.urls)
- registeredURLs.delete(url);
-});
--- a/toolkit/modules/tests/browser/browser_RemotePageManager.js
+++ b/toolkit/modules/tests/browser/browser_RemotePageManager.js
@@ -55,19 +55,19 @@ function swapDocShells(browser1, browser
browser1.swapDocShells(browser2);
// Swap permanentKeys.
let tmp = browser1.permanentKey;
browser1.permanentKey = browser2.permanentKey;
browser2.permanentKey = tmp;
}
-add_task(async function initialProcessData() {
+add_task(async function sharedData_aka_initialProcessData() {
const includesTest = () => Services.cpmm.
- initialProcessData["RemotePageManager:urls"].includes(TEST_URL);
+ sharedData.get("RemotePageManager:urls").has(TEST_URL);
is(includesTest(), false, "Shouldn't have test url in initial process data yet");
const loadedPort = waitForPort(TEST_URL);
is(includesTest(), true, "Should have test url when waiting for it to load");
await loadedPort;
is(includesTest(), false, "Should have test url removed when done listening");