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 if (this._debuggerModel) { | 89 if (this._debuggerModel) { |
| 92 var runtimeModel = this._debuggerModel.runtimeModel(); | 90 var runtimeModel = this._debuggerModel.runtimeModel(); |
| 93 this._eventListeners.push( | 91 this._eventListeners.push( |
| 94 runtimeModel.addEventListener( | 92 runtimeModel.addEventListener( |
| 95 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution ContextDestroyed, this), | 93 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution ContextDestroyed, this), |
| 96 this._debuggerModel.addEventListener( | 94 this._debuggerModel.addEventListener( |
| 97 SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSou rce, this), | 95 SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSou rce, this), |
| 98 this._debuggerModel.addEventListener( | 96 this._debuggerModel.addEventListener( |
| 99 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this)); | 97 SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedSc riptSource, this)); |
| 100 } | 98 } |
| 101 var cssModel = target.model(SDK.CSSModel); | 99 var cssModel = target.model(SDK.CSSModel); |
| 102 if (cssModel) { | 100 if (cssModel) { |
| 103 this._eventListeners.push( | 101 this._eventListeners.push( |
| 104 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this), | 102 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, this._s tyleSheetAdded, this), |
| 105 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this)); | 103 cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetRemoved, this. _styleSheetRemoved, this)); |
| 106 } | 104 } |
| 107 this._eventListeners.push(target.targetManager().addEventListener( | |
| 108 SDK.TargetManager.Events.SuspendStateChanged, this._suspendStateChanged, this)); | |
| 109 } | 105 } |
| 110 | 106 |
| 111 /** | 107 /** |
| 112 * @param {!SDK.Target} target | 108 * @param {!SDK.Target} target |
| 113 * @param {string} frameId | 109 * @param {string} frameId |
| 114 * @param {boolean} isContentScripts | 110 * @param {boolean} isContentScripts |
| 115 * @return {string} | 111 * @return {string} |
| 116 */ | 112 */ |
| 117 static projectId(target, frameId, isContentScripts) { | 113 static projectId(target, frameId, isContentScripts) { |
| 118 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : ''); | 114 return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscrip ts' : ''); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 * @param {!Common.Event} event | 336 * @param {!Common.Event} event |
| 341 */ | 337 */ |
| 342 _resourceAdded(event) { | 338 _resourceAdded(event) { |
| 343 var resource = /** @type {!SDK.Resource} */ (event.data); | 339 var resource = /** @type {!SDK.Resource} */ (event.data); |
| 344 this._addResource(resource); | 340 this._addResource(resource); |
| 345 } | 341 } |
| 346 | 342 |
| 347 /** | 343 /** |
| 348 * @param {!SDK.Resource} resource | 344 * @param {!SDK.Resource} resource |
| 349 */ | 345 */ |
| 346 _acceptsResource(resource) { | |
| 347 var resourceType = resource.resourceType(); | |
| 348 // Only load selected resource types from resources. | |
| 349 if (resourceType !== Common.resourceTypes.Image && resourceType !== Common.r esourceTypes.Font && | |
| 350 resourceType !== Common.resourceTypes.Document && resourceType !== Commo n.resourceTypes.Manifest) | |
| 351 return false; | |
| 352 | |
| 353 // Ignore non-images and non-fonts. | |
| 354 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res ource.mimeType.startsWith('image')) | |
| 355 return false; | |
| 356 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso urce.mimeType.includes('font')) | |
| 357 return false; | |
| 358 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && | |
| 359 resource.contentURL().startsWith('data:')) | |
| 360 return false; | |
| 361 return true; | |
| 362 } | |
| 363 | |
| 364 /** | |
| 365 * @param {!SDK.Resource} resource | |
| 366 */ | |
| 350 _addResource(resource) { | 367 _addResource(resource) { |
| 351 var resourceType = resource.resourceType(); | 368 if (!this._acceptsResource(resource)) |
| 352 // Only load selected resource types from resources. | |
| 353 if (resourceType !== Common.resourceTypes.Image && resourceType !== Common.r esourceTypes.Font && | |
| 354 resourceType !== Common.resourceTypes.Document && resourceType !== Commo n.resourceTypes.Manifest) | |
| 355 return; | |
| 356 | |
| 357 // Ignore non-images and non-fonts. | |
| 358 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res ource.mimeType.startsWith('image')) | |
| 359 return; | |
| 360 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso urce.mimeType.includes('font')) | |
| 361 return; | |
| 362 if ((resourceType === Common.resourceTypes.Image || resourceType === Common. resourceTypes.Font) && | |
| 363 resource.contentURL().startsWith('data:')) | |
| 364 return; | |
| 365 | |
| 366 // Never load document twice. | |
|
dgozman
2017/04/20 17:23:17
What was this about? Why it doesn't happen anymore
lushnikov
2017/04/21 00:51:27
This was introduced in https://codereview.chromium
| |
| 367 var projectId = Bindings.NetworkProject.projectId(this._target, resource.fra meId, false); | |
| 368 var project = this._workspaceProjects.get(projectId); | |
| 369 if (project && project.uiSourceCodeForURL(resource.url)) | |
| 370 return; | 369 return; |
| 371 | 370 |
| 372 var uiSourceCode = this._createFile(resource, resource.frameId, false); | 371 var uiSourceCode = this._createFile(resource, resource.frameId, false); |
| 373 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; | 372 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; |
| 374 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource)); | 373 this._addUISourceCodeWithProvider(uiSourceCode, resource, this._resourceMeta data(resource)); |
| 375 } | 374 } |
| 376 | 375 |
| 377 /** | 376 /** |
| 378 * @param {!SDK.ResourceTreeFrame} frame | 377 * @param {!SDK.ResourceTreeFrame} frame |
| 379 */ | 378 */ |
| 380 _removeFrameResources(frame) { | 379 _removeFrameResources(frame) { |
| 381 var project = this._workspaceProject(frame.id, false); | 380 var regularProject = this._workspaceProject(frame.id, false); |
| 382 for (var resource of frame.resources()) | 381 var contentScriptsProject = this._workspaceProject(frame.id, true); |
| 383 project.removeUISourceCode(resource.url); | 382 for (var resource of frame.resources()) { |
|
lushnikov
2017/04/20 02:52:50
this was a bug: it's incorrect to call project.rem
| |
| 384 project = this._workspaceProject(frame.id, true); | 383 if (!this._acceptsResource(resource)) |
| 385 for (var resource of frame.resources()) | 384 continue; |
| 386 project.removeUISourceCode(resource.url); | 385 regularProject.removeFile(resource.url); |
| 386 contentScriptsProject.removeFile(resource.url); | |
| 387 } | |
| 387 } | 388 } |
| 388 | 389 |
| 389 /** | 390 /** |
| 390 * @param {!Common.Event} event | 391 * @param {!Common.Event} event |
| 391 */ | 392 */ |
| 392 _frameWillNavigate(event) { | 393 _frameWillNavigate(event) { |
| 393 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | 394 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); |
| 394 this._removeFrameResources(frame); | 395 this._removeFrameResources(frame); |
| 395 } | 396 } |
| 396 | 397 |
| 397 /** | 398 /** |
| 398 * @param {!Common.Event} event | 399 * @param {!Common.Event} event |
| 399 */ | 400 */ |
| 400 _frameDetached(event) { | 401 _frameDetached(event) { |
| 401 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | 402 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); |
| 402 this._removeFrameResources(frame); | 403 this._removeFrameResources(frame); |
| 403 } | 404 } |
| 404 | 405 |
| 405 /** | 406 /** |
| 406 * @param {!Common.Event} event | |
| 407 */ | |
| 408 _mainFrameNavigated(event) { | |
| 409 this._reset(); | |
| 410 } | |
| 411 | |
| 412 _suspendStateChanged() { | |
|
dgozman
2017/04/20 17:23:17
Let's add a test for this.
lushnikov
2017/04/21 00:51:27
Done in a separate patch.
| |
| 413 if (this._target.targetManager().allTargetsSuspended()) | |
| 414 this._reset(); | |
| 415 else | |
| 416 this._populate(); | |
| 417 } | |
| 418 | |
| 419 /** | |
| 420 * @param {!Common.ContentProvider} contentProvider | 407 * @param {!Common.ContentProvider} contentProvider |
| 421 * @param {string} frameId | 408 * @param {string} frameId |
| 422 * @param {boolean} isContentScript | 409 * @param {boolean} isContentScript |
| 423 * @return {!Workspace.UISourceCode} | 410 * @return {!Workspace.UISourceCode} |
| 424 */ | 411 */ |
| 425 _createFile(contentProvider, frameId, isContentScript) { | 412 _createFile(contentProvider, frameId, isContentScript) { |
| 426 var url = contentProvider.contentURL(); | 413 var url = contentProvider.contentURL(); |
| 427 var project = this._workspaceProject(frameId, isContentScript); | 414 var project = this._workspaceProject(frameId, isContentScript); |
| 428 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); | 415 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); |
| 429 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this._target; | 416 uiSourceCode[Bindings.NetworkProject._targetSymbol] = this._target; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 } | 473 } |
| 487 }; | 474 }; |
| 488 | 475 |
| 489 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 476 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
| 490 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); | 477 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); |
| 491 Bindings.NetworkProject._scriptSymbol = Symbol('script'); | 478 Bindings.NetworkProject._scriptSymbol = Symbol('script'); |
| 492 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | 479 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); |
| 493 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 480 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
| 494 Bindings.NetworkProject._frameSymbol = Symbol('frame'); | 481 Bindings.NetworkProject._frameSymbol = Symbol('frame'); |
| 495 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); | 482 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); |
| OLD | NEW |