OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The Chromium Authors. All rights reserved. | 2 * Copyright 2014 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 SDK.TargetManager = class extends Common.Object { | 7 SDK.TargetManager = class extends Common.Object { |
8 constructor() { | 8 constructor() { |
9 super(); | 9 super(); |
10 /** @type {!Array.<!SDK.Target>} */ | 10 /** @type {!Array.<!SDK.Target>} */ |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 469 |
470 parentTarget.registerTargetDispatcher(this); | 470 parentTarget.registerTargetDispatcher(this); |
471 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS
tart: true}); | 471 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS
tart: true}); |
472 if (Runtime.experiments.isEnabled('autoAttachToCrossProcessSubframes')) | 472 if (Runtime.experiments.isEnabled('autoAttachToCrossProcessSubframes')) |
473 this._targetAgent.setAttachToFrames(true); | 473 this._targetAgent.setAttachToFrames(true); |
474 | 474 |
475 if (!parentTarget.parentTarget()) { | 475 if (!parentTarget.parentTarget()) { |
476 this._targetAgent.setRemoteLocations([{host: 'localhost', port: 9229}]); | 476 this._targetAgent.setRemoteLocations([{host: 'localhost', port: 9229}]); |
477 this._targetAgent.setDiscoverTargets(true); | 477 this._targetAgent.setDiscoverTargets(true); |
478 } | 478 } |
479 | |
480 this._eventListeners = []; | |
481 if (resourceTreeModel) { | |
482 this._eventListeners.push(resourceTreeModel.addEventListener( | |
483 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._detachWorkersOn
MainFrameNavigated, this)); | |
484 } | |
485 } | 479 } |
486 | 480 |
487 suspend() { | 481 suspend() { |
488 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS
tart: false}); | 482 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS
tart: false}); |
489 } | 483 } |
490 | 484 |
491 /** | 485 /** |
492 * @return {!Promise} | 486 * @return {!Promise} |
493 */ | 487 */ |
494 resume() { | 488 resume() { |
495 var fulfill; | 489 var fulfill; |
496 var promise = new Promise(callback => fulfill = callback); | 490 var promise = new Promise(callback => fulfill = callback); |
497 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS
tart: true}, fulfill); | 491 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS
tart: true}, fulfill); |
498 return promise; | 492 return promise; |
499 } | 493 } |
500 | 494 |
501 dispose() { | 495 dispose() { |
502 Common.EventTarget.removeEventListeners(this._eventListeners); | |
503 // TODO(dgozman): this is O(n^2) when removing main target. | 496 // TODO(dgozman): this is O(n^2) when removing main target. |
504 var childTargets = this._targetManager._targets.filter(child => child.parent
Target() === this._parentTarget); | 497 var childTargets = this._targetManager._targets.filter(child => child.parent
Target() === this._parentTarget); |
505 for (var child of childTargets) | 498 for (var child of childTargets) |
506 this.detachedFromTarget(child.id()); | 499 this.detachedFromTarget(child.id()); |
507 } | 500 } |
508 | 501 |
509 /** | 502 /** |
510 * @param {string} type | 503 * @param {string} type |
511 * @return {number} | 504 * @return {number} |
512 */ | 505 */ |
513 _capabilitiesForType(type) { | 506 _capabilitiesForType(type) { |
514 if (type === 'worker') | 507 if (type === 'worker') |
515 return SDK.Target.Capability.JS | SDK.Target.Capability.Log; | 508 return SDK.Target.Capability.JS | SDK.Target.Capability.Log; |
516 if (type === 'service_worker') | 509 if (type === 'service_worker') |
517 return SDK.Target.Capability.Log | SDK.Target.Capability.Network | SDK.Tar
get.Capability.Target; | 510 return SDK.Target.Capability.Log | SDK.Target.Capability.Network | SDK.Tar
get.Capability.Target; |
518 if (type === 'iframe') { | 511 if (type === 'iframe') { |
519 return SDK.Target.Capability.Browser | SDK.Target.Capability.DOM | SDK.Tar
get.Capability.JS | | 512 return SDK.Target.Capability.Browser | SDK.Target.Capability.DOM | SDK.Tar
get.Capability.JS | |
520 SDK.Target.Capability.Log | SDK.Target.Capability.Network | SDK.Target
.Capability.Target | | 513 SDK.Target.Capability.Log | SDK.Target.Capability.Network | SDK.Target
.Capability.Target | |
521 SDK.Target.Capability.Tracing; | 514 SDK.Target.Capability.Tracing; |
522 } | 515 } |
523 if (type === 'node') | 516 if (type === 'node') |
524 return SDK.Target.Capability.JS; | 517 return SDK.Target.Capability.JS; |
525 return 0; | 518 return 0; |
526 } | 519 } |
527 | 520 |
528 _detachWorkersOnMainFrameNavigated() { | |
529 // TODO(dgozman): send these from backend. | |
530 var idsToDetach = []; | |
531 for (var target of this._targetManager._targets) { | |
532 if (target.parentTarget() === this._parentTarget && target[SDK.TargetManag
er._isWorkerSymbol]) | |
533 idsToDetach.push(target.id()); | |
534 } | |
535 idsToDetach.forEach(id => this.detachedFromTarget(id)); | |
536 } | |
537 | |
538 /** | 521 /** |
539 * @override | 522 * @override |
540 * @param {!Protocol.Target.TargetInfo} targetInfo | 523 * @param {!Protocol.Target.TargetInfo} targetInfo |
541 */ | 524 */ |
542 targetCreated(targetInfo) { | 525 targetCreated(targetInfo) { |
543 if (targetInfo.type !== 'node') | 526 if (targetInfo.type !== 'node') |
544 return; | 527 return; |
545 if (Runtime.queryParam('nodeFrontend')) { | 528 if (Runtime.queryParam('nodeFrontend')) { |
546 this._targetAgent.attachToTarget(targetInfo.targetId); | 529 this._targetAgent.attachToTarget(targetInfo.targetId); |
547 } else { | 530 } else { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 /** | 683 /** |
701 * @param {!T} model | 684 * @param {!T} model |
702 */ | 685 */ |
703 modelRemoved(model) {}, | 686 modelRemoved(model) {}, |
704 }; | 687 }; |
705 | 688 |
706 /** | 689 /** |
707 * @type {!SDK.TargetManager} | 690 * @type {!SDK.TargetManager} |
708 */ | 691 */ |
709 SDK.targetManager = new SDK.TargetManager(); | 692 SDK.targetManager = new SDK.TargetManager(); |
OLD | NEW |