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

Side by Side 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 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 17 matching lines...) Expand all
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 * @implements {Bindings.DebuggerSourceMapping} 31 * @implements {Bindings.DebuggerSourceMapping}
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 Bindings.CompilerScriptMapping = class { 34 Bindings.CompilerScriptMapping = class {
35 /** 35 /**
36 * @param {!SDK.DebuggerModel} debuggerModel 36 * @param {!SDK.DebuggerModel} debuggerModel
37 * @param {!Workspace.Workspace} workspace 37 * @param {!Workspace.Workspace} workspace
38 * @param {!Bindings.NetworkProject} networkProject
39 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding 38 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
40 */ 39 */
41 constructor(debuggerModel, workspace, networkProject, debuggerWorkspaceBinding ) { 40 constructor(debuggerModel, workspace, debuggerWorkspaceBinding) {
42 this._debuggerModel = debuggerModel; 41 this._debuggerModel = debuggerModel;
43 this._sourceMapManager = this._debuggerModel.sourceMapManager(); 42 this._sourceMapManager = this._debuggerModel.sourceMapManager();
44 this._workspace = workspace; 43 this._workspace = workspace;
45 this._networkProject = networkProject;
46 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; 44 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding;
47 45
48 /** @type {!Multimap<!SDK.Script, !Workspace.UISourceCode>} */ 46 var target = debuggerModel.target();
49 this._scriptSources = new Multimap(); 47 this._regularProject = new Bindings.ContentProviderBasedProject(
48 workspace, Bindings.CompilerScriptMapping.projectId(target, false /* isC ontentScript */),
49 Workspace.projectTypes.Network, '', false /* isServiceProject */);
50 this._contentScriptsProject = new Bindings.ContentProviderBasedProject(
51 workspace, Bindings.CompilerScriptMapping.projectId(target, true /* isCo ntentScript */),
52 Workspace.projectTypes.ContentScripts, '', false /* isServiceProject */) ;
53 Bindings.NetworkProject.setTargetForProject(this._regularProject, target);
54 Bindings.NetworkProject.setTargetForProject(this._contentScriptsProject, tar get);
55
50 /** @type {!Map<!SDK.Script, !Workspace.UISourceCode>} */ 56 /** @type {!Map<!SDK.Script, !Workspace.UISourceCode>} */
51 this._stubUISourceCodes = new Map(); 57 this._stubUISourceCodes = new Map();
52 58
53 var projectId = Bindings.CompilerScriptMapping.projectIdForTarget(this._debu ggerModel.target());
54 this._stubProject = new Bindings.ContentProviderBasedProject( 59 this._stubProject = new Bindings.ContentProviderBasedProject(
55 workspace, projectId, Workspace.projectTypes.Service, '', true /* isServ iceProject */); 60 workspace, 'stub:jsSourceMaps:' + target.id(), Workspace.projectTypes.Se rvice, '', true /* isServiceProject */);
56 this._eventListeners = [ 61 this._eventListeners = [
57 this._sourceMapManager.addEventListener( 62 this._sourceMapManager.addEventListener(
58 SDK.SourceMapManager.Events.SourceMapWillAttach, this._sourceMapWillAt tach, this), 63 SDK.SourceMapManager.Events.SourceMapWillAttach, this._sourceMapWillAt tach, this),
59 this._sourceMapManager.addEventListener( 64 this._sourceMapManager.addEventListener(
60 SDK.SourceMapManager.Events.SourceMapFailedToAttach, this._sourceMapFa iledToAttach, this), 65 SDK.SourceMapManager.Events.SourceMapFailedToAttach, this._sourceMapFa iledToAttach, this),
61 this._sourceMapManager.addEventListener( 66 this._sourceMapManager.addEventListener(
62 SDK.SourceMapManager.Events.SourceMapAttached, this._sourceMapAttached , this), 67 SDK.SourceMapManager.Events.SourceMapAttached, this._sourceMapAttached , this),
63 this._sourceMapManager.addEventListener( 68 this._sourceMapManager.addEventListener(
64 SDK.SourceMapManager.Events.SourceMapDetached, this._sourceMapDetached , this), 69 SDK.SourceMapManager.Events.SourceMapDetached, this._sourceMapDetached , this),
65 ]; 70 ];
(...skipping 18 matching lines...) Expand all
84 var uiSourceCode = this._stubUISourceCodes.get(script); 89 var uiSourceCode = this._stubUISourceCodes.get(script);
85 this._stubUISourceCodes.delete(script); 90 this._stubUISourceCodes.delete(script);
86 this._stubProject.removeFile(uiSourceCode.url()); 91 this._stubProject.removeFile(uiSourceCode.url());
87 } 92 }
88 93
89 /** 94 /**
90 * @param {!Workspace.UISourceCode} uiSourceCode 95 * @param {!Workspace.UISourceCode} uiSourceCode
91 * @return {?string} 96 * @return {?string}
92 */ 97 */
93 static uiSourceCodeOrigin(uiSourceCode) { 98 static uiSourceCodeOrigin(uiSourceCode) {
94 var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; 99 var sourceMap = uiSourceCode[Bindings.CompilerScriptMapping._sourceMapSymbol ];
95 return script ? script.sourceURL : null; 100 if (!sourceMap)
101 return null;
102 return sourceMap.compiledURL();
96 } 103 }
97 104
98 /** 105 /**
99 * @param {!SDK.Target} target 106 * @param {!SDK.Target} target
107 * @param {boolean} isContentScript
100 * @return {string} 108 * @return {string}
101 */ 109 */
102 static projectIdForTarget(target) { 110 static projectId(target, isContentScript) {
103 return 'compiler-script-project:' + target.id(); 111 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.
104 } 112 }
105 113
106 /** 114 /**
107 * @param {!SDK.DebuggerModel.Location} rawLocation 115 * @param {!SDK.DebuggerModel.Location} rawLocation
108 * @return {boolean} 116 * @return {boolean}
109 */ 117 */
110 mapsToSourceCode(rawLocation) { 118 mapsToSourceCode(rawLocation) {
111 var script = rawLocation.script(); 119 var script = rawLocation.script();
112 var sourceMap = script ? this._sourceMapManager.sourceMapForClient(script) : null; 120 var sourceMap = script ? this._sourceMapManager.sourceMapForClient(script) : null;
113 if (!sourceMap) 121 if (!sourceMap)
114 return true; 122 return true;
115 return !!sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumbe r); 123 return !!sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumbe r);
116 } 124 }
117 125
118 /** 126 /**
127 * @param {string} url
128 * @param {boolean} isContentScript
129 */
130 uiSourceCodeForURL(url, isContentScript) {
131 return isContentScript ? this._contentScriptsProject.uiSourceCodeForURL(url) :
132 this._regularProject.uiSourceCodeForURL(url);
133 }
134
135 /**
119 * @override 136 * @override
120 * @param {!SDK.DebuggerModel.Location} rawLocation 137 * @param {!SDK.DebuggerModel.Location} rawLocation
121 * @return {?Workspace.UILocation} 138 * @return {?Workspace.UILocation}
122 */ 139 */
123 rawLocationToUILocation(rawLocation) { 140 rawLocationToUILocation(rawLocation) {
124 var script = rawLocation.script(); 141 var script = rawLocation.script();
125 if (!script) 142 if (!script)
126 return null; 143 return null;
127 144
128 var lineNumber = rawLocation.lineNumber; 145 var lineNumber = rawLocation.lineNumber;
129 var columnNumber = rawLocation.columnNumber || 0; 146 var columnNumber = rawLocation.columnNumber || 0;
130 var stubUISourceCode = this._stubUISourceCodes.get(script); 147 var stubUISourceCode = this._stubUISourceCodes.get(script);
131 if (stubUISourceCode) 148 if (stubUISourceCode)
132 return new Workspace.UILocation(stubUISourceCode, lineNumber, columnNumber ); 149 return new Workspace.UILocation(stubUISourceCode, lineNumber, columnNumber );
133 150
134 var sourceMap = this._sourceMapManager.sourceMapForClient(script); 151 var sourceMap = this._sourceMapManager.sourceMapForClient(script);
135 if (!sourceMap) 152 if (!sourceMap)
136 return null; 153 return null;
137 var entry = sourceMap.findEntry(lineNumber, columnNumber); 154 var entry = sourceMap.findEntry(lineNumber, columnNumber);
138 if (!entry || !entry.sourceURL) 155 if (!entry || !entry.sourceURL)
139 return null; 156 return null;
140 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForScriptURL( 157 var uiSourceCode = script.isContentScript() ? this._contentScriptsProject.ui SourceCodeForURL(entry.sourceURL) :
141 this._workspace, /** @type {string} */ (entry.sourceURL), script); 158 this._regularProject.uiSourceC odeForURL(entry.sourceURL);
142 if (!uiSourceCode) 159 if (!uiSourceCode)
143 return null; 160 return null;
144 return uiSourceCode.uiLocation( 161 return uiSourceCode.uiLocation(
145 /** @type {number} */ (entry.sourceLineNumber), /** @type {number} */ (e ntry.sourceColumnNumber)); 162 /** @type {number} */ (entry.sourceLineNumber), /** @type {number} */ (e ntry.sourceColumnNumber));
146 } 163 }
147 164
148 /** 165 /**
149 * @override 166 * @override
150 * @param {!Workspace.UISourceCode} uiSourceCode 167 * @param {!Workspace.UISourceCode} uiSourceCode
151 * @param {number} lineNumber 168 * @param {number} lineNumber
152 * @param {number} columnNumber 169 * @param {number} columnNumber
153 * @return {?SDK.DebuggerModel.Location} 170 * @return {?SDK.DebuggerModel.Location}
154 */ 171 */
155 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { 172 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) {
156 var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; 173 var sourceMap = uiSourceCode[Bindings.CompilerScriptMapping._sourceMapSymbol ];
174 if (!sourceMap)
175 return null;
176 var scripts = this._sourceMapManager.clientsForSourceMap(sourceMap);
177 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
157 if (!script) 178 if (!script)
158 return null; 179 return null;
159 var sourceMap = this._sourceMapManager.sourceMapForClient(script);
160 if (!sourceMap)
161 return null;
162 var entry = sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber) ; 180 var entry = sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber) ;
163 if (!entry) 181 if (!entry)
164 return null; 182 return null;
165 return this._debuggerModel.createRawLocation(script, entry.lineNumber, entry .columnNumber); 183 return this._debuggerModel.createRawLocation(script, entry.lineNumber, entry .columnNumber);
166 } 184 }
167 185
168 /** 186 /**
169 * @param {!Common.Event} event 187 * @param {!Common.Event} event
170 */ 188 */
171 _sourceMapWillAttach(event) { 189 _sourceMapWillAttach(event) {
(...skipping 25 matching lines...) Expand all
197 215
198 this._populateSourceMapSources(script, sourceMap); 216 this._populateSourceMapSources(script, sourceMap);
199 this._sourceMapAttachedForTest(sourceMap); 217 this._sourceMapAttachedForTest(sourceMap);
200 } 218 }
201 219
202 /** 220 /**
203 * @param {!Common.Event} event 221 * @param {!Common.Event} event
204 */ 222 */
205 _sourceMapDetached(event) { 223 _sourceMapDetached(event) {
206 var script = /** @type {!SDK.Script} */ (event.data.client); 224 var script = /** @type {!SDK.Script} */ (event.data.client);
207 var sources = this._scriptSources.get(script); 225 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
208 if (!sources.size) 226 var scripts = this._sourceMapManager.clientsForSourceMap(sourceMap);
209 return; 227 scripts = scripts.filter(someScript => someScript.isContentScript() === scri pt.isContentScript());
210 var frameId = script[Bindings.CompilerScriptMapping._frameIdSymbol]; 228 var project = script.isContentScript() ? this._contentScriptsProject : this. _regularProject;
211 for (var uiSourceCode of sources) { 229 if (!scripts.length) {
212 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSou rceCode, null); 230 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.
213 this._networkProject.removeSourceMapFile(uiSourceCode.url(), frameId, scri pt.isContentScript()); 231 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (project.uiSou rceCodeForURL(sourceURL));
232 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiS ourceCode, null);
233 project.removeFile(sourceURL);
234 }
235 } else {
236 var attribution = new Set(scripts.map(script => script[Bindings.CompilerSc riptMapping._frameIdSymbol]));
237 for (var sourceURL of sourceMap.sourceURLs()) {
238 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (project.uiSou rceCodeForURL(sourceURL));
239 Bindings.NetworkProject.changeFrameAttribution(uiSourceCode, attribution );
240 }
214 } 241 }
215 this._debuggerWorkspaceBinding.updateLocations(script); 242 this._debuggerWorkspaceBinding.updateLocations(script);
216 } 243 }
217 244
218 /** 245 /**
219 * @param {!SDK.Script} script 246 * @param {!SDK.Script} script
220 * @return {?SDK.SourceMap} 247 * @return {?SDK.SourceMap}
221 */ 248 */
222 sourceMapForScript(script) { 249 sourceMapForScript(script) {
223 return this._sourceMapManager.sourceMapForClient(script); 250 return this._sourceMapManager.sourceMapForClient(script);
224 } 251 }
225 252
226 /** 253 /**
227 * @param {!SDK.Script} script 254 * @param {!SDK.Script} script
228 */ 255 */
229 maybeLoadSourceMap(script) { 256 maybeLoadSourceMap(script) {
230 var sourceMap = this._sourceMapManager.sourceMapForClient(script); 257 var sourceMap = this._sourceMapManager.sourceMapForClient(script);
231 if (!sourceMap || this._scriptSources.has(script)) 258 if (!sourceMap)
232 return; 259 return;
233 this._populateSourceMapSources(script, sourceMap); 260 this._populateSourceMapSources(script, sourceMap);
234 } 261 }
235 262
236 /** 263 /**
237 * @param {?SDK.SourceMap} sourceMap 264 * @param {?SDK.SourceMap} sourceMap
238 */ 265 */
239 _sourceMapAttachedForTest(sourceMap) { 266 _sourceMapAttachedForTest(sourceMap) {
240 } 267 }
241 268
242 /** 269 /**
243 * @param {!SDK.Script} script 270 * @param {!SDK.Script} script
244 * @param {!SDK.SourceMap} sourceMap 271 * @param {!SDK.SourceMap} sourceMap
245 */ 272 */
246 _populateSourceMapSources(script, sourceMap) { 273 _populateSourceMapSources(script, sourceMap) {
247 var frameId = Bindings.frameIdForScript(script); 274 var frameId = Bindings.frameIdForScript(script);
248 script[Bindings.CompilerScriptMapping._frameIdSymbol] = frameId; 275 script[Bindings.CompilerScriptMapping._frameIdSymbol] = frameId;
276 var project = script.isContentScript() ? this._contentScriptsProject : this. _regularProject;
249 for (var sourceURL of sourceMap.sourceURLs()) { 277 for (var sourceURL of sourceMap.sourceURLs()) {
278 var uiSourceCode = project.uiSourceCodeForURL(sourceURL);
279 if (uiSourceCode) {
280 var attribution = Bindings.NetworkProject.frameAttribution(uiSourceCode) ;
281 attribution.add(frameId);
282 Bindings.NetworkProject.changeFrameAttribution(uiSourceCode, attribution );
283 continue;
284 }
285
250 var contentProvider = sourceMap.sourceContentProvider(sourceURL, Common.re sourceTypes.SourceMapScript); 286 var contentProvider = sourceMap.sourceContentProvider(sourceURL, Common.re sourceTypes.SourceMapScript);
251 var embeddedContent = sourceMap.embeddedContentByURL(sourceURL); 287 var embeddedContent = sourceMap.embeddedContentByURL(sourceURL);
252 var embeddedContentLength = typeof embeddedContent === 'string' ? embedded Content.length : null; 288 var metadata =
253 var uiSourceCode = this._networkProject.addSourceMapFile( 289 typeof embeddedContent === 'string' ? new Workspace.UISourceCodeMetada ta(null, embeddedContent.length) : null;
254 contentProvider, frameId, script.isContentScript(), embeddedContentLen gth); 290 uiSourceCode = project.createUISourceCode(sourceURL, contentProvider.conte ntType());
255 uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol] = script; 291 uiSourceCode[Bindings.CompilerScriptMapping._sourceMapSymbol] = sourceMap;
256 this._scriptSources.set(script, uiSourceCode); 292 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, new Set([ frameId]));
293 project.addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadat a);
257 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSou rceCode, this); 294 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel, uiSou rceCode, this);
258 } 295 }
259 this._debuggerWorkspaceBinding.updateLocations(script); 296 this._debuggerWorkspaceBinding.updateLocations(script);
260 } 297 }
261 298
262 /** 299 /**
263 * @override 300 * @override
264 * @return {boolean} 301 * @return {boolean}
265 */ 302 */
266 isIdentity() { 303 isIdentity() {
267 return false; 304 return false;
268 } 305 }
269 306
270 /** 307 /**
271 * @override 308 * @override
272 * @param {!Workspace.UISourceCode} uiSourceCode 309 * @param {!Workspace.UISourceCode} uiSourceCode
273 * @param {number} lineNumber 310 * @param {number} lineNumber
274 * @return {boolean} 311 * @return {boolean}
275 */ 312 */
276 uiLineHasMapping(uiSourceCode, lineNumber) { 313 uiLineHasMapping(uiSourceCode, lineNumber) {
277 var script = uiSourceCode[Bindings.CompilerScriptMapping._scriptSymbol]; 314 var sourceMap = uiSourceCode[Bindings.CompilerScriptMapping._sourceMapSymbol ];
278 var sourceMap = script ? this._sourceMapManager.sourceMapForClient(script) : null;
279 if (!sourceMap) 315 if (!sourceMap)
280 return true; 316 return true;
281 return !!sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber); 317 return !!sourceMap.firstSourceLineMapping(uiSourceCode.url(), lineNumber);
282 } 318 }
283 319
284 dispose() { 320 dispose() {
285 Common.EventTarget.removeEventListeners(this._eventListeners); 321 Common.EventTarget.removeEventListeners(this._eventListeners);
322 this._regularProject.dispose();
323 this._contentScriptsProject.dispose();
286 this._stubProject.dispose(); 324 this._stubProject.dispose();
287 } 325 }
288 }; 326 };
289 327
290 Bindings.CompilerScriptMapping._scriptSymbol = Symbol('Bindings.CompilerScriptMa pping._scriptSymbol'); 328 Bindings.CompilerScriptMapping._frameIdSymbol = Symbol('Bindings.CompilerScriptM apping._frameIdSymbol');
291 Bindings.CompilerScriptMapping._frameIdSymbol = Symbol('Bindings.CompilerScriptM apping._frameIdSymbol'); 329 Bindings.CompilerScriptMapping._sourceMapSymbol = Symbol('Bindings.CompilerScrip tMapping._sourceMapSymbol');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698