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

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: log error from first stylesheet 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 262 * @param {?string} error
265 * @this {WebInspector.StylesSourceMapping} 263 * @this {WebInspector.StylesSourceMapping}
264 * @return {?string}
266 */ 265 */
267 function callback(error) 266 function callback(error)
268 { 267 {
269 userCallback(error);
270 delete this._isSettingContent; 268 delete this._isSettingContent;
269 return error || null;
271 } 270 }
272 271
272 var promises = [];
273 for (var i = 0; i < styleSheetIds.length; ++i)
274 promises.push(this._cssModel.setStyleSheetText(styleSheetIds[i], con tent, majorChange));
273 275
274 for (var i = 0; i < styleSheetIds.length; ++i) 276 return Promise.all(promises).spread(callback.bind(this));
275 this._cssModel.setStyleSheetText(styleSheetIds[i], content, majorCha nge, i === styleSheetIds.length - 1 ? callback.bind(this) : null);
276 }, 277 },
277 278
278 /** 279 /**
279 * @param {!WebInspector.Event} event 280 * @param {!WebInspector.Event} event
280 */ 281 */
281 _styleSheetChanged: function(event) 282 _styleSheetChanged: function(event)
282 { 283 {
283 if (this._isSettingContent) 284 if (this._isSettingContent)
284 return; 285 return;
285 286
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 return; 376 return;
376 377
377 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), f alse); 378 this._commitThrottler.schedule(this._commitIncrementalEdit.bind(this), f alse);
378 }, 379 },
379 380
380 /** 381 /**
381 * @param {!WebInspector.Throttler.FinishCallback} finishCallback 382 * @param {!WebInspector.Throttler.FinishCallback} finishCallback
382 */ 383 */
383 _commitIncrementalEdit: function(finishCallback) 384 _commitIncrementalEdit: function(finishCallback)
384 { 385 {
385 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo rkingCopy(), this._isMajorChangePending, this._styleContentSet.bind(this, finish Callback)); 386 this._mapping._setStyleContent(this._uiSourceCode, this._uiSourceCode.wo rkingCopy(), this._isMajorChangePending)
387 .then(this._styleContentSet.bind(this))
388 .then(finishCallback)
389 .catch(/** @type {function()} */(finishCallback));
386 this._isMajorChangePending = false; 390 this._isMajorChangePending = false;
387 }, 391 },
388 392
389 /** 393 /**
390 * @param {!WebInspector.Throttler.FinishCallback} finishCallback
391 * @param {?string} error 394 * @param {?string} error
392 */ 395 */
393 _styleContentSet: function(finishCallback, error) 396 _styleContentSet: function(error)
394 { 397 {
395 if (error) 398 if (error)
396 WebInspector.console.error(error); 399 WebInspector.console.error(error);
397 finishCallback();
398 }, 400 },
399 401
400 /** 402 /**
401 * @param {string} content 403 * @param {string} content
402 */ 404 */
403 addRevision: function(content) 405 addRevision: function(content)
404 { 406 {
405 this._isAddingRevision = true; 407 this._isAddingRevision = true;
406 this._uiSourceCode.addRevision(content); 408 this._uiSourceCode.addRevision(content);
407 delete this._isAddingRevision; 409 delete this._isAddingRevision;
408 }, 410 },
409 411
410 dispose: function() 412 dispose: function()
411 { 413 {
412 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyCommitted, this._workingCopyCommitted, this); 414 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyCommitted, this._workingCopyCommitted, this);
413 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyChanged, this._workingCopyChanged, this); 415 this._uiSourceCode.removeEventListener(WebInspector.UISourceCode.Events. WorkingCopyChanged, this._workingCopyChanged, this);
414 } 416 }
415 } 417 }
OLDNEW
« no previous file with comments | « LayoutTests/inspector/elements/styles-4/styles-new-API.html ('k') | Source/devtools/front_end/sdk/CSSStyleModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698