Bug 1643180 - Part 7: Separate url-only file handling from url/line/column handling. r=jlast
authorLogan Smyth <loganfsmyth@gmail.com>
Fri, 05 Jun 2020 22:20:57 +0000
changeset 534226 f5f4f276e1711757b993dd454def121df87cf3ec
parent 534225 e3e927efe0d0220d919ee19a42c81a88090c7be6
child 534227 6e99a3e6c77b16b41f40d0edaada99a3e47a1927
push id37484
push userdluca@mozilla.com
push dateSat, 06 Jun 2020 09:46:03 +0000
treeherdermozilla-central@6237102f005d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast
bugs1643180
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1643180 - Part 7: Separate url-only file handling from url/line/column handling. r=jlast Differential Revision: https://phabricator.services.mozilla.com/D78388
devtools/client/framework/toolbox.js
devtools/client/inspector/markup/markup.js
devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
devtools/client/shared/view-source.js
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -3968,26 +3968,53 @@ Toolbox.prototype = {
   /**
    * Returns gViewSourceUtils for viewing source.
    */
   get gViewSourceUtils() {
     return this.win.gViewSourceUtils;
   },
 
   /**
+   * Open a CSS file when there is no line or column information available.
+   *
+   * @param {string} url The URL of the CSS file to open.
+   */
+  viewGeneratedSourceInStyleEditor: async function(url) {
+    if (typeof url !== "string") {
+      console.warn("Failed to open generated source, no url given");
+      return;
+    }
+
+    // The style editor hides the generated file if the file has original
+    // sources, so we have no choice but to open whichever original file
+    // corresponds to the first line of the generated file.
+    return viewSource.viewSourceInStyleEditor(this, url, 1);
+  },
+
+  /**
    * Given a URL for a stylesheet (generated or original), open in the style
    * editor if possible. Falls back to plain "view-source:".
    * If the stylesheet has a sourcemap, we will attempt to open the original
    * version of the file instead of the generated version.
    */
   viewSourceInStyleEditorByURL: async function(url, line, column) {
     if (typeof url !== "string") {
       console.warn("Failed to open source, no url given");
       return;
     }
+    if (typeof line !== "number") {
+      console.warn(
+        "No line given when navigating to source. If you're seeing this, there is a bug."
+      );
+
+      // This is a fallback in case of programming errors, but in a perfect
+      // world, viewSourceInStyleEditorByURL would always get a line/colum.
+      line = 1;
+      column = null;
+    }
 
     return viewSource.viewSourceInStyleEditor(this, url, line, column);
   },
 
   /**
    * Opens source in style editor. Falls back to plain "view-source:".
    * If the stylesheet has a sourcemap, we will attempt to open the original
    * version of the file instead of the generated version.
@@ -3996,16 +4023,26 @@ Toolbox.prototype = {
     stylesheetFront,
     line,
     column
   ) {
     if (!stylesheetFront || typeof stylesheetFront !== "object") {
       console.warn("Failed to open source, no stylesheet given");
       return;
     }
+    if (typeof line !== "number") {
+      console.warn(
+        "No line given when navigating to source. If you're seeing this, there is a bug."
+      );
+
+      // This is a fallback in case of programming errors, but in a perfect
+      // world, viewSourceInStyleEditorByFront would always get a line/colum.
+      line = 1;
+      column = null;
+    }
 
     return viewSource.viewSourceInStyleEditor(
       this,
       stylesheetFront,
       line,
       column
     );
   },
@@ -4019,16 +4056,30 @@ Toolbox.prototype = {
       inspectFromAnnotation
     );
     if (nodeFound) {
       await this.selectTool("inspector");
     }
   },
 
   /**
+   * Open a JS file when there is no line or column information available.
+   *
+   * @param {string} url The URL of the JS file to open.
+   */
+  viewGeneratedSourceInDebugger: async function(url) {
+    if (typeof url !== "string") {
+      console.warn("Failed to open generated source, no url given");
+      return;
+    }
+
+    return viewSource.viewSourceInDebugger(this, url, null, null, null, null);
+  },
+
+  /**
    * Opens source in debugger, the sourcemapped location will be selected in
    * the debugger panel, if the given location resolves to a know sourcemapped one.
    *
    * Falls back to plain "view-source:".
    *
    * @see devtools/client/shared/source-utils.js
    */
   viewSourceInDebugger: async function(
@@ -4037,16 +4088,26 @@ Toolbox.prototype = {
     sourceColumn,
     sourceId,
     reason
   ) {
     if (typeof sourceURL !== "string" && typeof sourceId !== "string") {
       console.warn("Failed to open generated source, no url/id given");
       return;
     }
+    if (typeof sourceLine !== "number") {
+      console.warn(
+        "No line given when navigating to source. If you're seeing this, there is a bug."
+      );
+
+      // This is a fallback in case of programming errors, but in a perfect
+      // world, viewSourceInDebugger would always get a line/colum.
+      sourceLine = 1;
+      sourceColumn = null;
+    }
 
     return viewSource.viewSourceInDebugger(
       this,
       sourceURL,
       sourceLine,
       sourceColumn,
       sourceId,
       reason
--- a/devtools/client/inspector/markup/markup.js
+++ b/devtools/client/inspector/markup/markup.js
@@ -1094,19 +1094,19 @@ MarkupView.prototype = {
     if (type === "uri" || type === "cssresource" || type === "jsresource") {
       // Open link in a new tab.
       nodeFront.inspectorFront
         .resolveRelativeURL(link, this.inspector.selection.nodeFront)
         .then(url => {
           if (type === "uri") {
             openContentLink(url);
           } else if (type === "cssresource") {
-            return this.toolbox.viewSourceInStyleEditorByURL(url);
+            return this.toolbox.viewGeneratedSourceInStyleEditor(url);
           } else if (type === "jsresource") {
-            return this.toolbox.viewSourceInDebugger(url);
+            return this.toolbox.viewGeneratedSourceInDebugger(url);
           }
           return null;
         })
         .catch(console.error);
     } else if (type == "idref") {
       // Select the node in the same document.
       nodeFront.walkerFront
         .document(nodeFront)
--- a/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
+++ b/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
@@ -429,25 +429,25 @@ class RequestListContextMenu {
     });
   }
 
   /**
    * Opens selected item in the debugger
    */
   openInDebugger(url) {
     const toolbox = gDevTools.getToolbox(this.props.connector.getTabTarget());
-    toolbox.viewSourceInDebugger(url, 0);
+    toolbox.viewGeneratedSourceInDebugger(url);
   }
 
   /**
    * Opens selected item in the style editor
    */
   openInStyleEditor(url) {
     const toolbox = gDevTools.getToolbox(this.props.connector.getTabTarget());
-    toolbox.viewSourceInStyleEditorByURL(url, 0);
+    toolbox.viewGeneratedSourceInStyleEditor(url);
   }
 
   /**
    * Copy the request url from the currently selected item.
    */
   copyUrl(url) {
     copyString(url);
   }
--- a/devtools/client/shared/view-source.js
+++ b/devtools/client/shared/view-source.js
@@ -178,16 +178,22 @@ async function getViewSourceInDebuggerLo
 }
 
 async function getOriginalLocation(
   toolbox,
   generatedID,
   generatedLine,
   generatedColumn
 ) {
+  // If there is no line number, then there's no chance that we'll get back
+  // a useful original location.
+  if (typeof generatedLine !== "number") {
+    return null;
+  }
+
   let originalLocation = null;
   try {
     originalLocation = await toolbox.sourceMapService.getOriginalLocation({
       sourceId: generatedID,
       line: generatedLine,
       column: generatedColumn,
     });
     if (originalLocation && originalLocation.sourceId === generatedID) {