Bug 1401343 - Expose a 'tabs' getter in the child-process actor. r=jryans,ochameau
MozReview-Commit-ID: U5xB35kBv8
--- a/devtools/server/actors/child-process.js
+++ b/devtools/server/actors/child-process.js
@@ -1,15 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { Cc, Ci, Cu } = require("chrome");
+const Services = require("Services");
const { ChromeDebuggerActor } = require("devtools/server/actors/script");
const { WebConsoleActor } = require("devtools/server/actors/webconsole");
const makeDebugger = require("devtools/server/actors/utils/make-debugger");
const { ActorPool } = require("devtools/server/main");
const { assert } = require("devtools/shared/DevToolsUtils");
const { TabSources } = require("./utils/TabSources");
@@ -22,21 +23,40 @@ function ChildProcessActor(connection) {
this.threadActor = null;
// Use a see-everything debugger
this.makeDebugger = makeDebugger.bind(null, {
findDebuggees: dbg => dbg.findAllGlobals(),
shouldAddNewGlobalAsDebuggee: global => true
});
+ let sandboxPrototype = {
+ get tabs() {
+ let tabs = [];
+ let windowEnumerator = Services.ww.getWindowEnumerator();
+ while (windowEnumerator.hasMoreElements()) {
+ let window = windowEnumerator.getNext().QueryInterface(Ci.nsIDOMWindow);
+ let tabChildGlobal = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDocShell)
+ .sameTypeRootTreeItem
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIContentFrameMessageManager);
+ tabs.push(tabChildGlobal);
+ }
+ return tabs;
+ },
+ };
+
// Scope into which the webconsole executes:
- // An empty sandbox with chrome privileges
+ // A sandbox with chrome privileges with a `tabs` getter.
let systemPrincipal = Cc["@mozilla.org/systemprincipal;1"]
.createInstance(Ci.nsIPrincipal);
- let sandbox = Cu.Sandbox(systemPrincipal);
+ let sandbox = Cu.Sandbox(systemPrincipal, {
+ sandboxPrototype,
+ });
this._consoleScope = sandbox;
this._workerList = null;
this._workerActorPool = null;
this._onWorkerListChanged = this._onWorkerListChanged.bind(this);
}
exports.ChildProcessActor = ChildProcessActor;