Bug 1290567 - Remove inner-window-destroyed observer in process-content.js at xpcom-shutdown. r?Gijs
It seems to be possible for an inner-window-destroyed notification to be dispatched
after xpcom-shutdown. This means that communications over the Services.cpmm are
attempted after the connection to the parent process has already been torn down. This
can cause an Exception to be thrown, which can keep the ContentProcessMessageManager
alive long enough to cause SpiderMonkey to complain that there are still living
elements in its heap at JS shutdown time.
MozReview-Commit-ID: wmCHtqcjkJ
--- a/toolkit/content/process-content.js
+++ b/toolkit/content/process-content.js
@@ -16,17 +16,49 @@ const gInContentProcess = Services.appin
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);
});
-// 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
if (gInContentProcess) {
- Services.obs.addObserver((subject, topic, data) => {
- let innerWindowID = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
- Services.cpmm.sendAsyncMessage("Toolkit:inner-window-destroyed", innerWindowID);
- }, "inner-window-destroyed", false);
+ let ProcessObserver = {
+ TOPICS: [
+ "inner-window-destroyed",
+ "xpcom-shutdown",
+ ],
+
+ init() {
+ for (let topic of this.TOPICS) {
+ Services.obs.addObserver(this, topic, false);
+ }
+ },
+
+ uninit() {
+ for (let topic of this.TOPICS) {
+ Services.obs.removeObserver(this, topic);
+ }
+ },
+
+ observe(subject, topic, data) {
+ switch (topic) {
+ 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);
+ break;
+ }
+ case "xpcom-shutdown": {
+ this.uninit();
+ break;
+ }
+ }
+ },
+ };
+
+ ProcessObserver.init();
}