Skip to content

Commit

Permalink
Bug 1470023: Lazily load PluginContent.jsm when it's first required. …
Browse files Browse the repository at this point in the history
…r=felipe

MozReview-Commit-ID: 2n9NP5mEEcG

--HG--
extra : rebase_source : 10413b701ec89ddf3eeba7ed101f903be4bb2650
  • Loading branch information
kmaglione committed Jun 25, 2018
1 parent eb4431c commit e4e6f4b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 50 deletions.
63 changes: 61 additions & 2 deletions browser/base/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,67 @@ ClickEventHandler.init();
ContentLinkHandler.init(this);
ContentMetaHandler.init(this);

// TODO: Load this lazily so the JSM is run only if a relevant event/message fires.
void new PluginContent(global);
var PluginContentStub = {
EVENTS: [
"PluginCrashed",
"PluginOutdated",
"PluginInstantiated",
"PluginRemoved",
"HiddenPlugin",
],

MESSAGES: [
"BrowserPlugins:ActivatePlugins",
"BrowserPlugins:NotificationShown",
"BrowserPlugins:ContextMenuCommand",
"BrowserPlugins:NPAPIPluginProcessCrashed",
"BrowserPlugins:CrashReportSubmitted",
"BrowserPlugins:Test:ClearCrashData",
],

_pluginContent: null,
get pluginContent() {
if (!this._pluginContent) {
this._pluginContent = new PluginContent(global);
}
return this._pluginContent;
},

init() {
addEventListener("unload", this);

addEventListener("PluginBindingAttached", this, true, true);

for (let event of this.EVENTS) {
addEventListener(event, this, true);
}
for (let msg of this.MESSAGES) {
addMessageListener(msg, this);
}
Services.obs.addObserver(this, "decoder-doctor-notification");
},

uninit() {
Services.obs.removeObserver(this, "decoder-doctor-notification");
},

observe(subject, topic, data) {
return this.pluginContent.observe(subject, topic, data);
},

handleEvent(event) {
if (event.type === "unload") {
return this.uninit();
}
return this.pluginContent.handleEvent(event);
},

receiveMessage(msg) {
return this.pluginContent.receiveMessage(msg);
},
};

PluginContentStub.init();

addEventListener("DOMWindowFocus", function(event) {
sendAsyncMessage("DOMWindowFocus", {});
Expand Down
48 changes: 0 additions & 48 deletions browser/modules/PluginContent.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -42,51 +42,8 @@ PluginContent.prototype = {
// Cache of plugin crash information sent from the parent
this.pluginCrashData = new Map();

// Note that the XBL binding is untrusted
global.addEventListener("PluginBindingAttached", this, true, true);
global.addEventListener("PluginCrashed", this, true);
global.addEventListener("PluginOutdated", this, true);
global.addEventListener("PluginInstantiated", this, true);
global.addEventListener("PluginRemoved", this, true);
global.addEventListener("pagehide", this, true);
global.addEventListener("pageshow", this, true);
global.addEventListener("unload", this);
global.addEventListener("HiddenPlugin", this, true);

global.addMessageListener("BrowserPlugins:ActivatePlugins", this);
global.addMessageListener("BrowserPlugins:NotificationShown", this);
global.addMessageListener("BrowserPlugins:ContextMenuCommand", this);
global.addMessageListener("BrowserPlugins:NPAPIPluginProcessCrashed", this);
global.addMessageListener("BrowserPlugins:CrashReportSubmitted", this);
global.addMessageListener("BrowserPlugins:Test:ClearCrashData", this);

Services.obs.addObserver(this, "decoder-doctor-notification");
},

uninit() {
let global = this.global;

global.removeEventListener("PluginBindingAttached", this, true);
global.removeEventListener("PluginCrashed", this, true);
global.removeEventListener("PluginOutdated", this, true);
global.removeEventListener("PluginInstantiated", this, true);
global.removeEventListener("PluginRemoved", this, true);
global.removeEventListener("pagehide", this, true);
global.removeEventListener("pageshow", this, true);
global.removeEventListener("unload", this);
global.removeEventListener("HiddenPlugin", this, true);

global.removeMessageListener("BrowserPlugins:ActivatePlugins", this);
global.removeMessageListener("BrowserPlugins:NotificationShown", this);
global.removeMessageListener("BrowserPlugins:ContextMenuCommand", this);
global.removeMessageListener("BrowserPlugins:NPAPIPluginProcessCrashed", this);
global.removeMessageListener("BrowserPlugins:CrashReportSubmitted", this);
global.removeMessageListener("BrowserPlugins:Test:ClearCrashData", this);

Services.obs.removeObserver(this, "decoder-doctor-notification");

delete this.global;
delete this.content;
},

receiveMessage(msg) {
Expand Down Expand Up @@ -444,11 +401,6 @@ PluginContent.prototype = {
handleEvent(event) {
let eventType = event.type;

if (eventType == "unload") {
this.uninit();
return;
}

if (eventType == "pagehide") {
this.onPageHide(event);
return;
Expand Down

0 comments on commit e4e6f4b

Please sign in to comment.