Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Side by Side Diff: Source/devtools/front_end/bindings/StylesSourceMapping.js

Issue 1212263002: DevTools: [CSS] migrate setStyleSheetText to promises (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 continue; 240 continue;
241 this._unbindUISourceCode(uiSourceCode); 241 this._unbindUISourceCode(uiSourceCode);
242 } 242 }
243 this._initialize(); 243 this._initialize();
244 }, 244 },
245 245
246 /** 246 /**
247 * @param {!WebInspector.UISourceCode} uiSourceCode 247 * @param {!WebInspector.UISourceCode} uiSourceCode
248 * @param {string} content 248 * @param {string} content
249 * @param {boolean} majorChange 249 * @param {boolean} majorChange
250 * @param {function(?string)} userCallback 250 * @return {!Promise<?string>}
251 */ 251 */
252 _setStyleContent: function(uiSourceCode, content, majorChange, userCallback) 252 _setStyleContent: function(uiSourceCode, content, majorChange)
253 { 253 {
254 var networkURL = this._networkMapping.networkURL(uiSourceCode); 254 var networkURL = this._networkMapping.networkURL(uiSourceCode);
255 var styleSheetIds = this._cssModel.styleSheetIdsForURL(networkURL); 255 var styleSheetIds = this._cssModel.styleSheetIdsForURL(networkURL);
256 if (!styleSheetIds.length) { 256 if (!styleSheetIds.length)
257 userCallback("No stylesheet found: " + networkURL); 257 return Promise.resolve(/** @type {?string} */("No stylesheet found: " + networkURL));
258 return;
259 }
260 258
261 this._isSettingContent = true; 259 this._isSettingContent = true;
262 260
263 /** 261 /**
264 * @param {?Protocol.Error} error
265 * @this {WebInspector.StylesSourceMapping} 262 * @this {WebInspector.StylesSourceMapping}
263 * @return {?string}
266 */ 264 */
267 function callback(error) 265 function callback()
268 { 266 {
269 userCallback(error);
pfeldman 2015/06/26 09:13:42 If there was one stylesheet, a very common case, w
lushnikov 2015/06/26 12:33:28 Done.
270 delete this._isSettingContent; 267 delete this._isSettingContent;
268 return null;
271 } 269 }
272 270
273 271 var promises = [];
274 for (var i = 0; i < styleSheetIds.length; ++i) 272 for (var i = 0; i < styleSheetIds.length; ++i)
275 this._cssModel.setStyleSheetText(styleSheetIds[i], content, majorCha nge, i === styleSheetIds.length - 1 ? callback.bind(this) : null); 273 promises.push(this._cssModel.setStyleSheetText(styleSheetIds[i], con tent, majorChange));
274 return Promise.all(promises).then(callback.bind(this));
276 }, 275 },
277 276
278 /** 277 /**
279 * @param {!WebInspector.Event} event 278 * @param {!WebInspector.Event} event
280 */ 279 */
281 _styleSheetChanged: function(event) 280 _styleSheetChanged: function(event)
282 { 281 {
283 if (this._isSettingContent) 282 if (this._isSettingContent)
284 return; 283 return;
285 284
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 { 372 {
374 if (this._isAddingRevision) 373 if (this._isAddingRevision)
375 return; 374 return;
376 375
377 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), f alse); 376 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), f alse);
378 }, 377 },
379 378
380 /** 379 /**
381 * @param {!WebInspector.Throttler.FinishCallback} finishCallback 380 * @param {!WebInspector.Throttler.FinishCallback} finishCallback
382 */ 381 */
383 _commitIncrementalEdit: function(finishCallback) 382 _commitIncrementalEdit: function(finishCallback)
pfeldman 2015/06/26 09:13:42 Add fixme to make it a promise?
lushnikov 2015/06/26 12:33:28 Acknowledged.
384 { 383 {
385 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo rkingCopy(), this._isMajorChangePending, this._styleContentSet.bind(this, finish Callback)); 384 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo rkingCopy(), this._isMajorChangePending)
385 .then(this._styleContentSet.bind(this))
386 .then(finishCallback)
387 .catch(/** @type {function()} */(finishCallback));
386 this._isMajorChangePending = false; 388 this._isMajorChangePending = false;
387 }, 389 },
388 390
389 /** 391 /**
390 * @param {!WebInspector.Throttler.FinishCallback} finishCallback
391 * @param {?string} error 392 * @param {?string} error
392 */ 393 */
393 _styleContentSet: function(finishCallback, error) 394 _styleContentSet: function(error)
394 { 395 {
395 if (error) 396 if (error)
396 WebInspector.console.error(error); 397 WebInspector.console.error(error);
397 finishCallback();
398 }, 398 },
399 399
400 /** 400 /**
401 * @param {string} content 401 * @param {string} content
402 */ 402 */
403 addRevision: function(content) 403 addRevision: function(content)
404 { 404 {
405 this._isAddingRevision = true; 405 this._isAddingRevision = true;
406 this._uiSourceCode.addRevision(content); 406 this._uiSourceCode.addRevision(content);
407 delete this._isAddingRevision; 407 delete this._isAddingRevision;
408 }, 408 },
409 409
410 dispose: function() 410 dispose: function()
411 { 411 {
412 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyCommitted, this._workingCopyCommitted, this); 412 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyCommitted, this._workingCopyCommitted, this);
413 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyChanged, this._workingCopyChanged, this); 413 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyChanged, this._workingCopyChanged, this);
414 } 414 }
415 } 415 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698