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

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

Issue 2168323002: [DevTools] Explicitly require ResourceTreeModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: URL management was split into a separate CL Created 4 years, 4 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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.SDKModel} 33 * @extends {WebInspector.SDKModel}
34 * @param {!WebInspector.Target} target 34 * @param {!WebInspector.Target} target
35 * @param {!WebInspector.DOMModel} domModel
35 */ 36 */
36 WebInspector.CSSModel = function(target) 37 WebInspector.CSSModel = function(target, domModel)
37 { 38 {
38 WebInspector.SDKModel.call(this, WebInspector.CSSModel, target); 39 WebInspector.SDKModel.call(this, WebInspector.CSSModel, target);
39 this._domModel = WebInspector.DOMModel.fromTarget(target); 40 this._domModel = domModel;
40 this._agent = target.cssAgent(); 41 this._agent = target.cssAgent();
41 this._styleLoader = new WebInspector.CSSModel.ComputedStyleLoader(this); 42 this._styleLoader = new WebInspector.CSSModel.ComputedStyleLoader(this);
42 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); 43 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.MainFrameNavigated, this._mainFrameNavigated, this);
43 target.registerCSSDispatcher(new WebInspector.CSSDispatcher(this)); 44 target.registerCSSDispatcher(new WebInspector.CSSDispatcher(this));
44 this._agent.enable().then(this._wasEnabled.bind(this)); 45 this._agent.enable().then(this._wasEnabled.bind(this));
45 /** @type {!Map.<string, !WebInspector.CSSStyleSheetHeader>} */ 46 /** @type {!Map.<string, !WebInspector.CSSStyleSheetHeader>} */
46 this._styleSheetIdToHeader = new Map(); 47 this._styleSheetIdToHeader = new Map();
47 /** @type {!Map.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAgent.Styl eSheetId>>>} */ 48 /** @type {!Map.<string, !Object.<!PageAgent.FrameId, !Array.<!CSSAgent.Styl eSheetId>>>} */
48 this._styleSheetIdsForURL = new Map(); 49 this._styleSheetIdsForURL = new Map();
49 50
50 /** @type {!Map.<!WebInspector.CSSStyleSheetHeader, !Promise<string>>} */ 51 /** @type {!Map.<!WebInspector.CSSStyleSheetHeader, !Promise<string>>} */
51 this._originalStyleSheetText = new Map(); 52 this._originalStyleSheetText = new Map();
52 53
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 if (!this._sourceMapURLToHeaders.has(header.sourceMapURL)) 230 if (!this._sourceMapURLToHeaders.has(header.sourceMapURL))
230 this._sourceMapByURL.delete(header.sourceMapURL); 231 this._sourceMapByURL.delete(header.sourceMapURL);
231 this.dispatchEventToListeners(WebInspector.CSSModel.Events.SourceMapDeta ched, header); 232 this.dispatchEventToListeners(WebInspector.CSSModel.Events.SourceMapDeta ched, header);
232 }, 233 },
233 234
234 /** 235 /**
235 * @return {!WebInspector.DOMModel} 236 * @return {!WebInspector.DOMModel}
236 */ 237 */
237 domModel: function() 238 domModel: function()
238 { 239 {
239 return /** @type {!WebInspector.DOMModel} */(this._domModel); 240 return this._domModel;
240 }, 241 },
241 242
242 /** 243 /**
243 * @param {!CSSAgent.StyleSheetId} styleSheetId 244 * @param {!CSSAgent.StyleSheetId} styleSheetId
244 * @param {!WebInspector.TextRange} range 245 * @param {!WebInspector.TextRange} range
245 * @param {string} text 246 * @param {string} text
246 * @param {boolean} majorChange 247 * @param {boolean} majorChange
247 * @return {!Promise<boolean>} 248 * @return {!Promise<boolean>}
248 */ 249 */
249 setStyleText: function(styleSheetId, range, text, majorChange) 250 setStyleText: function(styleSheetId, range, text, majorChange)
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 return null; 717 return null;
717 this._domModel.markUndoableState(); 718 this._domModel.markUndoableState();
718 var edit = new WebInspector.CSSModel.Edit(styleSheetId, ruleLocation , ruleText, rulePayload); 719 var edit = new WebInspector.CSSModel.Edit(styleSheetId, ruleLocation , ruleText, rulePayload);
719 this._fireStyleSheetChanged(styleSheetId, edit); 720 this._fireStyleSheetChanged(styleSheetId, edit);
720 return new WebInspector.CSSStyleRule(this, rulePayload); 721 return new WebInspector.CSSStyleRule(this, rulePayload);
721 } 722 }
722 }, 723 },
723 724
724 /** 725 /**
725 * @param {!WebInspector.DOMNode} node 726 * @param {!WebInspector.DOMNode} node
727 * @param {string} frameId
726 * @param {function(?WebInspector.CSSStyleSheetHeader)} userCallback 728 * @param {function(?WebInspector.CSSStyleSheetHeader)} userCallback
727 */ 729 */
728 requestViaInspectorStylesheet: function(node, userCallback) 730 requestViaInspectorStylesheet: function(node, frameId, userCallback)
729 { 731 {
730 var frameId = node.frameId() || this.target().resourceTreeModel.mainFram e.id;
731 var headers = this._styleSheetIdToHeader.valuesArray(); 732 var headers = this._styleSheetIdToHeader.valuesArray();
732 for (var i = 0; i < headers.length; ++i) { 733 for (var i = 0; i < headers.length; ++i) {
733 var styleSheetHeader = headers[i]; 734 var styleSheetHeader = headers[i];
734 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaIn spector()) { 735 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaIn spector()) {
735 userCallback(styleSheetHeader); 736 userCallback(styleSheetHeader);
736 return; 737 return;
737 } 738 }
738 } 739 }
739 740
740 /** 741 /**
741 * @param {?Protocol.Error} error 742 * @param {?Protocol.Error} error
742 * @param {?CSSAgent.StyleSheetId} styleSheetId 743 * @param {?CSSAgent.StyleSheetId} styleSheetId
743 * @return {?WebInspector.CSSStyleSheetHeader} 744 * @return {?WebInspector.CSSStyleSheetHeader}
744 * @this {WebInspector.CSSModel} 745 * @this {WebInspector.CSSModel}
745 */ 746 */
746 function innerCallback(error, styleSheetId) 747 function innerCallback(error, styleSheetId)
747 { 748 {
748 return !error && styleSheetId ? this._styleSheetIdToHeader.get(style SheetId) || null : null; 749 return !error && styleSheetId ? this._styleSheetIdToHeader.get(style SheetId) || null : null;
749 } 750 }
750 751
751 this._agent.createStyleSheet(frameId, innerCallback.bind(this)) 752 this._agent.createStyleSheet(frameId, innerCallback.bind(this))
pfeldman 2016/07/27 17:54:35 We should be able to send document node id here.
eostroukhov-old 2016/08/05 18:32:03 We discussed this offline and no change will be ma
752 .catchException(null) 753 .catchException(null)
753 .then(userCallback) 754 .then(userCallback)
754 }, 755 },
755 756
756 mediaQueryResultChanged: function() 757 mediaQueryResultChanged: function()
757 { 758 {
758 this.dispatchEventToListeners(WebInspector.CSSModel.Events.MediaQueryRes ultChanged); 759 this.dispatchEventToListeners(WebInspector.CSSModel.Events.MediaQueryRes ultChanged);
759 }, 760 },
760 761
761 /** 762 /**
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 text = ""; 933 text = "";
933 // Fall through. 934 // Fall through.
934 } 935 }
935 return WebInspector.CSSModel.trimSourceURL(text); 936 return WebInspector.CSSModel.trimSourceURL(text);
936 } 937 }
937 938
938 return this._agent.getStyleSheetText(styleSheetId, textCallback) 939 return this._agent.getStyleSheetText(styleSheetId, textCallback)
939 .catchException(/** @type {string} */("")); 940 .catchException(/** @type {string} */(""));
940 }, 941 },
941 942
942 _mainFrameNavigated: function() 943 /**
944 * @param {!WebInspector.Event} event
945 */
946 _mainFrameNavigated: function(event)
943 { 947 {
948 if (event.data.target() !== this.target())
949 return;
944 this._resetStyleSheets(); 950 this._resetStyleSheets();
945 }, 951 },
946 952
947 _resetStyleSheets: function() 953 _resetStyleSheets: function()
948 { 954 {
949 var headers = this._styleSheetIdToHeader.valuesArray(); 955 var headers = this._styleSheetIdToHeader.valuesArray();
950 this._styleSheetIdsForURL.clear(); 956 this._styleSheetIdsForURL.clear();
951 this._styleSheetIdToHeader.clear(); 957 this._styleSheetIdToHeader.clear();
952 for (var i = 0; i < headers.length; ++i) { 958 for (var i = 0; i < headers.length; ++i) {
953 this._detachSourceMap(headers[i]); 959 this._detachSourceMap(headers[i]);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 /** 1214 /**
1209 * @constructor 1215 * @constructor
1210 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle 1216 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle
1211 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle 1217 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle
1212 */ 1218 */
1213 WebInspector.CSSModel.InlineStyleResult = function(inlineStyle, attributesStyle) 1219 WebInspector.CSSModel.InlineStyleResult = function(inlineStyle, attributesStyle)
1214 { 1220 {
1215 this.inlineStyle = inlineStyle; 1221 this.inlineStyle = inlineStyle;
1216 this.attributesStyle = attributesStyle; 1222 this.attributesStyle = attributesStyle;
1217 } 1223 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698