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