Bug 1401343 - Expose a 'tabs' getter in the child-process actor. r=jryans,ochameau draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 28 Sep 2017 11:28:26 -0700
changeset 672067 8b966b825b798f2206d803c7d3154bc288cdedb6
parent 669354 3d72fdb0e561ea59d9e5850c3e71367dbb8a7148
child 680129 60cb0914410e5bc86f6183a3fbc4d88ed0853645
push id82146
push usermozilla@noorenberghe.ca
push dateThu, 28 Sep 2017 18:28:57 +0000
reviewersjryans, ochameau
bugs1401343
milestone58.0a1
Bug 1401343 - Expose a 'tabs' getter in the child-process actor. r=jryans,ochameau MozReview-Commit-ID: U5xB35kBv8
devtools/server/actors/child-process.js
--- 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;