Skip to content

Commit

Permalink
Bug 1285557 - Create a WebExtensionAddonActor based on ChromeActor an…
Browse files Browse the repository at this point in the history
…d TabActor. r=jryans

MozReview-Commit-ID: 70sLUzqHHsl

--HG--
rename : devtools/server/actors/chrome.js => devtools/server/actors/webextension.js
extra : rebase_source : 4e15cd90658dcc28e8cb90414c55cd66865c711e
  • Loading branch information
rpl committed Jul 25, 2016
1 parent 4425861 commit d01ad0f
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 15 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ devtools/server/**
!devtools/server/actors/inspector.js
!devtools/server/actors/highlighters/eye-dropper.js
!devtools/server/actors/webbrowser.js
!devtools/server/actors/webextension.js
!devtools/server/actors/styles.js
!devtools/server/actors/string.js
!devtools/server/actors/csscoverage.js
Expand Down
14 changes: 7 additions & 7 deletions devtools/client/framework/attach-thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ function attachThread(toolbox) {
});
};

if (target.isAddon) {
// Attaching an addon
if (target.isTabActor) {
// Attaching a tab, a browser process, or a WebExtensions add-on.
target.activeTab.attachThread(threadOptions, handleResponse);
} else if (target.isAddon) {
// Attaching a legacy addon.
target.client.attachAddon(actor, res => {
target.client.attachThread(res.threadActor, handleResponse);
});
} else if (target.isTabActor) {
// Attaching a normal thread
target.activeTab.attachThread(threadOptions, handleResponse);
} else {
// Attaching the browser debugger
} else {
// Attaching an old browser debugger or a content process.
target.client.attachThread(chromeDebugger, handleResponse);
}

Expand Down
9 changes: 8 additions & 1 deletion devtools/client/framework/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,15 @@ TabTarget.prototype = {
},

get isAddon() {
return !!(this._form && this._form.actor && (
this._form.actor.match(/conn\d+\.addon\d+/) ||
this._form.actor.match(/conn\d+\.webExtension\d+/)
));
},

get isWebExtension() {
return !!(this._form && this._form.actor &&
this._form.actor.match(/conn\d+\.addon\d+/));
this._form.actor.match(/conn\d+\.webExtension\d+/));
},

get isLocalTab() {
Expand Down
6 changes: 5 additions & 1 deletion devtools/client/framework/toolbox-process-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ var connect = Task.async(function*() {
if (addonID) {
gClient.listAddons(({addons}) => {
let addonActor = addons.filter(addon => addon.id === addonID).pop();
openToolbox({ form: addonActor, chrome: true, isTabActor: false });
openToolbox({
form: addonActor,
chrome: true,
isTabActor: addonActor.isWebExtension ? true : false
});
});
} else {
gClient.getProcess().then(aResponse => {
Expand Down
2 changes: 1 addition & 1 deletion devtools/client/framework/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ Toolbox.prototype = {
* Add buttons to the UI as specified in the devtools.toolbox.toolbarSpec pref
*/
_buildButtons: function () {
if (!this.target.isAddon) {
if (!this.target.isAddon || this.target.isWebExtension) {
this._buildPickerButton();
}

Expand Down
3 changes: 3 additions & 0 deletions devtools/server/actors/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ BrowserAddonActor.prototype = {

if (this.attached) {
this.onDetach();

// The BrowserAddonActor is not a TabActor and it has to send
// "tabDetached" directly to close the devtools toolbox window.
this.conn.send({ from: this.actorID, type: "tabDetached" });
}

Expand Down
1 change: 1 addition & 0 deletions devtools/server/actors/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ DevToolsModules(
'webaudio.js',
'webbrowser.js',
'webconsole.js',
'webextension.js',
'webgl.js',
'worker.js',
)
33 changes: 29 additions & 4 deletions devtools/server/actors/webbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ loader.lazyRequireGetter(this, "RootActor", "devtools/server/actors/root", true)
loader.lazyRequireGetter(this, "ThreadActor", "devtools/server/actors/script", true);
loader.lazyRequireGetter(this, "unwrapDebuggerObjectGlobal", "devtools/server/actors/script", true);
loader.lazyRequireGetter(this, "BrowserAddonActor", "devtools/server/actors/addon", true);
loader.lazyRequireGetter(this, "WebExtensionActor", "devtools/server/actors/webextension", true);
loader.lazyRequireGetter(this, "WorkerActorList", "devtools/server/actors/worker", true);
loader.lazyRequireGetter(this, "ServiceWorkerRegistrationActorList", "devtools/server/actors/worker", true);
loader.lazyRequireGetter(this, "ProcessActorList", "devtools/server/actors/process", true);
Expand Down Expand Up @@ -889,6 +890,14 @@ function TabActor(connection) {
TabActor.prototype = {
traits: null,

// Optional console API listener options (e.g. used by the WebExtensionActor to
// filter console messages by addonID), set to an empty (no options) object by default.
consoleAPIListenerOptions: {},

// Optional TabSources filter function (e.g. used by the WebExtensionActor to filter
// sources by addonID), allow all sources by default.
_allowSource() { return true; },

get exited() {
return this._exited;
},
Expand Down Expand Up @@ -1059,7 +1068,7 @@ TabActor.prototype = {

get sources() {
if (!this._sources) {
this._sources = new TabSources(this.threadActor);
this._sources = new TabSources(this.threadActor, this._allowSource);
}
return this._sources;
},
Expand Down Expand Up @@ -1364,17 +1373,28 @@ TabActor.prototype = {
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
}

// Collect the addonID from the document origin attributes.
let addonID = window.document.nodePrincipal.originAttributes.addonId;

return {
id: id,
id,
parentID,
addonID,
url: window.location.href,
title: window.document.title,
parentID: parentID
};
});
},

_notifyDocShellsUpdate(docshells) {
let windows = this._docShellsToWindows(docshells);

// Do not send the `frameUpdate` event if the windows array is empty.
if (windows.length == 0) {
return;
}

this.conn.send({ from: this.actorID,
type: "frameUpdate",
frames: windows
Expand Down Expand Up @@ -2267,7 +2287,12 @@ BrowserAddonList.prototype.getList = function () {
for (let addon of addons) {
let actor = this._actorByAddonId.get(addon.id);
if (!actor) {
actor = new BrowserAddonActor(this._connection, addon);
if (addon.isWebExtension) {
actor = new WebExtensionActor(this._connection, addon);
} else {
actor = new BrowserAddonActor(this._connection, addon);
}

this._actorByAddonId.set(addon.id, actor);
}
}
Expand Down
5 changes: 4 additions & 1 deletion devtools/server/actors/webconsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,11 @@ WebConsoleActor.prototype =
break;
case "ConsoleAPI":
if (!this.consoleAPIListener) {
// Create the consoleAPIListener (and apply the filtering options defined
// in the parent actor).
this.consoleAPIListener =
new ConsoleAPIListener(window, this);
new ConsoleAPIListener(window, this,
this.parentActor.consoleAPIListenerOptions);
this.consoleAPIListener.init();
}
startedListeners.push(listener);
Expand Down
Loading

0 comments on commit d01ad0f

Please sign in to comment.