Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Unified Diff: third_party/WebKit/Source/devtools/front_end/bindings/CompilerScriptMapping.js

Issue 2869293002: DevTools: make CompilerScriptMapping / SASSSourceMapping manage UISourceCodes (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/bindings/CompilerScriptMapping.js
diff --git a/third_party/WebKit/Source/devtools/front_end/bindings/CompilerScriptMapping.js b/third_party/WebKit/Source/devtools/front_end/bindings/CompilerScriptMapping.js
index 8ff4c7f32d14d7a318d4747efe8115547a205353..3f44fc67e1918ddb37707ecb4da2e4d972eeea07 100644
--- a/third_party/WebKit/Source/devtools/front_end/bindings/CompilerScriptMapping.js
+++ b/third_party/WebKit/Source/devtools/front_end/bindings/CompilerScriptMapping.js
@@ -35,24 +35,29 @@ Bindings.CompilerScriptMapping = class {
/**
* @param {!SDK.DebuggerModel} debuggerModel
* @param {!Workspace.Workspace} workspace
- * @param {!Bindings.NetworkProject} networkProject
* @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
*/
- constructor(debuggerModel, workspace, networkProject, debuggerWorkspaceBinding) {
+ constructor(debuggerModel, workspace, debuggerWorkspaceBinding) {
this._debuggerModel = debuggerModel;
this._sourceMapManager = this._debuggerModel.sourceMapManager();
this._workspace = workspace;
- this._networkProject = networkProject;
this._debuggerWorkspaceBinding = debuggerWorkspaceBinding;
- /** @type {!Multimap<!SDK.Script, !Workspace.UISourceCode>} */
- this._scriptSources = new Multimap();
+ var target = debuggerModel.target();
+ this._regularProject = new Bindings.ContentProviderBasedProject(
+ workspace, Bindings.CompilerScriptMapping.projectId(target, false /* isContentScript */),
+ Workspace.projectTypes.Network, '', false /* isServiceProject */);
+ this._contentScriptsProject = new Bindings.ContentProviderBasedProject(
+ workspace, Bindings.CompilerScriptMapping.projectId(target, true /* isContentScript */),
+ Workspace.projectTypes.ContentScripts, '', false /* isServiceProject */);
+ Bindings.NetworkProject.setTargetForProject(this._regularProject, target);
+ Bindings.NetworkProject.setTargetForProject(this._contentScriptsProject, target);
+
/** @type {!Map<!SDK.Script, !Workspace.UISourceCode>} */
this._stubUISourceCodes = new Map();
- var projectId = Bindings.CompilerScriptMapping.projectIdForTarget(this._debuggerModel.target());
this._stubProject = new Bindings.ContentProviderBasedProject(
- workspace, projectId, Workspace.projectTypes.Service, '', true /* isServiceProject */);
+ workspace, 'stub:jsSourceMaps:' + target.id(), Workspace.projectTypes.Service, '', true /* isServiceProject */);
this._eventListeners = [
this._sourceMapManager.addEventListener(
SDK.SourceMapManager.Events.SourceMapWillAttach, this._sourceMapWillAttach, this),
@@ -91,16 +96,19 @@ Bindings.CompilerScriptMapping = class {
* @return {?string}
*/
static uiSourceCodeOrigin(uiSourceCode) {
- var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol];
- return script ? script.sourceURL : null;
+ var sourceMap = uiSourceCode[Bindings.CompilerScriptMapping._sourceMapSymbol];
+ if (!sourceMap)
+ return null;
+ return sourceMap.compiledURL();
}
/**
* @param {!SDK.Target} target
+ * @param {boolean} isContentScript
* @return {string}
*/
- static projectIdForTarget(target) {
- return 'compiler-script-project:' + target.id();
+ static projectId(target, isContentScript) {
+ return (isContentScript ? 'extensions:' : '') + 'jsSourceMaps:' + target.id();
dgozman 2017/05/10 18:10:33 inline it?
dgozman 2017/05/10 18:10:33 Let's keep the equal amount of ':' in project ids.
lushnikov 2017/05/10 22:24:32 Done.
lushnikov 2017/05/10 22:24:32 Done.
}
/**
@@ -115,6 +123,15 @@ Bindings.CompilerScriptMapping = class {
return !!sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumber);
}
+ /**
+ * @param {string} url
+ * @param {boolean} isContentScript
+ */
+ uiSourceCodeForURL(url, isContentScript) {
+ return isContentScript ? this._contentScriptsProject.uiSourceCodeForURL(url) :
+ this._regularProject.uiSourceCodeForURL(url);
+ }
+
/**
* @override
* @param {!SDK.DebuggerModel.Location} rawLocation
@@ -137,8 +154,8 @@ Bindings.CompilerScriptMapping = class {
var entry = sourceMap.findEntry(lineNumber, columnNumber);
if (!entry || !entry.sourceURL)
return null;
- var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL(
- this._workspace, /** @type {string} */ (entry.sourceURL), script);
+ var uiSourceCode = script.isContentScript() ? this._contentScriptsProject.uiSourceCodeForURL(entry.sourceURL) :
+ this._regularProject.uiSourceCodeForURL(entry.sourceURL);
if (!uiSourceCode)
return null;
return uiSourceCode.uiLocation(
@@ -153,12 +170,13 @@ Bindings.CompilerScriptMapping = class {
* @return {?SDK.DebuggerModel.Location}
*/
uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) {
- var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol];
- if (!script)
- return null;
- var sourceMap = this._sourceMapManager.sourceMapForClient(script);
+ var sourceMap = uiSourceCode[Bindings.CompilerScriptMapping._sourceMapSymbol];
if (!sourceMap)
return null;
+ var scripts = this._sourceMapManager.clientsForSourceMap(sourceMap);
+ var script = scripts.length ? scripts[0] : null;
dgozman 2017/05/10 18:10:33 So, this is kind of wrong now?
lushnikov 2017/05/10 22:24:32 The whole thing of translating singe uiLocation in
+ if (!script)
+ return null;
var entry = sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber);
if (!entry)
return null;
@@ -204,13 +222,22 @@ Bindings.CompilerScriptMapping = class {
*/
_sourceMapDetached(event) {
var script = /** @type {!SDK.Script} */ (event.data.client);
- var sources = this._scriptSources.get(script);
- if (!sources.size)
- return;
- var frameId = script[Bindings.CompilerScriptMapping._frameIdSymbol];
- for (var uiSourceCode of sources) {
- this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSourceCode, null);
- this._networkProject.removeSourceMapFile(uiSourceCode.url(), frameId, script.isContentScript());
+ var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
+ var scripts = this._sourceMapManager.clientsForSourceMap(sourceMap);
+ scripts = scripts.filter(someScript => someScript.isContentScript() === script.isContentScript());
+ var project = script.isContentScript() ? this._contentScriptsProject : this._regularProject;
+ if (!scripts.length) {
+ for (var sourceURL of sourceMap.sourceURLs()) {
dgozman 2017/05/10 18:10:33 Let's combine both for-loops.
lushnikov 2017/05/10 22:24:32 Done.
+ var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (project.uiSourceCodeForURL(sourceURL));
+ this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSourceCode, null);
+ project.removeFile(sourceURL);
+ }
+ } else {
+ var attribution = new Set(scripts.map(script => script[Bindings.CompilerScriptMapping._frameIdSymbol]));
+ for (var sourceURL of sourceMap.sourceURLs()) {
+ var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (project.uiSourceCodeForURL(sourceURL));
+ Bindings.NetworkProject.changeFrameAttribution(uiSourceCode, attribution);
+ }
}
this._debuggerWorkspaceBinding.updateLocations(script);
}
@@ -228,7 +255,7 @@ Bindings.CompilerScriptMapping = class {
*/
maybeLoadSourceMap(script) {
var sourceMap = this._sourceMapManager.sourceMapForClient(script);
- if (!sourceMap || this._scriptSources.has(script))
+ if (!sourceMap)
return;
this._populateSourceMapSources(script, sourceMap);
}
@@ -246,14 +273,24 @@ Bindings.CompilerScriptMapping = class {
_populateSourceMapSources(script, sourceMap) {
var frameId = Bindings.frameIdForScript(script);
script[Bindings.CompilerScriptMapping._frameIdSymbol] = frameId;
+ var project = script.isContentScript() ? this._contentScriptsProject : this._regularProject;
for (var sourceURL of sourceMap.sourceURLs()) {
+ var uiSourceCode = project.uiSourceCodeForURL(sourceURL);
+ if (uiSourceCode) {
+ var attribution = Bindings.NetworkProject.frameAttribution(uiSourceCode);
+ attribution.add(frameId);
+ Bindings.NetworkProject.changeFrameAttribution(uiSourceCode, attribution);
+ continue;
+ }
+
var contentProvider = sourceMap.sourceContentProvider(sourceURL, Common.resourceTypes.SourceMapScript);
var embeddedContent = sourceMap.embeddedContentByURL(sourceURL);
- var embeddedContentLength = typeof embeddedContent === 'string' ? embeddedContent.length : null;
- var uiSourceCode = this._networkProject.addSourceMapFile(
- contentProvider, frameId, script.isContentScript(), embeddedContentLength);
- uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol] = script;
- this._scriptSources.set(script, uiSourceCode);
+ var metadata =
+ typeof embeddedContent === 'string' ? new Workspace.UISourceCodeMetadata(null, embeddedContent.length) : null;
+ uiSourceCode = project.createUISourceCode(sourceURL, contentProvider.contentType());
+ uiSourceCode[Bindings.CompilerScriptMapping._sourceMapSymbol] = sourceMap;
+ Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, new Set([frameId]));
+ project.addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata);
this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSourceCode, this);
}
this._debuggerWorkspaceBinding.updateLocations(script);
@@ -274,8 +311,7 @@ Bindings.CompilerScriptMapping = class {
* @return {boolean}
*/
uiLineHasMapping(uiSourceCode, lineNumber) {
- var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol];
- var sourceMap = script ? this._sourceMapManager.sourceMapForClient(script) : null;
+ var sourceMap = uiSourceCode[Bindings.CompilerScriptMapping._sourceMapSymbol];
if (!sourceMap)
return true;
return !!sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber);
@@ -283,9 +319,11 @@ Bindings.CompilerScriptMapping = class {
dispose() {
Common.EventTarget.removeEventListeners(this._eventListeners);
+ this._regularProject.dispose();
+ this._contentScriptsProject.dispose();
this._stubProject.dispose();
}
};
-Bindings.CompilerScriptMapping._scriptSymbol = Symbol('Bindings.CompilerScriptMapping._scriptSymbol');
-Bindings.CompilerScriptMapping._frameIdSymbol = Symbol('Bindings.CompilerScriptMapping._frameIdSymbol');
+Bindings.CompilerScriptMapping._frameIdSymbol = Symbol('Bindings.CompilerScriptMapping._frameIdSymbol');
+Bindings.CompilerScriptMapping._sourceMapSymbol = Symbol('Bindings.CompilerScriptMapping._sourceMapSymbol');

Powered by Google App Engine
This is Rietveld 408576698