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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 this._resourceTreeModel = resourceTreeModel; | 75 this._resourceTreeModel = resourceTreeModel; |
| 76 target[Bindings.NetworkProject._networkProjectSymbol] = this; | 76 target[Bindings.NetworkProject._networkProjectSymbol] = this; |
| 77 | 77 |
| 78 this._eventListeners = []; | 78 this._eventListeners = []; |
| 79 | 79 |
| 80 if (resourceTreeModel) { | 80 if (resourceTreeModel) { |
| 81 this._eventListeners.push( | 81 this._eventListeners.push( |
| 82 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Resour ceAdded, this._resourceAdded, this), | 82 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Resour ceAdded, this._resourceAdded, this), |
| 83 resourceTreeModel.addEventListener( | 83 resourceTreeModel.addEventListener( |
| 84 SDK.ResourceTreeModel.Events.FrameWillNavigate, this._frameWillNav igate, this), | 84 SDK.ResourceTreeModel.Events.FrameWillNavigate, this._frameWillNav igate, this), |
| 85 resourceTreeModel.addEventListener( | |
| 86 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._mainFrameNa vigated, this), | |
| 87 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.FrameD etached, this._frameDetached, this)); | 85 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.FrameD etached, this._frameDetached, this)); |
| 88 } | 86 } |
| 89 | 87 |
| 90 this._debuggerModel = target.model(SDK.DebuggerModel); | 88 this._debuggerModel = target.model(SDK.DebuggerModel); |
| 91 /** @type {!Set<!SDK.Script>} */ | 89 /** @type {!Set<!SDK.Script>} */ |
| 92 this._acceptedScripts = new Set(); | 90 this._acceptedScripts = new Set(); |
| 93 if (this._debuggerModel) { | 91 if (this._debuggerModel) { |
| 94 var runtimeModel = this._debuggerModel.runtimeModel(); | 92 var runtimeModel = this._debuggerModel.runtimeModel(); |
| 95 this._eventListeners.push( | 93 this._eventListeners.push( |
| 96 runtimeModel.addEventListener( | 94 runtimeModel.addEventListener( |
| 97 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution ContextDestroyed, this), | 95 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution ContextDestroyed, this), |
| 98 this._debuggerModel.addEventListener( | 96 this._debuggerModel.addEventListener( |
| 99 SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCl eared, this), | 97 SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCl eared, this), |
| 100 this._debuggerModel.addEventListener( | 98 this._debuggerModel.addEventListener( |
| 101 SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSou rce, this), | 99 SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSou rce, this), |
| 102 this._debuggerModel.addEventListener( | 100 this._debuggerModel.addEventListener( |
| 103 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this)); | 101 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this)); |
| 104 } | 102 } |
| 105 var cssModel = target.model(SDK.CSSModel); | 103 var cssModel = target.model(SDK.CSSModel); |
| 106 if (cssModel) { | 104 if (cssModel) { |
| 107 this._eventListeners.push( | 105 this._eventListeners.push( |
| 108 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this), | 106 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this), |
| 109 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this)); | 107 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this)); |
| 110 } | 108 } |
| 111 this._eventListeners.push(target.targetManager().addEventListener( | |
| 112 SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged, this)); | |
| 113 } | 109 } |
| 114 | 110 |
| 115 /** | 111 /** |
| 116 * @param {!SDK.Target} target | 112 * @param {!SDK.Target} target |
| 117 * @param {string} frameId | 113 * @param {string} frameId |
| 118 * @param {boolean} isContentScripts | 114 * @param {boolean} isContentScripts |
| 119 * @return {string} | 115 * @return {string} |
| 120 */ | 116 */ |
| 121 static projectId(target, frameId, isContentScripts) { | 117 static projectId(target, frameId, isContentScripts) { |
| 122 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : ''); | 118 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : ''); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 * @param {boolean} isContentScript | 221 * @param {boolean} isContentScript |
| 226 */ | 222 */ |
| 227 _removeFileForURL(url, frameId, isContentScript) { | 223 _removeFileForURL(url, frameId, isContentScript) { |
| 228 var project = | 224 var project = |
| 229 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._targ et, frameId, isContentScript)); | 225 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._targ et, frameId, isContentScript)); |
| 230 if (!project) | 226 if (!project) |
| 231 return; | 227 return; |
| 232 project.removeFile(url); | 228 project.removeFile(url); |
| 233 } | 229 } |
| 234 | 230 |
| 235 _populate() { | 231 _populate() { |
|
dgozman
2017/05/05 21:20:29
Not used anymore.
lushnikov
2017/05/05 21:54:35
Done.
| |
| 236 /** | 232 /** |
| 237 * @param {!SDK.ResourceTreeFrame} frame | 233 * @param {!SDK.ResourceTreeFrame} frame |
| 238 * @this {Bindings.NetworkProject} | 234 * @this {Bindings.NetworkProject} |
| 239 */ | 235 */ |
| 240 function populateFrame(frame) { | 236 function populateFrame(frame) { |
| 241 for (var i = 0; i < frame.childFrames.length; ++i) | 237 for (var i = 0; i < frame.childFrames.length; ++i) |
| 242 populateFrame.call(this, frame.childFrames[i]); | 238 populateFrame.call(this, frame.childFrames[i]); |
| 243 | 239 |
| 244 var resources = frame.resources(); | 240 var resources = frame.resources(); |
| 245 for (var i = 0; i < resources.length; ++i) | 241 for (var i = 0; i < resources.length; ++i) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 * @param {!Common.Event} event | 360 * @param {!Common.Event} event |
| 365 */ | 361 */ |
| 366 _resourceAdded(event) { | 362 _resourceAdded(event) { |
| 367 var resource = /** @type {!SDK.Resource} */ (event.data); | 363 var resource = /** @type {!SDK.Resource} */ (event.data); |
| 368 this._addResource(resource); | 364 this._addResource(resource); |
| 369 } | 365 } |
| 370 | 366 |
| 371 /** | 367 /** |
| 372 * @param {!SDK.Resource} resource | 368 * @param {!SDK.Resource} resource |
| 373 */ | 369 */ |
| 370 _acceptsResource(resource) { | |
| 371 var resourceType = resource.resourceType(); | |
| 372 // Only load selected resource types from resources. | |
| 373 if (resourceType !== Common.resourceTypes.Image && resourceType !== Common.r esourceTypes.Font && | |
| 374 resourceType !== Common.resourceTypes.Document && resourceType !== Commo n.resourceTypes.Manifest) | |
| 375 return false; | |
| 376 | |
| 377 // Ignore non-images and non-fonts. | |
| 378 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res ource.mimeType.startsWith('image')) | |
| 379 return false; | |
| 380 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso urce.mimeType.includes('font')) | |
| 381 return false; | |
| 382 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && | |
| 383 resource.contentURL().startsWith('data:')) | |
| 384 return false; | |
| 385 return true; | |
| 386 } | |
| 387 | |
| 388 /** | |
| 389 * @param {!SDK.Resource} resource | |
| 390 */ | |
| 374 _addResource(resource) { | 391 _addResource(resource) { |
| 375 var resourceType = resource.resourceType(); | 392 if (!this._acceptsResource(resource)) |
| 376 // Only load selected resource types from resources. | |
| 377 if (resourceType !== Common.resourceTypes.Image && resourceType !== Common.r esourceTypes.Font && | |
| 378 resourceType !== Common.resourceTypes.Document && resourceType !== Commo n.resourceTypes.Manifest) | |
| 379 return; | |
| 380 | |
| 381 // Ignore non-images and non-fonts. | |
| 382 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res ource.mimeType.startsWith('image')) | |
| 383 return; | |
| 384 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso urce.mimeType.includes('font')) | |
| 385 return; | |
| 386 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && | |
| 387 resource.contentURL().startsWith('data:')) | |
| 388 return; | |
| 389 | |
| 390 // Never load document twice. | |
| 391 var projectId = Bindings.NetworkProject.projectId(this._target, resource.fra meId, false); | |
| 392 var project = this._workspaceProjects.get(projectId); | |
| 393 if (project && project.uiSourceCodeForURL(resource.url)) | |
| 394 return; | 393 return; |
| 395 | 394 |
| 396 var uiSourceCode = this._createFile(resource, resource.frameId, false); | 395 var uiSourceCode = this._createFile(resource, resource.frameId, false); |
| 397 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; | 396 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; |
| 398 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.resourceM etadata(resource)); | 397 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.resourceM etadata(resource)); |
| 399 } | 398 } |
| 400 | 399 |
| 401 /** | 400 /** |
| 402 * @param {!SDK.ResourceTreeFrame} frame | 401 * @param {!SDK.ResourceTreeFrame} frame |
| 403 */ | 402 */ |
| 404 _removeFrameResources(frame) { | 403 _removeFrameResources(frame) { |
| 405 var project = this._workspaceProject(frame.id, false); | 404 var regularProject = this._workspaceProject(frame.id, false); |
| 406 for (var resource of frame.resources()) | 405 var contentScriptsProject = this._workspaceProject(frame.id, true); |
| 407 project.removeUISourceCode(resource.url); | 406 for (var resource of frame.resources()) { |
| 408 project = this._workspaceProject(frame.id, true); | 407 if (!this._acceptsResource(resource)) |
| 409 for (var resource of frame.resources()) | 408 continue; |
| 410 project.removeUISourceCode(resource.url); | 409 regularProject.removeFile(resource.url); |
| 410 contentScriptsProject.removeFile(resource.url); | |
| 411 } | |
| 411 } | 412 } |
| 412 | 413 |
| 413 /** | 414 /** |
| 414 * @param {!Common.Event} event | 415 * @param {!Common.Event} event |
| 415 */ | 416 */ |
| 416 _frameWillNavigate(event) { | 417 _frameWillNavigate(event) { |
| 417 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | 418 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); |
| 418 this._removeFrameResources(frame); | 419 this._removeFrameResources(frame); |
| 419 } | 420 } |
| 420 | 421 |
| 421 /** | 422 /** |
| 422 * @param {!Common.Event} event | 423 * @param {!Common.Event} event |
| 423 */ | 424 */ |
| 424 _frameDetached(event) { | 425 _frameDetached(event) { |
| 425 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | 426 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); |
| 426 this._removeFrameResources(frame); | 427 this._removeFrameResources(frame); |
| 427 } | 428 } |
| 428 | 429 |
| 429 /** | 430 /** |
| 430 * @param {!Common.Event} event | |
| 431 */ | |
| 432 _mainFrameNavigated(event) { | |
| 433 this._reset(); | |
| 434 } | |
| 435 | |
| 436 _suspendStateChanged() { | |
| 437 if (this._target.targetManager().allTargetsSuspended()) | |
| 438 this._reset(); | |
| 439 else | |
| 440 this._populate(); | |
| 441 } | |
| 442 | |
| 443 /** | |
| 444 * @param {!Common.ContentProvider} contentProvider | 431 * @param {!Common.ContentProvider} contentProvider |
| 445 * @param {string} frameId | 432 * @param {string} frameId |
| 446 * @param {boolean} isContentScript | 433 * @param {boolean} isContentScript |
| 447 * @return {!Workspace.UISourceCode} | 434 * @return {!Workspace.UISourceCode} |
| 448 */ | 435 */ |
| 449 _createFile(contentProvider, frameId, isContentScript) { | 436 _createFile(contentProvider, frameId, isContentScript) { |
| 450 var url = contentProvider.contentURL(); | 437 var url = contentProvider.contentURL(); |
| 451 var project = this._workspaceProject(frameId, isContentScript); | 438 var project = this._workspaceProject(frameId, isContentScript); |
| 452 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); | 439 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); |
| 453 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = frameId; | 440 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = frameId; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 }; | 502 }; |
| 516 | 503 |
| 517 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 504 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
| 518 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); | 505 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); |
| 519 Bindings.NetworkProject._scriptSymbol = Symbol('script'); | 506 Bindings.NetworkProject._scriptSymbol = Symbol('script'); |
| 520 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | 507 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); |
| 521 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 508 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
| 522 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); | 509 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); |
| 523 | 510 |
| 524 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol'); | 511 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol'); |
| OLD | NEW |