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

Unified Diff: third_party/WebKit/Source/devtools/front_end/bindings/SASSSourceMapping.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/SASSSourceMapping.js
diff --git a/third_party/WebKit/Source/devtools/front_end/bindings/SASSSourceMapping.js b/third_party/WebKit/Source/devtools/front_end/bindings/SASSSourceMapping.js
index 7b73dfcfaa9adc6a70b4ffc32e06ed0462bebd1e..758b627fff100b83a1ce648f47985eb2ee198ab1 100644
--- a/third_party/WebKit/Source/devtools/front_end/bindings/SASSSourceMapping.js
+++ b/third_party/WebKit/Source/devtools/front_end/bindings/SASSSourceMapping.js
@@ -33,14 +33,25 @@
*/
Bindings.SASSSourceMapping = class {
/**
+ * @param {!SDK.Target} target
+ * @return {string}
+ */
+ static projectId(target) {
dgozman 2017/05/10 18:10:33 inline it
lushnikov 2017/05/10 22:24:32 Done.
+ return 'cssSourceMaps:' + target.id();
+ }
+
+ /**
+ * @param {!SDK.Target} target
* @param {!SDK.SourceMapManager} sourceMapManager
* @param {!Workspace.Workspace} workspace
- * @param {!Bindings.NetworkProject} networkProject
*/
- constructor(sourceMapManager, workspace, networkProject) {
+ constructor(target, sourceMapManager, workspace) {
this._sourceMapManager = sourceMapManager;
- this._networkProject = networkProject;
- this._workspace = workspace;
+ this._project = new Bindings.ContentProviderBasedProject(
+ workspace, Bindings.SASSSourceMapping.projectId(target), Workspace.projectTypes.Network, '',
+ false /* isServiceProject */);
+ Bindings.NetworkProject.setTargetForProject(this._project, target);
+
this._eventListeners = [
this._sourceMapManager.addEventListener(
SDK.SourceMapManager.Events.SourceMapAttached, this._sourceMapAttached, this),
@@ -49,9 +60,6 @@ Bindings.SASSSourceMapping = class {
this._sourceMapManager.addEventListener(
SDK.SourceMapManager.Events.SourceMapChanged, this._sourceMapChanged, this)
];
-
- /** @type {!Multimap<string, !SDK.CSSStyleSheetHeader>} */
- this._sourceMapIdToHeaders = new Multimap();
}
/**
@@ -60,36 +68,29 @@ Bindings.SASSSourceMapping = class {
_sourceMapAttachedForTest(sourceMap) {
}
- /**
- * @param {string} frameId
- * @param {string} sourceMapURL
- * @return {string}
- */
- static _sourceMapId(frameId, sourceMapURL) {
- return frameId + ':' + sourceMapURL;
- }
-
/**
* @param {!Common.Event} event
*/
_sourceMapAttached(event) {
var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client);
var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
- var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, sourceMap.url());
- if (this._sourceMapIdToHeaders.has(sourceMapId)) {
- this._sourceMapIdToHeaders.set(sourceMapId, header);
- this._sourceMapAttachedForTest(sourceMap);
- return;
- }
- this._sourceMapIdToHeaders.set(sourceMapId, header);
-
for (var sassURL of sourceMap.sourceURLs()) {
+ var uiSourceCode = this._project.uiSourceCodeForURL(sassURL);
+ if (uiSourceCode) {
+ var attribution = Bindings.NetworkProject.frameAttribution(uiSourceCode);
+ attribution.add(header.frameId);
+ Bindings.NetworkProject.changeFrameAttribution(uiSourceCode, attribution);
+ continue;
+ }
+
var contentProvider = sourceMap.sourceContentProvider(sassURL, Common.resourceTypes.SourceMapStyleSheet);
var embeddedContent = sourceMap.embeddedContentByURL(sassURL);
- var embeddedContentLength = typeof embeddedContent === 'string' ? embeddedContent.length : null;
- var uiSourceCode =
- this._networkProject.addSourceMapFile(contentProvider, header.frameId, false, embeddedContentLength);
+ var metadata =
+ typeof embeddedContent === 'string' ? new Workspace.UISourceCodeMetadata(null, embeddedContent.length) : null;
+ uiSourceCode = this._project.createUISourceCode(sassURL, contentProvider.contentType());
+ Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, new Set([header.frameId]));
uiSourceCode[Bindings.SASSSourceMapping._sourceMapSymbol] = sourceMap;
+ this._project.addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata);
}
Bindings.cssWorkspaceBinding.updateLocations(header);
this._sourceMapAttachedForTest(sourceMap);
@@ -101,12 +102,19 @@ Bindings.SASSSourceMapping = class {
_sourceMapDetached(event) {
var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client);
var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
- var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, sourceMap.url());
- this._sourceMapIdToHeaders.remove(sourceMapId, header);
- if (this._sourceMapIdToHeaders.has(sourceMapId))
+ var headers = this._sourceMapManager.clientsForSourceMap(sourceMap);
+ if (!headers.length) {
dgozman 2017/05/10 18:10:33 Let's rewrite below for clarity: for (var sassURL
lushnikov 2017/05/10 22:24:32 Done.
+ for (var sassURL of sourceMap.sourceURLs())
+ this._project.removeFile(sassURL);
+ Bindings.cssWorkspaceBinding.updateLocations(header);
return;
- for (var sassURL of sourceMap.sourceURLs())
- this._networkProject.removeSourceMapFile(sassURL, header.frameId, false);
+ }
+
+ var attribution = new Set(headers.map(header => header.frameId));
dgozman 2017/05/10 18:10:33 Doing this here looks ugly. Should we instead intr
lushnikov 2017/05/10 22:24:32 In case of shadowDOM we might have many headers at
+ for (var sassURL of sourceMap.sourceURLs()) {
+ var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (this._project.uiSourceCodeForURL(sassURL));
+ Bindings.NetworkProject.changeFrameAttribution(uiSourceCode, attribution);
+ }
Bindings.cssWorkspaceBinding.updateLocations(header);
}
@@ -117,23 +125,17 @@ Bindings.SASSSourceMapping = class {
var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
var newSources = /** @type {!Map<string, string>} */ (event.data.newSources);
var headers = this._sourceMapManager.clientsForSourceMap(sourceMap);
- var handledUISourceCodes = new Set();
- for (var header of headers) {
- Bindings.cssWorkspaceBinding.updateLocations(header);
- for (var sourceURL of newSources.keys()) {
- var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._workspace, sourceURL, header);
- if (!uiSourceCode) {
- console.error('Failed to update source for ' + sourceURL);
- continue;
- }
- if (handledUISourceCodes.has(uiSourceCode))
- continue;
- handledUISourceCodes.add(uiSourceCode);
- uiSourceCode[Bindings.SASSSourceMapping._sourceMapSymbol] = sourceMap;
- var sassText = /** @type {string} */ (newSources.get(sourceURL));
- uiSourceCode.setWorkingCopy(sassText);
+ for (var sourceURL of newSources.keys()) {
+ var uiSourceCode = this._project.uiSourceCodeForURL(sourceURL);
+ if (!uiSourceCode) {
+ console.error('Failed to update source for ' + sourceURL);
+ continue;
}
+ var sassText = /** @type {string} */ (newSources.get(sourceURL));
+ uiSourceCode.setWorkingCopy(sassText);
}
+ for (var header of headers)
+ Bindings.cssWorkspaceBinding.updateLocations(header);
}
/**
@@ -151,7 +153,7 @@ Bindings.SASSSourceMapping = class {
var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumber);
if (!entry || !entry.sourceURL)
return null;
- var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._workspace, entry.sourceURL, header);
+ var uiSourceCode = this._project.uiSourceCodeForURL(entry.sourceURL);
if (!uiSourceCode)
return null;
return uiSourceCode.uiLocation(entry.sourceLineNumber || 0, entry.sourceColumnNumber);
@@ -175,6 +177,7 @@ Bindings.SASSSourceMapping = class {
}
dispose() {
+ this._project.dispose();
Common.EventTarget.removeEventListeners(this._eventListeners);
}
};

Powered by Google App Engine
This is Rietveld 408576698