Bug 1346316 - Add URL and title to Browser Content Toolbox. r=ochameau draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Tue, 18 Apr 2017 16:54:59 -0500
changeset 564715 52db792735e11042f46e86ccd6b81cf571702091
parent 564714 bc096bdba034ab4d6a2a34404f1d8d6bd3826980
child 624810 457d5a3999331b4a99fcdc7d6d6bfb76461d1316
push id54673
push userbmo:jryans@gmail.com
push dateTue, 18 Apr 2017 21:57:02 +0000
reviewersochameau
bugs1346316
milestone55.0a1
Bug 1346316 - Add URL and title to Browser Content Toolbox. r=ochameau MozReview-Commit-ID: DB3GYavw5WV
devtools/server/actors/child-process.js
--- a/devtools/server/actors/child-process.js
+++ b/devtools/server/actors/child-process.js
@@ -25,22 +25,23 @@ function ChildProcessActor(connection, o
   // Use a see-everything debugger
   this.makeDebugger = makeDebugger.bind(null, {
     findDebuggees: dbg => dbg.findAllGlobals(),
     shouldAddNewGlobalAsDebuggee: global => true
   });
 
   let sandboxPrototype = {};
   if (outerWindowID) {
-    let currentWindow = Services.wm.getOuterWindowWithId(outerWindowID);
-    if (currentWindow) {
-      let contentMM = currentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
-                                   .getInterface(Ci.nsIDocShell)
-                                   .QueryInterface(Ci.nsIInterfaceRequestor)
-                                   .getInterface(Ci.nsIContentFrameMessageManager);
+    this._currentWindow = Services.wm.getOuterWindowWithId(outerWindowID);
+    if (this._currentWindow) {
+      let contentMM = this._currentWindow
+                          .QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsIDocShell)
+                          .QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsIContentFrameMessageManager);
       sandboxPrototype = contentMM;
     }
   }
 
   // Scope into which the webconsole executes:
   // If an outerWindowID was supplied, then a chrome sandbox that has the content frame
   // message manager as its prototype (similar to the frame script environement).
   // If there's no outerWindowID, then this will be an empty chrome sandbox.
@@ -63,47 +64,85 @@ ChildProcessActor.prototype = {
   get isRootActor() {
     return true;
   },
 
   get exited() {
     return !this._contextPool;
   },
 
-  get url() {
-    return undefined;
-  },
-
   get window() {
     return this._consoleScope;
   },
 
   get sources() {
     if (!this._sources) {
       assert(this.threadActor, "threadActor should exist when creating sources.");
       this._sources = new TabSources(this.threadActor);
     }
     return this._sources;
   },
 
+  get docShell() {
+    if (!this._currentWindow) {
+      return null;
+    }
+    return this._currentWindow
+               .QueryInterface(Ci.nsIInterfaceRequestor)
+               .getInterface(Ci.nsIDocShell);
+  },
+
+  get webNavigation() {
+    if (!this.docShell) {
+      return null;
+    }
+    return this.docShell
+               .QueryInterface(Ci.nsIInterfaceRequestor)
+               .getInterface(Ci.nsIWebNavigation);
+  },
+
+  get contentDocument() {
+    if (!this.webNavigation) {
+      return null;
+    }
+    return this.webNavigation.document;
+  },
+
+  get title() {
+    if (!this.contentDocument) {
+      return null;
+    }
+    return this.contentDocument.title;
+  },
+
+  get url() {
+    if (!this.webNavigation || !this.webNavigation.currentURI) {
+      return null;
+    }
+    return this.webNavigation.currentURI.spec;
+  },
+
   form: function () {
     if (!this._consoleActor) {
       this._consoleActor = new WebConsoleActor(this.conn, this);
       this._contextPool.addActor(this._consoleActor);
     }
 
     if (!this.threadActor) {
       this.threadActor = new ChromeDebuggerActor(this.conn, this);
       this._contextPool.addActor(this.threadActor);
     }
 
     return {
       actor: this.actorID,
       name: "Content process",
 
+      url: this.url,
+      title: this.title,
+
       consoleActor: this._consoleActor.actorID,
       chromeDebugger: this.threadActor.actorID,
 
       traits: {
         highlightable: false,
         networkMonitor: false,
       },
     };
@@ -133,16 +172,18 @@ ChildProcessActor.prototype = {
   },
 
   _onWorkerListChanged: function () {
     this.conn.send({ from: this.actorID, type: "workerListChanged" });
     this._workerList.onListChanged = null;
   },
 
   destroy: function () {
+    this._currentWindow = null;
+
     this.conn.removeActorPool(this._contextPool);
     this._contextPool = null;
 
     // Tell the live lists we aren't watching any more.
     if (this._workerList) {
       this._workerList.onListChanged = null;
     }
   },