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

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

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done 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
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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
31 /** 30 /**
32 * @constructor
33 * @param {!WebInspector.TargetManager} targetManager
34 * @param {!WebInspector.Workspace} workspace
35 * @implements {WebInspector.TargetManager.Observer} 31 * @implements {WebInspector.TargetManager.Observer}
32 * @unrestricted
36 */ 33 */
37 WebInspector.NetworkProjectManager = function(targetManager, workspace) 34 WebInspector.NetworkProjectManager = class {
38 { 35 /**
36 * @param {!WebInspector.TargetManager} targetManager
37 * @param {!WebInspector.Workspace} workspace
38 */
39 constructor(targetManager, workspace) {
39 this._workspace = workspace; 40 this._workspace = workspace;
40 targetManager.observeTargets(this); 41 targetManager.observeTargets(this);
41 }; 42 }
42 43
43 WebInspector.NetworkProjectManager.prototype = { 44 /**
44 /** 45 * @override
45 * @override 46 * @param {!WebInspector.Target} target
46 * @param {!WebInspector.Target} target 47 */
47 */ 48 targetAdded(target) {
48 targetAdded: function(target) 49 new WebInspector.NetworkProject(target, this._workspace, WebInspector.Resour ceTreeModel.fromTarget(target));
49 { 50 }
50 new WebInspector.NetworkProject(target, this._workspace, WebInspector.Re sourceTreeModel.fromTarget(target));
51 },
52 51
53 /** 52 /**
54 * @override 53 * @override
55 * @param {!WebInspector.Target} target 54 * @param {!WebInspector.Target} target
56 */ 55 */
57 targetRemoved: function(target) 56 targetRemoved(target) {
58 { 57 WebInspector.NetworkProject.forTarget(target)._dispose();
59 WebInspector.NetworkProject.forTarget(target)._dispose(); 58 }
60 }
61 }; 59 };
62 60
63 /** 61 /**
64 * @constructor 62 * @unrestricted
65 * @extends {WebInspector.SDKObject}
66 * @param {!WebInspector.Target} target
67 * @param {!WebInspector.Workspace} workspace
68 * @param {?WebInspector.ResourceTreeModel} resourceTreeModel
69 */ 63 */
70 WebInspector.NetworkProject = function(target, workspace, resourceTreeModel) 64 WebInspector.NetworkProject = class extends WebInspector.SDKObject {
71 { 65 /**
72 WebInspector.SDKObject.call(this, target); 66 * @param {!WebInspector.Target} target
67 * @param {!WebInspector.Workspace} workspace
68 * @param {?WebInspector.ResourceTreeModel} resourceTreeModel
69 */
70 constructor(target, workspace, resourceTreeModel) {
71 super(target);
73 this._workspace = workspace; 72 this._workspace = workspace;
74 /** @type {!Map<string, !WebInspector.ContentProviderBasedProject>} */ 73 /** @type {!Map<string, !WebInspector.ContentProviderBasedProject>} */
75 this._workspaceProjects = new Map(); 74 this._workspaceProjects = new Map();
76 this._resourceTreeModel = resourceTreeModel; 75 this._resourceTreeModel = resourceTreeModel;
77 target[WebInspector.NetworkProject._networkProjectSymbol] = this; 76 target[WebInspector.NetworkProject._networkProjectSymbol] = this;
78 77
79 this._eventListeners = []; 78 this._eventListeners = [];
80 79
81 if (resourceTreeModel) { 80 if (resourceTreeModel) {
82 this._eventListeners.push( 81 this._eventListeners.push(
83 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Ev ents.ResourceAdded, this._resourceAdded, this), 82 resourceTreeModel.addEventListener(
84 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Ev ents.FrameWillNavigate, this._frameWillNavigate, this), 83 WebInspector.ResourceTreeModel.Events.ResourceAdded, this._resourc eAdded, this),
85 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Ev ents.MainFrameNavigated, this._mainFrameNavigated, this)); 84 resourceTreeModel.addEventListener(
85 WebInspector.ResourceTreeModel.Events.FrameWillNavigate, this._fra meWillNavigate, this),
86 resourceTreeModel.addEventListener(
87 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._ma inFrameNavigated, this));
86 } 88 }
87 89
88 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); 90 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
89 if (debuggerModel) { 91 if (debuggerModel) {
90 this._eventListeners.push( 92 this._eventListeners.push(
91 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.Par sedScriptSource, this._parsedScriptSource, this), 93 debuggerModel.addEventListener(
92 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.Fai ledToParseScriptSource, this._parsedScriptSource, this)); 94 WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsed ScriptSource, this),
95 debuggerModel.addEventListener(
96 WebInspector.DebuggerModel.Events.FailedToParseScriptSource, this. _parsedScriptSource, this));
93 } 97 }
94 var cssModel = WebInspector.CSSModel.fromTarget(target); 98 var cssModel = WebInspector.CSSModel.fromTarget(target);
95 if (cssModel) { 99 if (cssModel) {
96 this._eventListeners.push( 100 this._eventListeners.push(
97 cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetAdd ed, this._styleSheetAdded, this), 101 cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetAdded , this._styleSheetAdded, this),
98 cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetRem oved, this._styleSheetRemoved, this)); 102 cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetRemov ed, this._styleSheetRemoved, this));
99 } 103 }
100 this._eventListeners.push( 104 this._eventListeners.push(target.targetManager().addEventListener(
101 target.targetManager().addEventListener(WebInspector.TargetManager.Event s.SuspendStateChanged, this._suspendStateChanged, this)); 105 WebInspector.TargetManager.Events.SuspendStateChanged, this._suspendStat eChanged, this));
102 }; 106 }
103 107
104 WebInspector.NetworkProject._networkProjectSymbol = Symbol("networkProject"); 108 /**
105 WebInspector.NetworkProject._resourceSymbol = Symbol("resource"); 109 * @param {!WebInspector.Target} target
106 WebInspector.NetworkProject._scriptSymbol = Symbol("script"); 110 * @param {?WebInspector.ResourceTreeFrame} frame
107 WebInspector.NetworkProject._styleSheetSymbol = Symbol("styleSheet"); 111 * @param {boolean} isContentScripts
108 WebInspector.NetworkProject._targetSymbol = Symbol("target"); 112 * @return {string}
109 WebInspector.NetworkProject._frameSymbol = Symbol("frame"); 113 */
110 114 static projectId(target, frame, isContentScripts) {
111 /** 115 return target.id() + ':' + (frame ? frame.id : '') + ':' + (isContentScripts ? 'contentscripts' : '');
112 * @param {!WebInspector.Target} target 116 }
113 * @param {?WebInspector.ResourceTreeFrame} frame 117
114 * @param {boolean} isContentScripts 118 /**
115 * @return {string} 119 * @param {!WebInspector.Target} target
116 */ 120 * @return {!WebInspector.NetworkProject}
117 WebInspector.NetworkProject.projectId = function(target, frame, isContentScripts ) 121 */
118 { 122 static forTarget(target) {
119 return target.id() + ":" + (frame ? frame.id : "") + ":" + (isContentScripts ? "contentscripts" : "");
120 };
121
122 /**
123 * @param {!WebInspector.Target} target
124 * @return {!WebInspector.NetworkProject}
125 */
126 WebInspector.NetworkProject.forTarget = function(target)
127 {
128 return target[WebInspector.NetworkProject._networkProjectSymbol]; 123 return target[WebInspector.NetworkProject._networkProjectSymbol];
129 }; 124 }
130 125
131 /** 126 /**
132 * @param {!WebInspector.Project} project 127 * @param {!WebInspector.Project} project
133 * @return {?WebInspector.Target} target 128 * @return {?WebInspector.Target} target
134 */ 129 */
135 WebInspector.NetworkProject.targetForProject = function(project) 130 static targetForProject(project) {
136 {
137 return project[WebInspector.NetworkProject._targetSymbol] || null; 131 return project[WebInspector.NetworkProject._targetSymbol] || null;
138 }; 132 }
139 133
140 /** 134 /**
141 * @param {!WebInspector.Project} project 135 * @param {!WebInspector.Project} project
142 * @return {?WebInspector.ResourceTreeFrame} 136 * @return {?WebInspector.ResourceTreeFrame}
143 */ 137 */
144 WebInspector.NetworkProject.frameForProject = function(project) 138 static frameForProject(project) {
145 {
146 return project[WebInspector.NetworkProject._frameSymbol] || null; 139 return project[WebInspector.NetworkProject._frameSymbol] || null;
147 }; 140 }
148 141
149 /** 142 /**
150 * @param {!WebInspector.UISourceCode} uiSourceCode 143 * @param {!WebInspector.UISourceCode} uiSourceCode
151 * @return {?WebInspector.Target} target 144 * @return {?WebInspector.Target} target
152 */ 145 */
153 WebInspector.NetworkProject.targetForUISourceCode = function(uiSourceCode) 146 static targetForUISourceCode(uiSourceCode) {
154 {
155 return uiSourceCode[WebInspector.NetworkProject._targetSymbol] || null; 147 return uiSourceCode[WebInspector.NetworkProject._targetSymbol] || null;
156 }; 148 }
157 149
158 /** 150 /**
159 * @param {!WebInspector.UISourceCode} uiSourceCode 151 * @param {!WebInspector.UISourceCode} uiSourceCode
160 * @return {string} 152 * @return {string}
161 */ 153 */
162 WebInspector.NetworkProject.uiSourceCodeMimeType = function(uiSourceCode) 154 static uiSourceCodeMimeType(uiSourceCode) {
163 {
164 if (uiSourceCode[WebInspector.NetworkProject._scriptSymbol] || 155 if (uiSourceCode[WebInspector.NetworkProject._scriptSymbol] ||
165 uiSourceCode[WebInspector.NetworkProject._styleSheetSymbol]) { 156 uiSourceCode[WebInspector.NetworkProject._styleSheetSymbol]) {
166 return uiSourceCode.contentType().canonicalMimeType(); 157 return uiSourceCode.contentType().canonicalMimeType();
167 } 158 }
168 var resource = uiSourceCode[WebInspector.NetworkProject._resourceSymbol]; 159 var resource = uiSourceCode[WebInspector.NetworkProject._resourceSymbol];
169 if (resource) 160 if (resource)
170 return resource.mimeType; 161 return resource.mimeType;
171 var mimeType = WebInspector.ResourceType.mimeFromURL(uiSourceCode.url()); 162 var mimeType = WebInspector.ResourceType.mimeFromURL(uiSourceCode.url());
172 return mimeType || uiSourceCode.contentType().canonicalMimeType(); 163 return mimeType || uiSourceCode.contentType().canonicalMimeType();
164 }
165
166 /**
167 * @param {?WebInspector.ResourceTreeFrame} frame
168 * @param {boolean} isContentScripts
169 * @return {!WebInspector.ContentProviderBasedProject}
170 */
171 _workspaceProject(frame, isContentScripts) {
172 var projectId = WebInspector.NetworkProject.projectId(this.target(), frame, isContentScripts);
173 var projectType = isContentScripts ? WebInspector.projectTypes.ContentScript s : WebInspector.projectTypes.Network;
174
175 var project = this._workspaceProjects.get(projectId);
176 if (project)
177 return project;
178
179 project = new WebInspector.ContentProviderBasedProject(this._workspace, proj ectId, projectType, '');
180 project[WebInspector.NetworkProject._targetSymbol] = this.target();
181 project[WebInspector.NetworkProject._frameSymbol] = frame;
182 this._workspaceProjects.set(projectId, project);
183 return project;
184 }
185
186 /**
187 * @param {!WebInspector.ContentProvider} contentProvider
188 * @param {?WebInspector.ResourceTreeFrame} frame
189 * @param {boolean} isContentScript
190 * @param {?number} contentSize
191 * @return {!WebInspector.UISourceCode}
192 */
193 addFile(contentProvider, frame, isContentScript, contentSize) {
194 var uiSourceCode = this._createFile(contentProvider, frame, isContentScript || false);
195 var metadata = typeof contentSize === 'number' ? new WebInspector.UISourceCo deMetadata(null, contentSize) : null;
196 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata);
197 return uiSourceCode;
198 }
199
200 /**
201 * @param {?WebInspector.ResourceTreeFrame} frame
202 * @param {string} url
203 */
204 _removeFileForURL(frame, url) {
205 var project = this._workspaceProjects.get(WebInspector.NetworkProject.projec tId(this.target(), frame, false));
206 if (!project)
207 return;
208 project.removeFile(url);
209 }
210
211 _populate() {
212 /**
213 * @param {!WebInspector.ResourceTreeFrame} frame
214 * @this {WebInspector.NetworkProject}
215 */
216 function populateFrame(frame) {
217 for (var i = 0; i < frame.childFrames.length; ++i)
218 populateFrame.call(this, frame.childFrames[i]);
219
220 var resources = frame.resources();
221 for (var i = 0; i < resources.length; ++i)
222 this._addResource(resources[i]);
223 }
224
225 var resourceTreeModel = this._resourceTreeModel;
226 var mainFrame = resourceTreeModel && resourceTreeModel.mainFrame;
227 if (mainFrame)
228 populateFrame.call(this, mainFrame);
229 }
230
231 /**
232 * @param {!WebInspector.UISourceCode} uiSourceCode
233 * @param {!WebInspector.ContentProvider} contentProvider
234 * @param {?WebInspector.UISourceCodeMetadata} metadata
235 */
236 _addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata) {
237 /** @type {!WebInspector.ContentProviderBasedProject} */ (uiSourceCode.proje ct())
238 .addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata);
239 }
240
241 /**
242 * @param {!WebInspector.Event} event
243 */
244 _parsedScriptSource(event) {
245 var script = /** @type {!WebInspector.Script} */ (event.data);
246 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL))
247 return;
248 // Filter out embedder injected content scripts.
249 if (script.isContentScript() && !script.hasSourceURL) {
250 var parsedURL = new WebInspector.ParsedURL(script.sourceURL);
251 if (!parsedURL.isValid)
252 return;
253 }
254 var uiSourceCode =
255 this._createFile(script, WebInspector.ResourceTreeFrame.fromScript(scrip t), script.isContentScript());
256 uiSourceCode[WebInspector.NetworkProject._scriptSymbol] = script;
257 var resource = WebInspector.ResourceTreeModel.resourceForURL(uiSourceCode.ur l());
258 this._addUISourceCodeWithProvider(uiSourceCode, script, this._resourceMetada ta(resource));
259 }
260
261 /**
262 * @param {!WebInspector.Event} event
263 */
264 _styleSheetAdded(event) {
265 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.data);
266 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' )
267 return;
268
269 var originalContentProvider = header.originalContentProvider();
270 var uiSourceCode =
271 this._createFile(originalContentProvider, WebInspector.ResourceTreeFrame .fromStyleSheet(header), false);
272 uiSourceCode[WebInspector.NetworkProject._styleSheetSymbol] = header;
273 var resource = WebInspector.ResourceTreeModel.resourceForURL(uiSourceCode.ur l());
274 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, thi s._resourceMetadata(resource));
275 }
276
277 /**
278 * @param {!WebInspector.Event} event
279 */
280 _styleSheetRemoved(event) {
281 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.data);
282 if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector' )
283 return;
284
285 this._removeFileForURL(WebInspector.ResourceTreeFrame.fromStyleSheet(header) , header.resourceURL());
286 }
287
288 /**
289 * @param {!WebInspector.Event} event
290 */
291 _resourceAdded(event) {
292 var resource = /** @type {!WebInspector.Resource} */ (event.data);
293 this._addResource(resource);
294 }
295
296 /**
297 * @param {!WebInspector.Resource} resource
298 */
299 _addResource(resource) {
300 var resourceType = resource.resourceType();
301 // Only load selected resource types from resources.
302 if (resourceType !== WebInspector.resourceTypes.Image && resourceType !== We bInspector.resourceTypes.Font &&
303 resourceType !== WebInspector.resourceTypes.Document && resourceType !== WebInspector.resourceTypes.Manifest) {
304 return;
305 }
306
307 // Ignore non-images and non-fonts.
308 if (resourceType === WebInspector.resourceTypes.Image && resource.mimeType & &
309 !resource.mimeType.startsWith('image'))
310 return;
311 if (resourceType === WebInspector.resourceTypes.Font && resource.mimeType && !resource.mimeType.includes('font'))
312 return;
313 if ((resourceType === WebInspector.resourceTypes.Image || resourceType === W ebInspector.resourceTypes.Font) &&
314 resource.contentURL().startsWith('data:'))
315 return;
316
317 // Never load document twice.
318 if (this._workspace.uiSourceCodeForURL(resource.url))
319 return;
320
321 var uiSourceCode = this._createFile(resource, WebInspector.ResourceTreeFrame .fromResource(resource), false);
322 uiSourceCode[WebInspector.NetworkProject._resourceSymbol] = resource;
323 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource));
324 }
325
326 /**
327 * @param {!WebInspector.Event} event
328 */
329 _frameWillNavigate(event) {
330 var frame = /** @type {!WebInspector.ResourceTreeFrame} */ (event.data);
331 var project = this._workspaceProject(frame, false);
332 for (var resource of frame.resources())
333 project.removeUISourceCode(resource.url);
334 project = this._workspaceProject(frame, true);
335 for (var resource of frame.resources())
336 project.removeUISourceCode(resource.url);
337 }
338
339 /**
340 * @param {!WebInspector.Event} event
341 */
342 _mainFrameNavigated(event) {
343 this._reset();
344 this._populate();
345 }
346
347 _suspendStateChanged() {
348 if (this.target().targetManager().allTargetsSuspended())
349 this._reset();
350 else
351 this._populate();
352 }
353
354 /**
355 * @param {!WebInspector.ContentProvider} contentProvider
356 * @param {?WebInspector.ResourceTreeFrame} frame
357 * @param {boolean} isContentScript
358 * @return {!WebInspector.UISourceCode}
359 */
360 _createFile(contentProvider, frame, isContentScript) {
361 var url = contentProvider.contentURL();
362 var project = this._workspaceProject(frame, isContentScript);
363 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe());
364 uiSourceCode[WebInspector.NetworkProject._targetSymbol] = this.target();
365 return uiSourceCode;
366 }
367
368 /**
369 * @param {?WebInspector.Resource} resource
370 * @return {?WebInspector.UISourceCodeMetadata}
371 */
372 _resourceMetadata(resource) {
373 if (!resource || (typeof resource.contentSize() !== 'number' && !resource.la stModified()))
374 return null;
375 return new WebInspector.UISourceCodeMetadata(resource.lastModified(), resour ce.contentSize());
376 }
377
378 _dispose() {
379 this._reset();
380 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
381 delete this.target()[WebInspector.NetworkProject._networkProjectSymbol];
382 }
383
384 _reset() {
385 for (var project of this._workspaceProjects.values())
386 project.removeProject();
387 this._workspaceProjects.clear();
388 }
173 }; 389 };
174 390
175 WebInspector.NetworkProject.prototype = { 391 WebInspector.NetworkProject._networkProjectSymbol = Symbol('networkProject');
176 /** 392 WebInspector.NetworkProject._resourceSymbol = Symbol('resource');
177 * @param {?WebInspector.ResourceTreeFrame} frame 393 WebInspector.NetworkProject._scriptSymbol = Symbol('script');
178 * @param {boolean} isContentScripts 394 WebInspector.NetworkProject._styleSheetSymbol = Symbol('styleSheet');
179 * @return {!WebInspector.ContentProviderBasedProject} 395 WebInspector.NetworkProject._targetSymbol = Symbol('target');
180 */ 396 WebInspector.NetworkProject._frameSymbol = Symbol('frame');
181 _workspaceProject: function(frame, isContentScripts) 397
182 { 398
183 var projectId = WebInspector.NetworkProject.projectId(this.target(), fra me, isContentScripts);
184 var projectType = isContentScripts ? WebInspector.projectTypes.ContentSc ripts : WebInspector.projectTypes.Network;
185
186 var project = this._workspaceProjects.get(projectId);
187 if (project)
188 return project;
189
190 project = new WebInspector.ContentProviderBasedProject(this._workspace, projectId, projectType, "");
191 project[WebInspector.NetworkProject._targetSymbol] = this.target();
192 project[WebInspector.NetworkProject._frameSymbol] = frame;
193 this._workspaceProjects.set(projectId, project);
194 return project;
195 },
196
197 /**
198 * @param {!WebInspector.ContentProvider} contentProvider
199 * @param {?WebInspector.ResourceTreeFrame} frame
200 * @param {boolean} isContentScript
201 * @param {?number} contentSize
202 * @return {!WebInspector.UISourceCode}
203 */
204 addFile: function(contentProvider, frame, isContentScript, contentSize)
205 {
206 var uiSourceCode = this._createFile(contentProvider, frame, isContentScr ipt || false);
207 var metadata = typeof contentSize === "number" ? new WebInspector.UISour ceCodeMetadata(null, contentSize) : null;
208 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadat a);
209 return uiSourceCode;
210 },
211
212 /**
213 * @param {?WebInspector.ResourceTreeFrame} frame
214 * @param {string} url
215 */
216 _removeFileForURL: function(frame, url)
217 {
218 var project = this._workspaceProjects.get(WebInspector.NetworkProject.pr ojectId(this.target(), frame, false));
219 if (!project)
220 return;
221 project.removeFile(url);
222 },
223
224 _populate: function()
225 {
226 /**
227 * @param {!WebInspector.ResourceTreeFrame} frame
228 * @this {WebInspector.NetworkProject}
229 */
230 function populateFrame(frame)
231 {
232 for (var i = 0; i < frame.childFrames.length; ++i)
233 populateFrame.call(this, frame.childFrames[i]);
234
235 var resources = frame.resources();
236 for (var i = 0; i < resources.length; ++i)
237 this._addResource(resources[i]);
238 }
239
240 var resourceTreeModel = this._resourceTreeModel;
241 var mainFrame = resourceTreeModel && resourceTreeModel.mainFrame;
242 if (mainFrame)
243 populateFrame.call(this, mainFrame);
244 },
245
246 /**
247 * @param {!WebInspector.UISourceCode} uiSourceCode
248 * @param {!WebInspector.ContentProvider} contentProvider
249 * @param {?WebInspector.UISourceCodeMetadata} metadata
250 */
251 _addUISourceCodeWithProvider: function(uiSourceCode, contentProvider, metada ta)
252 {
253 /** @type {!WebInspector.ContentProviderBasedProject} */ (uiSourceCode.p roject()).addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata);
254 },
255
256 /**
257 * @param {!WebInspector.Event} event
258 */
259 _parsedScriptSource: function(event)
260 {
261 var script = /** @type {!WebInspector.Script} */ (event.data);
262 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL))
263 return;
264 // Filter out embedder injected content scripts.
265 if (script.isContentScript() && !script.hasSourceURL) {
266 var parsedURL = new WebInspector.ParsedURL(script.sourceURL);
267 if (!parsedURL.isValid)
268 return;
269 }
270 var uiSourceCode = this._createFile(script, WebInspector.ResourceTreeFra me.fromScript(script), script.isContentScript());
271 uiSourceCode[WebInspector.NetworkProject._scriptSymbol] = script;
272 var resource = WebInspector.ResourceTreeModel.resourceForURL(uiSourceCod e.url());
273 this._addUISourceCodeWithProvider(uiSourceCode, script, this._resourceMe tadata(resource));
274 },
275
276 /**
277 * @param {!WebInspector.Event} event
278 */
279 _styleSheetAdded: function(event)
280 {
281 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.dat a);
282 if (header.isInline && !header.hasSourceURL && header.origin !== "inspec tor")
283 return;
284
285 var originalContentProvider = header.originalContentProvider();
286 var uiSourceCode = this._createFile(originalContentProvider, WebInspecto r.ResourceTreeFrame.fromStyleSheet(header), false);
287 uiSourceCode[WebInspector.NetworkProject._styleSheetSymbol] = header;
288 var resource = WebInspector.ResourceTreeModel.resourceForURL(uiSourceCod e.url());
289 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, this._resourceMetadata(resource));
290 },
291
292 /**
293 * @param {!WebInspector.Event} event
294 */
295 _styleSheetRemoved: function(event)
296 {
297 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.dat a);
298 if (header.isInline && !header.hasSourceURL && header.origin !== "inspec tor")
299 return;
300
301 this._removeFileForURL(WebInspector.ResourceTreeFrame.fromStyleSheet(hea der), header.resourceURL());
302 },
303
304 /**
305 * @param {!WebInspector.Event} event
306 */
307 _resourceAdded: function(event)
308 {
309 var resource = /** @type {!WebInspector.Resource} */ (event.data);
310 this._addResource(resource);
311 },
312
313 /**
314 * @param {!WebInspector.Resource} resource
315 */
316 _addResource: function(resource)
317 {
318 var resourceType = resource.resourceType();
319 // Only load selected resource types from resources.
320 if (resourceType !== WebInspector.resourceTypes.Image &&
321 resourceType !== WebInspector.resourceTypes.Font &&
322 resourceType !== WebInspector.resourceTypes.Document &&
323 resourceType !== WebInspector.resourceTypes.Manifest) {
324 return;
325 }
326
327 // Ignore non-images and non-fonts.
328 if (resourceType === WebInspector.resourceTypes.Image && resource.mimeTy pe && !resource.mimeType.startsWith("image"))
329 return;
330 if (resourceType === WebInspector.resourceTypes.Font && resource.mimeTyp e && !resource.mimeType.includes("font"))
331 return;
332 if ((resourceType === WebInspector.resourceTypes.Image || resourceType = == WebInspector.resourceTypes.Font) && resource.contentURL().startsWith("data:") )
333 return;
334
335 // Never load document twice.
336 if (this._workspace.uiSourceCodeForURL(resource.url))
337 return;
338
339 var uiSourceCode = this._createFile(resource, WebInspector.ResourceTreeF rame.fromResource(resource), false);
340 uiSourceCode[WebInspector.NetworkProject._resourceSymbol] = resource;
341 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resource Metadata(resource));
342 },
343
344 /**
345 * @param {!WebInspector.Event} event
346 */
347 _frameWillNavigate: function(event)
348 {
349 var frame = /** @type {!WebInspector.ResourceTreeFrame} */ (event.data);
350 var project = this._workspaceProject(frame, false);
351 for (var resource of frame.resources())
352 project.removeUISourceCode(resource.url);
353 project = this._workspaceProject(frame, true);
354 for (var resource of frame.resources())
355 project.removeUISourceCode(resource.url);
356 },
357
358 /**
359 * @param {!WebInspector.Event} event
360 */
361 _mainFrameNavigated: function(event)
362 {
363 this._reset();
364 this._populate();
365 },
366
367 _suspendStateChanged: function()
368 {
369 if (this.target().targetManager().allTargetsSuspended())
370 this._reset();
371 else
372 this._populate();
373 },
374
375 /**
376 * @param {!WebInspector.ContentProvider} contentProvider
377 * @param {?WebInspector.ResourceTreeFrame} frame
378 * @param {boolean} isContentScript
379 * @return {!WebInspector.UISourceCode}
380 */
381 _createFile: function(contentProvider, frame, isContentScript)
382 {
383 var url = contentProvider.contentURL();
384 var project = this._workspaceProject(frame, isContentScript);
385 var uiSourceCode = project.createUISourceCode(url, contentProvider.conte ntType());
386 uiSourceCode[WebInspector.NetworkProject._targetSymbol] = this.target();
387 return uiSourceCode;
388 },
389
390 /**
391 * @param {?WebInspector.Resource} resource
392 * @return {?WebInspector.UISourceCodeMetadata}
393 */
394 _resourceMetadata: function(resource)
395 {
396 if (!resource || (typeof resource.contentSize() !== "number" && !resourc e.lastModified()))
397 return null;
398 return new WebInspector.UISourceCodeMetadata(resource.lastModified(), re source.contentSize());
399 },
400
401 _dispose: function()
402 {
403 this._reset();
404 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
405 delete this.target()[WebInspector.NetworkProject._networkProjectSymbol];
406 },
407
408 _reset: function()
409 {
410 for (var project of this._workspaceProjects.values())
411 project.removeProject();
412 this._workspaceProjects.clear();
413 },
414
415 __proto__: WebInspector.SDKObject.prototype
416 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698