Bug 1261857 - [webext] use addContentGlobal/removeContentGlobal to track/untrack globals associated to the content window.
MozReview-Commit-ID: 3zkozKcOt0r
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -35,16 +35,19 @@ XPCOMUtils.defineLazyModuleGetter(this,
"resource://gre/modules/PrivateBrowsingUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PromiseUtils",
"resource://gre/modules/PromiseUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "MessageChannel",
"resource://gre/modules/MessageChannel.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "WebNavigationFrames",
"resource://gre/modules/WebNavigationFrames.jsm");
+const {devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+const {addContentGlobal, removeContentGlobal} = devtools.require("devtools/server/content-globals");
+
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
var {
runSafeSyncWithoutClone,
BaseContext,
LocaleData,
Messenger,
injectAPI,
flushJarCache,
@@ -337,16 +340,27 @@ class ExtensionContext extends BaseConte
this.sandbox = Cu.Sandbox(prin, {
metadata,
sandboxPrototype: contentWindow,
wantXrays: true,
isWebExtensionContentScript: true,
wantGlobalProperties: ["XMLHttpRequest"],
});
+
+ try {
+ // add the content global to the devtools tracked globals
+ this.devtoolsGlobalDetails = {
+ global: this.sandbox,
+ "inner-window-id": innerWindowID,
+ };
+ addContentGlobal(this.devtoolsGlobalDetails);
+ } catch (e) {
+ Cu.reportError(`Exception on devtools addContentGlobal: ${e} - ${e.stack}.`);
+ }
}
let delegate = {
getSender(context, target, sender) {
// Nothing to do here.
},
};
@@ -407,16 +421,26 @@ class ExtensionContext extends BaseConte
// Overwrite the content script APIs with an empty object if the APIs objects are still
// defined in the content window (See Bug 1214658 for rationale).
if (this.isExtensionPage && !Cu.isDeadWrapper(this.contentWindow) &&
Cu.waiveXrays(this.contentWindow).browser === this.chromeObj) {
Cu.createObjectIn(this.contentWindow, {defineAs: "browser"});
Cu.createObjectIn(this.contentWindow, {defineAs: "chrome"});
}
+
+ if (this.devtoolsGlobalDetails) {
+ try {
+ removeContentGlobal(this.devtoolsGlobalDetails);
+ this.devtoolsGlobalDetails = null;
+ } catch (e) {
+ Cu.reportError(`Exception on devtools removeContentGlobal: ${e} - ${e.stack}.`);
+ }
+ }
+
Cu.nukeSandbox(this.sandbox);
this.sandbox = null;
}
}
// Responsible for creating ExtensionContexts and injecting content
// scripts into them when new documents are created.
DocumentManager = {