| OLD | NEW |
| 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.Capability = { |
| 35 Page: 1, | 35 Browser: 1, |
| 36 DedicatedWorker: 2, | 36 JS: 2, |
| 37 ServiceWorker: 4, | 37 Network: 4, |
| 38 JSInspector: 8 | 38 Worker: 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 * @param {number} capabilitiesMask |
| 70 * @return {boolean} |
| 71 */ |
| 72 hasAllCapabilities: function(capabilitiesMask) |
| 73 { |
| 74 return (this._capabilitiesMask & capabilitiesMask) === capabilitiesMask; |
| 75 }, |
| 76 |
| 77 /** |
| 79 * @param {string} label | 78 * @param {string} label |
| 80 * @return {string} | 79 * @return {string} |
| 81 */ | 80 */ |
| 82 decorateLabel: function(label) | 81 decorateLabel: function(label) |
| 83 { | 82 { |
| 84 return this.isWorker() ? "\u2699 " + label : label; | 83 return !this.hasBrowserCapability() ? "\u2699 " + label : label; |
| 85 }, | 84 }, |
| 86 | 85 |
| 87 /** | 86 /** |
| 88 * @override | 87 * @override |
| 89 * @param {string} domain | 88 * @param {string} domain |
| 90 * @param {!Object} dispatcher | 89 * @param {!Object} dispatcher |
| 91 */ | 90 */ |
| 92 registerDispatcher: function(domain, dispatcher) | 91 registerDispatcher: function(domain, dispatcher) |
| 93 { | 92 { |
| 94 this._connection.registerDispatcher(domain, dispatcher); | 93 this._connection.registerDispatcher(domain, dispatcher); |
| 95 }, | 94 }, |
| 96 | 95 |
| 97 /** | 96 /** |
| 98 * @return {boolean} | 97 * @return {boolean} |
| 99 */ | 98 */ |
| 100 isPage: function() | 99 hasBrowserCapability: function() |
| 101 { | 100 { |
| 102 return this._type === WebInspector.Target.Type.Page; | 101 return this.hasAllCapabilities(WebInspector.Target.Capability.Browser); |
| 103 }, | 102 }, |
| 104 | 103 |
| 105 /** | 104 /** |
| 106 * @return {boolean} | 105 * @return {boolean} |
| 107 */ | 106 */ |
| 108 isWorker: function() | 107 hasJSCapability: function() |
| 109 { | 108 { |
| 110 return this.isDedicatedWorker() || this.isServiceWorker() || this.isJSIn
spector(); | 109 return this.hasAllCapabilities(WebInspector.Target.Capability.JS); |
| 111 }, | 110 }, |
| 112 | 111 |
| 113 /** | 112 /** |
| 114 * @return {boolean} | 113 * @return {boolean} |
| 115 */ | 114 */ |
| 116 isDedicatedWorker: function() | 115 hasNetworkCapability: function() |
| 117 { | 116 { |
| 118 return this._type === WebInspector.Target.Type.DedicatedWorker; | 117 return this.hasAllCapabilities(WebInspector.Target.Capability.Network); |
| 119 }, | 118 }, |
| 120 | 119 |
| 121 /** | 120 /** |
| 122 * @return {boolean} | 121 * @return {boolean} |
| 123 */ | 122 */ |
| 124 isServiceWorker: function() | 123 hasWorkerCapability: function() |
| 125 { | 124 { |
| 126 return this._type === WebInspector.Target.Type.ServiceWorker; | 125 return this.hasAllCapabilities(WebInspector.Target.Capability.Worker); |
| 127 }, | 126 }, |
| 128 | 127 |
| 129 /** | 128 /** |
| 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} | 129 * @return {?WebInspector.Target} |
| 155 */ | 130 */ |
| 156 parentTarget: function() | 131 parentTarget: function() |
| 157 { | 132 { |
| 158 return this._parentTarget; | 133 return this._parentTarget; |
| 159 }, | 134 }, |
| 160 | 135 |
| 161 _onDisconnect: function() | 136 _onDisconnect: function() |
| 162 { | 137 { |
| 163 this._targetManager.removeTarget(this); | 138 this._targetManager.removeTarget(this); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 { | 236 { |
| 262 var target = /** @type {!WebInspector.Target} */ (event.data); | 237 var target = /** @type {!WebInspector.Target} */ (event.data); |
| 263 if (target !== this._target) | 238 if (target !== this._target) |
| 264 return; | 239 return; |
| 265 this.dispose(); | 240 this.dispose(); |
| 266 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage
r.Events.TargetDisposed, this._targetDisposed, this); | 241 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage
r.Events.TargetDisposed, this._targetDisposed, this); |
| 267 }, | 242 }, |
| 268 | 243 |
| 269 __proto__: WebInspector.SDKObject.prototype | 244 __proto__: WebInspector.SDKObject.prototype |
| 270 } | 245 } |
| OLD | NEW |