Chromium Code Reviews| Index: Source/devtools/front_end/sdk/Target.js |
| diff --git a/Source/devtools/front_end/sdk/Target.js b/Source/devtools/front_end/sdk/Target.js |
| index dc5ffba3f2747094417a59087b0c09755a1e0736..8a00c4a98f9e98b2a35dc2fd280abf2c34f942d2 100644 |
| --- a/Source/devtools/front_end/sdk/Target.js |
| +++ b/Source/devtools/front_end/sdk/Target.js |
| @@ -16,24 +16,26 @@ WebInspector.Target = function(name, connection, callback) |
| Protocol.Agents.call(this, connection.agentsMap()); |
| this._name = name; |
| this._connection = connection; |
| - /** @type {boolean} */ |
| - this.isMainFrontend = false; |
| this._id = WebInspector.Target._nextId++; |
| - /** @type {boolean} */ |
| - this.canScreencast = false; |
| - this.pageAgent().canScreencast(this._initializeCapability.bind(this, "canScreencast", null)); |
| - |
| - /** @type {boolean} */ |
| - this.hasTouchInputs = false; |
| - this.pageAgent().hasTouchInputs(this._initializeCapability.bind(this, "hasTouchInputs", null)); |
| - |
| + this.pageAgent().canScreencast(this._initializeCapability.bind(this, WebInspector.Target.Capabilities.canScreencast, null)); |
| + this.pageAgent().hasTouchInputs(this._initializeCapability.bind(this, WebInspector.Target.Capabilities.hasTouchInputs, null)); |
| if (WebInspector.experimentsSettings.timelinePowerProfiler.isEnabled()) |
| - this.powerAgent().canProfilePower(this._initializeCapability.bind(this, "canProfilePower", null)); |
| - |
| - this.workerAgent().canInspectWorkers(this._initializeCapability.bind(this, "isMainFrontend", this._loadedWithCapabilities.bind(this, callback))); |
| + this.powerAgent().canProfilePower(this._initializeCapability.bind(this, WebInspector.Target.Capabilities.canProfilePower, null)); |
| + this.workerAgent().canInspectWorkers(this._initializeCapability.bind(this, WebInspector.Target.Capabilities.canInspectWorkers, this._loadedWithCapabilities.bind(this, callback))); |
| /** @type {!WebInspector.Lock} */ |
| this.profilingLock = new WebInspector.Lock(); |
| + 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.
|
| +} |
| + |
| +/** |
| + * @enum {string} |
| + */ |
| +WebInspector.Target.Capabilities = { |
| + canScreencast: "canScreencast", |
| + hasTouchInputs: "hasTouchInputs", |
| + canProfilePower: "canProfilePower", |
| + canInspectWorkers: "canInspectWorkers" |
| } |
| WebInspector.Target._nextId = 1; |
| @@ -65,14 +67,21 @@ WebInspector.Target.prototype = { |
| */ |
| _initializeCapability: function(name, callback, error, result) |
| { |
| - this[name] = result; |
| - if (!Capabilities[name]) |
| - Capabilities[name] = result; |
| + this._capabilities[name] = result; |
| if (callback) |
| callback(); |
| }, |
| /** |
| + * @param {string} capability |
| + * @return {boolean} |
| + */ |
| + hasCapability: function(capability) |
| + { |
| + return !!this._capabilities[capability]; |
| + }, |
| + |
| + /** |
| * @param {function(!WebInspector.Target)=} callback |
| */ |
| _loadedWithCapabilities: function(callback) |
| @@ -119,11 +128,11 @@ WebInspector.Target.prototype = { |
| WebInspector.cssModel = this.cssModel; |
| /** @type {!WebInspector.WorkerManager} */ |
| - this.workerManager = new WebInspector.WorkerManager(this, this.isMainFrontend); |
| + this.workerManager = new WebInspector.WorkerManager(this, this.hasCapability(WebInspector.Target.Capabilities.canInspectWorkers)); |
| if (!WebInspector.workerManager) |
| WebInspector.workerManager = this.workerManager; |
| - if (this.canProfilePower) |
| + if (this.hasCapability(WebInspector.Target.Capabilities.canProfilePower)) |
| WebInspector.powerProfiler = new WebInspector.PowerProfiler(); |
| /** @type {!WebInspector.TimelineManager} */ |
| @@ -168,7 +177,7 @@ WebInspector.Target.prototype = { |
| */ |
| isWorkerTarget: function() |
| { |
| - return !this.isMainFrontend; |
| + return !this.hasCapability(WebInspector.Target.Capabilities.canInspectWorkers); |
| }, |
| /** |
| @@ -177,7 +186,7 @@ WebInspector.Target.prototype = { |
| isMobile: function() |
| { |
| // FIXME: either add a separate capability or rename canScreencast to isMobile. |
| - return this.canScreencast; |
| + return this.hasCapability(WebInspector.Target.Capabilities.canScreencast); |
| }, |
| dispose: function() |