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

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

Issue 2451363002: [DevTools] Move main target/connection to TargetManager. (Closed)
Patch Set: Created 4 years, 1 month 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 /** 7 /**
8 * @constructor 8 * @constructor
9 * @extends {WebInspector.Object} 9 * @extends {WebInspector.Object}
10 */ 10 */
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 if (target.hasBrowserCapability()) { 229 if (target.hasBrowserCapability()) {
230 target.subTargetsManager = new WebInspector.SubTargetsManager(target ); 230 target.subTargetsManager = new WebInspector.SubTargetsManager(target );
231 target.serviceWorkerManager = new WebInspector.ServiceWorkerManager( target, target.subTargetsManager); 231 target.serviceWorkerManager = new WebInspector.ServiceWorkerManager( target, target.subTargetsManager);
232 } 232 }
233 233
234 this.addTarget(target); 234 this.addTarget(target);
235 return target; 235 return target;
236 }, 236 },
237 237
238 /** 238 /**
239 * @param {function(function(string)):!Promise<!InspectorBackendClass.Connec tion>} interceptor
240 */
241 setMainConnectionInterceptor: function(interceptor)
242 {
243 this._mainConnectionInterceptor = interceptor;
244 },
245
246 /**
247 * @param {function(string)} onMessage
248 * @return {!Promise<!InspectorBackendClass.Connection>}
249 */
250 interceptMainConnection: function(onMessage)
251 {
252 return this._mainConnectionInterceptor.call(null, onMessage);
253 },
254
255 /**
256 * @param {!WebInspector.Target} target 239 * @param {!WebInspector.Target} target
257 * @return {!Array<!WebInspector.TargetManager.Observer>} 240 * @return {!Array<!WebInspector.TargetManager.Observer>}
258 */ 241 */
259 _observersForTarget: function(target) 242 _observersForTarget: function(target)
260 { 243 {
261 return this._observers.filter((observer) => target.hasAllCapabilities(ob server[this._observerCapabiliesMaskSymbol] || 0)); 244 return this._observers.filter((observer) => target.hasAllCapabilities(ob server[this._observerCapabiliesMaskSymbol] || 0));
262 }, 245 },
263 246
264 /** 247 /**
265 * @param {!WebInspector.Target} target 248 * @param {!WebInspector.Target} target
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 /** 358 /**
376 * @param {!WebInspector.Target} target 359 * @param {!WebInspector.Target} target
377 */ 360 */
378 resumeReload: function(target) 361 resumeReload: function(target)
379 { 362 {
380 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target ); 363 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(target );
381 if (resourceTreeModel) 364 if (resourceTreeModel)
382 setImmediate(resourceTreeModel.resumeReload.bind(resourceTreeModel)) ; 365 setImmediate(resourceTreeModel.resumeReload.bind(resourceTreeModel)) ;
383 }, 366 },
384 367
368 /**
369 * @param {function()} webSocketConnectionLostCallback
370 */
371 connectToMainTarget: function(webSocketConnectionLostCallback)
372 {
373 this._webSocketConnectionLostCallback = webSocketConnectionLostCallback;
374 this._connectAndCreateMainTarget();
375 },
376
377 _connectAndCreateMainTarget: function()
378 {
379 var capabilities =
380 WebInspector.Target.Capability.Browser | WebInspector.Target.Capabil ity.DOM |
381 WebInspector.Target.Capability.JS | WebInspector.Target.Capability.L og |
382 WebInspector.Target.Capability.Network | WebInspector.Target.Capabil ity.Worker;
383 if (Runtime.queryParam("isSharedWorker")) {
384 capabilities =
385 WebInspector.Target.Capability.Browser | WebInspector.Target.Cap ability.Log |
386 WebInspector.Target.Capability.Network | WebInspector.Target.Cap ability.Worker;
387 } else if (Runtime.queryParam("v8only")) {
388 capabilities = WebInspector.Target.Capability.JS;
389 }
390
391 var target = this.createTarget(WebInspector.UIString("Main"), capabiliti es, this._createMainConnection.bind(this), null);
392 target.runtimeAgent().runIfWaitingForDebugger();
393 },
394
395 /**
396 * @param {!InspectorBackendClass.Connection.Params} params
397 * @return {!InspectorBackendClass.Connection}
398 */
399 _createMainConnection: function(params)
400 {
401 if (Runtime.queryParam("ws")) {
402 var ws = "ws://" + Runtime.queryParam("ws");
403 this._mainConnection = new WebInspector.WebSocketConnection(ws, this ._webSocketConnectionLostCallback, params);
404 } else if (InspectorFrontendHost.isHostedMode()) {
405 this._mainConnection = new WebInspector.StubConnection(params);
406 } else {
407 this._mainConnection = new WebInspector.MainConnection(params);
408 }
409 return this._mainConnection;
410 },
411
412 /**
413 * @param {function(string)} onMessage
414 * @return {!Promise<!InspectorBackendClass.Connection>}
415 */
416 interceptMainConnection: function(onMessage)
417 {
418 var params = {
419 onMessage: onMessage,
420 onDisconnect: this._connectAndCreateMainTarget.bind(this)
421 };
422 return this._mainConnection.disconnect().then(this._createMainConnection .bind(this, params));
423 },
424
385 __proto__: WebInspector.Object.prototype 425 __proto__: WebInspector.Object.prototype
386 }; 426 };
387 427
388 /** 428 /**
389 * @interface 429 * @interface
390 */ 430 */
391 WebInspector.TargetManager.Observer = function() 431 WebInspector.TargetManager.Observer = function()
392 { 432 {
393 }; 433 };
394 434
395 WebInspector.TargetManager.Observer.prototype = { 435 WebInspector.TargetManager.Observer.prototype = {
396 /** 436 /**
397 * @param {!WebInspector.Target} target 437 * @param {!WebInspector.Target} target
398 */ 438 */
399 targetAdded: function(target) { }, 439 targetAdded: function(target) { },
400 440
401 /** 441 /**
402 * @param {!WebInspector.Target} target 442 * @param {!WebInspector.Target} target
403 */ 443 */
404 targetRemoved: function(target) { }, 444 targetRemoved: function(target) { },
405 }; 445 };
406 446
407 /** 447 /**
408 * @type {!WebInspector.TargetManager} 448 * @type {!WebInspector.TargetManager}
409 */ 449 */
410 WebInspector.targetManager = new WebInspector.TargetManager(); 450 WebInspector.targetManager = new WebInspector.TargetManager();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698