Bug 1067325 - Allow DevTools to use view source in tab. r=jsantell
authorJ. Ryan Stinnett <jryans@gmail.com>
Mon, 18 May 2015 11:10:41 -0500
changeset 265172 732494b7a816f351531cf94a3238c24f5c06b447
parent 265171 4f686a4f83ddd276e7a5ebd391a7b120171769aa
child 550976 72f4579aed3fdd43255243328399a446a3bf9e32
push id2101
push userjryans@gmail.com
push dateMon, 18 May 2015 16:11:00 +0000
reviewersjsantell
bugs1067325
milestone41.0a1
Bug 1067325 - Allow DevTools to use view source in tab. r=jsantell
browser/devtools/shared/source-utils.js
browser/devtools/webconsole/hudservice.js
--- a/browser/devtools/shared/source-utils.js
+++ b/browser/devtools/shared/source-utils.js
@@ -118,11 +118,20 @@ exports.viewSourceInScratchpad = Task.as
  *
  * @param {Toolbox} toolbox
  * @param {string} sourceURL
  * @param {number} sourceLine
  *
  * @return {Promise}
  */
 exports.viewSource = Task.async(function *(toolbox, sourceURL, sourceLine) {
+  // Attempt to access view source via a browser first, which may display it in
+  // a tab, if enabled.
+  let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
+  if (browserWin) {
+    return browserWin.BrowserViewSourceOfDocument({
+      URL: sourceURL,
+      lineNumber: sourceLine
+    });
+  }
   let utils = toolbox.gViewSourceUtils;
   utils.viewSource(sourceURL, null, toolbox.doc, sourceLine || 0);
 });
--- a/browser/devtools/webconsole/hudservice.js
+++ b/browser/devtools/webconsole/hudservice.js
@@ -429,16 +429,25 @@ WebConsole.prototype = {
    * Open a link in Firefox's view source.
    *
    * @param string aSourceURL
    *        The URL of the file.
    * @param integer aSourceLine
    *        The line number which should be highlighted.
    */
   viewSource: function WC_viewSource(aSourceURL, aSourceLine) {
+    // Attempt to access view source via a browser first, which may display it in
+    // a tab, if enabled.
+    let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
+    if (browserWin) {
+      return browserWin.BrowserViewSourceOfDocument({
+        URL: aSourceURL,
+        lineNumber: aSourceLine
+      });
+    }
     this.gViewSourceUtils.viewSource(aSourceURL, null, this.iframeWindow.document, aSourceLine || 0);
   },
 
   /**
    * Tries to open a Stylesheet file related to the web page for the web console
    * instance in the Style Editor. If the file is not found, it is opened in
    * source view instead.
    *