Bug 1645500: Part 1 - Strip down process-content.js to save memory. r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D79541
This commit is contained in:
Kris Maglione 2020-06-12 22:10:59 +00:00
Родитель 4aac0566ba
Коммит 43c9fc5cc9
2 изменённых файлов: 21 добавлений и 52 удалений

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

@ -13,10 +13,10 @@ const { MessagePort } = ChromeUtils.import(
// The content side of a message port
class ChildMessagePort extends MessagePort {
constructor(actor, window) {
constructor(window) {
let portID =
Services.appinfo.processID + ":" + ChildMessagePort.nextPortID++;
super(actor, portID);
super(window.docShell.messageManager, portID);
this.window = window;

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

@ -1,7 +1,6 @@
/* 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/. */
"use strict";
// Creates a new PageListener for this process. This will listen for page loads
@ -9,37 +8,18 @@
// a dedicated message port and notify the parent process.
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const gInContentProcess =
Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT;
Services.cpmm.addMessageListener("gmp-plugin-crash", msg => {
let gmpservice = Cc["@mozilla.org/gecko-media-plugin-service;1"].getService(
Ci.mozIGeckoMediaPluginService
);
gmpservice.RunPluginCrashCallbacks(msg.data.pluginID, msg.data.pluginName);
Services.cpmm.addMessageListener("gmp-plugin-crash", ({ data }) => {
Cc["@mozilla.org/gecko-media-plugin-service;1"]
.getService(Ci.mozIGeckoMediaPluginService)
.RunPluginCrashCallbacks(data.pluginID, data.pluginName);
});
let TOPICS = [
"chrome-document-global-created",
"content-document-global-created",
];
if (gInContentProcess) {
TOPICS.push("inner-window-destroyed");
TOPICS.push("xpcom-shutdown");
}
let ProcessObserver = {
init() {
for (let topic of TOPICS) {
Services.obs.addObserver(this, topic);
}
},
uninit() {
for (let topic of TOPICS) {
Services.obs.removeObserver(this, topic);
Services.obs.addObserver(this, "chrome-document-global-created");
Services.obs.addObserver(this, "content-document-global-created");
if (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT) {
Services.obs.addObserver(this, "inner-window-destroyed");
}
},
@ -49,44 +29,33 @@ let ProcessObserver = {
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 url = window.document.documentURI.replace(/[#?].*$/, "");
let registeredURLs = Services.cpmm.sharedData.get(
"RemotePageManager:urls"
);
if (!registeredURLs || !registeredURLs.has(url)) {
return;
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);
}
// Get the frame message manager for this window so we can associate this
// page with a browser element
let messageManager = window.docShell.messageManager;
let { ChildMessagePort } = ChromeUtils.import(
"resource://gre/modules/remotepagemanager/RemotePageManagerChild.jsm"
);
// Set up the child side of the message port
new ChildMessagePort(messageManager, window);
break;
}
case "inner-window-destroyed": {
case "inner-window-destroyed":
// Forward inner-window-destroyed notifications with the
// inner window ID, so that code in the parent that should
// do something when content windows go away can do it
let innerWindowID = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
Services.cpmm.sendAsyncMessage(
"Toolkit:inner-window-destroyed",
innerWindowID
subject.nsISupportsPRUint64.data
);
break;
}
case "xpcom-shutdown": {
this.uninit();
break;
}
}
},
};
ProcessObserver.init();
// Drop the reference so it can be GCed.
ProcessObserver.init = null;