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

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

Issue 2137773002: [DevTools] Replace the target type with capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [DevTools] Replace target type with capabilities Created 4 years, 5 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 /** 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} type 12 * @param {number} capabilitiesMask
13 * @param {!InspectorBackendClass.Connection} connection 13 * @param {!InspectorBackendClass.Connection} connection
14 * @param {?WebInspector.Target} parentTarget 14 * @param {?WebInspector.Target} parentTarget
15 */ 15 */
16 WebInspector.Target = function(targetManager, name, type, connection, parentTarg et) 16 WebInspector.Target = function(targetManager, name, capabilitiesMask, connection , parentTarget)
17 { 17 {
18 Protocol.Agents.call(this, connection.agentsMap()); 18 Protocol.Agents.call(this, connection.agentsMap());
19 this._targetManager = targetManager; 19 this._targetManager = targetManager;
20 this._name = name; 20 this._name = name;
21 this._type = type; 21 this._capabilitiesMask = capabilitiesMask;
22 this._connection = connection; 22 this._connection = connection;
23 this._parentTarget = parentTarget; 23 this._parentTarget = parentTarget;
24 connection.addEventListener(InspectorBackendClass.Connection.Events.Disconne cted, this._onDisconnect, this); 24 connection.addEventListener(InspectorBackendClass.Connection.Events.Disconne cted, this._onDisconnect, this);
25 this._id = WebInspector.Target._nextId++; 25 this._id = WebInspector.Target._nextId++;
26 26
27 /** @type {!Map.<!Function, !WebInspector.SDKModel>} */ 27 /** @type {!Map.<!Function, !WebInspector.SDKModel>} */
28 this._modelByConstructor = new Map(); 28 this._modelByConstructor = new Map();
29 } 29 }
30 30
31 /** 31 /**
32 * @enum {number} 32 * @enum {number}
33 */ 33 */
34 WebInspector.Target.Type = { 34 WebInspector.Target.Capabilities = {
dgozman 2016/07/12 00:34:11 Capability
eostroukhov-old 2016/07/12 21:46:16 Done.
35 Page: 1, 35 BROWSER_DOMAINS: 1,
dgozman 2016/07/12 00:34:11 Browser, JS, Network, Worker
eostroukhov-old 2016/07/12 21:46:15 Done.
36 DedicatedWorker: 2, 36 JS_DOMAINS: 2,
37 ServiceWorker: 4, 37 NETWORK_DOMAINS: 4,
38 JSInspector: 8 38 WORKER_DOMAINS: 8,
39 } 39 }
40 40
41 WebInspector.Target._nextId = 1; 41 WebInspector.Target._nextId = 1;
42 42
43 WebInspector.Target.prototype = { 43 WebInspector.Target.prototype = {
44 /** 44 /**
45 * @return {number} 45 * @return {number}
46 */ 46 */
47 id: function() 47 id: function()
48 { 48 {
49 return this._id; 49 return this._id;
50 }, 50 },
51 51
52 /** 52 /**
53 * @return {string} 53 * @return {string}
54 */ 54 */
55 name: function() 55 name: function()
56 { 56 {
57 return this._name; 57 return this._name;
58 }, 58 },
59 59
60 /** 60 /**
61 *
62 * @return {number}
63 */
64 type: function()
65 {
66 return this._type;
67 },
68
69 /**
70 *
71 * @return {!WebInspector.TargetManager} 61 * @return {!WebInspector.TargetManager}
72 */ 62 */
73 targetManager: function() 63 targetManager: function()
74 { 64 {
75 return this._targetManager; 65 return this._targetManager;
76 }, 66 },
77 67
78 /** 68 /**
69 * @return {number}
70 */
71 capabilitiesMask: function()
dgozman 2016/07/12 00:34:11 Who uses this? Let's not expose.
eostroukhov-old 2016/07/12 21:46:16 It was used by the TargetManager - now that have c
72 {
73 return this._capabilitiesMask;
74 },
75
76 /**
79 * @param {string} label 77 * @param {string} label
80 * @return {string} 78 * @return {string}
81 */ 79 */
82 decorateLabel: function(label) 80 decorateLabel: function(label)
83 { 81 {
84 return this.isWorker() ? "\u2699 " + label : label; 82 return !this.hasBrowserDomains() ? "\u2699 " + label : label;
85 }, 83 },
86 84
87 /** 85 /**
88 * @override 86 * @override
89 * @param {string} domain 87 * @param {string} domain
90 * @param {!Object} dispatcher 88 * @param {!Object} dispatcher
91 */ 89 */
92 registerDispatcher: function(domain, dispatcher) 90 registerDispatcher: function(domain, dispatcher)
93 { 91 {
94 this._connection.registerDispatcher(domain, dispatcher); 92 this._connection.registerDispatcher(domain, dispatcher);
95 }, 93 },
96 94
95 _hasCapability: function(capability)
dgozman 2016/07/12 00:34:11 Annotate please.
eostroukhov-old 2016/07/12 21:46:16 This function is now gone.
96 {
97 return (this._capabilitiesMask & capability) === capability;
98 },
99
97 /** 100 /**
98 * @return {boolean} 101 * @return {boolean}
99 */ 102 */
100 isPage: function() 103 hasBrowserDomains: function()
dgozman 2016/07/12 00:34:11 Now I think maybe we should call this hasBrowserCa
eostroukhov-old 2016/07/12 21:46:16 Done.
101 { 104 {
102 return this._type === WebInspector.Target.Type.Page; 105 return this._hasCapability(WebInspector.Target.Capabilities.BROWSER_DOMA INS);
103 }, 106 },
104 107
105 /** 108 /**
106 * @return {boolean} 109 * @return {boolean}
107 */ 110 */
108 isWorker: function() 111 hasJSDomains: function()
109 { 112 {
110 return this.isDedicatedWorker() || this.isServiceWorker() || this.isJSIn spector(); 113 return this._hasCapability(WebInspector.Target.Capabilities.JS_DOMAINS);
111 }, 114 },
112 115
113 /** 116 /**
114 * @return {boolean} 117 * @return {boolean}
115 */ 118 */
116 isDedicatedWorker: function() 119 hasNetworkDomains: function()
117 { 120 {
118 return this._type === WebInspector.Target.Type.DedicatedWorker; 121 return this._hasCapability(WebInspector.Target.Capabilities.NETWORK_DOMA INS);
119 }, 122 },
120 123
121 /** 124 /**
122 * @return {boolean} 125 * @return {boolean}
123 */ 126 */
124 isServiceWorker: function() 127 hasWorkerDomains: function()
125 { 128 {
126 return this._type === WebInspector.Target.Type.ServiceWorker; 129 return this._hasCapability(WebInspector.Target.Capabilities.WORKER_DOMAI NS);
127 }, 130 },
128 131
129 /** 132 /**
130 * @return {boolean}
131 */
132 isJSInspector: function()
133 {
134 return this._type === WebInspector.Target.Type.JSInspector;
135 },
136
137 /**
138 * @return {boolean}
139 */
140 hasJSContext: function()
141 {
142 return !this.isServiceWorker();
143 },
144
145 /**
146 * @return {boolean}
147 */
148 supportsWorkers: function()
149 {
150 return this.isPage() || this.isServiceWorker();
151 },
152
153 /**
154 * @return {?WebInspector.Target} 133 * @return {?WebInspector.Target}
155 */ 134 */
156 parentTarget: function() 135 parentTarget: function()
157 { 136 {
158 return this._parentTarget; 137 return this._parentTarget;
159 }, 138 },
160 139
161 _onDisconnect: function() 140 _onDisconnect: function()
162 { 141 {
163 this._targetManager.removeTarget(this); 142 this._targetManager.removeTarget(this);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 { 240 {
262 var target = /** @type {!WebInspector.Target} */ (event.data); 241 var target = /** @type {!WebInspector.Target} */ (event.data);
263 if (target !== this._target) 242 if (target !== this._target)
264 return; 243 return;
265 this.dispose(); 244 this.dispose();
266 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage r.Events.TargetDisposed, this._targetDisposed, this); 245 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage r.Events.TargetDisposed, this._targetDisposed, this);
267 }, 246 },
268 247
269 __proto__: WebInspector.SDKObject.prototype 248 __proto__: WebInspector.SDKObject.prototype
270 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698