Created
April 6, 2016 12:41
-
-
Save rpl/9f67f45eab824de84dbfab6495295d26 to your computer and use it in GitHub Desktop.
recognize content scripts on developer toolbox first opened
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/devtools/server/actors/webbrowser.js b/devtools/server/actors/webbrowser.js | |
--- a/devtools/server/actors/webbrowser.js | |
+++ b/devtools/server/actors/webbrowser.js | |
@@ -30,16 +30,17 @@ loader.lazyRequireGetter(this, "ProcessA | |
loader.lazyImporter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm"); | |
// Assumptions on events module: | |
// events needs to be dispatched synchronously, | |
// by calling the listeners in the order or registration. | |
loader.lazyRequireGetter(this, "events", "sdk/event/core"); | |
loader.lazyRequireGetter(this, "StyleSheetActor", "devtools/server/actors/stylesheets", true); | |
+loader.lazyRequireGetter(this, "getContentGlobals", "devtools/server/content-globals", true); | |
function getWindowID(window) { | |
return window.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIDOMWindowUtils) | |
.currentInnerWindowID; | |
} | |
function getDocShellChromeEventHandler(docShell) { | |
@@ -713,18 +714,21 @@ function TabActor(aConnection) | |
this._sources = null; | |
// Map of DOM stylesheets to StyleSheetActors | |
this._styleSheetActors = new Map(); | |
this._shouldAddNewGlobalAsDebuggee = this._shouldAddNewGlobalAsDebuggee.bind(this); | |
this.makeDebugger = makeDebugger.bind(null, { | |
- findDebuggees: () => this.windows, | |
- shouldAddNewGlobalAsDebuggee: this._shouldAddNewGlobalAsDebuggee | |
+ findDebuggees: () => { | |
+ // add the registered content script globals to the available debuggees. | |
+ return [].concat(this.windows, this.contentGlobals); | |
+ }, | |
+ shouldAddNewGlobalAsDebuggee: this._shouldAddNewGlobalAsDebuggee, | |
}); | |
// Flag eventually overloaded by sub classes in order to watch new docshells | |
// Used on b2g to catch activity frames and in chrome to list all frames | |
this.listenForNewDocShells = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT; | |
this.traits = { | |
reconfigure: true, | |
@@ -801,16 +805,27 @@ TabActor.prototype = { | |
return this.docShell | |
.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIDOMWindow); | |
} | |
return null; | |
}, | |
/** | |
+ * Getter for the existent contentGlobals for the innerWindowId of the tab content's DOM window. | |
+ */ | |
+ get contentGlobals() { | |
+ if (this.window) { | |
+ return getContentGlobals({"inner-window-id": getWindowID(this.window)}); | |
+ } | |
+ | |
+ return []; | |
+ }, | |
+ | |
+ /** | |
* Getter for the list of all content DOM windows in this tabActor | |
* @return {Array} | |
*/ | |
get windows() { | |
return this.docShells.map(docShell => { | |
return docShell.QueryInterface(Ci.nsIInterfaceRequestor) | |
.getInterface(Ci.nsIDOMWindow); | |
}); | |
@@ -891,16 +906,26 @@ TabActor.prototype = { | |
// currentURI. | |
return null; | |
}, | |
get sources() { | |
if (!this._sources) { | |
assert(this.threadActor, "threadActor should exist when creating sources."); | |
this._sources = new TabSources(this.threadActor); | |
+ | |
+ // add the sources of the registered content scripts. | |
+ this.contentGlobals.forEach(global => { | |
+ this.threadActor.dbg | |
+ .findScripts({global}) | |
+ .forEach(({ source }) => { | |
+ dump(`*** CANARY SOURCES: ${source.introductionType}\n`); | |
+ this._sources.createSourceActors(source); | |
+ }); | |
+ }); | |
} | |
return this._sources; | |
}, | |
/** | |
* This is called by BrowserTabList.getList for existing tab actors prior to | |
* calling |form| below. It can be used to do any async work that may be | |
* needed to assemble the form. | |
@@ -1044,16 +1069,21 @@ TabActor.prototype = { | |
this._originalWindow = this.window; | |
// Ensure replying to attach() request first | |
// before notifying about new docshells. | |
DevToolsUtils.executeSoon(() => this._watchDocshells()); | |
} | |
this._attached = true; | |
+ | |
+ // NOTE: add the debuggee here to intercept any registered content script sources. | |
+ if (this.contentGlobals.length) { | |
+ this.threadActor.dbg.addDebuggees(); | |
+ } | |
}, | |
_watchDocshells: function BTA_watchDocshells() { | |
// In child processes, we watch all docshells living in the process. | |
if (this.listenForNewDocShells) { | |
Services.obs.addObserver(this, "webnavigation-create", false); | |
} | |
Services.obs.addObserver(this, "webnavigation-destroy", false); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment