| 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 {string} name | 10 * @param {string} name |
| 11 * @param {!InspectorBackendClass.Connection} connection | 11 * @param {!InspectorBackendClass.Connection} connection |
| 12 * @param {function(!WebInspector.Target)=} callback | 12 * @param {function(!WebInspector.Target)=} callback |
| 13 */ | 13 */ |
| 14 WebInspector.Target = function(name, connection, callback) | 14 WebInspector.Target = function(name, connection, callback) |
| 15 { | 15 { |
| 16 Protocol.Agents.call(this, connection.agentsMap()); | 16 Protocol.Agents.call(this, connection.agentsMap()); |
| 17 /** @type {!WeakReference.<!WebInspector.Target>} */ | 17 /** @type {!WeakReference.<!WebInspector.Target>} */ |
| 18 this._weakReference = new WeakReference(this); | 18 this._weakReference = new WeakReference(this); |
| 19 this._name = name; | 19 this._name = name; |
| 20 this._connection = connection; | 20 this._connection = connection; |
| 21 /** @type {boolean} */ | |
| 22 this.isMainFrontend = false; | |
| 23 this._id = WebInspector.Target._nextId++; | 21 this._id = WebInspector.Target._nextId++; |
| 24 /** @type {boolean} */ | |
| 25 this.canScreencast = false; | |
| 26 this.pageAgent().canScreencast(this._initializeCapability.bind(this, "canScr
eencast", null)); | |
| 27 | 22 |
| 28 /** @type {boolean} */ | 23 /** @type {!Object.<string, boolean>} */ |
| 29 this.hasTouchInputs = false; | 24 this._capabilities = {}; |
| 30 this.pageAgent().hasTouchInputs(this._initializeCapability.bind(this, "hasTo
uchInputs", null)); | 25 this.pageAgent().canScreencast(this._initializeCapability.bind(this, WebInsp
ector.Target.Capabilities.canScreencast, null)); |
| 31 | 26 this.pageAgent().hasTouchInputs(this._initializeCapability.bind(this, WebIns
pector.Target.Capabilities.hasTouchInputs, null)); |
| 32 if (WebInspector.experimentsSettings.timelinePowerProfiler.isEnabled()) | 27 if (WebInspector.experimentsSettings.timelinePowerProfiler.isEnabled()) |
| 33 this.powerAgent().canProfilePower(this._initializeCapability.bind(this,
"canProfilePower", null)); | 28 this.powerAgent().canProfilePower(this._initializeCapability.bind(this,
WebInspector.Target.Capabilities.canProfilePower, null)); |
| 34 | 29 this.workerAgent().canInspectWorkers(this._initializeCapability.bind(this, W
ebInspector.Target.Capabilities.canInspectWorkers, this._loadedWithCapabilities.
bind(this, callback))); |
| 35 this.workerAgent().canInspectWorkers(this._initializeCapability.bind(this, "
isMainFrontend", this._loadedWithCapabilities.bind(this, callback))); | |
| 36 | 30 |
| 37 /** @type {!WebInspector.Lock} */ | 31 /** @type {!WebInspector.Lock} */ |
| 38 this.profilingLock = new WebInspector.Lock(); | 32 this.profilingLock = new WebInspector.Lock(); |
| 39 } | 33 } |
| 40 | 34 |
| 35 /** |
| 36 * @enum {string} |
| 37 */ |
| 38 WebInspector.Target.Capabilities = { |
| 39 canScreencast: "canScreencast", |
| 40 hasTouchInputs: "hasTouchInputs", |
| 41 canProfilePower: "canProfilePower", |
| 42 canInspectWorkers: "canInspectWorkers" |
| 43 } |
| 44 |
| 41 WebInspector.Target._nextId = 1; | 45 WebInspector.Target._nextId = 1; |
| 42 | 46 |
| 43 WebInspector.Target.prototype = { | 47 WebInspector.Target.prototype = { |
| 44 | 48 |
| 45 /** | 49 /** |
| 46 * @return {number} | 50 * @return {number} |
| 47 */ | 51 */ |
| 48 id: function() | 52 id: function() |
| 49 { | 53 { |
| 50 return this._id; | 54 return this._id; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 64 */ | 68 */ |
| 65 weakReference: function() | 69 weakReference: function() |
| 66 { | 70 { |
| 67 return this._weakReference; | 71 return this._weakReference; |
| 68 }, | 72 }, |
| 69 | 73 |
| 70 /** | 74 /** |
| 71 * @param {string} name | 75 * @param {string} name |
| 72 * @param {function()|null} callback | 76 * @param {function()|null} callback |
| 73 * @param {?Protocol.Error} error | 77 * @param {?Protocol.Error} error |
| 74 * @param {*} result | 78 * @param {boolean} result |
| 75 */ | 79 */ |
| 76 _initializeCapability: function(name, callback, error, result) | 80 _initializeCapability: function(name, callback, error, result) |
| 77 { | 81 { |
| 78 this[name] = result; | 82 this._capabilities[name] = result; |
| 79 if (!Capabilities[name]) | |
| 80 Capabilities[name] = result; | |
| 81 if (callback) | 83 if (callback) |
| 82 callback(); | 84 callback(); |
| 83 }, | 85 }, |
| 84 | 86 |
| 85 /** | 87 /** |
| 88 * @param {string} capability |
| 89 * @return {boolean} |
| 90 */ |
| 91 hasCapability: function(capability) |
| 92 { |
| 93 return !!this._capabilities[capability]; |
| 94 }, |
| 95 |
| 96 /** |
| 86 * @param {function(!WebInspector.Target)=} callback | 97 * @param {function(!WebInspector.Target)=} callback |
| 87 */ | 98 */ |
| 88 _loadedWithCapabilities: function(callback) | 99 _loadedWithCapabilities: function(callback) |
| 89 { | 100 { |
| 90 /** @type {!WebInspector.ConsoleModel} */ | 101 /** @type {!WebInspector.ConsoleModel} */ |
| 91 this.consoleModel = new WebInspector.ConsoleModel(this); | 102 this.consoleModel = new WebInspector.ConsoleModel(this); |
| 92 // This and similar lines are needed for compatibility. | 103 // This and similar lines are needed for compatibility. |
| 93 if (!WebInspector.consoleModel) | 104 if (!WebInspector.consoleModel) |
| 94 WebInspector.consoleModel = this.consoleModel; | 105 WebInspector.consoleModel = this.consoleModel; |
| 95 | 106 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 122 this.domModel = new WebInspector.DOMModel(this); | 133 this.domModel = new WebInspector.DOMModel(this); |
| 123 if (!WebInspector.domModel) | 134 if (!WebInspector.domModel) |
| 124 WebInspector.domModel = this.domModel; | 135 WebInspector.domModel = this.domModel; |
| 125 | 136 |
| 126 /** @type {!WebInspector.CSSStyleModel} */ | 137 /** @type {!WebInspector.CSSStyleModel} */ |
| 127 this.cssModel = new WebInspector.CSSStyleModel(this); | 138 this.cssModel = new WebInspector.CSSStyleModel(this); |
| 128 if (!WebInspector.cssModel) | 139 if (!WebInspector.cssModel) |
| 129 WebInspector.cssModel = this.cssModel; | 140 WebInspector.cssModel = this.cssModel; |
| 130 | 141 |
| 131 /** @type {!WebInspector.WorkerManager} */ | 142 /** @type {!WebInspector.WorkerManager} */ |
| 132 this.workerManager = new WebInspector.WorkerManager(this, this.isMainFro
ntend); | 143 this.workerManager = new WebInspector.WorkerManager(this, this.hasCapabi
lity(WebInspector.Target.Capabilities.canInspectWorkers)); |
| 133 if (!WebInspector.workerManager) | 144 if (!WebInspector.workerManager) |
| 134 WebInspector.workerManager = this.workerManager; | 145 WebInspector.workerManager = this.workerManager; |
| 135 | 146 |
| 136 if (this.canProfilePower) | 147 if (this.hasCapability(WebInspector.Target.Capabilities.canProfilePower)
) |
| 137 WebInspector.powerProfiler = new WebInspector.PowerProfiler(); | 148 WebInspector.powerProfiler = new WebInspector.PowerProfiler(); |
| 138 | 149 |
| 139 /** @type {!WebInspector.TimelineManager} */ | 150 /** @type {!WebInspector.TimelineManager} */ |
| 140 this.timelineManager = new WebInspector.TimelineManager(this); | 151 this.timelineManager = new WebInspector.TimelineManager(this); |
| 141 if (!WebInspector.timelineManager) | 152 if (!WebInspector.timelineManager) |
| 142 WebInspector.timelineManager = this.timelineManager; | 153 WebInspector.timelineManager = this.timelineManager; |
| 143 | 154 |
| 144 /** @type {!WebInspector.DatabaseModel} */ | 155 /** @type {!WebInspector.DatabaseModel} */ |
| 145 this.databaseModel = new WebInspector.DatabaseModel(this); | 156 this.databaseModel = new WebInspector.DatabaseModel(this); |
| 146 if (!WebInspector.databaseModel) | 157 if (!WebInspector.databaseModel) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 171 registerDispatcher: function(domain, dispatcher) | 182 registerDispatcher: function(domain, dispatcher) |
| 172 { | 183 { |
| 173 this._connection.registerDispatcher(domain, dispatcher); | 184 this._connection.registerDispatcher(domain, dispatcher); |
| 174 }, | 185 }, |
| 175 | 186 |
| 176 /** | 187 /** |
| 177 * @return {boolean} | 188 * @return {boolean} |
| 178 */ | 189 */ |
| 179 isWorkerTarget: function() | 190 isWorkerTarget: function() |
| 180 { | 191 { |
| 181 return !this.isMainFrontend; | 192 return !this.hasCapability(WebInspector.Target.Capabilities.canInspectWo
rkers); |
| 182 }, | 193 }, |
| 183 | 194 |
| 184 /** | 195 /** |
| 185 * @return {boolean} | 196 * @return {boolean} |
| 186 */ | 197 */ |
| 187 isMobile: function() | 198 isMobile: function() |
| 188 { | 199 { |
| 189 // FIXME: either add a separate capability or rename canScreencast to is
Mobile. | 200 // FIXME: either add a separate capability or rename canScreencast to is
Mobile. |
| 190 return this.canScreencast; | 201 return this.hasCapability(WebInspector.Target.Capabilities.canScreencast
); |
| 191 }, | 202 }, |
| 192 | 203 |
| 193 dispose: function() | 204 dispose: function() |
| 194 { | 205 { |
| 195 this._weakReference.clear(); | 206 this._weakReference.clear(); |
| 196 this.debuggerModel.dispose(); | 207 this.debuggerModel.dispose(); |
| 197 this.networkManager.dispose(); | 208 this.networkManager.dispose(); |
| 198 this.cpuProfilerModel.dispose(); | 209 this.cpuProfilerModel.dispose(); |
| 199 }, | 210 }, |
| 200 | 211 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 /** | 342 /** |
| 332 * @param {!WebInspector.Target} target | 343 * @param {!WebInspector.Target} target |
| 333 */ | 344 */ |
| 334 targetRemoved: function(target) { }, | 345 targetRemoved: function(target) { }, |
| 335 } | 346 } |
| 336 | 347 |
| 337 /** | 348 /** |
| 338 * @type {!WebInspector.TargetManager} | 349 * @type {!WebInspector.TargetManager} |
| 339 */ | 350 */ |
| 340 WebInspector.targetManager = new WebInspector.TargetManager(); | 351 WebInspector.targetManager = new WebInspector.TargetManager(); |
| OLD | NEW |