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

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

Issue 1238103002: [DevTools] Do not report edited resources via Page.getResourceContent. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Same for CSS Created 5 years, 4 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 | Annotate | Revision Log
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 var projectType = isContentScripts ? WebInspector.projectTypes.ContentSc ripts : WebInspector.projectTypes.Network; 237 var projectType = isContentScripts ? WebInspector.projectTypes.ContentSc ripts : WebInspector.projectTypes.Network;
238 238
239 if (this._projectDelegates[projectId]) 239 if (this._projectDelegates[projectId])
240 return this._projectDelegates[projectId]; 240 return this._projectDelegates[projectId];
241 var projectDelegate = new WebInspector.NetworkProjectDelegate(this.targe t(), this._workspace, projectId, projectURL, projectType); 241 var projectDelegate = new WebInspector.NetworkProjectDelegate(this.targe t(), this._workspace, projectId, projectURL, projectType);
242 this._projectDelegates[projectId] = projectDelegate; 242 this._projectDelegates[projectId] = projectDelegate;
243 return projectDelegate; 243 return projectDelegate;
244 }, 244 },
245 245
246 /** 246 /**
247 * @param {!WebInspector.Resource} resource
248 * @return {!WebInspector.ContentProvider}
249 */
250 _contentProviderForResource: function(resource)
251 {
252 return resource.resourceType() === WebInspector.resourceTypes.Document ? new WebInspector.NetworkProject.DocumentFallbackResource(resource) : resource;
pfeldman 2015/08/11 23:22:43 Lets use this opportunity to nuke the concatenated
dgozman 2015/08/12 23:22:11 Done.
253 },
254
255 /**
247 * @param {string} url 256 * @param {string} url
248 * @param {!WebInspector.ContentProvider} contentProvider 257 * @param {!WebInspector.ContentProvider} contentProvider
249 * @param {boolean=} isContentScript 258 * @param {boolean=} isContentScript
250 * @return {!WebInspector.UISourceCode} 259 * @return {!WebInspector.UISourceCode}
251 */ 260 */
252 addFileForURL: function(url, contentProvider, isContentScript) 261 addFileForURL: function(url, contentProvider, isContentScript)
253 { 262 {
254 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url); 263 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url);
255 var projectURL = splitURL[0]; 264 var projectURL = splitURL[0];
256 var parentPath = splitURL.slice(1, -1).join("/"); 265 var parentPath = splitURL.slice(1, -1).join("/");
(...skipping 23 matching lines...) Expand all
280 * @param {!WebInspector.ResourceTreeFrame} frame 289 * @param {!WebInspector.ResourceTreeFrame} frame
281 * @this {WebInspector.NetworkProject} 290 * @this {WebInspector.NetworkProject}
282 */ 291 */
283 function populateFrame(frame) 292 function populateFrame(frame)
284 { 293 {
285 for (var i = 0; i < frame.childFrames.length; ++i) 294 for (var i = 0; i < frame.childFrames.length; ++i)
286 populateFrame.call(this, frame.childFrames[i]); 295 populateFrame.call(this, frame.childFrames[i]);
287 296
288 var resources = frame.resources(); 297 var resources = frame.resources();
289 for (var i = 0; i < resources.length; ++i) 298 for (var i = 0; i < resources.length; ++i)
290 this._addFile(resources[i].url, new WebInspector.NetworkProject. FallbackResource(resources[i])); 299 this._addFile(resources[i].url, this._contentProviderForResource (resources[i]));
291 } 300 }
292 301
293 var mainFrame = this.target().resourceTreeModel.mainFrame; 302 var mainFrame = this.target().resourceTreeModel.mainFrame;
294 if (mainFrame) 303 if (mainFrame)
295 populateFrame.call(this, mainFrame); 304 populateFrame.call(this, mainFrame);
296 }, 305 },
297 306
298 /** 307 /**
299 * @param {!WebInspector.Event} event 308 * @param {!WebInspector.Event} event
300 */ 309 */
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 344
336 this._removeFile(header.resourceURL()); 345 this._removeFile(header.resourceURL());
337 }, 346 },
338 347
339 /** 348 /**
340 * @param {!WebInspector.Event} event 349 * @param {!WebInspector.Event} event
341 */ 350 */
342 _resourceAdded: function(event) 351 _resourceAdded: function(event)
343 { 352 {
344 var resource = /** @type {!WebInspector.Resource} */ (event.data); 353 var resource = /** @type {!WebInspector.Resource} */ (event.data);
345 this._addFile(resource.url, new WebInspector.NetworkProject.FallbackReso urce(resource)); 354 if (resource.resourceType() === WebInspector.resourceTypes.Script || res ource.resourceType() === WebInspector.resourceTypes.Stylesheet)
pfeldman 2015/08/11 23:22:43 Why would we do anything upon resourceAdded? I tho
dgozman 2015/08/12 23:22:11 Done.
355 return;
356 this._addFile(resource.url, this._contentProviderForResource(resource));
346 }, 357 },
347 358
348 /** 359 /**
349 * @param {!WebInspector.Event} event 360 * @param {!WebInspector.Event} event
350 */ 361 */
351 _mainFrameNavigated: function(event) 362 _mainFrameNavigated: function(event)
352 { 363 {
353 this._reset(); 364 this._reset();
354 this._populate(); 365 this._populate();
355 }, 366 },
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 }, 423 },
413 424
414 __proto__: WebInspector.SDKObject.prototype 425 __proto__: WebInspector.SDKObject.prototype
415 } 426 }
416 427
417 /** 428 /**
418 * @constructor 429 * @constructor
419 * @implements {WebInspector.ContentProvider} 430 * @implements {WebInspector.ContentProvider}
420 * @param {!WebInspector.Resource} resource 431 * @param {!WebInspector.Resource} resource
421 */ 432 */
422 WebInspector.NetworkProject.FallbackResource = function(resource) 433 WebInspector.NetworkProject.DocumentFallbackResource = function(resource)
423 { 434 {
435 console.assert(resource.resourceType() === WebInspector.resourceTypes.Docume nt);
424 this._resource = resource; 436 this._resource = resource;
425 } 437 }
426 438
427 WebInspector.NetworkProject.FallbackResource.prototype = { 439 WebInspector.NetworkProject.DocumentFallbackResource.prototype = {
428 440
429 /** 441 /**
430 * @override 442 * @override
431 * @return {string} 443 * @return {string}
432 */ 444 */
433 contentURL: function() 445 contentURL: function()
434 { 446 {
435 return this._resource.contentURL(); 447 return this._resource.contentURL();
436 }, 448 },
437 449
438 /** 450 /**
439 * @override 451 * @override
440 * @return {!WebInspector.ResourceType} 452 * @return {!WebInspector.ResourceType}
441 */ 453 */
442 contentType: function() 454 contentType: function()
443 { 455 {
444 return this._resource.resourceType(); 456 return this._resource.resourceType();
445 }, 457 },
446 458
447 /** 459 /**
448 * @override 460 * @override
449 * @param {function(?string)} callback 461 * @param {function(?string)} callback
450 */ 462 */
451 requestContent: function(callback) 463 requestContent: function(callback)
452 { 464 {
453 /** 465 /**
454 * @this {WebInspector.NetworkProject.FallbackResource} 466 * @param {?string} content
467 * @this {WebInspector.NetworkProject.DocumentFallbackResource}
455 */ 468 */
456 function loadFallbackContent() 469 function loadFallbackContent(content)
457 { 470 {
458 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._reso urce.target()); 471 if (content) {
459 if (!debuggerModel) { 472 callback(content);
460 callback(null);
461 return; 473 return;
462 } 474 }
463 var scripts = debuggerModel.scriptsForSourceURL(this._resource.url); 475
476 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._reso urce.target());
477 var scripts = debuggerModel ? debuggerModel.scriptsForSourceURL(this ._resource.url) : [];
464 if (!scripts.length) { 478 if (!scripts.length) {
465 callback(null); 479 callback(null);
466 return; 480 return;
467 } 481 }
468 482
469 var contentProvider; 483 new WebInspector.ConcatenatedScriptsContentProvider(scripts).request Content(callback);
470 var type = this._resource.resourceType();
471 if (type === WebInspector.resourceTypes.Document)
472 contentProvider = new WebInspector.ConcatenatedScriptsContentPro vider(scripts);
473 else if (type === WebInspector.resourceTypes.Script)
474 contentProvider = scripts[0];
475
476 console.assert(contentProvider, "Resource content request failed. " + this._resource.url);
477
478 contentProvider.requestContent(callback);
479 } 484 }
480 485
481 /** 486 this._resource.requestContent(loadFallbackContent.bind(this));
482 * @param {?string} content
483 * @this {WebInspector.NetworkProject.FallbackResource}
484 */
485 function requestContentLoaded(content)
486 {
487 if (content)
488 callback(content)
489 else
490 loadFallbackContent.call(this);
491 }
492
493 this._resource.requestContent(requestContentLoaded.bind(this));
494 }, 487 },
495 488
496 /** 489 /**
497 * @override 490 * @override
498 * @param {string} query 491 * @param {string} query
499 * @param {boolean} caseSensitive 492 * @param {boolean} caseSensitive
500 * @param {boolean} isRegex 493 * @param {boolean} isRegex
501 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal lback 494 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal lback
502 */ 495 */
503 searchInContent: function(query, caseSensitive, isRegex, callback) 496 searchInContent: function(query, caseSensitive, isRegex, callback)
504 { 497 {
505 /** 498 /**
506 * @param {?string} content 499 * @param {?string} content
507 */ 500 */
508 function documentContentLoaded(content) 501 function documentContentLoaded(content)
509 { 502 {
510 if (content === null) { 503 if (content === null) {
511 callback([]); 504 callback([]);
512 return; 505 return;
513 } 506 }
514 507
515 var result = WebInspector.ContentProvider.performSearchInContent(con tent, query, caseSensitive, isRegex); 508 var result = WebInspector.ContentProvider.performSearchInContent(con tent, query, caseSensitive, isRegex);
516 callback(result); 509 callback(result);
517 } 510 }
518 511
519 if (this.contentType() === WebInspector.resourceTypes.Document) { 512 this.requestContent(documentContentLoaded);
520 this.requestContent(documentContentLoaded);
521 return;
522 }
523
524 this._resource.searchInContent(query, caseSensitive, isRegex, callback);
525 } 513 }
526 } 514 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698