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