Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1002)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/TargetManager.js

Issue 2851913002: [DevTools] Do not expose agents on Target
Patch Set: storage and tests.js Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>} */
11 this._targets = []; 11 this._targets = [];
12 /** @type {!Array.<!SDK.TargetManager.Observer>} */ 12 /** @type {!Array.<!SDK.TargetManager.Observer>} */
13 this._observers = []; 13 this._observers = [];
14 this._observerCapabiliesMaskSymbol = Symbol('observerCapabilitiesMask'); 14 this._observerCapabiliesMaskSymbol = Symbol('observerCapabilitiesMask');
15 /** @type {!Map<symbol, !Array<{modelClass: !Function, thisObject: (!Object| undefined), listener: function(!Common.Event)}>>} */ 15 /** @type {!Map<symbol, !Array<{modelClass: !Function, thisObject: (!Object| undefined), listener: function(!Common.Event)}>>} */
16 this._modelListeners = new Map(); 16 this._modelListeners = new Map();
17 /** @type {!Map<function(new:SDK.SDKModel, !SDK.Target), !Array<!SDK.SDKMode lObserver>>} */ 17 /** @type {!Map<function(new:SDK.SDKModel, !SDK.Target, !Protocol.Dispatcher ), !Array<!SDK.SDKModelObserver>>} */
18 this._modelObservers = new Map(); 18 this._modelObservers = new Map();
19 this._isSuspended = false; 19 this._isSuspended = false;
20 this._lastAnonymousTargetId = 0; 20 this._lastAnonymousTargetId = 0;
21 /** @type {!Map<!SDK.Target, !SDK.ChildTargetManager>} */ 21 /** @type {!Map<!SDK.Target, !SDK.ChildTargetManager>} */
22 this._childTargetManagers = new Map(); 22 this._childTargetManagers = new Map();
23 /** @type {!Set<string>} */ 23 /** @type {!Set<string>} */
24 this._nodeTargetIds = new Set(); 24 this._nodeTargetIds = new Set();
25 /** @type {!Protocol.InspectorBackend.Connection} */ 25 /** @type {!Protocol.InspectorBackend.Connection} */
26 this._mainConnection; 26 this._mainConnection;
27 /** @type {function()} */ 27 /** @type {function()} */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 65
66 /** 66 /**
67 * @return {boolean} 67 * @return {boolean}
68 */ 68 */
69 allTargetsSuspended() { 69 allTargetsSuspended() {
70 return this._isSuspended; 70 return this._isSuspended;
71 } 71 }
72 72
73 /** 73 /**
74 * @param {function(new:T,!SDK.Target)} modelClass 74 * @param {function(new:T, !SDK.Target, !Protocol.Dispatcher)} modelClass
75 * @return {!Array<!T>} 75 * @return {!Array<!T>}
76 * @template T 76 * @template T
77 */ 77 */
78 models(modelClass) { 78 models(modelClass) {
79 var result = []; 79 var result = [];
80 for (var i = 0; i < this._targets.length; ++i) { 80 for (var i = 0; i < this._targets.length; ++i) {
81 var model = this._targets[i].model(modelClass); 81 var model = this._targets[i].model(modelClass);
82 if (model) 82 if (model)
83 result.push(model); 83 result.push(model);
84 } 84 }
85 return result; 85 return result;
86 } 86 }
87 87
88 /** 88 /**
89 * @return {string} 89 * @return {string}
90 */ 90 */
91 inspectedURL() { 91 inspectedURL() {
92 return this._targets[0] ? this._targets[0].inspectedURL() : ''; 92 return this._targets[0] ? this._targets[0].inspectedURL() : '';
93 } 93 }
94 94
95 /** 95 /**
96 * @param {function(new:T,!SDK.Target)} modelClass 96 * @param {function(new:T, !SDK.Target, !Protocol.Dispatcher)} modelClass
97 * @param {!SDK.SDKModelObserver<T>} observer 97 * @param {!SDK.SDKModelObserver<T>} observer
98 * @template T 98 * @template T
99 */ 99 */
100 observeModels(modelClass, observer) { 100 observeModels(modelClass, observer) {
101 if (!this._modelObservers.has(modelClass)) 101 if (!this._modelObservers.has(modelClass))
102 this._modelObservers.set(modelClass, []); 102 this._modelObservers.set(modelClass, []);
103 this._modelObservers.get(modelClass).push(observer); 103 this._modelObservers.get(modelClass).push(observer);
104 for (var model of this.models(modelClass)) 104 for (var model of this.models(modelClass))
105 observer.modelAdded(model); 105 observer.modelAdded(model);
106 } 106 }
107 107
108 /** 108 /**
109 * @param {function(new:T,!SDK.Target)} modelClass 109 * @param {function(new:T, !SDK.Target, !Protocol.Dispatcher)} modelClass
110 * @param {!SDK.SDKModelObserver<T>} observer 110 * @param {!SDK.SDKModelObserver<T>} observer
111 * @template T 111 * @template T
112 */ 112 */
113 unobserveModels(modelClass, observer) { 113 unobserveModels(modelClass, observer) {
114 if (!this._modelObservers.has(modelClass)) 114 if (!this._modelObservers.has(modelClass))
115 return; 115 return;
116 var observers = this._modelObservers.get(modelClass); 116 var observers = this._modelObservers.get(modelClass);
117 observers.remove(observer); 117 observers.remove(observer);
118 if (!observers.length) 118 if (!observers.length)
119 this._modelObservers.delete(modelClass); 119 this._modelObservers.delete(modelClass);
120 } 120 }
121 121
122 /** 122 /**
123 * @param {!SDK.Target} target 123 * @param {!SDK.Target} target
124 * @param {function(new:SDK.SDKModel,!SDK.Target)} modelClass 124 * @param {function(new:SDK.SDKModel,!SDK.Target, !Protocol.Dispatcher)} model Class
125 * @param {!SDK.SDKModel} model 125 * @param {!SDK.SDKModel} model
126 */ 126 */
127 modelAdded(target, modelClass, model) { 127 modelAdded(target, modelClass, model) {
128 if (!this._modelObservers.has(modelClass)) 128 if (!this._modelObservers.has(modelClass))
129 return; 129 return;
130 for (var observer of this._modelObservers.get(modelClass).slice()) 130 for (var observer of this._modelObservers.get(modelClass).slice())
131 observer.modelAdded(model); 131 observer.modelAdded(model);
132 } 132 }
133 133
134 /** 134 /**
135 * @param {!SDK.Target} target 135 * @param {!SDK.Target} target
136 * @param {function(new:SDK.SDKModel,!SDK.Target)} modelClass 136 * @param {function(new:SDK.SDKModel, !SDK.Target, !Protocol.Dispatcher)} mode lClass
137 * @param {!SDK.SDKModel} model 137 * @param {!SDK.SDKModel} model
138 */ 138 */
139 _modelRemoved(target, modelClass, model) { 139 _modelRemoved(target, modelClass, model) {
140 if (!this._modelObservers.has(modelClass)) 140 if (!this._modelObservers.has(modelClass))
141 return; 141 return;
142 for (var observer of this._modelObservers.get(modelClass).slice()) 142 for (var observer of this._modelObservers.get(modelClass).slice())
143 observer.modelRemoved(model); 143 observer.modelRemoved(model);
144 } 144 }
145 145
146 /** 146 /**
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 */ 203 */
204 unobserveTargets(targetObserver) { 204 unobserveTargets(targetObserver) {
205 delete targetObserver[this._observerCapabiliesMaskSymbol]; 205 delete targetObserver[this._observerCapabiliesMaskSymbol];
206 this._observers.remove(targetObserver); 206 this._observers.remove(targetObserver);
207 } 207 }
208 208
209 /** 209 /**
210 * @param {string} id 210 * @param {string} id
211 * @param {string} name 211 * @param {string} name
212 * @param {number} capabilitiesMask 212 * @param {number} capabilitiesMask
213 * @param {!Protocol.InspectorBackend.Connection.Factory} connectionFactory 213 * @param {!Protocol.Dispatcher} dispatcher
214 * @param {?SDK.Target} parentTarget 214 * @param {?SDK.Target} parentTarget
215 * @return {!SDK.Target} 215 * @return {!SDK.Target}
216 */ 216 */
217 createTarget(id, name, capabilitiesMask, connectionFactory, parentTarget) { 217 createTarget(id, name, capabilitiesMask, dispatcher, parentTarget) {
218 var target = new SDK.Target(this, id, name, capabilitiesMask, connectionFact ory, parentTarget); 218 var target = new SDK.Target(this, id, name, capabilitiesMask, dispatcher, pa rentTarget);
219 target.createModels(new Set(this._modelObservers.keys())); 219 target.createModels(new Set(this._modelObservers.keys()));
220 if (target.hasTargetCapability()) 220 if (target.hasTargetCapability())
221 this._childTargetManagers.set(target, new SDK.ChildTargetManager(this, tar get)); 221 this._childTargetManagers.set(target, new SDK.ChildTargetManager(this, tar get, dispatcher));
222 this._targets.push(target); 222 this._targets.push(target);
223 223
224 var copy = this._observersForTarget(target); 224 var copy = this._observersForTarget(target);
225 for (var i = 0; i < copy.length; ++i) 225 for (var i = 0; i < copy.length; ++i)
226 copy[i].targetAdded(target); 226 copy[i].targetAdded(target);
227 227
228 for (var modelClass of target.models().keys()) 228 for (var modelClass of target.models().keys())
229 this.modelAdded(target, modelClass, target.models().get(modelClass)); 229 this.modelAdded(target, modelClass, target.models().get(modelClass));
230 230
231 for (var pair of this._modelListeners) { 231 for (var pair of this._modelListeners) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 /** 315 /**
316 * @param {function()} webSocketConnectionLostCallback 316 * @param {function()} webSocketConnectionLostCallback
317 */ 317 */
318 connectToMainTarget(webSocketConnectionLostCallback) { 318 connectToMainTarget(webSocketConnectionLostCallback) {
319 this._webSocketConnectionLostCallback = webSocketConnectionLostCallback; 319 this._webSocketConnectionLostCallback = webSocketConnectionLostCallback;
320 this._connectAndCreateMainTarget(); 320 this._connectAndCreateMainTarget();
321 } 321 }
322 322
323 _connectAndCreateMainTarget() { 323 _connectAndCreateMainTarget() {
324 if (Runtime.queryParam('nodeFrontend')) { 324 if (Runtime.queryParam('nodeFrontend')) {
325 var target = new SDK.Target( 325 var dispatcher = new Protocol.Dispatcher(this._createMainConnection.bind(t his));
326 this, 'main', Common.UIString('Node'), SDK.Target.Capability.Target, t his._createMainConnection.bind(this), 326 var target =
327 null); 327 new SDK.Target(this, 'main', Common.UIString('Node'), SDK.Target.Capab ility.Target, dispatcher, null);
328 target.setInspectedURL('Node'); 328 target.setInspectedURL('Node');
329 this._childTargetManagers.set(target, new SDK.ChildTargetManager(this, tar get)); 329 this._childTargetManagers.set(target, new SDK.ChildTargetManager(this, tar get, dispatcher));
330 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConnectToNodeJSFromFr ontend); 330 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConnectToNodeJSFromFr ontend);
331 return; 331 return;
332 } 332 }
333 333
334 var capabilities = SDK.Target.Capability.Browser | SDK.Target.Capability.DOM | SDK.Target.Capability.JS | 334 var capabilities = SDK.Target.Capability.Browser | SDK.Target.Capability.DOM | SDK.Target.Capability.JS |
335 SDK.Target.Capability.Log | SDK.Target.Capability.Network | SDK.Target.C apability.Target | 335 SDK.Target.Capability.Log | SDK.Target.Capability.Network | SDK.Target.C apability.Target |
336 SDK.Target.Capability.ScreenCapture | SDK.Target.Capability.Tracing | SD K.Target.Capability.Emulation | 336 SDK.Target.Capability.ScreenCapture | SDK.Target.Capability.Tracing | SD K.Target.Capability.Emulation |
337 SDK.Target.Capability.Security | SDK.Target.Capability.Input | SDK.Targe t.Capability.Inspector | 337 SDK.Target.Capability.Security | SDK.Target.Capability.Input | SDK.Targe t.Capability.Inspector |
338 SDK.Target.Capability.DeviceEmulation; 338 SDK.Target.Capability.DeviceEmulation;
339 if (Runtime.queryParam('isSharedWorker')) { 339 if (Runtime.queryParam('isSharedWorker')) {
340 capabilities = SDK.Target.Capability.Browser | SDK.Target.Capability.Log | SDK.Target.Capability.Network | 340 capabilities = SDK.Target.Capability.Browser | SDK.Target.Capability.Log | SDK.Target.Capability.Network |
341 SDK.Target.Capability.Target | SDK.Target.Capability.Inspector; 341 SDK.Target.Capability.Target | SDK.Target.Capability.Inspector;
342 } else if (Runtime.queryParam('v8only')) { 342 } else if (Runtime.queryParam('v8only')) {
343 capabilities = SDK.Target.Capability.JS; 343 capabilities = SDK.Target.Capability.JS;
344 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConnectToNodeJSDirect ly); 344 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ConnectToNodeJSDirect ly);
345 } 345 }
346 346
347 var target = 347 var dispatcher = new Protocol.Dispatcher(this._createMainConnection.bind(thi s));
348 this.createTarget('main', Common.UIString('Main'), capabilities, this._c reateMainConnection.bind(this), null); 348 var target = this.createTarget('main', Common.UIString('Main'), capabilities , dispatcher, null);
349 target.runtimeAgent().runIfWaitingForDebugger(); 349 dispatcher.runtimeAgent().runIfWaitingForDebugger();
350 } 350 }
351 351
352 /** 352 /**
353 * @param {!Protocol.InspectorBackend.Connection.Params} params 353 * @param {!Protocol.InspectorBackend.Connection.Params} params
354 * @return {!Protocol.InspectorBackend.Connection} 354 * @return {!Protocol.InspectorBackend.Connection}
355 */ 355 */
356 _createMainConnection(params) { 356 _createMainConnection(params) {
357 var wsParam = Runtime.queryParam('ws'); 357 var wsParam = Runtime.queryParam('ws');
358 var wssParam = Runtime.queryParam('wss'); 358 var wssParam = Runtime.queryParam('wss');
359 if (wsParam || wssParam) { 359 if (wsParam || wssParam) {
(...skipping 24 matching lines...) Expand all
384 } 384 }
385 }; 385 };
386 386
387 /** 387 /**
388 * @implements {Protocol.TargetDispatcher} 388 * @implements {Protocol.TargetDispatcher}
389 */ 389 */
390 SDK.ChildTargetManager = class { 390 SDK.ChildTargetManager = class {
391 /** 391 /**
392 * @param {!SDK.TargetManager} targetManager 392 * @param {!SDK.TargetManager} targetManager
393 * @param {!SDK.Target} parentTarget 393 * @param {!SDK.Target} parentTarget
394 * @param {!Protocol.Dispatcher} dispatcher
394 */ 395 */
395 constructor(targetManager, parentTarget) { 396 constructor(targetManager, parentTarget, dispatcher) {
396 this._targetManager = targetManager; 397 this._targetManager = targetManager;
397 this._parentTarget = parentTarget; 398 this._parentTarget = parentTarget;
398 this._targetAgent = parentTarget.targetAgent(); 399 this._targetAgent = dispatcher.targetAgent();
399 400
400 /** @type {!Map<string, !SDK.ChildConnection>} */ 401 /** @type {!Map<string, !SDK.ChildConnection>} */
401 this._childConnections = new Map(); 402 this._childConnections = new Map();
402 403
403 parentTarget.registerTargetDispatcher(this); 404 dispatcher.registerTargetDispatcher(this);
404 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS tart: true}); 405 this._targetAgent.invoke_setAutoAttach({autoAttach: true, waitForDebuggerOnS tart: true});
405 if (Runtime.experiments.isEnabled('autoAttachToCrossProcessSubframes')) 406 if (Runtime.experiments.isEnabled('autoAttachToCrossProcessSubframes'))
406 this._targetAgent.setAttachToFrames(true); 407 this._targetAgent.setAttachToFrames(true);
407 408
408 if (!parentTarget.parentTarget()) { 409 if (!parentTarget.parentTarget()) {
409 this._targetAgent.setRemoteLocations([{host: 'localhost', port: 9229}]); 410 this._targetAgent.setRemoteLocations([{host: 'localhost', port: 9229}]);
410 this._targetAgent.setDiscoverTargets(true); 411 this._targetAgent.setDiscoverTargets(true);
411 } 412 }
412 } 413 }
413 414
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 */ 482 */
482 attachedToTarget(targetInfo, waitingForDebugger) { 483 attachedToTarget(targetInfo, waitingForDebugger) {
483 var targetName = ''; 484 var targetName = '';
484 if (targetInfo.type === 'node') { 485 if (targetInfo.type === 'node') {
485 targetName = Common.UIString('Node: %s', targetInfo.url); 486 targetName = Common.UIString('Node: %s', targetInfo.url);
486 } else if (targetInfo.type !== 'iframe') { 487 } else if (targetInfo.type !== 'iframe') {
487 var parsedURL = targetInfo.url.asParsedURL(); 488 var parsedURL = targetInfo.url.asParsedURL();
488 targetName = 489 targetName =
489 parsedURL ? parsedURL.lastPathComponentWithFragment() : '#' + (++this. _targetManager._lastAnonymousTargetId); 490 parsedURL ? parsedURL.lastPathComponentWithFragment() : '#' + (++this. _targetManager._lastAnonymousTargetId);
490 } 491 }
492 var dispatcher =
493 new Protocol.Dispatcher(this._createChildConnection.bind(this, this._tar getAgent, targetInfo.targetId));
491 var target = this._targetManager.createTarget( 494 var target = this._targetManager.createTarget(
492 targetInfo.targetId, targetName, this._capabilitiesForType(targetInfo.ty pe), 495 targetInfo.targetId, targetName, this._capabilitiesForType(targetInfo.ty pe), dispatcher, this._parentTarget);
493 this._createChildConnection.bind(this, this._targetAgent, targetInfo.tar getId), this._parentTarget);
494 target[SDK.TargetManager._isWorkerSymbol] = targetInfo.type === 'worker'; 496 target[SDK.TargetManager._isWorkerSymbol] = targetInfo.type === 'worker';
495 497
496 // Only pause the new worker if debugging SW - we are going through the paus e on start checkbox. 498 // Only pause the new worker if debugging SW - we are going through the paus e on start checkbox.
497 if (!this._parentTarget.parentTarget() && Runtime.queryParam('isSharedWorker ') && waitingForDebugger) { 499 if (!this._parentTarget.parentTarget() && Runtime.queryParam('isSharedWorker ') && waitingForDebugger) {
498 var debuggerModel = target.model(SDK.DebuggerModel); 500 var debuggerModel = target.model(SDK.DebuggerModel);
499 if (debuggerModel) 501 if (debuggerModel)
500 debuggerModel.pause(); 502 debuggerModel.pause();
501 } 503 }
502 target.runtimeAgent().runIfWaitingForDebugger(); 504 dispatcher.runtimeAgent().runIfWaitingForDebugger();
503 } 505 }
504 506
505 /** 507 /**
506 * @override 508 * @override
507 * @param {string} childTargetId 509 * @param {string} childTargetId
508 */ 510 */
509 detachedFromTarget(childTargetId) { 511 detachedFromTarget(childTargetId) {
510 this._childConnections.get(childTargetId)._onDisconnect.call(null, 'target t erminated'); 512 this._childConnections.get(childTargetId)._onDisconnect.call(null, 'target t erminated');
511 this._childConnections.delete(childTargetId); 513 this._childConnections.delete(childTargetId);
512 } 514 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 /** 612 /**
611 * @param {!T} model 613 * @param {!T} model
612 */ 614 */
613 modelRemoved(model) {}, 615 modelRemoved(model) {},
614 }; 616 };
615 617
616 /** 618 /**
617 * @type {!SDK.TargetManager} 619 * @type {!SDK.TargetManager}
618 */ 620 */
619 SDK.targetManager = new SDK.TargetManager(); 621 SDK.targetManager = new SDK.TargetManager();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698