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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 this._resourceTreeModel.addEventListener( 47 this._resourceTreeModel.addEventListener(
48 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._resetStyleSheet s, this); 48 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._resetStyleSheet s, this);
49 } 49 }
50 target.registerCSSDispatcher(new SDK.CSSDispatcher(this)); 50 target.registerCSSDispatcher(new SDK.CSSDispatcher(this));
51 this._agent.enable().then(this._wasEnabled.bind(this)); 51 this._agent.enable().then(this._wasEnabled.bind(this));
52 /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */ 52 /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */
53 this._styleSheetIdToHeader = new Map(); 53 this._styleSheetIdToHeader = new Map();
54 /** @type {!Map.<string, !Object.<!Protocol.Page.FrameId, !Array.<!Protocol. CSS.StyleSheetId>>>} */ 54 /** @type {!Map.<string, !Object.<!Protocol.Page.FrameId, !Array.<!Protocol. CSS.StyleSheetId>>>} */
55 this._styleSheetIdsForURL = new Map(); 55 this._styleSheetIdsForURL = new Map();
56 56
57 /** @type {!Multimap<string, function(!SDK.CSSStyleSheetHeader)>} */
58 this._styleSheetChangeSubscribers = new Multimap();
59
57 /** @type {!Map.<!SDK.CSSStyleSheetHeader, !Promise<?string>>} */ 60 /** @type {!Map.<!SDK.CSSStyleSheetHeader, !Promise<?string>>} */
58 this._originalStyleSheetText = new Map(); 61 this._originalStyleSheetText = new Map();
59 62
60 this._sourceMapManager.setEnabled(Common.moduleSetting('cssSourceMapsEnabled ').get()); 63 this._sourceMapManager.setEnabled(Common.moduleSetting('cssSourceMapsEnabled ').get());
61 Common.moduleSetting('cssSourceMapsEnabled') 64 Common.moduleSetting('cssSourceMapsEnabled')
62 .addChangeListener(event => this._sourceMapManager.setEnabled(/** @type {boolean} */ (event.data))); 65 .addChangeListener(event => this._sourceMapManager.setEnabled(/** @type {boolean} */ (event.data)));
63 } 66 }
64 67
65 /** 68 /**
66 * @return {!SDK.SourceMapManager<!SDK.CSSStyleSheetHeader>} 69 * @return {!SDK.SourceMapManager<!SDK.CSSStyleSheetHeader>}
(...skipping 17 matching lines...) Expand all
84 if (sourceURLLineIndex === -1) 87 if (sourceURLLineIndex === -1)
85 return text; 88 return text;
86 var sourceURLLine = text.substr(sourceURLLineIndex + 1).split('\n', 1)[0]; 89 var sourceURLLine = text.substr(sourceURLLineIndex + 1).split('\n', 1)[0];
87 var sourceURLRegex = /[\040\t]*\/\*[#@] sourceURL=[\040\t]*([^\s]*)[\040\t]* \*\/[\040\t]*$/; 90 var sourceURLRegex = /[\040\t]*\/\*[#@] sourceURL=[\040\t]*([^\s]*)[\040\t]* \*\/[\040\t]*$/;
88 if (sourceURLLine.search(sourceURLRegex) === -1) 91 if (sourceURLLine.search(sourceURLRegex) === -1)
89 return text; 92 return text;
90 return text.substr(0, sourceURLLineIndex) + text.substr(sourceURLLineIndex + sourceURLLine.length + 1); 93 return text.substr(0, sourceURLLineIndex) + text.substr(sourceURLLineIndex + sourceURLLine.length + 1);
91 } 94 }
92 95
93 /** 96 /**
97 * @param {string} headerId
98 * @param {function(!SDK.CSSStyleSheetHeader)} callback
99 */
100 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
101 this._styleSheetChangeSubscribers.set(headerId, callback);
102 }
103
104 /**
105 * @param {string} headerId
106 * @param {function(!SDK.CSSStyleSheetHeader)} callback
107 */
108 unsubscribeFromStyleSheetChanged(headerId, callback) {
109 this._styleSheetChangeSubscribers.remove(headerId, callback);
110 }
111
112 /**
94 * @return {!SDK.DOMModel} 113 * @return {!SDK.DOMModel}
95 */ 114 */
96 domModel() { 115 domModel() {
97 return this._domModel; 116 return this._domModel;
98 } 117 }
99 118
100 /** 119 /**
101 * @param {!Protocol.CSS.StyleSheetId} styleSheetId 120 * @param {!Protocol.CSS.StyleSheetId} styleSheetId
102 * @param {!TextUtils.TextRange} range 121 * @param {!TextUtils.TextRange} range
103 * @param {string} text 122 * @param {string} text
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 */ 648 */
630 styleSheetHeaders() { 649 styleSheetHeaders() {
631 return this._styleSheetIdToHeader.valuesArray(); 650 return this._styleSheetIdToHeader.valuesArray();
632 } 651 }
633 652
634 /** 653 /**
635 * @param {!Protocol.CSS.StyleSheetId} styleSheetId 654 * @param {!Protocol.CSS.StyleSheetId} styleSheetId
636 * @param {!SDK.CSSModel.Edit=} edit 655 * @param {!SDK.CSSModel.Edit=} edit
637 */ 656 */
638 _fireStyleSheetChanged(styleSheetId, edit) { 657 _fireStyleSheetChanged(styleSheetId, edit) {
658 if (this._styleSheetChangeSubscribers.has(styleSheetId)) {
659 var header = this._styleSheetIdToHeader.get(styleSheetId);
660 var subscribers = Array.from(this._styleSheetChangeSubscribers.get(styleSh eetId));
661 if (header && subscribers)
662 subscribers.forEach(subscriber => subscriber.call(null, header));
663 }
639 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetChanged, {styleS heetId: styleSheetId, edit: edit}); 664 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetChanged, {styleS heetId: styleSheetId, edit: edit});
640 } 665 }
641 666
642 /** 667 /**
643 * @param {!Protocol.CSS.StyleSheetId} styleSheetId 668 * @param {!Protocol.CSS.StyleSheetId} styleSheetId
644 * @return {!Promise<?string>} 669 * @return {!Promise<?string>}
645 */ 670 */
646 _ensureOriginalStyleSheetText(styleSheetId) { 671 _ensureOriginalStyleSheetText(styleSheetId) {
647 var header = this.styleSheetHeaderForId(styleSheetId); 672 var header = this.styleSheetHeaderForId(styleSheetId);
648 if (!header) 673 if (!header)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 718
694 /** 719 /**
695 * @param {!Protocol.CSS.StyleSheetId} id 720 * @param {!Protocol.CSS.StyleSheetId} id
696 */ 721 */
697 _styleSheetRemoved(id) { 722 _styleSheetRemoved(id) {
698 var header = this._styleSheetIdToHeader.get(id); 723 var header = this._styleSheetIdToHeader.get(id);
699 console.assert(header); 724 console.assert(header);
700 if (!header) 725 if (!header)
701 return; 726 return;
702 this._styleSheetIdToHeader.remove(id); 727 this._styleSheetIdToHeader.remove(id);
728 this._styleSheetChangeSubscribers.removeAll(id);
703 var url = header.resourceURL(); 729 var url = header.resourceURL();
704 var frameIdToStyleSheetIds = /** @type {!Object.<!Protocol.Page.FrameId, !Ar ray.<!Protocol.CSS.StyleSheetId>>} */ ( 730 var frameIdToStyleSheetIds = /** @type {!Object.<!Protocol.Page.FrameId, !Ar ray.<!Protocol.CSS.StyleSheetId>>} */ (
705 this._styleSheetIdsForURL.get(url)); 731 this._styleSheetIdsForURL.get(url));
706 console.assert(frameIdToStyleSheetIds, 'No frameId to styleSheetId map is av ailable for given style sheet URL.'); 732 console.assert(frameIdToStyleSheetIds, 'No frameId to styleSheetId map is av ailable for given style sheet URL.');
707 frameIdToStyleSheetIds[header.frameId].remove(id); 733 frameIdToStyleSheetIds[header.frameId].remove(id);
708 if (!frameIdToStyleSheetIds[header.frameId].length) { 734 if (!frameIdToStyleSheetIds[header.frameId].length) {
709 delete frameIdToStyleSheetIds[header.frameId]; 735 delete frameIdToStyleSheetIds[header.frameId];
710 if (!Object.keys(frameIdToStyleSheetIds).length) 736 if (!Object.keys(frameIdToStyleSheetIds).length)
711 this._styleSheetIdsForURL.remove(url); 737 this._styleSheetIdsForURL.remove(url);
712 } 738 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 SDK.CSSModel.InlineStyleResult = class { 1051 SDK.CSSModel.InlineStyleResult = class {
1026 /** 1052 /**
1027 * @param {?SDK.CSSStyleDeclaration} inlineStyle 1053 * @param {?SDK.CSSStyleDeclaration} inlineStyle
1028 * @param {?SDK.CSSStyleDeclaration} attributesStyle 1054 * @param {?SDK.CSSStyleDeclaration} attributesStyle
1029 */ 1055 */
1030 constructor(inlineStyle, attributesStyle) { 1056 constructor(inlineStyle, attributesStyle) {
1031 this.inlineStyle = inlineStyle; 1057 this.inlineStyle = inlineStyle;
1032 this.attributesStyle = attributesStyle; 1058 this.attributesStyle = attributesStyle;
1033 } 1059 }
1034 }; 1060 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698