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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 constructor(target, workspace, resourceTreeModel) { | 76 constructor(target, workspace, resourceTreeModel) { |
77 this._target = target; | 77 this._target = target; |
78 this._workspace = workspace; | 78 this._workspace = workspace; |
79 /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */ | 79 /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */ |
80 this._workspaceProjects = new Map(); | 80 this._workspaceProjects = new Map(); |
81 this._resourceTreeModel = resourceTreeModel; | 81 this._resourceTreeModel = resourceTreeModel; |
82 target[Bindings.NetworkProject._networkProjectSymbol] = this; | 82 target[Bindings.NetworkProject._networkProjectSymbol] = this; |
83 | 83 |
84 this._eventListeners = []; | 84 this._eventListeners = []; |
85 | 85 |
86 if (resourceTreeModel) { | |
87 this._eventListeners.push( | |
88 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.Resour
ceAdded, this._resourceAdded, this), | |
89 resourceTreeModel.addEventListener( | |
90 SDK.ResourceTreeModel.Events.FrameWillNavigate, this._frameWillNav
igate, this), | |
91 resourceTreeModel.addEventListener(SDK.ResourceTreeModel.Events.FrameD
etached, this._frameDetached, this)); | |
92 } | |
93 | |
94 this._debuggerModel = target.model(SDK.DebuggerModel); | 86 this._debuggerModel = target.model(SDK.DebuggerModel); |
95 /** @type {!Set<!SDK.Script>} */ | 87 /** @type {!Set<!SDK.Script>} */ |
96 this._acceptedScripts = new Set(); | 88 this._acceptedScripts = new Set(); |
97 if (this._debuggerModel) { | 89 if (this._debuggerModel) { |
98 var runtimeModel = this._debuggerModel.runtimeModel(); | 90 var runtimeModel = this._debuggerModel.runtimeModel(); |
99 this._eventListeners.push( | 91 this._eventListeners.push( |
100 runtimeModel.addEventListener( | 92 runtimeModel.addEventListener( |
101 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution
ContextDestroyed, this), | 93 SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._execution
ContextDestroyed, this), |
102 this._debuggerModel.addEventListener( | 94 this._debuggerModel.addEventListener( |
103 SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCl
eared, this), | 95 SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCl
eared, this), |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 * @param {!Common.Event} event | 349 * @param {!Common.Event} event |
358 */ | 350 */ |
359 _styleSheetRemoved(event) { | 351 _styleSheetRemoved(event) { |
360 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); | 352 var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data); |
361 if (!this._acceptsHeader(header)) | 353 if (!this._acceptsHeader(header)) |
362 return; | 354 return; |
363 this._removeFileForURL(header.resourceURL(), header.frameId, false); | 355 this._removeFileForURL(header.resourceURL(), header.frameId, false); |
364 } | 356 } |
365 | 357 |
366 /** | 358 /** |
367 * @param {!Common.Event} event | |
368 */ | |
369 _resourceAdded(event) { | |
370 var resource = /** @type {!SDK.Resource} */ (event.data); | |
371 this._addResource(resource); | |
372 } | |
373 | |
374 /** | |
375 * @param {!SDK.Resource} resource | |
376 */ | |
377 _acceptsResource(resource) { | |
378 var resourceType = resource.resourceType(); | |
379 // Only load selected resource types from resources. | |
380 if (resourceType !== Common.resourceTypes.Image && resourceType !== Common.r
esourceTypes.Font && | |
381 resourceType !== Common.resourceTypes.Document && resourceType !== Commo
n.resourceTypes.Manifest) | |
382 return false; | |
383 | |
384 // Ignore non-images and non-fonts. | |
385 if (resourceType === Common.resourceTypes.Image && resource.mimeType && !res
ource.mimeType.startsWith('image')) | |
386 return false; | |
387 if (resourceType === Common.resourceTypes.Font && resource.mimeType && !reso
urce.mimeType.includes('font')) | |
388 return false; | |
389 if ((resourceType === Common.resourceTypes.Image || resourceType === Common.
resourceTypes.Font) && | |
390 resource.contentURL().startsWith('data:')) | |
391 return false; | |
392 return true; | |
393 } | |
394 | |
395 /** | |
396 * @param {!SDK.Resource} resource | |
397 */ | |
398 _addResource(resource) { | |
399 if (!this._acceptsResource(resource)) | |
400 return; | |
401 | |
402 var uiSourceCode = this._createFile(resource, resource.frameId, false); | |
403 this._addUISourceCodeWithProvider(uiSourceCode, resource, Bindings.resourceM
etadata(resource), resource.mimeType); | |
404 } | |
405 | |
406 /** | |
407 * @param {!SDK.ResourceTreeFrame} frame | |
408 */ | |
409 _removeFrameResources(frame) { | |
410 var regularProject = this._workspaceProject(frame.id, false); | |
411 var contentScriptsProject = this._workspaceProject(frame.id, true); | |
412 for (var resource of frame.resources()) { | |
413 if (!this._acceptsResource(resource)) | |
414 continue; | |
415 regularProject.removeFile(resource.url); | |
416 contentScriptsProject.removeFile(resource.url); | |
417 } | |
418 } | |
419 | |
420 /** | |
421 * @param {!Common.Event} event | |
422 */ | |
423 _frameWillNavigate(event) { | |
424 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | |
425 this._removeFrameResources(frame); | |
426 } | |
427 | |
428 /** | |
429 * @param {!Common.Event} event | |
430 */ | |
431 _frameDetached(event) { | |
432 var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data); | |
433 this._removeFrameResources(frame); | |
434 } | |
435 | |
436 /** | |
437 * @param {!Common.ContentProvider} contentProvider | 359 * @param {!Common.ContentProvider} contentProvider |
438 * @param {string} frameId | 360 * @param {string} frameId |
439 * @param {boolean} isContentScript | 361 * @param {boolean} isContentScript |
440 * @return {!Workspace.UISourceCode} | 362 * @return {!Workspace.UISourceCode} |
441 */ | 363 */ |
442 _createFile(contentProvider, frameId, isContentScript) { | 364 _createFile(contentProvider, frameId, isContentScript) { |
443 var url = contentProvider.contentURL(); | 365 var url = contentProvider.contentURL(); |
444 var project = this._workspaceProject(frameId, isContentScript); | 366 var project = this._workspaceProject(frameId, isContentScript); |
445 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy
pe()); | 367 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy
pe()); |
446 if (frameId) | 368 if (frameId) |
447 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId); | 369 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId); |
448 return uiSourceCode; | 370 return uiSourceCode; |
449 } | 371 } |
450 | 372 |
451 /** | 373 /** |
452 * @param {string} frameId | 374 * @param {string} frameId |
453 * @param {string} url | 375 * @param {string} url |
454 * @return {?Workspace.UISourceCodeMetadata} | 376 * @return {?Workspace.UISourceCodeMetadata} |
455 */ | 377 */ |
456 _fetchMetadata(frameId, url) { | 378 _fetchMetadata(frameId, url) { |
457 if (!this._resourceTreeModel) | 379 if (!this._resourceTreeModel) |
458 return null; | 380 return null; |
459 var frame = this._resourceTreeModel.frameForId(frameId); | 381 var frame = this._resourceTreeModel.frameForId(frameId); |
460 if (!frame) | 382 if (!frame) |
461 return null; | 383 return null; |
462 return Bindings.resourceMetadata(frame.resourceForURL(url)); | 384 return Bindings.resourceMetadata(frame.resourceForURL(url)); |
463 } | 385 } |
464 | 386 |
465 _dispose() { | 387 _dispose() { |
466 this._reset(); | 388 for (var project of this._workspaceProjects.values()) |
| 389 project.removeProject(); |
467 Common.EventTarget.removeEventListeners(this._eventListeners); | 390 Common.EventTarget.removeEventListeners(this._eventListeners); |
468 delete this._target[Bindings.NetworkProject._networkProjectSymbol]; | 391 delete this._target[Bindings.NetworkProject._networkProjectSymbol]; |
| 392 this._workspaceProjects.clear(); |
469 } | 393 } |
470 | 394 |
471 _reset() { | 395 _resetForTest() { |
472 for (var project of this._workspaceProjects.values()) | 396 for (var project of this._workspaceProjects.values()) |
473 project.removeProject(); | 397 project.removeProject(); |
474 this._workspaceProjects.clear(); | 398 this._workspaceProjects.clear(); |
475 } | 399 } |
476 | 400 |
477 /** | 401 /** |
478 * @param {!Workspace.Workspace} workspace | 402 * @param {!Workspace.Workspace} workspace |
479 * @param {string} url | 403 * @param {string} url |
480 * @param {!SDK.Script} script | 404 * @param {!SDK.Script} script |
481 * @return {?Workspace.UISourceCode} | 405 * @return {?Workspace.UISourceCode} |
(...skipping 25 matching lines...) Expand all Loading... |
507 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol]; | 431 return uiSourceCode[Bindings.NetworkProject._styleSheetSymbol]; |
508 } | 432 } |
509 }; | 433 }; |
510 | 434 |
511 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 435 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
512 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | 436 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); |
513 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 437 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
514 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); | 438 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); |
515 | 439 |
516 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec
t._frameAttributionSymbol'); | 440 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec
t._frameAttributionSymbol'); |
OLD | NEW |