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

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

Issue 2869293002: DevTools: make CompilerScriptMapping / SASSSourceMapping manage UISourceCodes (Closed)
Patch Set: address comments 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) 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
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 * @implements {SDK.TargetManager.Observer} 31 * @implements {SDK.TargetManager.Observer}
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 Bindings.NetworkProjectManager = class { 34 Bindings.NetworkProjectManager = class extends Common.Object {
35 /** 35 /**
36 * @param {!SDK.TargetManager} targetManager 36 * @param {!SDK.TargetManager} targetManager
37 * @param {!Workspace.Workspace} workspace 37 * @param {!Workspace.Workspace} workspace
38 */ 38 */
39 constructor(targetManager, workspace) { 39 constructor(targetManager, workspace) {
40 super();
40 this._workspace = workspace; 41 this._workspace = workspace;
41 targetManager.observeTargets(this); 42 targetManager.observeTargets(this);
42 } 43 }
43 44
44 /** 45 /**
45 * @override 46 * @override
46 * @param {!SDK.Target} target 47 * @param {!SDK.Target} target
47 */ 48 */
48 targetAdded(target) { 49 targetAdded(target) {
49 new Bindings.NetworkProject(target, this._workspace, target.model(SDK.Resour ceTreeModel)); 50 new Bindings.NetworkProject(target, this._workspace, target.model(SDK.Resour ceTreeModel));
50 } 51 }
51 52
52 /** 53 /**
53 * @override 54 * @override
54 * @param {!SDK.Target} target 55 * @param {!SDK.Target} target
55 */ 56 */
56 targetRemoved(target) { 57 targetRemoved(target) {
57 Bindings.NetworkProject.forTarget(target)._dispose(); 58 Bindings.NetworkProject.forTarget(target)._dispose();
58 } 59 }
59 }; 60 };
60 61
62 Bindings.NetworkProjectManager.Events = {
63 FrameAttributionAdded: Symbol('FrameAttributionAdded'),
64 FrameAttributionRemoved: Symbol('FrameAttributionRemoved')
65 };
66
61 /** 67 /**
62 * @unrestricted 68 * @unrestricted
63 */ 69 */
64 Bindings.NetworkProject = class { 70 Bindings.NetworkProject = class {
65 /** 71 /**
66 * @param {!SDK.Target} target 72 * @param {!SDK.Target} target
67 * @param {!Workspace.Workspace} workspace 73 * @param {!Workspace.Workspace} workspace
68 * @param {?SDK.ResourceTreeModel} resourceTreeModel 74 * @param {?SDK.ResourceTreeModel} resourceTreeModel
69 */ 75 */
70 constructor(target, workspace, resourceTreeModel) { 76 constructor(target, workspace, resourceTreeModel) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 /** 127 /**
122 * @param {!SDK.Target} target 128 * @param {!SDK.Target} target
123 * @return {!Bindings.NetworkProject} 129 * @return {!Bindings.NetworkProject}
124 */ 130 */
125 static forTarget(target) { 131 static forTarget(target) {
126 return target[Bindings.NetworkProject._networkProjectSymbol]; 132 return target[Bindings.NetworkProject._networkProjectSymbol];
127 } 133 }
128 134
129 /** 135 /**
130 * @param {!Workspace.UISourceCode} uiSourceCode 136 * @param {!Workspace.UISourceCode} uiSourceCode
131 * @return {?Set<string>} 137 * @param {string} frameId
132 */ 138 */
133 static frameAttribution(uiSourceCode) { 139 static _resolveFrame(uiSourceCode, frameId) {
134 var frameId = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol]; 140 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode);
135 return frameId ? new Set([frameId]) : null; 141 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel);
142 return resourceTreeModel ? resourceTreeModel.frameForId(frameId) : null;
136 } 143 }
137 144
138 /** 145 /**
146 * @param {!Workspace.UISourceCode} uiSourceCode
147 * @param {string} frameId
148 */
149 static setInitialFrameAttribution(uiSourceCode, frameId) {
150 var frame = Bindings.NetworkProject._resolveFrame(uiSourceCode, frameId);
151 if (!frame)
152 return;
153 var attribution = new Map();
154 attribution.set(frameId, {frame: frame, count: 1});
155 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = attribution;
156 }
157
158 /**
159 * @param {!Workspace.UISourceCode} uiSourceCode
160 * @param {string} frameId
161 */
162 static addFrameAttribution(uiSourceCode, frameId) {
163 var frame = Bindings.NetworkProject._resolveFrame(uiSourceCode, frameId);
164 if (!frame)
165 return;
166 var frameAttribution = uiSourceCode[Bindings.NetworkProject._frameAttributio nSymbol];
167 var attributionInfo = frameAttribution.get(frameId) || {frame: frame, count: 0};
168 attributionInfo.count += 1;
169 frameAttribution.set(frameId, attributionInfo);
170 if (attributionInfo.count !== 1)
171 return;
172
173 var data = {uiSourceCode: uiSourceCode, frame: frame};
174 Bindings.networkProjectManager.dispatchEventToListeners(
175 Bindings.NetworkProjectManager.Events.FrameAttributionAdded, data);
176 }
177
178 /**
179 * @param {!Workspace.UISourceCode} uiSourceCode
180 * @param {string} frameId
181 */
182 static removeFrameAttribution(uiSourceCode, frameId) {
183 var frameAttribution = uiSourceCode[Bindings.NetworkProject._frameAttributio nSymbol];
184 var attributionInfo = frameAttribution.get(frameId);
185 console.assert(attributionInfo, 'Failed to remove frame attribution for url: ' + uiSourceCode.url());
186 attributionInfo.count -= 1;
187 if (attributionInfo.count > 0)
188 return;
189 frameAttribution.delete(frameId);
190 var data = {uiSourceCode: uiSourceCode, frame: attributionInfo.frame};
191 Bindings.networkProjectManager.dispatchEventToListeners(
192 Bindings.NetworkProjectManager.Events.FrameAttributionRemoved, data);
193 }
194
195 /**
139 * @param {!Workspace.UISourceCode} uiSourceCode 196 * @param {!Workspace.UISourceCode} uiSourceCode
140 * @return {?SDK.Target} target 197 * @return {?SDK.Target} target
141 */ 198 */
142 static targetForUISourceCode(uiSourceCode) { 199 static targetForUISourceCode(uiSourceCode) {
143 return uiSourceCode.project()[Bindings.NetworkProject._targetSymbol] || null ; 200 return uiSourceCode.project()[Bindings.NetworkProject._targetSymbol] || null ;
144 } 201 }
145 202
146 /** 203 /**
204 * @param {!Workspace.Project} project
205 * @param {!SDK.Target} target
206 */
207 static setTargetForProject(project, target) {
208 project[Bindings.NetworkProject._targetSymbol] = target;
209 }
210
211 /**
147 * @param {!Workspace.UISourceCode} uiSourceCode 212 * @param {!Workspace.UISourceCode} uiSourceCode
148 * @return {!Array<!SDK.ResourceTreeFrame>} 213 * @return {!Array<!SDK.ResourceTreeFrame>}
149 */ 214 */
150 static framesForUISourceCode(uiSourceCode) { 215 static framesForUISourceCode(uiSourceCode) {
151 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); 216 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode);
152 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); 217 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel);
153 var frameIds = Bindings.NetworkProject.frameAttribution(uiSourceCode); 218 var attribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymb ol];
154 if (!resourceTreeModel || !frameIds) 219 if (!resourceTreeModel || !attribution)
155 return []; 220 return [];
156 var frames = Array.from(frameIds).map(frameId => resourceTreeModel.frameForI d(frameId)); 221 var frames = Array.from(attribution.keys()).map(frameId => resourceTreeModel .frameForId(frameId));
157 return frames.filter(frame => !!frame); 222 return frames.filter(frame => !!frame);
158 } 223 }
159 224
160 /** 225 /**
161 * @param {!Workspace.UISourceCode} uiSourceCode 226 * @param {!Workspace.UISourceCode} uiSourceCode
162 * @return {string} 227 * @return {string}
163 */ 228 */
164 static uiSourceCodeMimeType(uiSourceCode) { 229 static uiSourceCodeMimeType(uiSourceCode) {
165 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind ings.NetworkProject._styleSheetSymbol]) 230 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind ings.NetworkProject._styleSheetSymbol])
166 return uiSourceCode.contentType().canonicalMimeType(); 231 return uiSourceCode.contentType().canonicalMimeType();
(...skipping 19 matching lines...) Expand all
186 return project; 251 return project;
187 252
188 project = new Bindings.ContentProviderBasedProject( 253 project = new Bindings.ContentProviderBasedProject(
189 this._workspace, projectId, projectType, '', false /* isServiceProject * /); 254 this._workspace, projectId, projectType, '', false /* isServiceProject * /);
190 project[Bindings.NetworkProject._targetSymbol] = this._target; 255 project[Bindings.NetworkProject._targetSymbol] = this._target;
191 this._workspaceProjects.set(projectId, project); 256 this._workspaceProjects.set(projectId, project);
192 return project; 257 return project;
193 } 258 }
194 259
195 /** 260 /**
196 * @param {!Common.ContentProvider} contentProvider
197 * @param {string} frameId
198 * @param {boolean} isContentScript
199 * @param {?number} contentSize
200 * @return {!Workspace.UISourceCode}
201 */
202 addSourceMapFile(contentProvider, frameId, isContentScript, contentSize) {
203 var uiSourceCode = this._createFile(contentProvider, frameId, isContentScrip t || false);
204 var metadata = typeof contentSize === 'number' ? new Workspace.UISourceCodeM etadata(null, contentSize) : null;
205 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata);
206 return uiSourceCode;
207 }
208
209 /**
210 * @param {string} url
211 * @param {string} frameId
212 * @param {boolean} isContentScript
213 */
214 removeSourceMapFile(url, frameId, isContentScript) {
215 this._removeFileForURL(url, frameId, isContentScript);
216 }
217
218 /**
219 * @param {string} frameId 261 * @param {string} frameId
220 * @param {string} url 262 * @param {string} url
221 * @param {boolean} isContentScript 263 * @param {boolean} isContentScript
222 */ 264 */
223 _removeFileForURL(url, frameId, isContentScript) { 265 _removeFileForURL(url, frameId, isContentScript) {
224 var project = 266 var project =
225 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._targ et, frameId, isContentScript)); 267 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._targ et, frameId, isContentScript));
226 if (!project) 268 if (!project)
227 return; 269 return;
228 project.removeFile(url); 270 project.removeFile(url);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 /** 452 /**
411 * @param {!Common.ContentProvider} contentProvider 453 * @param {!Common.ContentProvider} contentProvider
412 * @param {string} frameId 454 * @param {string} frameId
413 * @param {boolean} isContentScript 455 * @param {boolean} isContentScript
414 * @return {!Workspace.UISourceCode} 456 * @return {!Workspace.UISourceCode}
415 */ 457 */
416 _createFile(contentProvider, frameId, isContentScript) { 458 _createFile(contentProvider, frameId, isContentScript) {
417 var url = contentProvider.contentURL(); 459 var url = contentProvider.contentURL();
418 var project = this._workspaceProject(frameId, isContentScript); 460 var project = this._workspaceProject(frameId, isContentScript);
419 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); 461 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe());
420 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = frameId; 462 if (frameId)
463 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId);
421 return uiSourceCode; 464 return uiSourceCode;
422 } 465 }
423 466
424 /** 467 /**
425 * @param {string} frameId 468 * @param {string} frameId
426 * @param {string} url 469 * @param {string} url
427 * @return {?Workspace.UISourceCodeMetadata} 470 * @return {?Workspace.UISourceCodeMetadata}
428 */ 471 */
429 _fetchMetadata(frameId, url) { 472 _fetchMetadata(frameId, url) {
430 if (!this._resourceTreeModel) 473 if (!this._resourceTreeModel)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 }; 525 };
483 526
484 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); 527 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject');
485 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); 528 Bindings.NetworkProject._resourceSymbol = Symbol('resource');
486 Bindings.NetworkProject._scriptSymbol = Symbol('script'); 529 Bindings.NetworkProject._scriptSymbol = Symbol('script');
487 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); 530 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet');
488 Bindings.NetworkProject._targetSymbol = Symbol('target'); 531 Bindings.NetworkProject._targetSymbol = Symbol('target');
489 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); 532 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid');
490 533
491 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol'); 534 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698