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

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/CSSModel.js

Issue 2893523002: DevTools: make StyleSourceMapping in charge of managing UISourceCodes (Closed)
Patch Set: update test Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sdk/CSSModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/CSSModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/CSSModel.js
index 13c1d7b3b4628e673d1a1f6205e6d0315144393f..9698bdb413fe040fef6d3d18c43563e90b7d0909 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/CSSModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/CSSModel.js
@@ -54,6 +54,9 @@ SDK.CSSModel = class extends SDK.SDKModel {
/** @type {!Map.<string, !Object.<!Protocol.Page.FrameId, !Array.<!Protocol.CSS.StyleSheetId>>>} */
this._styleSheetIdsForURL = new Map();
+ /** @type {!Multimap<string, function(!SDK.CSSStyleSheetHeader)>} */
+ this._styleSheetChangeSubscribers = new Multimap();
+
/** @type {!Map.<!SDK.CSSStyleSheetHeader, !Promise<?string>>} */
this._originalStyleSheetText = new Map();
@@ -91,6 +94,22 @@ SDK.CSSModel = class extends SDK.SDKModel {
}
/**
+ * @param {string} headerId
+ * @param {function(!SDK.CSSStyleSheetHeader)} callback
+ */
+ subscribeToStyleSheetChanged(headerId, callback) {
dgozman 2017/05/17 16:46:20 Why subscribe here and not route through StyleSour
lushnikov 2017/05/20 01:24:18 Subscribe/unsubscribe is a natural API to get upda
+ this._styleSheetChangeSubscribers.set(headerId, callback);
+ }
+
+ /**
+ * @param {string} headerId
+ * @param {function(!SDK.CSSStyleSheetHeader)} callback
+ */
+ unsubscribeFromStyleSheetChanged(headerId, callback) {
+ this._styleSheetChangeSubscribers.remove(headerId, callback);
+ }
+
+ /**
* @return {!SDK.DOMModel}
*/
domModel() {
@@ -636,6 +655,12 @@ SDK.CSSModel = class extends SDK.SDKModel {
* @param {!SDK.CSSModel.Edit=} edit
*/
_fireStyleSheetChanged(styleSheetId, edit) {
+ if (this._styleSheetChangeSubscribers.has(styleSheetId)) {
+ var header = this._styleSheetIdToHeader.get(styleSheetId);
+ var subscribers = Array.from(this._styleSheetChangeSubscribers.get(styleSheetId));
+ if (header && subscribers)
+ subscribers.forEach(subscriber => subscriber.call(null, header));
+ }
this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetChanged, {styleSheetId: styleSheetId, edit: edit});
}
@@ -700,6 +725,7 @@ SDK.CSSModel = class extends SDK.SDKModel {
if (!header)
return;
this._styleSheetIdToHeader.remove(id);
+ this._styleSheetChangeSubscribers.removeAll(id);
var url = header.resourceURL();
var frameIdToStyleSheetIds = /** @type {!Object.<!Protocol.Page.FrameId, !Array.<!Protocol.CSS.StyleSheetId>>} */ (
this._styleSheetIdsForURL.get(url));

Powered by Google App Engine
This is Rietveld 408576698