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

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

Issue 2702583003: DevTools: do not assign empty content to CSS UISourceCode in case of protocol error (Closed)
Patch Set: fix test Created 3 years, 10 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 this._resourceTreeModel.addEventListener( 45 this._resourceTreeModel.addEventListener(
46 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._resetStyleSheet s, this); 46 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._resetStyleSheet s, this);
47 } 47 }
48 target.registerCSSDispatcher(new SDK.CSSDispatcher(this)); 48 target.registerCSSDispatcher(new SDK.CSSDispatcher(this));
49 this._agent.enable().then(this._wasEnabled.bind(this)); 49 this._agent.enable().then(this._wasEnabled.bind(this));
50 /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */ 50 /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */
51 this._styleSheetIdToHeader = new Map(); 51 this._styleSheetIdToHeader = new Map();
52 /** @type {!Map.<string, !Object.<!Protocol.Page.FrameId, !Array.<!Protocol. CSS.StyleSheetId>>>} */ 52 /** @type {!Map.<string, !Object.<!Protocol.Page.FrameId, !Array.<!Protocol. CSS.StyleSheetId>>>} */
53 this._styleSheetIdsForURL = new Map(); 53 this._styleSheetIdsForURL = new Map();
54 54
55 /** @type {!Map.<!SDK.CSSStyleSheetHeader, !Promise<string>>} */ 55 /** @type {!Map.<!SDK.CSSStyleSheetHeader, !Promise<?string>>} */
56 this._originalStyleSheetText = new Map(); 56 this._originalStyleSheetText = new Map();
57 57
58 /** @type {!Multimap<string, !Protocol.CSS.StyleSheetId>} */ 58 /** @type {!Multimap<string, !Protocol.CSS.StyleSheetId>} */
59 this._sourceMapLoadingStyleSheetsIds = new Multimap(); 59 this._sourceMapLoadingStyleSheetsIds = new Multimap();
60 60
61 /** @type {!Map<string, !SDK.SourceMap>} */ 61 /** @type {!Map<string, !SDK.SourceMap>} */
62 this._sourceMapByURL = new Map(); 62 this._sourceMapByURL = new Map();
63 /** @type {!Multimap<string, !SDK.CSSStyleSheetHeader>} */ 63 /** @type {!Multimap<string, !SDK.CSSStyleSheetHeader>} */
64 this._sourceMapURLToHeaders = new Multimap(); 64 this._sourceMapURLToHeaders = new Multimap();
65 Common.moduleSetting('cssSourceMapsEnabled').addChangeListener(this._toggleS ourceMapSupport, this); 65 Common.moduleSetting('cssSourceMapsEnabled').addChangeListener(this._toggleS ourceMapSupport, this);
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 /** 777 /**
778 * @param {!Protocol.CSS.StyleSheetId} styleSheetId 778 * @param {!Protocol.CSS.StyleSheetId} styleSheetId
779 * @param {!SDK.CSSModel.Edit=} edit 779 * @param {!SDK.CSSModel.Edit=} edit
780 */ 780 */
781 _fireStyleSheetChanged(styleSheetId, edit) { 781 _fireStyleSheetChanged(styleSheetId, edit) {
782 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetChanged, {styleS heetId: styleSheetId, edit: edit}); 782 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetChanged, {styleS heetId: styleSheetId, edit: edit});
783 } 783 }
784 784
785 /** 785 /**
786 * @param {!Protocol.CSS.StyleSheetId} styleSheetId 786 * @param {!Protocol.CSS.StyleSheetId} styleSheetId
787 * @return {!Promise<string>} 787 * @return {!Promise<?string>}
788 */ 788 */
789 _ensureOriginalStyleSheetText(styleSheetId) { 789 _ensureOriginalStyleSheetText(styleSheetId) {
790 var header = this.styleSheetHeaderForId(styleSheetId); 790 var header = this.styleSheetHeaderForId(styleSheetId);
791 if (!header) 791 if (!header)
792 return Promise.resolve(''); 792 return Promise.resolve(/** @type {?string} */ (null));
793 var promise = this._originalStyleSheetText.get(header); 793 var promise = this._originalStyleSheetText.get(header);
794 if (!promise) { 794 if (!promise) {
795 promise = this.getStyleSheetText(header.id); 795 promise = this.getStyleSheetText(header.id);
796 this._originalStyleSheetText.set(header, promise); 796 this._originalStyleSheetText.set(header, promise);
797 this._originalContentRequestedForTest(header); 797 this._originalContentRequestedForTest(header);
798 } 798 }
799 return promise; 799 return promise;
800 } 800 }
801 801
802 /** 802 /**
803 * @param {!SDK.CSSStyleSheetHeader} header 803 * @param {!SDK.CSSStyleSheetHeader} header
804 */ 804 */
805 _originalContentRequestedForTest(header) { 805 _originalContentRequestedForTest(header) {
806 } 806 }
807 807
808 /** 808 /**
809 * @param {!SDK.CSSStyleSheetHeader} header 809 * @param {!SDK.CSSStyleSheetHeader} header
810 * @return {!Promise<string>} 810 * @return {!Promise<?string>}
811 */ 811 */
812 originalStyleSheetText(header) { 812 originalStyleSheetText(header) {
813 return this._ensureOriginalStyleSheetText(header.id); 813 return this._ensureOriginalStyleSheetText(header.id);
814 } 814 }
815 815
816 /** 816 /**
817 * @param {!Protocol.CSS.CSSStyleSheetHeader} header 817 * @param {!Protocol.CSS.CSSStyleSheetHeader} header
818 */ 818 */
819 _styleSheetAdded(header) { 819 _styleSheetAdded(header) {
820 console.assert(!this._styleSheetIdToHeader.get(header.styleSheetId)); 820 console.assert(!this._styleSheetIdToHeader.get(header.styleSheetId));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 return error; 902 return error;
903 if (majorChange) 903 if (majorChange)
904 this._domModel.markUndoableState(); 904 this._domModel.markUndoableState();
905 this._fireStyleSheetChanged(styleSheetId); 905 this._fireStyleSheetChanged(styleSheetId);
906 return null; 906 return null;
907 } 907 }
908 } 908 }
909 909
910 /** 910 /**
911 * @param {!Protocol.CSS.StyleSheetId} styleSheetId 911 * @param {!Protocol.CSS.StyleSheetId} styleSheetId
912 * @return {!Promise<string>} 912 * @return {!Promise<?string>}
913 */ 913 */
914 getStyleSheetText(styleSheetId) { 914 getStyleSheetText(styleSheetId) {
915 /** 915 /**
916 * @param {?Protocol.Error} error 916 * @param {?Protocol.Error} error
917 * @param {?string} text 917 * @param {?string} text
918 * @return {string} 918 * @return {?string}
919 */ 919 */
920 function textCallback(error, text) { 920 function textCallback(error, text) {
921 if (error || text === null) { 921 if (error || text === null) {
922 console.error('Failed to get text for stylesheet ' + styleSheetId + ': ' + error); 922 console.error('Failed to get text for stylesheet ' + styleSheetId + ': ' + error);
923 text = ''; 923 return null;
924 // Fall through.
925 } 924 }
926 return SDK.CSSModel.trimSourceURL(text); 925 return SDK.CSSModel.trimSourceURL(text);
927 } 926 }
928 927
929 return this._agent.getStyleSheetText(styleSheetId, textCallback).catchExcept ion(/** @type {string} */ ('')); 928 return this._agent.getStyleSheetText(styleSheetId, textCallback).catchExcept ion(/** @type {?string} */ (null));
930 } 929 }
931 930
932 _resetStyleSheets() { 931 _resetStyleSheets() {
933 var headers = this._styleSheetIdToHeader.valuesArray(); 932 var headers = this._styleSheetIdToHeader.valuesArray();
934 this._styleSheetIdsForURL.clear(); 933 this._styleSheetIdsForURL.clear();
935 this._styleSheetIdToHeader.clear(); 934 this._styleSheetIdToHeader.clear();
936 for (var i = 0; i < headers.length; ++i) { 935 for (var i = 0; i < headers.length; ++i) {
937 this._detachSourceMap(headers[i]); 936 this._detachSourceMap(headers[i]);
938 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetRemoved, heade rs[i]); 937 this.dispatchEventToListeners(SDK.CSSModel.Events.StyleSheetRemoved, heade rs[i]);
939 } 938 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 SDK.CSSModel.InlineStyleResult = class { 1166 SDK.CSSModel.InlineStyleResult = class {
1168 /** 1167 /**
1169 * @param {?SDK.CSSStyleDeclaration} inlineStyle 1168 * @param {?SDK.CSSStyleDeclaration} inlineStyle
1170 * @param {?SDK.CSSStyleDeclaration} attributesStyle 1169 * @param {?SDK.CSSStyleDeclaration} attributesStyle
1171 */ 1170 */
1172 constructor(inlineStyle, attributesStyle) { 1171 constructor(inlineStyle, attributesStyle) {
1173 this.inlineStyle = inlineStyle; 1172 this.inlineStyle = inlineStyle;
1174 this.attributesStyle = attributesStyle; 1173 this.attributesStyle = attributesStyle;
1175 } 1174 }
1176 }; 1175 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698