Bug 1643180 - Part 7: Separate url-only file handling from url/line/column handling. r=jlast

Differential Revision: https://phabricator.services.mozilla.com/D78388
This commit is contained in:
Logan Smyth 2020-06-05 22:20:57 +00:00
Родитель 3ce268493b
Коммит 5a1f19d2c4
4 изменённых файлов: 71 добавлений и 4 удалений

Просмотреть файл

@ -3972,6 +3972,23 @@ Toolbox.prototype = {
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:".
@ -3983,6 +4000,16 @@ Toolbox.prototype = {
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);
},
@ -4001,6 +4028,16 @@ Toolbox.prototype = {
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,
@ -4023,6 +4060,20 @@ Toolbox.prototype = {
}
},
/**
* 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.
@ -4042,6 +4093,16 @@ Toolbox.prototype = {
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,

Просмотреть файл

@ -1099,9 +1099,9 @@ MarkupView.prototype = {
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;
})

Просмотреть файл

@ -434,7 +434,7 @@ class RequestListContextMenu {
*/
openInDebugger(url) {
const toolbox = gDevTools.getToolbox(this.props.connector.getTabTarget());
toolbox.viewSourceInDebugger(url, 0);
toolbox.viewGeneratedSourceInDebugger(url);
}
/**
@ -442,7 +442,7 @@ class RequestListContextMenu {
*/
openInStyleEditor(url) {
const toolbox = gDevTools.getToolbox(this.props.connector.getTabTarget());
toolbox.viewSourceInStyleEditorByURL(url, 0);
toolbox.viewGeneratedSourceInStyleEditor(url);
}
/**

Просмотреть файл

@ -183,6 +183,12 @@ async function getOriginalLocation(
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({