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

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

Issue 2441933002: [DevTools] Refactor connection-related classes. (Closed)
Patch Set: test fixes 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 {Protocol.Agents} 9 * @extends {Protocol.Agents}
10 * @param {!WebInspector.TargetManager} targetManager 10 * @param {!WebInspector.TargetManager} targetManager
11 * @param {string} name 11 * @param {string} name
12 * @param {number} capabilitiesMask 12 * @param {number} capabilitiesMask
13 * @param {!InspectorBackendClass.Connection} connection 13 * @param {!InspectorBackendClass.Channel} channel
14 * @param {?WebInspector.Target} parentTarget 14 * @param {?WebInspector.Target} parentTarget
15 */ 15 */
16 WebInspector.Target = function(targetManager, name, capabilitiesMask, connection , parentTarget) 16 WebInspector.Target = function(targetManager, name, capabilitiesMask, channel, p arentTarget)
17 { 17 {
18 var connection = new InspectorBackendClass.Connection(channel, this._dispose .bind(this));
18 Protocol.Agents.call(this, connection.agentsMap()); 19 Protocol.Agents.call(this, connection.agentsMap());
19 this._targetManager = targetManager; 20 this._targetManager = targetManager;
20 this._name = name; 21 this._name = name;
21 this._inspectedURL = ""; 22 this._inspectedURL = "";
22 this._capabilitiesMask = capabilitiesMask; 23 this._capabilitiesMask = capabilitiesMask;
23 this._connection = connection; 24 this._connection = connection;
24 this._parentTarget = parentTarget; 25 this._parentTarget = parentTarget;
25 connection.addEventListener(InspectorBackendClass.Connection.Events.Disconne cted, this.dispose, this);
26 this._id = WebInspector.Target._nextId++; 26 this._id = WebInspector.Target._nextId++;
27 this._disposed = false;
27 28
28 /** @type {!Map.<!Function, !WebInspector.SDKModel>} */ 29 /** @type {!Map.<!Function, !WebInspector.SDKModel>} */
29 this._modelByConstructor = new Map(); 30 this._modelByConstructor = new Map();
30 } 31 }
31 32
32 /** 33 /**
33 * @enum {number} 34 * @enum {number}
34 */ 35 */
35 WebInspector.Target.Capability = { 36 WebInspector.Target.Capability = {
36 Browser: 1, 37 Browser: 1,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 /** 86 /**
86 * @param {number} capabilitiesMask 87 * @param {number} capabilitiesMask
87 * @return {boolean} 88 * @return {boolean}
88 */ 89 */
89 hasAllCapabilities: function(capabilitiesMask) 90 hasAllCapabilities: function(capabilitiesMask)
90 { 91 {
91 return (this._capabilitiesMask & capabilitiesMask) === capabilitiesMask; 92 return (this._capabilitiesMask & capabilitiesMask) === capabilitiesMask;
92 }, 93 },
93 94
94 /** 95 /**
95 * @return {!InspectorBackendClass.Connection}
96 */
97 connection: function()
98 {
99 return this._connection;
100 },
101
102 /**
103 * @param {string} label 96 * @param {string} label
104 * @return {string} 97 * @return {string}
105 */ 98 */
106 decorateLabel: function(label) 99 decorateLabel: function(label)
107 { 100 {
108 return !this.hasBrowserCapability() ? "\u2699 " + label : label; 101 return !this.hasBrowserCapability() ? "\u2699 " + label : label;
109 }, 102 },
110 103
111 /** 104 /**
112 * @override 105 * @override
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 }, 160 },
168 161
169 /** 162 /**
170 * @return {?WebInspector.Target} 163 * @return {?WebInspector.Target}
171 */ 164 */
172 parentTarget: function() 165 parentTarget: function()
173 { 166 {
174 return this._parentTarget; 167 return this._parentTarget;
175 }, 168 },
176 169
177 dispose: function() 170 /**
171 * @param {string} reason
172 */
173 _dispose: function(reason)
178 { 174 {
175 this._disposed = true;
179 this._targetManager.removeTarget(this); 176 this._targetManager.removeTarget(this);
180 for (var model of this._modelByConstructor.valuesArray()) 177 for (var model of this._modelByConstructor.valuesArray())
181 model.dispose(); 178 model.dispose();
182 if (this.workerManager) 179 if (this.workerManager)
183 this.workerManager.dispose(); 180 this.workerManager.dispose();
184 }, 181 },
185 182
186 /** 183 /**
187 * @return {boolean} 184 * @return {boolean}
188 */ 185 */
189 isDetached: function() 186 isDisposed: function()
190 { 187 {
191 return this._connection.isClosed(); 188 return this._disposed;
192 }, 189 },
193 190
194 /** 191 /**
195 * @param {!Function} modelClass 192 * @param {!Function} modelClass
196 * @return {?WebInspector.SDKModel} 193 * @return {?WebInspector.SDKModel}
197 */ 194 */
198 model: function(modelClass) 195 model: function(modelClass)
199 { 196 {
200 return this._modelByConstructor.get(modelClass) || null; 197 return this._modelByConstructor.get(modelClass) || null;
201 }, 198 },
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 _targetDisposed: function(event) 291 _targetDisposed: function(event)
295 { 292 {
296 var target = /** @type {!WebInspector.Target} */ (event.data); 293 var target = /** @type {!WebInspector.Target} */ (event.data);
297 if (target !== this._target) 294 if (target !== this._target)
298 return; 295 return;
299 this.dispose(); 296 this.dispose();
300 }, 297 },
301 298
302 __proto__: WebInspector.SDKObject.prototype 299 __proto__: WebInspector.SDKObject.prototype
303 } 300 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698