Chromium Code Reviews| 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 this._name = name; | 17 this._name = name; |
| 18 this._connection = connection; | 18 this._connection = connection; |
| 19 /** @type {boolean} */ | |
| 20 this.isMainFrontend = false; | |
| 21 this._id = WebInspector.Target._nextId++; | 19 this._id = WebInspector.Target._nextId++; |
| 22 /** @type {boolean} */ | 20 this.pageAgent().canScreencast(this._initializeCapability.bind(this, WebInsp ector.Target.Capabilities.canScreencast, null)); |
| 23 this.canScreencast = false; | 21 this.pageAgent().hasTouchInputs(this._initializeCapability.bind(this, WebIns pector.Target.Capabilities.hasTouchInputs, null)); |
| 24 this.pageAgent().canScreencast(this._initializeCapability.bind(this, "canScr eencast", null)); | |
| 25 | |
| 26 /** @type {boolean} */ | |
| 27 this.hasTouchInputs = false; | |
| 28 this.pageAgent().hasTouchInputs(this._initializeCapability.bind(this, "hasTo uchInputs", null)); | |
| 29 | |
| 30 if (WebInspector.experimentsSettings.timelinePowerProfiler.isEnabled()) | 22 if (WebInspector.experimentsSettings.timelinePowerProfiler.isEnabled()) |
| 31 this.powerAgent().canProfilePower(this._initializeCapability.bind(this, "canProfilePower", null)); | 23 this.powerAgent().canProfilePower(this._initializeCapability.bind(this, WebInspector.Target.Capabilities.canProfilePower, null)); |
| 32 | 24 this.workerAgent().canInspectWorkers(this._initializeCapability.bind(this, W ebInspector.Target.Capabilities.canInspectWorkers, this._loadedWithCapabilities. bind(this, callback))); |
| 33 this.workerAgent().canInspectWorkers(this._initializeCapability.bind(this, " isMainFrontend", this._loadedWithCapabilities.bind(this, callback))); | |
| 34 | 25 |
| 35 /** @type {!WebInspector.Lock} */ | 26 /** @type {!WebInspector.Lock} */ |
| 36 this.profilingLock = new WebInspector.Lock(); | 27 this.profilingLock = new WebInspector.Lock(); |
| 28 this._capabilities = {}; | |
|
dgozman
2014/07/14 20:47:11
I'd move this before initializeCapability calls an
pfeldman
2014/07/15 04:53:13
Done.
| |
| 29 } | |
| 30 | |
| 31 /** | |
| 32 * @enum {string} | |
| 33 */ | |
| 34 WebInspector.Target.Capabilities = { | |
| 35 canScreencast: "canScreencast", | |
| 36 hasTouchInputs: "hasTouchInputs", | |
| 37 canProfilePower: "canProfilePower", | |
| 38 canInspectWorkers: "canInspectWorkers" | |
| 37 } | 39 } |
| 38 | 40 |
| 39 WebInspector.Target._nextId = 1; | 41 WebInspector.Target._nextId = 1; |
| 40 | 42 |
| 41 WebInspector.Target.prototype = { | 43 WebInspector.Target.prototype = { |
| 42 | 44 |
| 43 /** | 45 /** |
| 44 * @return {number} | 46 * @return {number} |
| 45 */ | 47 */ |
| 46 id: function() | 48 id: function() |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 58 }, | 60 }, |
| 59 | 61 |
| 60 /** | 62 /** |
| 61 * @param {string} name | 63 * @param {string} name |
| 62 * @param {function()|null} callback | 64 * @param {function()|null} callback |
| 63 * @param {?Protocol.Error} error | 65 * @param {?Protocol.Error} error |
| 64 * @param {*} result | 66 * @param {*} result |
| 65 */ | 67 */ |
| 66 _initializeCapability: function(name, callback, error, result) | 68 _initializeCapability: function(name, callback, error, result) |
| 67 { | 69 { |
| 68 this[name] = result; | 70 this._capabilities[name] = result; |
| 69 if (!Capabilities[name]) | |
| 70 Capabilities[name] = result; | |
| 71 if (callback) | 71 if (callback) |
| 72 callback(); | 72 callback(); |
| 73 }, | 73 }, |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * @param {string} capability | |
| 77 * @return {boolean} | |
| 78 */ | |
| 79 hasCapability: function(capability) | |
| 80 { | |
| 81 return !!this._capabilities[capability]; | |
| 82 }, | |
| 83 | |
| 84 /** | |
| 76 * @param {function(!WebInspector.Target)=} callback | 85 * @param {function(!WebInspector.Target)=} callback |
| 77 */ | 86 */ |
| 78 _loadedWithCapabilities: function(callback) | 87 _loadedWithCapabilities: function(callback) |
| 79 { | 88 { |
| 80 /** @type {!WebInspector.ConsoleModel} */ | 89 /** @type {!WebInspector.ConsoleModel} */ |
| 81 this.consoleModel = new WebInspector.ConsoleModel(this); | 90 this.consoleModel = new WebInspector.ConsoleModel(this); |
| 82 // This and similar lines are needed for compatibility. | 91 // This and similar lines are needed for compatibility. |
| 83 if (!WebInspector.consoleModel) | 92 if (!WebInspector.consoleModel) |
| 84 WebInspector.consoleModel = this.consoleModel; | 93 WebInspector.consoleModel = this.consoleModel; |
| 85 | 94 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 112 this.domModel = new WebInspector.DOMModel(this); | 121 this.domModel = new WebInspector.DOMModel(this); |
| 113 if (!WebInspector.domModel) | 122 if (!WebInspector.domModel) |
| 114 WebInspector.domModel = this.domModel; | 123 WebInspector.domModel = this.domModel; |
| 115 | 124 |
| 116 /** @type {!WebInspector.CSSStyleModel} */ | 125 /** @type {!WebInspector.CSSStyleModel} */ |
| 117 this.cssModel = new WebInspector.CSSStyleModel(this); | 126 this.cssModel = new WebInspector.CSSStyleModel(this); |
| 118 if (!WebInspector.cssModel) | 127 if (!WebInspector.cssModel) |
| 119 WebInspector.cssModel = this.cssModel; | 128 WebInspector.cssModel = this.cssModel; |
| 120 | 129 |
| 121 /** @type {!WebInspector.WorkerManager} */ | 130 /** @type {!WebInspector.WorkerManager} */ |
| 122 this.workerManager = new WebInspector.WorkerManager(this, this.isMainFro ntend); | 131 this.workerManager = new WebInspector.WorkerManager(this, this.hasCapabi lity(WebInspector.Target.Capabilities.canInspectWorkers)); |
| 123 if (!WebInspector.workerManager) | 132 if (!WebInspector.workerManager) |
| 124 WebInspector.workerManager = this.workerManager; | 133 WebInspector.workerManager = this.workerManager; |
| 125 | 134 |
| 126 if (this.canProfilePower) | 135 if (this.hasCapability(WebInspector.Target.Capabilities.canProfilePower) ) |
| 127 WebInspector.powerProfiler = new WebInspector.PowerProfiler(); | 136 WebInspector.powerProfiler = new WebInspector.PowerProfiler(); |
| 128 | 137 |
| 129 /** @type {!WebInspector.TimelineManager} */ | 138 /** @type {!WebInspector.TimelineManager} */ |
| 130 this.timelineManager = new WebInspector.TimelineManager(this); | 139 this.timelineManager = new WebInspector.TimelineManager(this); |
| 131 if (!WebInspector.timelineManager) | 140 if (!WebInspector.timelineManager) |
| 132 WebInspector.timelineManager = this.timelineManager; | 141 WebInspector.timelineManager = this.timelineManager; |
| 133 | 142 |
| 134 /** @type {!WebInspector.DatabaseModel} */ | 143 /** @type {!WebInspector.DatabaseModel} */ |
| 135 this.databaseModel = new WebInspector.DatabaseModel(this); | 144 this.databaseModel = new WebInspector.DatabaseModel(this); |
| 136 if (!WebInspector.databaseModel) | 145 if (!WebInspector.databaseModel) |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 161 registerDispatcher: function(domain, dispatcher) | 170 registerDispatcher: function(domain, dispatcher) |
| 162 { | 171 { |
| 163 this._connection.registerDispatcher(domain, dispatcher); | 172 this._connection.registerDispatcher(domain, dispatcher); |
| 164 }, | 173 }, |
| 165 | 174 |
| 166 /** | 175 /** |
| 167 * @return {boolean} | 176 * @return {boolean} |
| 168 */ | 177 */ |
| 169 isWorkerTarget: function() | 178 isWorkerTarget: function() |
| 170 { | 179 { |
| 171 return !this.isMainFrontend; | 180 return !this.hasCapability(WebInspector.Target.Capabilities.canInspectWo rkers); |
| 172 }, | 181 }, |
| 173 | 182 |
| 174 /** | 183 /** |
| 175 * @return {boolean} | 184 * @return {boolean} |
| 176 */ | 185 */ |
| 177 isMobile: function() | 186 isMobile: function() |
| 178 { | 187 { |
| 179 // FIXME: either add a separate capability or rename canScreencast to is Mobile. | 188 // FIXME: either add a separate capability or rename canScreencast to is Mobile. |
| 180 return this.canScreencast; | 189 return this.hasCapability(WebInspector.Target.Capabilities.canScreencast ); |
| 181 }, | 190 }, |
| 182 | 191 |
| 183 dispose: function() | 192 dispose: function() |
| 184 { | 193 { |
| 185 this.debuggerModel.dispose(); | 194 this.debuggerModel.dispose(); |
| 186 this.networkManager.dispose(); | 195 this.networkManager.dispose(); |
| 187 this.cpuProfilerModel.dispose(); | 196 this.cpuProfilerModel.dispose(); |
| 188 }, | 197 }, |
| 189 | 198 |
| 190 __proto__: Protocol.Agents.prototype | 199 __proto__: Protocol.Agents.prototype |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 target: function() | 367 target: function() |
| 359 { | 368 { |
| 360 return this._target; | 369 return this._target; |
| 361 } | 370 } |
| 362 } | 371 } |
| 363 | 372 |
| 364 /** | 373 /** |
| 365 * @type {!WebInspector.TargetManager} | 374 * @type {!WebInspector.TargetManager} |
| 366 */ | 375 */ |
| 367 WebInspector.targetManager = new WebInspector.TargetManager(); | 376 WebInspector.targetManager = new WebInspector.TargetManager(); |
| OLD | NEW |