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); | 143 } |
142 | 144 |
143 if (!headersById.size) { | 145 _styleSheetChanged(event) { |
dgozman
2017/06/13 19:09:38
JSDoc
lushnikov
2017/06/13 19:25:21
Done.
| |
144 map.delete(header.frameId); | 146 var header = this._cssModel.styleSheetHeaderForId(event.data.styleSheetId); |
145 if (!map.size) { | 147 if (!header || !this._acceptsHeader(header)) |
146 this._urlToHeadersByFrameId.delete(url); | 148 return; |
147 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this. _workspace, url, header); | 149 var styleFile = this._styleFiles.get(header.resourceURL()); |
148 if (uiSourceCode) | 150 styleFile._styleSheetChanged(header); |
149 this._unbindUISourceCode(uiSourceCode); | 151 } |
150 } | 152 |
151 } | 153 dispose() { |
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 } | |
164 | |
165 /** | |
166 * @param {!Common.Event} event | |
167 */ | |
168 _unbindAllUISourceCodes(event) { | |
169 for (var styleFile of this._styleFiles.values()) | 154 for (var styleFile of this._styleFiles.values()) |
170 styleFile.dispose(); | 155 styleFile.dispose(); |
171 this._styleFiles.clear(); | 156 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); | 157 Common.EventTarget.removeEventListeners(this._eventListeners); |
158 this._project.removeProject(); | |
293 } | 159 } |
294 }; | 160 }; |
295 | 161 |
296 Bindings.StylesSourceMapping.ChangeUpdateTimeoutMs = 200; | |
297 | |
298 /** | 162 /** |
163 * @implements {Common.ContentProvider} | |
299 * @unrestricted | 164 * @unrestricted |
300 */ | 165 */ |
301 Bindings.StyleFile = class { | 166 Bindings.StyleFile = class { |
302 /** | 167 /** |
303 * @param {!Workspace.UISourceCode} uiSourceCode | 168 * @param {!SDK.CSSModel} cssModel |
304 * @param {!Bindings.StylesSourceMapping} mapping | 169 * @param {!Bindings.ContentProviderBasedProject} project |
305 */ | 170 * @param {!SDK.CSSStyleSheetHeader} header |
306 constructor(uiSourceCode, mapping) { | 171 */ |
307 this._uiSourceCode = uiSourceCode; | 172 constructor(cssModel, project, header) { |
308 this._mapping = mapping; | 173 this._cssModel = cssModel; |
174 this._project = project; | |
175 /** @type {!Set<!SDK.CSSStyleSheetHeader>} */ | |
176 this._headers = new Set([header]); | |
177 | |
178 var target = cssModel.target(); | |
179 | |
180 var url = header.resourceURL(); | |
181 var metadata = Bindings.metadataForURL(target, header.frameId, url); | |
182 | |
183 this._uiSourceCode = this._project.createUISourceCode(url, header.contentTyp e()); | |
184 this._uiSourceCode[Bindings.StyleFile._symbol] = this; | |
185 Bindings.NetworkProject.setInitialFrameAttribution(this._uiSourceCode, heade r.frameId); | |
186 this._project.addUISourceCodeWithProvider(this._uiSourceCode, this, metadata , 'text/css'); | |
187 | |
309 this._eventListeners = [ | 188 this._eventListeners = [ |
310 this._uiSourceCode.addEventListener( | 189 this._uiSourceCode.addEventListener( |
311 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCha nged, this), | 190 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCha nged, this), |
312 this._uiSourceCode.addEventListener( | 191 this._uiSourceCode.addEventListener( |
313 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyC ommitted, this) | 192 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyC ommitted, this) |
314 ]; | 193 ]; |
315 this._commitThrottler = new Common.Throttler(Bindings.StyleFile.updateTimeou t); | 194 this._throttler = new Common.Throttler(Bindings.StyleFile.updateTimeout); |
316 this._terminated = false; | 195 this._terminated = false; |
317 } | 196 } |
318 | 197 |
319 /** | 198 /** |
199 * @param {!SDK.CSSStyleSheetHeader} header | |
200 */ | |
201 addHeader(header) { | |
202 this._headers.add(header); | |
203 Bindings.NetworkProject.addFrameAttribution(this._uiSourceCode, header.frame Id); | |
204 } | |
205 | |
206 /** | |
207 * @param {!SDK.CSSStyleSheetHeader} header | |
208 */ | |
209 removeHeader(header) { | |
210 this._headers.delete(header); | |
211 Bindings.NetworkProject.removeFrameAttribution(this._uiSourceCode, header.fr ameId); | |
212 } | |
213 | |
214 /** | |
215 * @param {!SDK.CSSStyleSheetHeader} header | |
216 */ | |
217 _styleSheetChanged(header) { | |
218 if (this._isUpdatingHeaders || !this._headers.has(header)) | |
dgozman
2017/06/13 19:09:38
Let's assert instead.
lushnikov
2017/06/13 19:25:21
Done.
| |
219 return; | |
220 var mirrorContentBound = this._mirrorContent.bind(this, header, true /* majo rChange */); | |
221 this._throttler.schedule(mirrorContentBound, false /* asSoonAsPossible */); | |
222 } | |
223 | |
224 /** | |
320 * @param {!Common.Event} event | 225 * @param {!Common.Event} event |
321 */ | 226 */ |
322 _workingCopyCommitted(event) { | 227 _workingCopyCommitted(event) { |
323 if (this._isAddingRevision) | 228 if (this._isAddingRevision) |
324 return; | 229 return; |
325 | 230 var mirrorContentBound = this._mirrorContent.bind(this, this._uiSourceCode, true /* majorChange */); |
326 this._isMajorChangePending = true; | 231 this._throttler.schedule(mirrorContentBound, true /* asSoonAsPossible */); |
327 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), true) ; | |
328 } | 232 } |
329 | 233 |
330 /** | 234 /** |
331 * @param {!Common.Event} event | 235 * @param {!Common.Event} event |
332 */ | 236 */ |
333 _workingCopyChanged(event) { | 237 _workingCopyChanged(event) { |
334 if (this._isAddingRevision) | 238 if (this._isAddingRevision) |
335 return; | 239 return; |
336 | 240 var mirrorContentBound = this._mirrorContent.bind(this, this._uiSourceCode, false /* majorChange */); |
337 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), false ); | 241 this._throttler.schedule(mirrorContentBound, false /* asSoonAsPossible */); |
338 } | 242 } |
339 | 243 |
340 _commitIncrementalEdit() { | 244 /** |
245 * @param {!Common.ContentProvider} fromProvider | |
246 * @param {boolean} majorChange | |
247 * @return {!Promise} | |
248 */ | |
249 async _mirrorContent(fromProvider, majorChange) { | |
341 if (this._terminated) | 250 if (this._terminated) |
342 return; | 251 return; |
dgozman
2017/06/13 19:09:38
this._styleFileSyncedForTest();
lushnikov
2017/06/13 19:25:21
Done.
| |
343 var promise = | 252 |
344 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo rkingCopy(), this._isMajorChangePending) | 253 var newContent = null; |
345 .then(this._styleContentSet.bind(this)); | 254 if (fromProvider === this._uiSourceCode) { |
346 this._isMajorChangePending = false; | 255 newContent = this._uiSourceCode.workingCopy(); |
347 return promise; | 256 } else { |
348 } | 257 // ------ ASYNC ------ |
349 | 258 newContent = await fromProvider.requestContent(); |
350 /** | 259 } |
351 * @param {?string} error | 260 |
352 */ | 261 if (newContent === null || this._terminated) { |
353 _styleContentSet(error) { | 262 this._styleFileSyncedForTest(); |
354 if (error) | 263 return; |
355 console.error(error); | 264 } |
356 } | 265 |
357 | 266 if (fromProvider !== this._uiSourceCode) { |
358 /** | 267 this._isAddingRevision = true; |
359 * @param {string} content | 268 this._uiSourceCode.addRevision(newContent); |
360 */ | 269 this._isAddingRevision = false; |
361 addRevision(content) { | 270 } |
362 this._isAddingRevision = true; | 271 |
363 this._uiSourceCode.addRevision(content); | 272 this._isUpdatingHeaders = true; |
364 delete this._isAddingRevision; | 273 var promises = []; |
274 for (var header of this._headers) { | |
275 if (header === fromProvider) | |
276 continue; | |
277 promises.push(this._cssModel.setStyleSheetText(header.id, newContent, majo rChange)); | |
278 } | |
279 // ------ ASYNC ------ | |
280 await Promise.all(promises); | |
281 this._isUpdatingHeaders = false; | |
282 this._styleFileSyncedForTest(); | |
283 } | |
284 | |
285 _styleFileSyncedForTest() { | |
365 } | 286 } |
366 | 287 |
367 dispose() { | 288 dispose() { |
368 if (this._terminated) | 289 if (this._terminated) |
369 return; | 290 return; |
370 this._terminated = true; | 291 this._terminated = true; |
292 this._project.removeFile(this._uiSourceCode.url()); | |
371 Common.EventTarget.removeEventListeners(this._eventListeners); | 293 Common.EventTarget.removeEventListeners(this._eventListeners); |
372 } | 294 } |
295 | |
296 /** | |
297 * @override | |
298 * @return {string} | |
299 */ | |
300 contentURL() { | |
301 return this._headers.firstValue().originalContentProvider().contentURL(); | |
302 } | |
303 | |
304 /** | |
305 * @override | |
306 * @return {!Common.ResourceType} | |
307 */ | |
308 contentType() { | |
309 return this._headers.firstValue().originalContentProvider().contentType(); | |
310 } | |
311 | |
312 /** | |
313 * @override | |
314 * @return {!Promise<?string>} | |
315 */ | |
316 requestContent() { | |
317 return this._headers.firstValue().originalContentProvider().requestContent() ; | |
318 } | |
319 | |
320 /** | |
321 * @override | |
322 * @param {string} query | |
323 * @param {boolean} caseSensitive | |
324 * @param {boolean} isRegex | |
325 * @return {!Promise<!Array<!Common.ContentProvider.SearchMatch>>} | |
326 */ | |
327 searchInContent(query, caseSensitive, isRegex) { | |
328 return this._headers.firstValue().originalContentProvider().searchInContent( query, caseSensitive, isRegex); | |
329 } | |
373 }; | 330 }; |
374 | 331 |
332 Bindings.StyleFile._symbol = Symbol('Bindings.StyleFile._symbol'); | |
333 | |
375 Bindings.StyleFile.updateTimeout = 200; | 334 Bindings.StyleFile.updateTimeout = 200; |
OLD | NEW |