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
4 * found in the LICENSE file.
9 * @extends {Protocol.Agents}
10 * @param {!InspectorBackendClass.Connection} connection
11 * @param {function(!WebInspector.Target)=} callback
13 WebInspector.Target = function(connection, callback)
15 Protocol.Agents.call(this, connection.agentsMap());
16 this._connection = connection;
17 /** @type {boolean} */
18 this.isMainFrontend = false;
20 /** @type {boolean} */
21 this.canScreencast = false;
22 this.pageAgent().canScreencast(this._initializeCapability.bind(this, "canScreencast", null));
24 /** @type {boolean} */
25 this.hasTouchInputs = false;
26 this.pageAgent().hasTouchInputs(this._initializeCapability.bind(this, "hasTouchInputs", null));
28 if (WebInspector.experimentsSettings.powerProfiler.isEnabled())
29 this.powerAgent().canProfilePower(this._initializeCapability.bind(this, "canProfilePower", null));
31 this.workerAgent().canInspectWorkers(this._initializeCapability.bind(this, "isMainFrontend", this._loadedWithCapabilities.bind(this, callback)));
33 /** @type {!WebInspector.Lock} */
34 this.profilingLock = new WebInspector.Lock();
37 WebInspector.Target.prototype = {
39 * @param {string} name
40 * @param {function()|null} callback
42 _initializeCapability: function(name, callback, error, result)
45 if (!Capabilities[name])
46 Capabilities[name] = result;
52 * @param {function(!WebInspector.Target)=} callback
54 _loadedWithCapabilities: function(callback)
56 /** @type {!WebInspector.ConsoleModel} */
57 this.consoleModel = new WebInspector.ConsoleModel(this);
58 // This and similar lines are needed for compatibility.
59 if (!WebInspector.console)
60 WebInspector.console = this.consoleModel;
62 /** @type {!WebInspector.NetworkManager} */
63 this.networkManager = new WebInspector.NetworkManager(this);
64 if (!WebInspector.networkManager)
65 WebInspector.networkManager = this.networkManager;
67 /** @type {!WebInspector.ResourceTreeModel} */
68 this.resourceTreeModel = new WebInspector.ResourceTreeModel(this);
69 if (!WebInspector.resourceTreeModel)
70 WebInspector.resourceTreeModel = this.resourceTreeModel;
72 /** @type {!WebInspector.NetworkLog} */
73 this.networkLog = new WebInspector.NetworkLog(this);
74 if (!WebInspector.networkLog)
75 WebInspector.networkLog = this.networkLog;
77 /** @type {!WebInspector.DebuggerModel} */
78 this.debuggerModel = new WebInspector.DebuggerModel(this);
79 if (!WebInspector.debuggerModel)
80 WebInspector.debuggerModel = this.debuggerModel;
82 /** @type {!WebInspector.RuntimeModel} */
83 this.runtimeModel = new WebInspector.RuntimeModel(this);
84 if (!WebInspector.runtimeModel)
85 WebInspector.runtimeModel = this.runtimeModel;
87 /** @type {!WebInspector.DOMModel} */
88 this.domModel = new WebInspector.DOMModel(this);
89 if (!WebInspector.domModel)
90 WebInspector.domModel = this.domModel;
92 /** @type {!WebInspector.CSSStyleModel} */
93 this.cssModel = new WebInspector.CSSStyleModel(this);
94 if (!WebInspector.cssModel)
95 WebInspector.cssModel = this.cssModel;
97 /** @type {!WebInspector.WorkerManager} */
98 this.workerManager = new WebInspector.WorkerManager(this, this.isMainFrontend);
99 if (!WebInspector.workerManager)
100 WebInspector.workerManager = this.workerManager;
102 if (this.canProfilePower)
103 WebInspector.powerProfiler = new WebInspector.PowerProfiler();
105 /** @type {!WebInspector.TimelineManager} */
106 this.timelineManager = new WebInspector.TimelineManager(this);
107 if (!WebInspector.timelineManager)
108 WebInspector.timelineManager = this.timelineManager;
110 /** @type {!WebInspector.DatabaseModel} */
111 this.databaseModel = new WebInspector.DatabaseModel(this);
112 if (!WebInspector.databaseModel)
113 WebInspector.databaseModel = this.databaseModel;
115 /** @type {!WebInspector.DOMStorageModel} */
116 this.domStorageModel = new WebInspector.DOMStorageModel(this);
117 if (!WebInspector.domStorageModel)
118 WebInspector.domStorageModel = this.domStorageModel;
120 /** @type {!WebInspector.CPUProfilerModel} */
121 this.cpuProfilerModel = new WebInspector.CPUProfilerModel(this);
122 if (!WebInspector.cpuProfilerModel)
123 WebInspector.cpuProfilerModel = this.cpuProfilerModel;
131 * @param {string} domain
132 * @param {!Object} dispatcher
134 registerDispatcher: function(domain, dispatcher)
136 this._connection.registerDispatcher(domain, dispatcher);
142 isWorkerTarget: function()
144 return !this.isMainFrontend;
152 // FIXME: either add a separate capability or rename canScreencast to isMobile.
153 return this.canScreencast;
156 __proto__: Protocol.Agents.prototype
161 * @param {!WebInspector.Target} target
163 WebInspector.TargetAware = function(target)
165 this._target = target;
168 WebInspector.TargetAware.prototype = {
170 * @return {!WebInspector.Target}
180 * @extends {WebInspector.Object}
181 * @param {!WebInspector.Target} target
183 WebInspector.TargetAwareObject = function(target)
185 WebInspector.Object.call(this);
186 this._target = target;
189 WebInspector.TargetAwareObject.prototype = {
191 * @return {!WebInspector.Target}
198 __proto__: WebInspector.Object.prototype
204 WebInspector.TargetManager = function()
206 /** @type {!Array.<!WebInspector.Target>} */
208 /** @type {!Array.<!WebInspector.TargetManager.Observer>} */
209 this._observers = [];
212 WebInspector.TargetManager.prototype = {
215 * @param {!WebInspector.TargetManager.Observer} targetObserver
217 observeTargets: function(targetObserver)
219 WebInspector.targetManager.targets().forEach(targetObserver.targetAdded.bind(targetObserver));
220 this._observers.push(targetObserver);
224 * @param {!InspectorBackendClass.Connection} connection
225 * @param {function(!WebInspector.Target)=} callback
227 createTarget: function(connection, callback)
229 var target = new WebInspector.Target(connection, callbackWrapper.bind(this));
232 * @this {WebInspector.TargetManager}
235 function callbackWrapper(newTarget)
237 this._targets.push(newTarget);
238 var copy = this._observers;
239 for (var i = 0; i < copy.length; ++i)
240 copy[i].targetAdded(newTarget);
248 * @return {!Array.<!WebInspector.Target>}
252 return this._targets;
256 * @return {?WebInspector.Target}
258 activeTarget: function()
260 return this._targets[0];
267 WebInspector.TargetManager.Observer = function()
271 WebInspector.TargetManager.Observer.prototype = {
273 * @param {!WebInspector.Target} target
275 targetAdded: function(target) { },
278 * @param {!WebInspector.Target} target
280 targetRemoved: function(target) { },
284 * @type {!WebInspector.TargetManager}
286 WebInspector.targetManager;