--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -619,28 +619,26 @@ DocumentManager = {
DocumentManager.getExtensionPageContext(extension, window);
} else if (apiLevel == FULL_PRIVILEGES) {
ExtensionChild.createExtensionContext(extension, window);
}
}
}
},
- observe(subject, topic, data) {
+ observers: {
// For some types of documents (about:blank), we only see the first
// notification, for others (data: URIs) we only observe the second.
- if (topic == "content-document-global-created" || topic == "document-element-inserted") {
+ "content-document-global-created"(subject, topic, data) {
+ this.observers["document-element-inserted"].call(this, subject.document, topic, data);
+ },
+ "document-element-inserted"(subject, topic, data) {
let document = subject;
let window = document && document.defaultView;
- if (topic == "content-document-global-created") {
- window = subject;
- document = window && window.document;
- }
-
if (!document || !document.location || !window) {
return;
}
// Make sure we only load into frames that ExtensionContent.init
// was called on (i.e., not frames for social or sidebars).
let mm = getWindowMessageManager(window);
if (!mm || !ExtensionContent.globals.has(mm)) {
@@ -653,17 +651,18 @@ DocumentManager = {
this.loadInto(window);
this.trigger("document_start", window);
}
/* eslint-disable mozilla/balanced-listeners */
window.addEventListener("DOMContentLoaded", this, true);
window.addEventListener("load", this, true);
/* eslint-enable mozilla/balanced-listeners */
- } else if (topic == "inner-window-destroyed") {
+ },
+ "inner-window-destroyed"(subject, topic, data) {
let windowId = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
MessageChannel.abortResponses({innerWindowID: windowId});
// Close any existent content-script context for the destroyed window.
if (this.contentScriptWindows.has(windowId)) {
let extensions = this.contentScriptWindows.get(windowId);
for (let [, context] of extensions) {
@@ -676,32 +675,38 @@ DocumentManager = {
// Close any existent iframe extension page context for the destroyed window.
if (this.extensionPageWindows.has(windowId)) {
let context = this.extensionPageWindows.get(windowId);
context.close();
this.extensionPageWindows.delete(windowId);
}
ExtensionChild.destroyExtensionContext(windowId);
- } else if (topic === "http-on-opening-request") {
+ },
+ "http-on-opening-request"(subject, topic, data) {
let {loadInfo} = subject.QueryInterface(Ci.nsIChannel);
if (loadInfo) {
let {externalContentPolicyType: type} = loadInfo;
if (type === Ci.nsIContentPolicy.TYPE_DOCUMENT ||
type === Ci.nsIContentPolicy.TYPE_SUBDOCUMENT) {
this.preloadScripts(subject.URI, loadInfo);
}
}
- } else if (topic === "memory-pressure") {
+ },
+ "memory-pressure"(subject, topic, data) {
let timeout = data === "heap-minimize" ? 0 : undefined;
for (let cache of ChromeUtils.nondeterministicGetWeakSetKeys(scriptCaches)) {
cache.clear(timeout);
}
- }
+ },
+ },
+
+ observe(subject, topic, data) {
+ this.observers[topic].call(this, subject, topic, data);
},
handleEvent(event) {
let window = event.currentTarget;
if (event.target != window.document) {
// We use capturing listeners so we have precedence over content script
// listeners, but only care about events targeted to the element we're
// listening on.