| 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 21 matching lines...) Expand all Loading... |
| 32 * @implements {Bindings.CSSWorkspaceBinding.SourceMapping} | 32 * @implements {Bindings.CSSWorkspaceBinding.SourceMapping} |
| 33 * @unrestricted | 33 * @unrestricted |
| 34 */ | 34 */ |
| 35 Bindings.StylesSourceMapping = class { | 35 Bindings.StylesSourceMapping = class { |
| 36 /** | 36 /** |
| 37 * @param {!SDK.CSSModel} cssModel | 37 * @param {!SDK.CSSModel} cssModel |
| 38 * @param {!Workspace.Workspace} workspace | 38 * @param {!Workspace.Workspace} workspace |
| 39 */ | 39 */ |
| 40 constructor(cssModel, workspace) { | 40 constructor(cssModel, workspace) { |
| 41 this._cssModel = cssModel; | 41 this._cssModel = cssModel; |
| 42 this._workspace = workspace; | 42 var target = this._cssModel.target(); |
| 43 this._project = new Bindings.ContentProviderBasedProject( |
| 44 workspace, 'css:' + target.id(), Workspace.projectTypes.Network, '', fal
se /* isServiceProject */); |
| 45 Bindings.NetworkProject.setTargetForProject(this._project, target); |
| 43 | 46 |
| 44 /** @type {!Map<string, !Map<string, !Map<string, !SDK.CSSStyleSheetHeader>>
>} */ | 47 /** @type {!Map.<string, !Bindings.StyleFile>} */ |
| 45 this._urlToHeadersByFrameId = new Map(); | |
| 46 /** @type {!Map.<!Workspace.UISourceCode, !Bindings.StyleFile>} */ | |
| 47 this._styleFiles = new Map(); | 48 this._styleFiles = new Map(); |
| 48 | |
| 49 this._eventListeners = [ | 49 this._eventListeners = [ |
| 50 this._workspace.addEventListener(Workspace.Workspace.Events.ProjectRemoved
, this._projectRemoved, this), | |
| 51 this._workspace.addEventListener( | |
| 52 Workspace.Workspace.Events.UISourceCodeAdded, this._uiSourceCodeAddedT
oWorkspace, this), | |
| 53 this._workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeRe
moved, this._uiSourceCodeRemoved, this), | |
| 54 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this.
_styleSheetAdded, this), | 50 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this.
_styleSheetAdded, this), |
| 55 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, thi
s._styleSheetRemoved, this), | 51 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, thi
s._styleSheetRemoved, this), |
| 56 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetChanged, thi
s._styleSheetChanged, this), | 52 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetChanged, thi
s._styleSheetChanged, this), |
| 57 cssModel.target() | |
| 58 .model(SDK.ResourceTreeModel) | |
| 59 .addEventListener(SDK.ResourceTreeModel.Events.MainFrameNavigated, thi
s._unbindAllUISourceCodes, this) | |
| 60 ]; | 53 ]; |
| 61 } | 54 } |
| 62 | 55 |
| 63 /** | 56 /** |
| 64 * @override | 57 * @override |
| 65 * @param {!SDK.CSSLocation} rawLocation | 58 * @param {!SDK.CSSLocation} rawLocation |
| 66 * @return {?Workspace.UILocation} | 59 * @return {?Workspace.UILocation} |
| 67 */ | 60 */ |
| 68 rawLocationToUILocation(rawLocation) { | 61 rawLocationToUILocation(rawLocation) { |
| 69 var header = rawLocation.header(); | 62 var header = rawLocation.header(); |
| 70 if (!header) | 63 if (!header || !this._acceptsHeader(header)) |
| 71 return null; | 64 return null; |
| 72 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._wor
kspace, rawLocation.url, header); | 65 var styleFile = this._styleFiles.get(header.resourceURL()); |
| 73 if (!uiSourceCode) | 66 if (!styleFile) |
| 74 return null; | 67 return null; |
| 75 var lineNumber = rawLocation.lineNumber; | 68 var lineNumber = rawLocation.lineNumber; |
| 76 var columnNumber = rawLocation.columnNumber; | 69 var columnNumber = rawLocation.columnNumber; |
| 77 if (header.isInline && header.hasSourceURL) { | 70 if (header.isInline && header.hasSourceURL) { |
| 78 lineNumber -= header.lineNumberInSource(0); | 71 lineNumber -= header.lineNumberInSource(0); |
| 79 columnNumber -= header.columnNumberInSource(lineNumber, 0); | 72 columnNumber -= header.columnNumberInSource(lineNumber, 0); |
| 80 } | 73 } |
| 81 return uiSourceCode.uiLocation(lineNumber, columnNumber); | 74 return styleFile._uiSourceCode.uiLocation(lineNumber, columnNumber); |
| 82 } | 75 } |
| 83 | 76 |
| 84 /** | 77 /** |
| 85 * @override | 78 * @override |
| 86 * @param {!Workspace.UILocation} uiLocation | 79 * @param {!Workspace.UILocation} uiLocation |
| 87 * @return {!Array<!SDK.CSSLocation>} | 80 * @return {!Array<!SDK.CSSLocation>} |
| 88 */ | 81 */ |
| 89 uiLocationToRawLocations(uiLocation) { | 82 uiLocationToRawLocations(uiLocation) { |
| 90 // TODO(caseq,lushnikov): return multiple raw locations. | 83 var styleFile = uiLocation.uiSourceCode[Bindings.StyleFile._symbol]; |
| 91 var header = Bindings.NetworkProject.styleHeaderForUISourceCode(uiLocation.u
iSourceCode); | 84 if (!styleFile) |
| 92 if (!header) | |
| 93 return []; | 85 return []; |
| 94 var lineNumber = uiLocation.lineNumber; | 86 var rawLocations = []; |
| 95 var columnNumber = uiLocation.columnNumber; | 87 for (var header of styleFile._headers) { |
| 96 if (header.isInline && header.hasSourceURL) { | 88 var lineNumber = uiLocation.lineNumber; |
| 97 columnNumber = header.columnNumberInSource(lineNumber, columnNumber); | 89 var columnNumber = uiLocation.columnNumber; |
| 98 lineNumber = header.lineNumberInSource(lineNumber); | 90 if (header.isInline && header.hasSourceURL) { |
| 91 columnNumber = header.columnNumberInSource(lineNumber, columnNumber); |
| 92 lineNumber = header.lineNumberInSource(lineNumber); |
| 93 } |
| 94 rawLocations.push(new SDK.CSSLocation(header, lineNumber, columnNumber)); |
| 99 } | 95 } |
| 100 return [new SDK.CSSLocation(header, lineNumber, columnNumber)]; | 96 return rawLocations; |
| 101 } | 97 } |
| 102 | 98 |
| 103 /** | 99 /** |
| 100 * @param {!SDK.CSSStyleSheetHeader} header |
| 101 */ |
| 102 _acceptsHeader(header) { |
| 103 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector'
) |
| 104 return false; |
| 105 if (!header.resourceURL()) |
| 106 return false; |
| 107 return true; |
| 108 } |
| 109 |
| 110 /** |
| 104 * @param {!Common.Event} event | 111 * @param {!Common.Event} event |
| 105 */ | 112 */ |
| 106 _styleSheetAdded(event) { | 113 _styleSheetAdded(event) { |
| 107 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | 114 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
| 108 var url = header.resourceURL(); | 115 if (!this._acceptsHeader(header)) |
| 109 if (!url) | |
| 110 return; | 116 return; |
| 111 | 117 |
| 112 var map = this._urlToHeadersByFrameId.get(url); | 118 var url = header.resourceURL(); |
| 113 if (!map) { | 119 var styleFile = this._styleFiles.get(url); |
| 114 map = /** @type {!Map.<string, !Map.<string, !SDK.CSSStyleSheetHeader>>} *
/ (new Map()); | 120 if (!styleFile) { |
| 115 this._urlToHeadersByFrameId.set(url, map); | 121 styleFile = new Bindings.StyleFile(this._cssModel, this._project, header); |
| 122 this._styleFiles.set(url, styleFile); |
| 123 } else { |
| 124 styleFile.addHeader(header); |
| 116 } | 125 } |
| 117 var headersById = map.get(header.frameId); | |
| 118 if (!headersById) { | |
| 119 headersById = /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */ (new
Map()); | |
| 120 map.set(header.frameId, headersById); | |
| 121 } | |
| 122 headersById.set(header.id, header); | |
| 123 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._wor
kspace, url, header); | |
| 124 if (uiSourceCode) | |
| 125 this._bindUISourceCode(uiSourceCode, header); | |
| 126 } | 126 } |
| 127 | 127 |
| 128 /** | 128 /** |
| 129 * @param {!Common.Event} event | 129 * @param {!Common.Event} event |
| 130 */ | 130 */ |
| 131 _styleSheetRemoved(event) { | 131 _styleSheetRemoved(event) { |
| 132 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | 132 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
| 133 if (!this._acceptsHeader(header)) |
| 134 return; |
| 133 var url = header.resourceURL(); | 135 var url = header.resourceURL(); |
| 134 if (!url) | 136 var styleFile = this._styleFiles.get(url); |
| 135 return; | 137 if (styleFile._headers.size === 1) { |
| 136 | 138 styleFile.dispose(); |
| 137 var map = this._urlToHeadersByFrameId.get(url); | 139 this._styleFiles.delete(url); |
| 138 console.assert(map); | 140 } else { |
| 139 var headersById = map.get(header.frameId); | 141 styleFile.removeHeader(header); |
| 140 console.assert(headersById); | 142 } |
| 141 headersById.delete(header.id); | |
| 142 | |
| 143 if (!headersById.size) { | |
| 144 map.delete(header.frameId); | |
| 145 if (!map.size) { | |
| 146 this._urlToHeadersByFrameId.delete(url); | |
| 147 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this.
_workspace, url, header); | |
| 148 if (uiSourceCode) | |
| 149 this._unbindUISourceCode(uiSourceCode); | |
| 150 } | |
| 151 } | |
| 152 } | |
| 153 | |
| 154 /** | |
| 155 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 156 */ | |
| 157 _unbindUISourceCode(uiSourceCode) { | |
| 158 var styleFile = this._styleFiles.get(uiSourceCode); | |
| 159 if (!styleFile) | |
| 160 return; | |
| 161 styleFile.dispose(); | |
| 162 this._styleFiles.delete(uiSourceCode); | |
| 163 } | 143 } |
| 164 | 144 |
| 165 /** | 145 /** |
| 166 * @param {!Common.Event} event | 146 * @param {!Common.Event} event |
| 167 */ | 147 */ |
| 168 _unbindAllUISourceCodes(event) { | 148 _styleSheetChanged(event) { |
| 149 var header = this._cssModel.styleSheetHeaderForId(event.data.styleSheetId); |
| 150 if (!header || !this._acceptsHeader(header)) |
| 151 return; |
| 152 var styleFile = this._styleFiles.get(header.resourceURL()); |
| 153 styleFile._styleSheetChanged(header); |
| 154 } |
| 155 |
| 156 dispose() { |
| 169 for (var styleFile of this._styleFiles.values()) | 157 for (var styleFile of this._styleFiles.values()) |
| 170 styleFile.dispose(); | 158 styleFile.dispose(); |
| 171 this._styleFiles.clear(); | 159 this._styleFiles.clear(); |
| 172 this._urlToHeadersByFrameId = new Map(); | |
| 173 } | |
| 174 | |
| 175 /** | |
| 176 * @param {!Common.Event} event | |
| 177 */ | |
| 178 _uiSourceCodeAddedToWorkspace(event) { | |
| 179 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); | |
| 180 if (!this._urlToHeadersByFrameId.has(uiSourceCode.url())) | |
| 181 return; | |
| 182 this._bindUISourceCode( | |
| 183 uiSourceCode, this._urlToHeadersByFrameId.get(uiSourceCode.url()).values
Array()[0].valuesArray()[0]); | |
| 184 } | |
| 185 | |
| 186 /** | |
| 187 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 188 * @param {!SDK.CSSStyleSheetHeader} header | |
| 189 */ | |
| 190 _bindUISourceCode(uiSourceCode, header) { | |
| 191 if (this._styleFiles.get(uiSourceCode) || (header.isInline && !header.hasSou
rceURL)) | |
| 192 return; | |
| 193 this._styleFiles.set(uiSourceCode, new Bindings.StyleFile(uiSourceCode, this
)); | |
| 194 Bindings.cssWorkspaceBinding.updateLocations(header); | |
| 195 } | |
| 196 | |
| 197 /** | |
| 198 * @param {!Common.Event} event | |
| 199 */ | |
| 200 _projectRemoved(event) { | |
| 201 var project = /** @type {!Workspace.Project} */ (event.data); | |
| 202 var uiSourceCodes = project.uiSourceCodes(); | |
| 203 for (var i = 0; i < uiSourceCodes.length; ++i) | |
| 204 this._unbindUISourceCode(uiSourceCodes[i]); | |
| 205 } | |
| 206 | |
| 207 /** | |
| 208 * @param {!Common.Event} event | |
| 209 */ | |
| 210 _uiSourceCodeRemoved(event) { | |
| 211 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); | |
| 212 this._unbindUISourceCode(uiSourceCode); | |
| 213 } | |
| 214 | |
| 215 /** | |
| 216 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 217 * @param {string} content | |
| 218 * @param {boolean} majorChange | |
| 219 * @return {!Promise<?string>} | |
| 220 */ | |
| 221 async _setStyleContent(uiSourceCode, content, majorChange) { | |
| 222 var styleSheetIds = this._cssModel.styleSheetIdsForURL(uiSourceCode.url()); | |
| 223 if (!styleSheetIds.length) | |
| 224 return 'No stylesheet found: ' + uiSourceCode.url(); | |
| 225 this._isSettingContent = true; | |
| 226 var promises = styleSheetIds.map(id => this._cssModel.setStyleSheetText(id,
content, majorChange)); | |
| 227 | |
| 228 var results = await Promise.all(promises); | |
| 229 | |
| 230 delete this._isSettingContent; | |
| 231 return results.find(error => !!error); | |
| 232 } | |
| 233 | |
| 234 /** | |
| 235 * @param {!Common.Event} event | |
| 236 */ | |
| 237 _styleSheetChanged(event) { | |
| 238 if (this._isSettingContent) | |
| 239 return; | |
| 240 | |
| 241 this._updateStyleSheetTextSoon(event.data.styleSheetId); | |
| 242 } | |
| 243 | |
| 244 /** | |
| 245 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | |
| 246 */ | |
| 247 _updateStyleSheetTextSoon(styleSheetId) { | |
| 248 if (this._updateStyleSheetTextTimer) | |
| 249 clearTimeout(this._updateStyleSheetTextTimer); | |
| 250 | |
| 251 this._updateStyleSheetTextTimer = setTimeout( | |
| 252 this._updateStyleSheetText.bind(this, styleSheetId), Bindings.StylesSour
ceMapping.ChangeUpdateTimeoutMs); | |
| 253 } | |
| 254 | |
| 255 /** | |
| 256 * @param {!Protocol.CSS.StyleSheetId} styleSheetId | |
| 257 */ | |
| 258 _updateStyleSheetText(styleSheetId) { | |
| 259 if (this._updateStyleSheetTextTimer) { | |
| 260 clearTimeout(this._updateStyleSheetTextTimer); | |
| 261 delete this._updateStyleSheetTextTimer; | |
| 262 } | |
| 263 | |
| 264 var header = this._cssModel.styleSheetHeaderForId(styleSheetId); | |
| 265 if (!header) | |
| 266 return; | |
| 267 var styleSheetURL = header.resourceURL(); | |
| 268 if (!styleSheetURL) | |
| 269 return; | |
| 270 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._wor
kspace, styleSheetURL, header); | |
| 271 if (!uiSourceCode) | |
| 272 return; | |
| 273 header.requestContent().then(callback.bind(this, uiSourceCode)); | |
| 274 | |
| 275 /** | |
| 276 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 277 * @param {?string} content | |
| 278 * @this {Bindings.StylesSourceMapping} | |
| 279 */ | |
| 280 function callback(uiSourceCode, content) { | |
| 281 var styleFile = this._styleFiles.get(uiSourceCode); | |
| 282 if (typeof content === 'string' && styleFile) | |
| 283 styleFile.addRevision(content); | |
| 284 this._styleFileSyncedForTest(); | |
| 285 } | |
| 286 } | |
| 287 | |
| 288 _styleFileSyncedForTest() { | |
| 289 } | |
| 290 | |
| 291 dispose() { | |
| 292 Common.EventTarget.removeEventListeners(this._eventListeners); | 160 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 161 this._project.removeProject(); |
| 293 } | 162 } |
| 294 }; | 163 }; |
| 295 | 164 |
| 296 Bindings.StylesSourceMapping.ChangeUpdateTimeoutMs = 200; | |
| 297 | |
| 298 /** | 165 /** |
| 166 * @implements {Common.ContentProvider} |
| 299 * @unrestricted | 167 * @unrestricted |
| 300 */ | 168 */ |
| 301 Bindings.StyleFile = class { | 169 Bindings.StyleFile = class { |
| 302 /** | 170 /** |
| 303 * @param {!Workspace.UISourceCode} uiSourceCode | 171 * @param {!SDK.CSSModel} cssModel |
| 304 * @param {!Bindings.StylesSourceMapping} mapping | 172 * @param {!Bindings.ContentProviderBasedProject} project |
| 305 */ | 173 * @param {!SDK.CSSStyleSheetHeader} header |
| 306 constructor(uiSourceCode, mapping) { | 174 */ |
| 307 this._uiSourceCode = uiSourceCode; | 175 constructor(cssModel, project, header) { |
| 308 this._mapping = mapping; | 176 this._cssModel = cssModel; |
| 177 this._project = project; |
| 178 /** @type {!Set<!SDK.CSSStyleSheetHeader>} */ |
| 179 this._headers = new Set([header]); |
| 180 |
| 181 var target = cssModel.target(); |
| 182 |
| 183 var url = header.resourceURL(); |
| 184 var metadata = Bindings.metadataForURL(target, header.frameId, url); |
| 185 |
| 186 this._uiSourceCode = this._project.createUISourceCode(url, header.contentTyp
e()); |
| 187 this._uiSourceCode[Bindings.StyleFile._symbol] = this; |
| 188 Bindings.NetworkProject.setInitialFrameAttribution(this._uiSourceCode, heade
r.frameId); |
| 189 this._project.addUISourceCodeWithProvider(this._uiSourceCode, this, metadata
, 'text/css'); |
| 190 |
| 309 this._eventListeners = [ | 191 this._eventListeners = [ |
| 310 this._uiSourceCode.addEventListener( | 192 this._uiSourceCode.addEventListener( |
| 311 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCha
nged, this), | 193 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCha
nged, this), |
| 312 this._uiSourceCode.addEventListener( | 194 this._uiSourceCode.addEventListener( |
| 313 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyC
ommitted, this) | 195 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyC
ommitted, this) |
| 314 ]; | 196 ]; |
| 315 this._commitThrottler = new Common.Throttler(Bindings.StyleFile.updateTimeou
t); | 197 this._throttler = new Common.Throttler(Bindings.StyleFile.updateTimeout); |
| 316 this._terminated = false; | 198 this._terminated = false; |
| 317 } | 199 } |
| 318 | 200 |
| 319 /** | 201 /** |
| 202 * @param {!SDK.CSSStyleSheetHeader} header |
| 203 */ |
| 204 addHeader(header) { |
| 205 this._headers.add(header); |
| 206 Bindings.NetworkProject.addFrameAttribution(this._uiSourceCode, header.frame
Id); |
| 207 } |
| 208 |
| 209 /** |
| 210 * @param {!SDK.CSSStyleSheetHeader} header |
| 211 */ |
| 212 removeHeader(header) { |
| 213 this._headers.delete(header); |
| 214 Bindings.NetworkProject.removeFrameAttribution(this._uiSourceCode, header.fr
ameId); |
| 215 } |
| 216 |
| 217 /** |
| 218 * @param {!SDK.CSSStyleSheetHeader} header |
| 219 */ |
| 220 _styleSheetChanged(header) { |
| 221 console.assert(this._headers.has(header)); |
| 222 if (this._isUpdatingHeaders || !this._headers.has(header)) |
| 223 return; |
| 224 var mirrorContentBound = this._mirrorContent.bind(this, header, true /* majo
rChange */); |
| 225 this._throttler.schedule(mirrorContentBound, false /* asSoonAsPossible */); |
| 226 } |
| 227 |
| 228 /** |
| 320 * @param {!Common.Event} event | 229 * @param {!Common.Event} event |
| 321 */ | 230 */ |
| 322 _workingCopyCommitted(event) { | 231 _workingCopyCommitted(event) { |
| 323 if (this._isAddingRevision) | 232 if (this._isAddingRevision) |
| 324 return; | 233 return; |
| 325 | 234 var mirrorContentBound = this._mirrorContent.bind(this, this._uiSourceCode,
true /* majorChange */); |
| 326 this._isMajorChangePending = true; | 235 this._throttler.schedule(mirrorContentBound, true /* asSoonAsPossible */); |
| 327 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), true)
; | |
| 328 } | 236 } |
| 329 | 237 |
| 330 /** | 238 /** |
| 331 * @param {!Common.Event} event | 239 * @param {!Common.Event} event |
| 332 */ | 240 */ |
| 333 _workingCopyChanged(event) { | 241 _workingCopyChanged(event) { |
| 334 if (this._isAddingRevision) | 242 if (this._isAddingRevision) |
| 335 return; | 243 return; |
| 336 | 244 var mirrorContentBound = this._mirrorContent.bind(this, this._uiSourceCode,
false /* majorChange */); |
| 337 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), false
); | 245 this._throttler.schedule(mirrorContentBound, false /* asSoonAsPossible */); |
| 338 } | 246 } |
| 339 | 247 |
| 340 _commitIncrementalEdit() { | 248 /** |
| 341 if (this._terminated) | 249 * @param {!Common.ContentProvider} fromProvider |
| 342 return; | 250 * @param {boolean} majorChange |
| 343 var promise = | 251 * @return {!Promise} |
| 344 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo
rkingCopy(), this._isMajorChangePending) | 252 */ |
| 345 .then(this._styleContentSet.bind(this)); | 253 async _mirrorContent(fromProvider, majorChange) { |
| 346 this._isMajorChangePending = false; | 254 if (this._terminated) { |
| 347 return promise; | 255 this._styleFileSyncedForTest(); |
| 348 } | 256 return; |
| 349 | 257 } |
| 350 /** | 258 |
| 351 * @param {?string} error | 259 var newContent = null; |
| 352 */ | 260 if (fromProvider === this._uiSourceCode) { |
| 353 _styleContentSet(error) { | 261 newContent = this._uiSourceCode.workingCopy(); |
| 354 if (error) | 262 } else { |
| 355 console.error(error); | 263 // ------ ASYNC ------ |
| 356 } | 264 newContent = await fromProvider.requestContent(); |
| 357 | 265 } |
| 358 /** | 266 |
| 359 * @param {string} content | 267 if (newContent === null || this._terminated) { |
| 360 */ | 268 this._styleFileSyncedForTest(); |
| 361 addRevision(content) { | 269 return; |
| 362 this._isAddingRevision = true; | 270 } |
| 363 this._uiSourceCode.addRevision(content); | 271 |
| 364 delete this._isAddingRevision; | 272 if (fromProvider !== this._uiSourceCode) { |
| 273 this._isAddingRevision = true; |
| 274 this._uiSourceCode.addRevision(newContent); |
| 275 this._isAddingRevision = false; |
| 276 } |
| 277 |
| 278 this._isUpdatingHeaders = true; |
| 279 var promises = []; |
| 280 for (var header of this._headers) { |
| 281 if (header === fromProvider) |
| 282 continue; |
| 283 promises.push(this._cssModel.setStyleSheetText(header.id, newContent, majo
rChange)); |
| 284 } |
| 285 // ------ ASYNC ------ |
| 286 await Promise.all(promises); |
| 287 this._isUpdatingHeaders = false; |
| 288 this._styleFileSyncedForTest(); |
| 289 } |
| 290 |
| 291 _styleFileSyncedForTest() { |
| 365 } | 292 } |
| 366 | 293 |
| 367 dispose() { | 294 dispose() { |
| 368 if (this._terminated) | 295 if (this._terminated) |
| 369 return; | 296 return; |
| 370 this._terminated = true; | 297 this._terminated = true; |
| 298 this._project.removeFile(this._uiSourceCode.url()); |
| 371 Common.EventTarget.removeEventListeners(this._eventListeners); | 299 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 372 } | 300 } |
| 301 |
| 302 /** |
| 303 * @override |
| 304 * @return {string} |
| 305 */ |
| 306 contentURL() { |
| 307 return this._headers.firstValue().originalContentProvider().contentURL(); |
| 308 } |
| 309 |
| 310 /** |
| 311 * @override |
| 312 * @return {!Common.ResourceType} |
| 313 */ |
| 314 contentType() { |
| 315 return this._headers.firstValue().originalContentProvider().contentType(); |
| 316 } |
| 317 |
| 318 /** |
| 319 * @override |
| 320 * @return {!Promise<?string>} |
| 321 */ |
| 322 requestContent() { |
| 323 return this._headers.firstValue().originalContentProvider().requestContent()
; |
| 324 } |
| 325 |
| 326 /** |
| 327 * @override |
| 328 * @param {string} query |
| 329 * @param {boolean} caseSensitive |
| 330 * @param {boolean} isRegex |
| 331 * @return {!Promise<!Array<!Common.ContentProvider.SearchMatch>>} |
| 332 */ |
| 333 searchInContent(query, caseSensitive, isRegex) { |
| 334 return this._headers.firstValue().originalContentProvider().searchInContent(
query, caseSensitive, isRegex); |
| 335 } |
| 373 }; | 336 }; |
| 374 | 337 |
| 338 Bindings.StyleFile._symbol = Symbol('Bindings.StyleFile._symbol'); |
| 339 |
| 375 Bindings.StyleFile.updateTimeout = 200; | 340 Bindings.StyleFile.updateTimeout = 200; |
| OLD | NEW |