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

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

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

Powered by Google App Engine
This is Rietveld 408576698