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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/SASSSourceMapping.js

Issue 2869293002: DevTools: make CompilerScriptMapping / SASSSourceMapping manage UISourceCodes (Closed)
Patch Set: address comments 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @implements {Bindings.CSSWorkspaceBinding.SourceMapping} 32 * @implements {Bindings.CSSWorkspaceBinding.SourceMapping}
33 */ 33 */
34 Bindings.SASSSourceMapping = class { 34 Bindings.SASSSourceMapping = class {
35 /** 35 /**
36 * @param {!SDK.Target} target
36 * @param {!SDK.SourceMapManager} sourceMapManager 37 * @param {!SDK.SourceMapManager} sourceMapManager
37 * @param {!Workspace.Workspace} workspace 38 * @param {!Workspace.Workspace} workspace
38 * @param {!Bindings.NetworkProject} networkProject
39 */ 39 */
40 constructor(sourceMapManager, workspace, networkProject) { 40 constructor(target, sourceMapManager, workspace) {
41 this._sourceMapManager = sourceMapManager; 41 this._sourceMapManager = sourceMapManager;
42 this._networkProject = networkProject; 42 this._project = new Bindings.ContentProviderBasedProject(
43 this._workspace = workspace; 43 workspace, 'cssSourceMaps:' + target.id(), Workspace.projectTypes.Networ k, '', false /* isServiceProject */);
44 Bindings.NetworkProject.setTargetForProject(this._project, target);
45
44 this._eventListeners = [ 46 this._eventListeners = [
45 this._sourceMapManager.addEventListener( 47 this._sourceMapManager.addEventListener(
46 SDK.SourceMapManager.Events.SourceMapAttached, this._sourceMapAttached , this), 48 SDK.SourceMapManager.Events.SourceMapAttached, this._sourceMapAttached , this),
47 this._sourceMapManager.addEventListener( 49 this._sourceMapManager.addEventListener(
48 SDK.SourceMapManager.Events.SourceMapDetached, this._sourceMapDetached , this), 50 SDK.SourceMapManager.Events.SourceMapDetached, this._sourceMapDetached , this),
49 this._sourceMapManager.addEventListener( 51 this._sourceMapManager.addEventListener(
50 SDK.SourceMapManager.Events.SourceMapChanged, this._sourceMapChanged, this) 52 SDK.SourceMapManager.Events.SourceMapChanged, this._sourceMapChanged, this)
51 ]; 53 ];
52
53 /** @type {!Multimap<string, !SDK.CSSStyleSheetHeader>} */
54 this._sourceMapIdToHeaders = new Multimap();
55 } 54 }
56 55
57 /** 56 /**
58 * @param {?SDK.SourceMap} sourceMap 57 * @param {?SDK.SourceMap} sourceMap
59 */ 58 */
60 _sourceMapAttachedForTest(sourceMap) { 59 _sourceMapAttachedForTest(sourceMap) {
61 } 60 }
62 61
63 /** 62 /**
64 * @param {string} frameId
65 * @param {string} sourceMapURL
66 * @return {string}
67 */
68 static _sourceMapId(frameId, sourceMapURL) {
69 return frameId + ':' + sourceMapURL;
70 }
71
72 /**
73 * @param {!Common.Event} event 63 * @param {!Common.Event} event
74 */ 64 */
75 _sourceMapAttached(event) { 65 _sourceMapAttached(event) {
76 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client); 66 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client);
77 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); 67 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
78 var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, so urceMap.url()); 68 for (var sassURL of sourceMap.sourceURLs()) {
79 if (this._sourceMapIdToHeaders.has(sourceMapId)) { 69 var uiSourceCode = this._project.uiSourceCodeForURL(sassURL);
80 this._sourceMapIdToHeaders.set(sourceMapId, header); 70 if (uiSourceCode) {
81 this._sourceMapAttachedForTest(sourceMap); 71 Bindings.NetworkProject.addFrameAttribution(uiSourceCode, header.frameId );
82 return; 72 continue;
83 } 73 }
84 this._sourceMapIdToHeaders.set(sourceMapId, header);
85 74
86 for (var sassURL of sourceMap.sourceURLs()) {
87 var contentProvider = sourceMap.sourceContentProvider(sassURL, Common.reso urceTypes.SourceMapStyleSheet); 75 var contentProvider = sourceMap.sourceContentProvider(sassURL, Common.reso urceTypes.SourceMapStyleSheet);
88 var embeddedContent = sourceMap.embeddedContentByURL(sassURL); 76 var embeddedContent = sourceMap.embeddedContentByURL(sassURL);
89 var embeddedContentLength = typeof embeddedContent === 'string' ? embedded Content.length : null; 77 var metadata =
90 var uiSourceCode = 78 typeof embeddedContent === 'string' ? new Workspace.UISourceCodeMetada ta(null, embeddedContent.length) : null;
91 this._networkProject.addSourceMapFile(contentProvider, header.frameId, false, embeddedContentLength); 79 uiSourceCode = this._project.createUISourceCode(sassURL, contentProvider.c ontentType());
80 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, header.fr ameId);
92 uiSourceCode[Bindings.SASSSourceMapping._sourceMapSymbol] = sourceMap; 81 uiSourceCode[Bindings.SASSSourceMapping._sourceMapSymbol] = sourceMap;
82 this._project.addUISourceCodeWithProvider(uiSourceCode, contentProvider, m etadata);
93 } 83 }
94 Bindings.cssWorkspaceBinding.updateLocations(header); 84 Bindings.cssWorkspaceBinding.updateLocations(header);
95 this._sourceMapAttachedForTest(sourceMap); 85 this._sourceMapAttachedForTest(sourceMap);
96 } 86 }
97 87
98 /** 88 /**
99 * @param {!Common.Event} event 89 * @param {!Common.Event} event
100 */ 90 */
101 _sourceMapDetached(event) { 91 _sourceMapDetached(event) {
102 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client); 92 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client);
103 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); 93 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
104 var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, so urceMap.url()); 94 var headers = this._sourceMapManager.clientsForSourceMap(sourceMap);
105 this._sourceMapIdToHeaders.remove(sourceMapId, header); 95 for (var sassURL of sourceMap.sourceURLs()) {
106 if (this._sourceMapIdToHeaders.has(sourceMapId)) 96 if (headers.length) {
107 return; 97 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (this._project .uiSourceCodeForURL(sassURL));
108 for (var sassURL of sourceMap.sourceURLs()) 98 Bindings.NetworkProject.removeFrameAttribution(uiSourceCode, header.fram eId);
109 this._networkProject.removeSourceMapFile(sassURL, header.frameId, false); 99 } else {
100 this._project.removeFile(sassURL);
101 }
102 }
110 Bindings.cssWorkspaceBinding.updateLocations(header); 103 Bindings.cssWorkspaceBinding.updateLocations(header);
111 } 104 }
112 105
113 /** 106 /**
114 * @param {!Common.Event} event 107 * @param {!Common.Event} event
115 */ 108 */
116 _sourceMapChanged(event) { 109 _sourceMapChanged(event) {
117 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); 110 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
118 var newSources = /** @type {!Map<string, string>} */ (event.data.newSources) ; 111 var newSources = /** @type {!Map<string, string>} */ (event.data.newSources) ;
119 var headers = this._sourceMapManager.clientsForSourceMap(sourceMap); 112 var headers = this._sourceMapManager.clientsForSourceMap(sourceMap);
120 var handledUISourceCodes = new Set(); 113 for (var sourceURL of newSources.keys()) {
121 for (var header of headers) { 114 var uiSourceCode = this._project.uiSourceCodeForURL(sourceURL);
115 if (!uiSourceCode) {
116 console.error('Failed to update source for ' + sourceURL);
117 continue;
118 }
119 var sassText = /** @type {string} */ (newSources.get(sourceURL));
120 uiSourceCode.setWorkingCopy(sassText);
121 }
122 for (var header of headers)
122 Bindings.cssWorkspaceBinding.updateLocations(header); 123 Bindings.cssWorkspaceBinding.updateLocations(header);
123 for (var sourceURL of newSources.keys()) {
124 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this. _workspace, sourceURL, header);
125 if (!uiSourceCode) {
126 console.error('Failed to update source for ' + sourceURL);
127 continue;
128 }
129 if (handledUISourceCodes.has(uiSourceCode))
130 continue;
131 handledUISourceCodes.add(uiSourceCode);
132 uiSourceCode[Bindings.SASSSourceMapping._sourceMapSymbol] = sourceMap;
133 var sassText = /** @type {string} */ (newSources.get(sourceURL));
134 uiSourceCode.setWorkingCopy(sassText);
135 }
136 }
137 } 124 }
138 125
139 /** 126 /**
140 * @override 127 * @override
141 * @param {!SDK.CSSLocation} rawLocation 128 * @param {!SDK.CSSLocation} rawLocation
142 * @return {?Workspace.UILocation} 129 * @return {?Workspace.UILocation}
143 */ 130 */
144 rawLocationToUILocation(rawLocation) { 131 rawLocationToUILocation(rawLocation) {
145 var header = rawLocation.header(); 132 var header = rawLocation.header();
146 if (!header) 133 if (!header)
147 return null; 134 return null;
148 var sourceMap = this._sourceMapManager.sourceMapForClient(header); 135 var sourceMap = this._sourceMapManager.sourceMapForClient(header);
149 if (!sourceMap) 136 if (!sourceMap)
150 return null; 137 return null;
151 var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNu mber); 138 var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNu mber);
152 if (!entry || !entry.sourceURL) 139 if (!entry || !entry.sourceURL)
153 return null; 140 return null;
154 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._wor kspace, entry.sourceURL, header); 141 var uiSourceCode = this._project.uiSourceCodeForURL(entry.sourceURL);
155 if (!uiSourceCode) 142 if (!uiSourceCode)
156 return null; 143 return null;
157 return uiSourceCode.uiLocation(entry.sourceLineNumber || 0, entry.sourceColu mnNumber); 144 return uiSourceCode.uiLocation(entry.sourceLineNumber || 0, entry.sourceColu mnNumber);
158 } 145 }
159 146
160 /** 147 /**
161 * @override 148 * @override
162 * @param {!Workspace.UILocation} uiLocation 149 * @param {!Workspace.UILocation} uiLocation
163 * @return {!Array<!SDK.CSSLocation>} 150 * @return {!Array<!SDK.CSSLocation>}
164 */ 151 */
165 uiLocationToRawLocations(uiLocation) { 152 uiLocationToRawLocations(uiLocation) {
166 var sourceMap = uiLocation.uiSourceCode[Bindings.SASSSourceMapping._sourceMa pSymbol]; 153 var sourceMap = uiLocation.uiSourceCode[Bindings.SASSSourceMapping._sourceMa pSymbol];
167 if (!sourceMap) 154 if (!sourceMap)
168 return []; 155 return [];
169 var entries = 156 var entries =
170 sourceMap.findReverseEntries(uiLocation.uiSourceCode.url(), uiLocation.l ineNumber, uiLocation.columnNumber); 157 sourceMap.findReverseEntries(uiLocation.uiSourceCode.url(), uiLocation.l ineNumber, uiLocation.columnNumber);
171 var locations = []; 158 var locations = [];
172 for (var header of this._sourceMapManager.clientsForSourceMap(sourceMap)) 159 for (var header of this._sourceMapManager.clientsForSourceMap(sourceMap))
173 locations.pushAll(entries.map(entry => new SDK.CSSLocation(header, entry.l ineNumber, entry.columnNumber))); 160 locations.pushAll(entries.map(entry => new SDK.CSSLocation(header, entry.l ineNumber, entry.columnNumber)));
174 return locations; 161 return locations;
175 } 162 }
176 163
177 dispose() { 164 dispose() {
165 this._project.dispose();
178 Common.EventTarget.removeEventListeners(this._eventListeners); 166 Common.EventTarget.removeEventListeners(this._eventListeners);
179 } 167 }
180 }; 168 };
181 169
182 Bindings.SASSSourceMapping._sourceMapSymbol = Symbol('sourceMap'); 170 Bindings.SASSSourceMapping._sourceMapSymbol = Symbol('sourceMap');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698