Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 */ | 149 */ |
| 150 WebInspector.NetworkProject = function(target, workspace, networkMapping) | 150 WebInspector.NetworkProject = function(target, workspace, networkMapping) |
| 151 { | 151 { |
| 152 WebInspector.SDKObject.call(this, target); | 152 WebInspector.SDKObject.call(this, target); |
| 153 this._workspace = workspace; | 153 this._workspace = workspace; |
| 154 this._networkMapping = networkMapping; | 154 this._networkMapping = networkMapping; |
| 155 this._projectDelegates = {}; | 155 this._projectDelegates = {}; |
| 156 this._processedURLs = {}; | 156 this._processedURLs = {}; |
| 157 target[WebInspector.NetworkProject._networkProjectSymbol] = this; | 157 target[WebInspector.NetworkProject._networkProjectSymbol] = this; |
| 158 | 158 |
| 159 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve ntTypes.ResourceAdded, this._resourceAdded, this); | |
| 160 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); | 159 target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Eve ntTypes.MainFrameNavigated, this._mainFrameNavigated, this); |
| 161 | 160 |
| 162 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | 161 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); |
| 163 if (debuggerModel) { | 162 if (debuggerModel) { |
| 164 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedS criptSource, this._parsedScriptSource, this); | 163 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedS criptSource, this._parsedScriptSource, this); |
| 165 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedT oParseScriptSource, this._parsedScriptSource, this); | 164 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedT oParseScriptSource, this._parsedScriptSource, this); |
| 166 } | 165 } |
| 167 var cssModel = WebInspector.CSSStyleModel.fromTarget(target); | 166 var cssModel = WebInspector.CSSStyleModel.fromTarget(target); |
| 168 if (cssModel) { | 167 if (cssModel) { |
| 169 cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetAd ded, this._styleSheetAdded, this); | 168 cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetAd ded, this._styleSheetAdded, this); |
| 170 cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetRe moved, this._styleSheetRemoved, this); | 169 cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetRe moved, this._styleSheetRemoved, this); |
| 171 } | 170 } |
| 171 | |
| 172 if (debuggerModel && !debuggerModel.debuggerEnabled()) | |
| 173 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.Debugge rWasEnabled, this._debuggerEnabled, this); | |
| 174 else | |
| 175 this._debuggerEnabled(); | |
| 172 } | 176 } |
| 173 | 177 |
| 174 WebInspector.NetworkProject._networkProjectSymbol = Symbol("networkProject"); | 178 WebInspector.NetworkProject._networkProjectSymbol = Symbol("networkProject"); |
| 175 WebInspector.NetworkProject._contentTypeSymbol = Symbol("networkContentType"); | 179 WebInspector.NetworkProject._contentTypeSymbol = Symbol("networkContentType"); |
| 176 | 180 |
| 177 /** | 181 /** |
| 178 * @param {!WebInspector.Target} target | 182 * @param {!WebInspector.Target} target |
| 179 * @param {string} projectURL | 183 * @param {string} projectURL |
| 180 * @param {boolean} isContentScripts | 184 * @param {boolean} isContentScripts |
| 181 * @return {string} | 185 * @return {string} |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 */ | 271 */ |
| 268 _removeFileForURL: function(url) | 272 _removeFileForURL: function(url) |
| 269 { | 273 { |
| 270 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url); | 274 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url); |
| 271 var projectURL = splitURL[0]; | 275 var projectURL = splitURL[0]; |
| 272 var path = splitURL.slice(1).join("/"); | 276 var path = splitURL.slice(1).join("/"); |
| 273 var projectDelegate = this._projectDelegates[WebInspector.NetworkProject .projectId(this.target(), projectURL, false)]; | 277 var projectDelegate = this._projectDelegates[WebInspector.NetworkProject .projectId(this.target(), projectURL, false)]; |
| 274 projectDelegate.removeFile(path); | 278 projectDelegate.removeFile(path); |
| 275 }, | 279 }, |
| 276 | 280 |
| 281 _debuggerEnabled: function() | |
| 282 { | |
| 283 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this.target()) ; | |
| 284 if (debuggerModel) | |
| 285 debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events. DebuggerWasEnabled, this._debuggerEnabled, this); | |
| 286 this._populate(); | |
| 287 this.target().resourceTreeModel.addEventListener(WebInspector.ResourceTr eeModel.EventTypes.ResourceAdded, this._resourceAdded, this); | |
| 288 }, | |
| 289 | |
| 277 _populate: function() | 290 _populate: function() |
| 278 { | 291 { |
| 279 /** | 292 /** |
| 280 * @param {!WebInspector.ResourceTreeFrame} frame | 293 * @param {!WebInspector.ResourceTreeFrame} frame |
| 281 * @this {WebInspector.NetworkProject} | 294 * @this {WebInspector.NetworkProject} |
| 282 */ | 295 */ |
| 283 function populateFrame(frame) | 296 function populateFrame(frame) |
| 284 { | 297 { |
| 285 for (var i = 0; i < frame.childFrames.length; ++i) | 298 for (var i = 0; i < frame.childFrames.length; ++i) |
| 286 populateFrame.call(this, frame.childFrames[i]); | 299 populateFrame.call(this, frame.childFrames[i]); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 }, | 399 }, |
| 387 | 400 |
| 388 _dispose: function() | 401 _dispose: function() |
| 389 { | 402 { |
| 390 this._reset(); | 403 this._reset(); |
| 391 var target = this.target(); | 404 var target = this.target(); |
| 392 target.resourceTreeModel.removeEventListener(WebInspector.ResourceTreeMo del.EventTypes.ResourceAdded, this._resourceAdded, this); | 405 target.resourceTreeModel.removeEventListener(WebInspector.ResourceTreeMo del.EventTypes.ResourceAdded, this._resourceAdded, this); |
| 393 target.resourceTreeModel.removeEventListener(WebInspector.ResourceTreeMo del.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this); | 406 target.resourceTreeModel.removeEventListener(WebInspector.ResourceTreeMo del.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this); |
| 394 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | 407 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); |
| 395 if (debuggerModel) { | 408 if (debuggerModel) { |
| 409 debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events. DebuggerWasEnabled, this._debuggerEnabled, this); | |
| 396 debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events. ParsedScriptSource, this._parsedScriptSource, this); | 410 debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events. ParsedScriptSource, this._parsedScriptSource, this); |
| 397 debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events. FailedToParseScriptSource, this._parsedScriptSource, this); | 411 debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events. FailedToParseScriptSource, this._parsedScriptSource, this); |
| 398 } | 412 } |
| 399 var cssModel = WebInspector.CSSStyleModel.fromTarget(target); | 413 var cssModel = WebInspector.CSSStyleModel.fromTarget(target); |
| 400 if (cssModel) { | 414 if (cssModel) { |
| 401 cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Style SheetAdded, this._styleSheetAdded, this); | 415 cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Style SheetAdded, this._styleSheetAdded, this); |
| 402 cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Style SheetRemoved, this._styleSheetRemoved, this); | 416 cssModel.removeEventListener(WebInspector.CSSStyleModel.Events.Style SheetRemoved, this._styleSheetRemoved, this); |
| 403 } | 417 } |
| 404 }, | 418 }, |
| 405 | 419 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 return this._resource.resourceType(); | 458 return this._resource.resourceType(); |
| 445 }, | 459 }, |
| 446 | 460 |
| 447 /** | 461 /** |
| 448 * @override | 462 * @override |
| 449 * @param {function(?string)} callback | 463 * @param {function(?string)} callback |
| 450 */ | 464 */ |
| 451 requestContent: function(callback) | 465 requestContent: function(callback) |
| 452 { | 466 { |
| 453 /** | 467 /** |
| 468 * @param {!WebInspector.Target} target | |
| 469 * @param {string} url | |
| 470 * @return {!Array.<!WebInspector.Script>} | |
| 471 */ | |
| 472 function findScripts(target, url) | |
| 473 { | |
| 474 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | |
| 475 return debuggerModel ? debuggerModel.scriptsForSourceURL(url) : []; | |
| 476 } | |
| 477 | |
| 478 /** | |
| 479 * @param {?string} content | |
| 454 * @this {WebInspector.NetworkProject.FallbackResource} | 480 * @this {WebInspector.NetworkProject.FallbackResource} |
| 455 */ | 481 */ |
| 456 function loadFallbackContent() | 482 function loadFallbackContent(content) |
| 457 { | 483 { |
| 458 var debuggerModel = WebInspector.DebuggerModel.fromTarget(this._reso urce.target()); | 484 if (content) { |
| 459 if (!debuggerModel) { | 485 callback(content); |
| 460 callback(null); | |
| 461 return; | 486 return; |
| 462 } | 487 } |
| 463 var scripts = debuggerModel.scriptsForSourceURL(this._resource.url); | 488 |
| 489 var scripts = findScripts(this._resource.target(), this._resource.ur l); | |
| 464 if (!scripts.length) { | 490 if (!scripts.length) { |
| 465 callback(null); | 491 callback(null); |
| 466 return; | 492 return; |
| 467 } | 493 } |
| 468 | 494 |
| 469 var contentProvider; | 495 var contentProvider; |
| 470 var type = this._resource.resourceType(); | 496 var type = this._resource.resourceType(); |
| 471 if (type === WebInspector.resourceTypes.Document) | 497 if (type === WebInspector.resourceTypes.Document) |
| 472 contentProvider = new WebInspector.ConcatenatedScriptsContentPro vider(scripts); | 498 contentProvider = new WebInspector.ConcatenatedScriptsContentPro vider(scripts); |
| 473 else if (type === WebInspector.resourceTypes.Script) | 499 else if (type === WebInspector.resourceTypes.Script) |
| 474 contentProvider = scripts[0]; | 500 contentProvider = scripts[0]; |
| 475 | 501 |
| 476 console.assert(contentProvider, "Resource content request failed. " + this._resource.url); | 502 console.assert(contentProvider, "Resource content request failed. " + this._resource.url); |
| 477 | 503 |
| 478 contentProvider.requestContent(callback); | 504 contentProvider.requestContent(callback); |
| 479 } | 505 } |
| 480 | 506 |
| 481 /** | 507 /** |
| 482 * @param {?string} content | 508 * @param {?string} content |
| 483 * @this {WebInspector.NetworkProject.FallbackResource} | 509 * @this {WebInspector.NetworkProject.FallbackResource} |
| 484 */ | 510 */ |
| 485 function requestContentLoaded(content) | 511 function loadResourceContent(content) |
| 486 { | 512 { |
| 487 if (content) | 513 if (content) { |
| 488 callback(content) | 514 callback(content); |
| 489 else | 515 return; |
| 490 loadFallbackContent.call(this); | 516 } |
| 517 this._resource.requestContent(loadFallbackContent.bind(this)); | |
| 491 } | 518 } |
| 492 | 519 |
| 493 this._resource.requestContent(requestContentLoaded.bind(this)); | 520 /** |
| 521 * @this {WebInspector.NetworkProject.FallbackResource} | |
| 522 */ | |
| 523 function loadScriptContent() | |
| 524 { | |
| 525 if (this._resource.resourceType() !== WebInspector.resourceTypes.Scr ipt) { | |
| 526 loadResourceContent.call(this, null); | |
| 527 return; | |
| 528 } | |
| 529 | |
| 530 var scripts = findScripts(this._resource.target(), this._resource.ur l); | |
| 531 if (scripts.length) | |
| 532 scripts[0].requestContent(loadResourceContent.bind(this)); | |
|
yurys
2015/07/16 16:30:35
Why not scripts[0].requestContent(callback); ? Can
dgozman
2015/07/17 14:39:16
Fixed.
| |
| 533 else | |
| 534 loadResourceContent.call(this, null); | |
| 535 } | |
| 536 | |
| 537 loadScriptContent.call(this); | |
| 494 }, | 538 }, |
| 495 | 539 |
| 496 /** | 540 /** |
| 497 * @override | 541 * @override |
| 498 * @param {string} query | 542 * @param {string} query |
| 499 * @param {boolean} caseSensitive | 543 * @param {boolean} caseSensitive |
| 500 * @param {boolean} isRegex | 544 * @param {boolean} isRegex |
| 501 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal lback | 545 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal lback |
| 502 */ | 546 */ |
| 503 searchInContent: function(query, caseSensitive, isRegex, callback) | 547 searchInContent: function(query, caseSensitive, isRegex, callback) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 517 } | 561 } |
| 518 | 562 |
| 519 if (this.contentType() === WebInspector.resourceTypes.Document) { | 563 if (this.contentType() === WebInspector.resourceTypes.Document) { |
| 520 this.requestContent(documentContentLoaded); | 564 this.requestContent(documentContentLoaded); |
| 521 return; | 565 return; |
| 522 } | 566 } |
| 523 | 567 |
| 524 this._resource.searchInContent(query, caseSensitive, isRegex, callback); | 568 this._resource.searchInContent(query, caseSensitive, isRegex, callback); |
| 525 } | 569 } |
| 526 } | 570 } |
| OLD | NEW |