| 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() { | |
| 236 /** | |
| 237 * @param {!SDK.ResourceTreeFrame} frame | |
| 238 * @this {Bindings.NetworkProject} | |
| 239 */ | |
| 240 function populateFrame(frame) { | |
| 241 for (var i = 0; i < frame.childFrames.length; ++i) | |
| 242 populateFrame.call(this, frame.childFrames[i]); | |
| 243 | |
| 244 var resources = frame.resources(); | |
| 245 for (var i = 0; i < resources.length; ++i) | |
| 246 this._addResource(resources[i]); | |
| 247 } | |
| 248 | |
| 249 var resourceTreeModel = this._resourceTreeModel; | |
| 250 var mainFrame = resourceTreeModel && resourceTreeModel.mainFrame; | |
| 251 if (mainFrame) | |
| 252 populateFrame.call(this, mainFrame); | |
| 253 } | |
| 254 | |
| 255 /** | 231 /** |
| 256 * @param {!Workspace.UISourceCode} uiSourceCode | 232 * @param {!Workspace.UISourceCode} uiSourceCode |
| 257 * @param {!Common.ContentProvider} contentProvider | 233 * @param {!Common.ContentProvider} contentProvider |
| 258 * @param {?Workspace.UISourceCodeMetadata} metadata | 234 * @param {?Workspace.UISourceCodeMetadata} metadata |
| 259 */ | 235 */ |
| 260 _addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata) { | 236 _addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata) { |
| 261 /** @type {!Bindings.ContentProviderBasedProject} */ (uiSourceCode.project()
) | 237 /** @type {!Bindings.ContentProviderBasedProject} */ (uiSourceCode.project()
) |
| 262 .addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata); | 238 .addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata); |
| 263 } | 239 } |
| 264 | 240 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 * @param {!Common.Event} event | 340 * @param {!Common.Event} event |
| 365 */ | 341 */ |
| 366 _resourceAdded(event) { | 342 _resourceAdded(event) { |
| 367 var resource = /** @type {!SDK.Resource} */ (event.data); | 343 var resource = /** @type {!SDK.Resource} */ (event.data); |
| 368 this._addResource(resource); | 344 this._addResource(resource); |
| 369 } | 345 } |
| 370 | 346 |
| 371 /** | 347 /** |
| 372 * @param {!SDK.Resource} resource | 348 * @param {!SDK.Resource} resource |
| 373 */ | 349 */ |
| 350 _acceptsResource(resource) { |
| 351 var resourceType = resource.resourceType(); |
| 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 false; |
| 356 |
| 357 // Ignore non-images and non-fonts. |
| 358 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res
ource.mimeType.startsWith('image')) |
| 359 return false; |
| 360 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso
urce.mimeType.includes('font')) |
| 361 return false; |
| 362 if ((resourceType === Common.resourceTypes.Image || resourceType === Common.
resourceTypes.Font) && |
| 363 resource.contentURL().startsWith('data:')) |
| 364 return false; |
| 365 return true; |
| 366 } |
| 367 |
| 368 /** |
| 369 * @param {!SDK.Resource} resource |
| 370 */ |
| 374 _addResource(resource) { | 371 _addResource(resource) { |
| 375 var resourceType = resource.resourceType(); | 372 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; | 373 return; |
| 395 | 374 |
| 396 var uiSourceCode = this._createFile(resource, resource.frameId, false); | 375 var uiSourceCode = this._createFile(resource, resource.frameId, false); |
| 397 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; | 376 uiSourceCode[Bindings.NetworkProject._resourceSymbol] = resource; |
| 398 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.resourceM
etadata(resource)); | 377 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.resourceM
etadata(resource)); |
| 399 } | 378 } |
| 400 | 379 |
| 401 /** | 380 /** |
| 402 * @param {!SDK.ResourceTreeFrame} frame | 381 * @param {!SDK.ResourceTreeFrame} frame |
| 403 */ | 382 */ |
| 404 _removeFrameResources(frame) { | 383 _removeFrameResources(frame) { |
| 405 var project = this._workspaceProject(frame.id, false); | 384 var regularProject = this._workspaceProject(frame.id, false); |
| 406 for (var resource of frame.resources()) | 385 var contentScriptsProject = this._workspaceProject(frame.id, true); |
| 407 project.removeUISourceCode(resource.url); | 386 for (var resource of frame.resources()) { |
| 408 project = this._workspaceProject(frame.id, true); | 387 if (!this._acceptsResource(resource)) |
| 409 for (var resource of frame.resources()) | 388 continue; |
| 410 project.removeUISourceCode(resource.url); | 389 regularProject.removeFile(resource.url); |
| 390 contentScriptsProject.removeFile(resource.url); |
| 391 } |
| 411 } | 392 } |
| 412 | 393 |
| 413 /** | 394 /** |
| 414 * @param {!Common.Event} event | 395 * @param {!Common.Event} event |
| 415 */ | 396 */ |
| 416 _frameWillNavigate(event) { | 397 _frameWillNavigate(event) { |
| 417 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | 398 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); |
| 418 this._removeFrameResources(frame); | 399 this._removeFrameResources(frame); |
| 419 } | 400 } |
| 420 | 401 |
| 421 /** | 402 /** |
| 422 * @param {!Common.Event} event | 403 * @param {!Common.Event} event |
| 423 */ | 404 */ |
| 424 _frameDetached(event) { | 405 _frameDetached(event) { |
| 425 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | 406 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); |
| 426 this._removeFrameResources(frame); | 407 this._removeFrameResources(frame); |
| 427 } | 408 } |
| 428 | 409 |
| 429 /** | 410 /** |
| 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 | 411 * @param {!Common.ContentProvider} contentProvider |
| 445 * @param {string} frameId | 412 * @param {string} frameId |
| 446 * @param {boolean} isContentScript | 413 * @param {boolean} isContentScript |
| 447 * @return {!Workspace.UISourceCode} | 414 * @return {!Workspace.UISourceCode} |
| 448 */ | 415 */ |
| 449 _createFile(contentProvider, frameId, isContentScript) { | 416 _createFile(contentProvider, frameId, isContentScript) { |
| 450 var url = contentProvider.contentURL(); | 417 var url = contentProvider.contentURL(); |
| 451 var project = this._workspaceProject(frameId, isContentScript); | 418 var project = this._workspaceProject(frameId, isContentScript); |
| 452 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy
pe()); | 419 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy
pe()); |
| 453 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = frameId; | 420 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = frameId; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 }; | 482 }; |
| 516 | 483 |
| 517 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 484 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
| 518 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); | 485 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); |
| 519 Bindings.NetworkProject._scriptSymbol = Symbol('script'); | 486 Bindings.NetworkProject._scriptSymbol = Symbol('script'); |
| 520 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | 487 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); |
| 521 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 488 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
| 522 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); | 489 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); |
| 523 | 490 |
| 524 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec
t._frameAttributionSymbol'); | 491 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec
t._frameAttributionSymbol'); |
| OLD | NEW |