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 15 matching lines...) Expand all Loading... | |
| 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 | |
| 37 * @return {string} | |
| 38 */ | |
| 39 static projectId(target) { | |
|
dgozman
2017/05/10 18:10:33
inline it
lushnikov
2017/05/10 22:24:32
Done.
| |
| 40 return 'cssSourceMaps:' + target.id(); | |
| 41 } | |
| 42 | |
| 43 /** | |
| 44 * @param {!SDK.Target} target | |
| 36 * @param {!SDK.SourceMapManager} sourceMapManager | 45 * @param {!SDK.SourceMapManager} sourceMapManager |
| 37 * @param {!Workspace.Workspace} workspace | 46 * @param {!Workspace.Workspace} workspace |
| 38 * @param {!Bindings.NetworkProject} networkProject | |
| 39 */ | 47 */ |
| 40 constructor(sourceMapManager, workspace, networkProject) { | 48 constructor(target, sourceMapManager, workspace) { |
| 41 this._sourceMapManager = sourceMapManager; | 49 this._sourceMapManager = sourceMapManager; |
| 42 this._networkProject = networkProject; | 50 this._project = new Bindings.ContentProviderBasedProject( |
| 43 this._workspace = workspace; | 51 workspace, Bindings.SASSSourceMapping.projectId(target), Workspace.proje ctTypes.Network, '', |
| 52 false /* isServiceProject */); | |
| 53 Bindings.NetworkProject.setTargetForProject(this._project, target); | |
| 54 | |
| 44 this._eventListeners = [ | 55 this._eventListeners = [ |
| 45 this._sourceMapManager.addEventListener( | 56 this._sourceMapManager.addEventListener( |
| 46 SDK.SourceMapManager.Events.SourceMapAttached, this._sourceMapAttached , this), | 57 SDK.SourceMapManager.Events.SourceMapAttached, this._sourceMapAttached , this), |
| 47 this._sourceMapManager.addEventListener( | 58 this._sourceMapManager.addEventListener( |
| 48 SDK.SourceMapManager.Events.SourceMapDetached, this._sourceMapDetached , this), | 59 SDK.SourceMapManager.Events.SourceMapDetached, this._sourceMapDetached , this), |
| 49 this._sourceMapManager.addEventListener( | 60 this._sourceMapManager.addEventListener( |
| 50 SDK.SourceMapManager.Events.SourceMapChanged, this._sourceMapChanged, this) | 61 SDK.SourceMapManager.Events.SourceMapChanged, this._sourceMapChanged, this) |
| 51 ]; | 62 ]; |
| 52 | |
| 53 /** @type {!Multimap<string, !SDK.CSSStyleSheetHeader>} */ | |
| 54 this._sourceMapIdToHeaders = new Multimap(); | |
| 55 } | 63 } |
| 56 | 64 |
| 57 /** | 65 /** |
| 58 * @param {?SDK.SourceMap} sourceMap | 66 * @param {?SDK.SourceMap} sourceMap |
| 59 */ | 67 */ |
| 60 _sourceMapAttachedForTest(sourceMap) { | 68 _sourceMapAttachedForTest(sourceMap) { |
| 61 } | 69 } |
| 62 | 70 |
| 63 /** | 71 /** |
| 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 | 72 * @param {!Common.Event} event |
| 74 */ | 73 */ |
| 75 _sourceMapAttached(event) { | 74 _sourceMapAttached(event) { |
| 76 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client); | 75 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client); |
| 77 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); | 76 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); |
| 78 var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, so urceMap.url()); | 77 for (var sassURL of sourceMap.sourceURLs()) { |
| 79 if (this._sourceMapIdToHeaders.has(sourceMapId)) { | 78 var uiSourceCode = this._project.uiSourceCodeForURL(sassURL); |
| 80 this._sourceMapIdToHeaders.set(sourceMapId, header); | 79 if (uiSourceCode) { |
| 81 this._sourceMapAttachedForTest(sourceMap); | 80 var attribution = Bindings.NetworkProject.frameAttribution(uiSourceCode) ; |
| 82 return; | 81 attribution.add(header.frameId); |
| 83 } | 82 Bindings.NetworkProject.changeFrameAttribution(uiSourceCode, attribution ); |
| 84 this._sourceMapIdToHeaders.set(sourceMapId, header); | 83 continue; |
| 84 } | |
| 85 | 85 |
| 86 for (var sassURL of sourceMap.sourceURLs()) { | |
| 87 var contentProvider = sourceMap.sourceContentProvider(sassURL, Common.reso urceTypes.SourceMapStyleSheet); | 86 var contentProvider = sourceMap.sourceContentProvider(sassURL, Common.reso urceTypes.SourceMapStyleSheet); |
| 88 var embeddedContent = sourceMap.embeddedContentByURL(sassURL); | 87 var embeddedContent = sourceMap.embeddedContentByURL(sassURL); |
| 89 var embeddedContentLength = typeof embeddedContent === 'string' ? embedded Content.length : null; | 88 var metadata = |
| 90 var uiSourceCode = | 89 typeof embeddedContent === 'string' ? new Workspace.UISourceCodeMetada ta(null, embeddedContent.length) : null; |
| 91 this._networkProject.addSourceMapFile(contentProvider, header.frameId, false, embeddedContentLength); | 90 uiSourceCode = this._project.createUISourceCode(sassURL, contentProvider.c ontentType()); |
| 91 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, new Set([ header.frameId])); | |
| 92 uiSourceCode[Bindings.SASSSourceMapping._sourceMapSymbol] = sourceMap; | 92 uiSourceCode[Bindings.SASSSourceMapping._sourceMapSymbol] = sourceMap; |
| 93 this._project.addUISourceCodeWithProvider(uiSourceCode, contentProvider, m etadata); | |
| 93 } | 94 } |
| 94 Bindings.cssWorkspaceBinding.updateLocations(header); | 95 Bindings.cssWorkspaceBinding.updateLocations(header); |
| 95 this._sourceMapAttachedForTest(sourceMap); | 96 this._sourceMapAttachedForTest(sourceMap); |
| 96 } | 97 } |
| 97 | 98 |
| 98 /** | 99 /** |
| 99 * @param {!Common.Event} event | 100 * @param {!Common.Event} event |
| 100 */ | 101 */ |
| 101 _sourceMapDetached(event) { | 102 _sourceMapDetached(event) { |
| 102 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client); | 103 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client); |
| 103 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); | 104 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); |
| 104 var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, so urceMap.url()); | 105 var headers = this._sourceMapManager.clientsForSourceMap(sourceMap); |
| 105 this._sourceMapIdToHeaders.remove(sourceMapId, header); | 106 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.
| |
| 106 if (this._sourceMapIdToHeaders.has(sourceMapId)) | 107 for (var sassURL of sourceMap.sourceURLs()) |
| 108 this._project.removeFile(sassURL); | |
| 109 Bindings.cssWorkspaceBinding.updateLocations(header); | |
| 107 return; | 110 return; |
| 108 for (var sassURL of sourceMap.sourceURLs()) | 111 } |
| 109 this._networkProject.removeSourceMapFile(sassURL, header.frameId, false); | 112 |
| 113 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
| |
| 114 for (var sassURL of sourceMap.sourceURLs()) { | |
| 115 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (this._project.u iSourceCodeForURL(sassURL)); | |
| 116 Bindings.NetworkProject.changeFrameAttribution(uiSourceCode, attribution); | |
| 117 } | |
| 110 Bindings.cssWorkspaceBinding.updateLocations(header); | 118 Bindings.cssWorkspaceBinding.updateLocations(header); |
| 111 } | 119 } |
| 112 | 120 |
| 113 /** | 121 /** |
| 114 * @param {!Common.Event} event | 122 * @param {!Common.Event} event |
| 115 */ | 123 */ |
| 116 _sourceMapChanged(event) { | 124 _sourceMapChanged(event) { |
| 117 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); | 125 var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap); |
| 118 var newSources = /** @type {!Map<string, string>} */ (event.data.newSources) ; | 126 var newSources = /** @type {!Map<string, string>} */ (event.data.newSources) ; |
| 119 var headers = this._sourceMapManager.clientsForSourceMap(sourceMap); | 127 var headers = this._sourceMapManager.clientsForSourceMap(sourceMap); |
| 120 var handledUISourceCodes = new Set(); | 128 for (var sourceURL of newSources.keys()) { |
| 121 for (var header of headers) { | 129 var uiSourceCode = this._project.uiSourceCodeForURL(sourceURL); |
| 130 if (!uiSourceCode) { | |
| 131 console.error('Failed to update source for ' + sourceURL); | |
| 132 continue; | |
| 133 } | |
| 134 var sassText = /** @type {string} */ (newSources.get(sourceURL)); | |
| 135 uiSourceCode.setWorkingCopy(sassText); | |
| 136 } | |
| 137 for (var header of headers) | |
| 122 Bindings.cssWorkspaceBinding.updateLocations(header); | 138 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 } | 139 } |
| 138 | 140 |
| 139 /** | 141 /** |
| 140 * @override | 142 * @override |
| 141 * @param {!SDK.CSSLocation} rawLocation | 143 * @param {!SDK.CSSLocation} rawLocation |
| 142 * @return {?Workspace.UILocation} | 144 * @return {?Workspace.UILocation} |
| 143 */ | 145 */ |
| 144 rawLocationToUILocation(rawLocation) { | 146 rawLocationToUILocation(rawLocation) { |
| 145 var header = rawLocation.header(); | 147 var header = rawLocation.header(); |
| 146 if (!header) | 148 if (!header) |
| 147 return null; | 149 return null; |
| 148 var sourceMap = this._sourceMapManager.sourceMapForClient(header); | 150 var sourceMap = this._sourceMapManager.sourceMapForClient(header); |
| 149 if (!sourceMap) | 151 if (!sourceMap) |
| 150 return null; | 152 return null; |
| 151 var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNu mber); | 153 var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNu mber); |
| 152 if (!entry || !entry.sourceURL) | 154 if (!entry || !entry.sourceURL) |
| 153 return null; | 155 return null; |
| 154 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._wor kspace, entry.sourceURL, header); | 156 var uiSourceCode = this._project.uiSourceCodeForURL(entry.sourceURL); |
| 155 if (!uiSourceCode) | 157 if (!uiSourceCode) |
| 156 return null; | 158 return null; |
| 157 return uiSourceCode.uiLocation(entry.sourceLineNumber || 0, entry.sourceColu mnNumber); | 159 return uiSourceCode.uiLocation(entry.sourceLineNumber || 0, entry.sourceColu mnNumber); |
| 158 } | 160 } |
| 159 | 161 |
| 160 /** | 162 /** |
| 161 * @override | 163 * @override |
| 162 * @param {!Workspace.UILocation} uiLocation | 164 * @param {!Workspace.UILocation} uiLocation |
| 163 * @return {!Array<!SDK.CSSLocation>} | 165 * @return {!Array<!SDK.CSSLocation>} |
| 164 */ | 166 */ |
| 165 uiLocationToRawLocations(uiLocation) { | 167 uiLocationToRawLocations(uiLocation) { |
| 166 var sourceMap = uiLocation.uiSourceCode[Bindings.SASSSourceMapping._sourceMa pSymbol]; | 168 var sourceMap = uiLocation.uiSourceCode[Bindings.SASSSourceMapping._sourceMa pSymbol]; |
| 167 if (!sourceMap) | 169 if (!sourceMap) |
| 168 return []; | 170 return []; |
| 169 var entries = | 171 var entries = |
| 170 sourceMap.findReverseEntries(uiLocation.uiSourceCode.url(), uiLocation.l ineNumber, uiLocation.columnNumber); | 172 sourceMap.findReverseEntries(uiLocation.uiSourceCode.url(), uiLocation.l ineNumber, uiLocation.columnNumber); |
| 171 var locations = []; | 173 var locations = []; |
| 172 for (var header of this._sourceMapManager.clientsForSourceMap(sourceMap)) | 174 for (var header of this._sourceMapManager.clientsForSourceMap(sourceMap)) |
| 173 locations.pushAll(entries.map(entry => new SDK.CSSLocation(header, entry.l ineNumber, entry.columnNumber))); | 175 locations.pushAll(entries.map(entry => new SDK.CSSLocation(header, entry.l ineNumber, entry.columnNumber))); |
| 174 return locations; | 176 return locations; |
| 175 } | 177 } |
| 176 | 178 |
| 177 dispose() { | 179 dispose() { |
| 180 this._project.dispose(); | |
| 178 Common.EventTarget.removeEventListeners(this._eventListeners); | 181 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 179 } | 182 } |
| 180 }; | 183 }; |
| 181 | 184 |
| 182 Bindings.SASSSourceMapping._sourceMapSymbol = Symbol('sourceMap'); | 185 Bindings.SASSSourceMapping._sourceMapSymbol = Symbol('sourceMap'); |
| OLD | NEW |