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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/StylesSourceMapping.js

Issue 2501883002: DevTools: kill Bindings.NetworkMapping (Closed)
Patch Set: rebaseline Created 4 years, 1 month 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) 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 17 matching lines...) Expand all
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 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 Bindings.StylesSourceMapping = class { 34 Bindings.StylesSourceMapping = class {
35 /** 35 /**
36 * @param {!SDK.CSSModel} cssModel 36 * @param {!SDK.CSSModel} cssModel
37 * @param {!Workspace.Workspace} workspace 37 * @param {!Workspace.Workspace} workspace
38 * @param {!Bindings.NetworkMapping} networkMapping
39 */ 38 */
40 constructor(cssModel, workspace, networkMapping) { 39 constructor(cssModel, workspace) {
41 this._cssModel = cssModel; 40 this._cssModel = cssModel;
42 this._workspace = workspace; 41 this._workspace = workspace;
43 this._networkMapping = networkMapping;
44 42
45 /** @type {!Map<string, !Map<string, !Map<string, !SDK.CSSStyleSheetHeader>> >} */ 43 /** @type {!Map<string, !Map<string, !Map<string, !SDK.CSSStyleSheetHeader>> >} */
46 this._urlToHeadersByFrameId = new Map(); 44 this._urlToHeadersByFrameId = new Map();
47 /** @type {!Map.<!Workspace.UISourceCode, !Bindings.StyleFile>} */ 45 /** @type {!Map.<!Workspace.UISourceCode, !Bindings.StyleFile>} */
48 this._styleFiles = new Map(); 46 this._styleFiles = new Map();
49 47
50 this._eventListeners = [ 48 this._eventListeners = [
51 this._workspace.addEventListener(Workspace.Workspace.Events.ProjectRemoved , this._projectRemoved, this), 49 this._workspace.addEventListener(Workspace.Workspace.Events.ProjectRemoved , this._projectRemoved, this),
52 this._workspace.addEventListener( 50 this._workspace.addEventListener(
53 Workspace.Workspace.Events.UISourceCodeAdded, this._uiSourceCodeAddedT oWorkspace, this), 51 Workspace.Workspace.Events.UISourceCodeAdded, this._uiSourceCodeAddedT oWorkspace, this),
54 this._workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeRe moved, this._uiSourceCodeRemoved, this), 52 this._workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeRe moved, this._uiSourceCodeRemoved, this),
55 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this. _styleSheetAdded, this), 53 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this. _styleSheetAdded, this),
56 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, thi s._styleSheetRemoved, this), 54 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, thi s._styleSheetRemoved, this),
57 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetChanged, thi s._styleSheetChanged, this), 55 this._cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetChanged, thi s._styleSheetChanged, this),
58 SDK.ResourceTreeModel.fromTarget(cssModel.target()) 56 SDK.ResourceTreeModel.fromTarget(cssModel.target())
59 .addEventListener(SDK.ResourceTreeModel.Events.MainFrameNavigated, thi s._unbindAllUISourceCodes, this) 57 .addEventListener(SDK.ResourceTreeModel.Events.MainFrameNavigated, thi s._unbindAllUISourceCodes, this)
60 ]; 58 ];
61 } 59 }
62 60
63 /** 61 /**
64 * @param {!SDK.CSSLocation} rawLocation 62 * @param {!SDK.CSSLocation} rawLocation
65 * @return {?Workspace.UILocation} 63 * @return {?Workspace.UILocation}
66 */ 64 */
67 rawLocationToUILocation(rawLocation) { 65 rawLocationToUILocation(rawLocation) {
68 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(rawLocation. url, rawLocation.header()); 66 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._wor kspace, rawLocation.url, rawLocation.header());
69 if (!uiSourceCode) 67 if (!uiSourceCode)
70 return null; 68 return null;
71 var lineNumber = rawLocation.lineNumber; 69 var lineNumber = rawLocation.lineNumber;
72 var columnNumber = rawLocation.columnNumber; 70 var columnNumber = rawLocation.columnNumber;
73 var header = this._cssModel.styleSheetHeaderForId(rawLocation.styleSheetId); 71 var header = this._cssModel.styleSheetHeaderForId(rawLocation.styleSheetId);
74 if (header && header.isInline && header.hasSourceURL) { 72 if (header && header.isInline && header.hasSourceURL) {
75 lineNumber -= header.lineNumberInSource(0); 73 lineNumber -= header.lineNumberInSource(0);
76 columnNumber -= header.columnNumberInSource(lineNumber, 0); 74 columnNumber -= header.columnNumberInSource(lineNumber, 0);
77 } 75 }
78 return uiSourceCode.uiLocation(lineNumber, columnNumber); 76 return uiSourceCode.uiLocation(lineNumber, columnNumber);
(...skipping 12 matching lines...) Expand all
91 if (!map) { 89 if (!map) {
92 map = /** @type {!Map.<string, !Map.<string, !SDK.CSSStyleSheetHeader>>} * / (new Map()); 90 map = /** @type {!Map.<string, !Map.<string, !SDK.CSSStyleSheetHeader>>} * / (new Map());
93 this._urlToHeadersByFrameId.set(url, map); 91 this._urlToHeadersByFrameId.set(url, map);
94 } 92 }
95 var headersById = map.get(header.frameId); 93 var headersById = map.get(header.frameId);
96 if (!headersById) { 94 if (!headersById) {
97 headersById = /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */ (new Map()); 95 headersById = /** @type {!Map.<string, !SDK.CSSStyleSheetHeader>} */ (new Map());
98 map.set(header.frameId, headersById); 96 map.set(header.frameId, headersById);
99 } 97 }
100 headersById.set(header.id, header); 98 headersById.set(header.id, header);
101 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(url, header) ; 99 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._wor kspace, url, header);
102 if (uiSourceCode) 100 if (uiSourceCode)
103 this._bindUISourceCode(uiSourceCode, header); 101 this._bindUISourceCode(uiSourceCode, header);
104 } 102 }
105 103
106 /** 104 /**
107 * @param {!Common.Event} event 105 * @param {!Common.Event} event
108 */ 106 */
109 _styleSheetRemoved(event) { 107 _styleSheetRemoved(event) {
110 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); 108 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
111 var url = header.resourceURL(); 109 var url = header.resourceURL();
112 if (!url) 110 if (!url)
113 return; 111 return;
114 112
115 var map = this._urlToHeadersByFrameId.get(url); 113 var map = this._urlToHeadersByFrameId.get(url);
116 console.assert(map); 114 console.assert(map);
117 var headersById = map.get(header.frameId); 115 var headersById = map.get(header.frameId);
118 console.assert(headersById); 116 console.assert(headersById);
119 headersById.delete(header.id); 117 headersById.delete(header.id);
120 118
121 if (!headersById.size) { 119 if (!headersById.size) {
122 map.delete(header.frameId); 120 map.delete(header.frameId);
123 if (!map.size) { 121 if (!map.size) {
124 this._urlToHeadersByFrameId.delete(url); 122 this._urlToHeadersByFrameId.delete(url);
125 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(url, hea der); 123 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this. _workspace, url, header);
126 if (uiSourceCode) 124 if (uiSourceCode)
127 this._unbindUISourceCode(uiSourceCode); 125 this._unbindUISourceCode(uiSourceCode);
128 } 126 }
129 } 127 }
130 } 128 }
131 129
132 /** 130 /**
133 * @param {!Workspace.UISourceCode} uiSourceCode 131 * @param {!Workspace.UISourceCode} uiSourceCode
134 */ 132 */
135 _unbindUISourceCode(uiSourceCode) { 133 _unbindUISourceCode(uiSourceCode) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 clearTimeout(this._updateStyleSheetTextTimer); 249 clearTimeout(this._updateStyleSheetTextTimer);
252 delete this._updateStyleSheetTextTimer; 250 delete this._updateStyleSheetTextTimer;
253 } 251 }
254 252
255 var header = this._cssModel.styleSheetHeaderForId(styleSheetId); 253 var header = this._cssModel.styleSheetHeaderForId(styleSheetId);
256 if (!header) 254 if (!header)
257 return; 255 return;
258 var styleSheetURL = header.resourceURL(); 256 var styleSheetURL = header.resourceURL();
259 if (!styleSheetURL) 257 if (!styleSheetURL)
260 return; 258 return;
261 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(styleSheetUR L, header); 259 var uiSourceCode = Bindings.NetworkProject.uiSourceCodeForStyleURL(this._wor kspace, styleSheetURL, header);
262 if (!uiSourceCode) 260 if (!uiSourceCode)
263 return; 261 return;
264 header.requestContent().then(callback.bind(this, uiSourceCode)); 262 header.requestContent().then(callback.bind(this, uiSourceCode));
265 263
266 /** 264 /**
267 * @param {!Workspace.UISourceCode} uiSourceCode 265 * @param {!Workspace.UISourceCode} uiSourceCode
268 * @param {?string} content 266 * @param {?string} content
269 * @this {Bindings.StylesSourceMapping} 267 * @this {Bindings.StylesSourceMapping}
270 */ 268 */
271 function callback(uiSourceCode, content) { 269 function callback(uiSourceCode, content) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 351
354 dispose() { 352 dispose() {
355 if (this._terminated) 353 if (this._terminated)
356 return; 354 return;
357 this._terminated = true; 355 this._terminated = true;
358 Common.EventTarget.removeEventListeners(this._eventListeners); 356 Common.EventTarget.removeEventListeners(this._eventListeners);
359 } 357 }
360 }; 358 };
361 359
362 Bindings.StyleFile.updateTimeout = 200; 360 Bindings.StyleFile.updateTimeout = 200;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698