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

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

Issue 2408203007: DevTools: teach network UISourceCodes to return metadata (Closed)
Patch Set: address comments Created 4 years, 2 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 project = new WebInspector.ContentProviderBasedProject(this._workspace, projectId, projectType, ""); 190 project = new WebInspector.ContentProviderBasedProject(this._workspace, projectId, projectType, "");
191 project[WebInspector.NetworkProject._targetSymbol] = this.target(); 191 project[WebInspector.NetworkProject._targetSymbol] = this.target();
192 project[WebInspector.NetworkProject._frameSymbol] = frame; 192 project[WebInspector.NetworkProject._frameSymbol] = frame;
193 this._workspaceProjects.set(projectId, project); 193 this._workspaceProjects.set(projectId, project);
194 return project; 194 return project;
195 }, 195 },
196 196
197 /** 197 /**
198 * @param {!WebInspector.ContentProvider} contentProvider 198 * @param {!WebInspector.ContentProvider} contentProvider
199 * @param {?WebInspector.ResourceTreeFrame} frame 199 * @param {?WebInspector.ResourceTreeFrame} frame
200 * @param {boolean=} isContentScript 200 * @param {boolean} isContentScript
201 * @param {?number} contentSize
201 * @return {!WebInspector.UISourceCode} 202 * @return {!WebInspector.UISourceCode}
202 */ 203 */
203 addFile: function(contentProvider, frame, isContentScript) 204 addFile: function(contentProvider, frame, isContentScript, contentSize)
204 { 205 {
205 var uiSourceCode = this._createFile(contentProvider, frame, isContentScr ipt || false); 206 var uiSourceCode = this._createFile(contentProvider, frame, isContentScr ipt || false);
206 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider); 207 var metadata = typeof contentSize === "number" ? new WebInspector.UISour ceCodeMetadata(null, contentSize) : null;
208 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadat a);
207 return uiSourceCode; 209 return uiSourceCode;
208 }, 210 },
209 211
210 /** 212 /**
211 * @param {?WebInspector.ResourceTreeFrame} frame 213 * @param {?WebInspector.ResourceTreeFrame} frame
212 * @param {string} url 214 * @param {string} url
213 */ 215 */
214 _removeFileForURL: function(frame, url) 216 _removeFileForURL: function(frame, url)
215 { 217 {
216 var project = this._workspaceProjects.get(WebInspector.NetworkProject.pr ojectId(this.target(), frame, false)); 218 var project = this._workspaceProjects.get(WebInspector.NetworkProject.pr ojectId(this.target(), frame, false));
(...skipping 20 matching lines...) Expand all
237 239
238 var resourceTreeModel = this._resourceTreeModel; 240 var resourceTreeModel = this._resourceTreeModel;
239 var mainFrame = resourceTreeModel && resourceTreeModel.mainFrame; 241 var mainFrame = resourceTreeModel && resourceTreeModel.mainFrame;
240 if (mainFrame) 242 if (mainFrame)
241 populateFrame.call(this, mainFrame); 243 populateFrame.call(this, mainFrame);
242 }, 244 },
243 245
244 /** 246 /**
245 * @param {!WebInspector.UISourceCode} uiSourceCode 247 * @param {!WebInspector.UISourceCode} uiSourceCode
246 * @param {!WebInspector.ContentProvider} contentProvider 248 * @param {!WebInspector.ContentProvider} contentProvider
249 * @param {?WebInspector.UISourceCodeMetadata} metadata
247 */ 250 */
248 _addUISourceCodeWithProvider: function(uiSourceCode, contentProvider) 251 _addUISourceCodeWithProvider: function(uiSourceCode, contentProvider, metada ta)
249 { 252 {
250 /** @type {!WebInspector.ContentProviderBasedProject} */ (uiSourceCode.p roject()).addUISourceCodeWithProvider(uiSourceCode, contentProvider); 253 /** @type {!WebInspector.ContentProviderBasedProject} */ (uiSourceCode.p roject()).addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata);
251 }, 254 },
252 255
253 /** 256 /**
254 * @param {!WebInspector.Event} event 257 * @param {!WebInspector.Event} event
255 */ 258 */
256 _parsedScriptSource: function(event) 259 _parsedScriptSource: function(event)
257 { 260 {
258 var script = /** @type {!WebInspector.Script} */ (event.data); 261 var script = /** @type {!WebInspector.Script} */ (event.data);
259 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL)) 262 if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL))
260 return; 263 return;
261 // Filter out embedder injected content scripts. 264 // Filter out embedder injected content scripts.
262 if (script.isContentScript() && !script.hasSourceURL) { 265 if (script.isContentScript() && !script.hasSourceURL) {
263 var parsedURL = new WebInspector.ParsedURL(script.sourceURL); 266 var parsedURL = new WebInspector.ParsedURL(script.sourceURL);
264 if (!parsedURL.isValid) 267 if (!parsedURL.isValid)
265 return; 268 return;
266 } 269 }
267 var uiSourceCode = this._createFile(script, WebInspector.ResourceTreeFra me.fromScript(script), script.isContentScript()); 270 var uiSourceCode = this._createFile(script, WebInspector.ResourceTreeFra me.fromScript(script), script.isContentScript());
268 uiSourceCode[WebInspector.NetworkProject._scriptSymbol] = script; 271 uiSourceCode[WebInspector.NetworkProject._scriptSymbol] = script;
269 this._addUISourceCodeWithProvider(uiSourceCode, script); 272 var resource = WebInspector.ResourceTreeModel.resourceForURL(uiSourceCod e.url());
273 this._addUISourceCodeWithProvider(uiSourceCode, script, this._resourceMe tadata(resource));
270 }, 274 },
271 275
272 /** 276 /**
273 * @param {!WebInspector.Event} event 277 * @param {!WebInspector.Event} event
274 */ 278 */
275 _styleSheetAdded: function(event) 279 _styleSheetAdded: function(event)
276 { 280 {
277 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.dat a); 281 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.dat a);
278 if (header.isInline && !header.hasSourceURL && header.origin !== "inspec tor") 282 if (header.isInline && !header.hasSourceURL && header.origin !== "inspec tor")
279 return; 283 return;
280 284
281 var originalContentProvider = header.originalContentProvider(); 285 var originalContentProvider = header.originalContentProvider();
282 var uiSourceCode = this._createFile(originalContentProvider, WebInspecto r.ResourceTreeFrame.fromStyleSheet(header), false); 286 var uiSourceCode = this._createFile(originalContentProvider, WebInspecto r.ResourceTreeFrame.fromStyleSheet(header), false);
283 uiSourceCode[WebInspector.NetworkProject._styleSheetSymbol] = header; 287 uiSourceCode[WebInspector.NetworkProject._styleSheetSymbol] = header;
284 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider) ; 288 var resource = WebInspector.ResourceTreeModel.resourceForURL(uiSourceCod e.url());
289 this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, this._resourceMetadata(resource));
285 }, 290 },
286 291
287 /** 292 /**
288 * @param {!WebInspector.Event} event 293 * @param {!WebInspector.Event} event
289 */ 294 */
290 _styleSheetRemoved: function(event) 295 _styleSheetRemoved: function(event)
291 { 296 {
292 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.dat a); 297 var header = /** @type {!WebInspector.CSSStyleSheetHeader} */ (event.dat a);
293 if (header.isInline && !header.hasSourceURL && header.origin !== "inspec tor") 298 if (header.isInline && !header.hasSourceURL && header.origin !== "inspec tor")
294 return; 299 return;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return; 331 return;
327 if ((resourceType === WebInspector.resourceTypes.Image || resourceType = == WebInspector.resourceTypes.Font) && resource.contentURL().startsWith("data:") ) 332 if ((resourceType === WebInspector.resourceTypes.Image || resourceType = == WebInspector.resourceTypes.Font) && resource.contentURL().startsWith("data:") )
328 return; 333 return;
329 334
330 // Never load document twice. 335 // Never load document twice.
331 if (this._workspace.uiSourceCodeForURL(resource.url)) 336 if (this._workspace.uiSourceCodeForURL(resource.url))
332 return; 337 return;
333 338
334 var uiSourceCode = this._createFile(resource, WebInspector.ResourceTreeF rame.fromResource(resource), false); 339 var uiSourceCode = this._createFile(resource, WebInspector.ResourceTreeF rame.fromResource(resource), false);
335 uiSourceCode[WebInspector.NetworkProject._resourceSymbol] = resource; 340 uiSourceCode[WebInspector.NetworkProject._resourceSymbol] = resource;
336 this._addUISourceCodeWithProvider(uiSourceCode, resource); 341 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resource Metadata(resource));
337 }, 342 },
338 343
339 /** 344 /**
340 * @param {!WebInspector.Event} event 345 * @param {!WebInspector.Event} event
341 */ 346 */
342 _frameWillNavigate: function(event) 347 _frameWillNavigate: function(event)
343 { 348 {
344 var frame = /** @type {!WebInspector.ResourceTreeFrame} */ (event.data); 349 var frame = /** @type {!WebInspector.ResourceTreeFrame} */ (event.data);
345 var project = this._workspaceProject(frame, false); 350 var project = this._workspaceProject(frame, false);
346 for (var resource of frame.resources()) 351 for (var resource of frame.resources())
(...skipping 28 matching lines...) Expand all
375 */ 380 */
376 _createFile: function(contentProvider, frame, isContentScript) 381 _createFile: function(contentProvider, frame, isContentScript)
377 { 382 {
378 var url = contentProvider.contentURL(); 383 var url = contentProvider.contentURL();
379 var project = this._workspaceProject(frame, isContentScript); 384 var project = this._workspaceProject(frame, isContentScript);
380 var uiSourceCode = project.createUISourceCode(url, contentProvider.conte ntType()); 385 var uiSourceCode = project.createUISourceCode(url, contentProvider.conte ntType());
381 uiSourceCode[WebInspector.NetworkProject._targetSymbol] = this.target(); 386 uiSourceCode[WebInspector.NetworkProject._targetSymbol] = this.target();
382 return uiSourceCode; 387 return uiSourceCode;
383 }, 388 },
384 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
385 _dispose: function() 401 _dispose: function()
386 { 402 {
387 this._reset(); 403 this._reset();
388 WebInspector.EventTarget.removeEventListeners(this._eventListeners); 404 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
389 delete this.target()[WebInspector.NetworkProject._networkProjectSymbol]; 405 delete this.target()[WebInspector.NetworkProject._networkProjectSymbol];
390 }, 406 },
391 407
392 _reset: function() 408 _reset: function()
393 { 409 {
394 for (var project of this._workspaceProjects.values()) 410 for (var project of this._workspaceProjects.values())
395 project.removeProject(); 411 project.removeProject();
396 this._workspaceProjects.clear(); 412 this._workspaceProjects.clear();
397 }, 413 },
398 414
399 __proto__: WebInspector.SDKObject.prototype 415 __proto__: WebInspector.SDKObject.prototype
400 } 416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698