Index: Source/devtools/front_end/Target.js |
diff --git a/Source/devtools/front_end/Target.js b/Source/devtools/front_end/Target.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1e3969fcc528f0c3ac957851d7938572583c0b43 |
--- /dev/null |
+++ b/Source/devtools/front_end/Target.js |
@@ -0,0 +1,110 @@ |
+/* |
+ * Copyright 2014 The Chromium Authors. All rights reserved. |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+Protocol = {}; |
+Protocol.Agents = function(){}; |
+ |
+/** |
+ * @constructor |
+ * @extends {Protocol.Agents} |
+ * @param {!InspectorBackendClass.Connection} connection |
+ * @param {function(!WebInspector.Target)=} callback |
+ */ |
+WebInspector.Target = function(connection, callback) |
+{ |
+ Protocol.Agents.call(this); |
+ this._connection = connection; |
+ this.canScreenCast = false; |
+ this.canInspectWorkers = false; |
+ |
+ this._generateProtocolAgentsMethods(); |
+ |
+ this.pageAgent().canScreencast(this._initializeCapability.bind(this, "canScreencast", null)); |
+ this.workerAgent().canInspectWorkers(this._initializeCapability.bind(this, "canInspectWorkers", this._loadedWithCapabilities.bind(this, callback))); |
+ |
+ // In case of loading as a web page with no bindings / harness, kick off initialization manually. |
+ if (InspectorFrontendHost.isStub) { |
+ // give a chance to add listeners of WebInspector.Target.Events.TargetIsReady |
+ setTimeout(this._loadedWithCapabilities.bind(this, callback), 0); |
+ } |
+} |
+ |
+WebInspector.Target.prototype = { |
+ |
+ _generateProtocolAgentsMethods: function() |
vsevik
2014/03/06 14:49:45
Can we generate them on prototype instead?
sergeyv
2014/03/06 16:18:34
Done.
|
+ { |
+ var domains = this._connection.domains(); |
+ |
+ for (var i = 0; i < domains.length; ++i) { |
+ var upperCaseLength = 0; |
+ while (upperCaseLength < domains[i].length && domains[i][upperCaseLength].toLowerCase() !== domains[i][upperCaseLength]) |
+ ++upperCaseLength; |
+ |
+ var methodName = domains[i].substr(0, upperCaseLength).toLowerCase() + domains[i].slice(upperCaseLength) + "Agent"; |
+ this[methodName] = this._connection.agent.bind(this._connection, domains[i]); |
+ } |
+ |
+ }, |
+ |
+ _initializeCapability: function(name, callback, error, result) |
+ { |
+ this[name] = result; |
+ if (callback) |
+ callback(); |
+ }, |
+ |
+ /** |
+ * @param {function(!WebInspector.Target)=} callback |
+ */ |
+ _loadedWithCapabilities: function(callback) |
+ { |
+ this.consoleModel = new WebInspector.ConsoleModel(); |
+ //This and similar lines are needed for compatibility |
+ WebInspector.console = this.consoleModel; |
+ this.networkManager = new WebInspector.NetworkManager(); |
+ WebInspector.networkManager = this.networkManager; |
+ this.resourceTreeModel = new WebInspector.ResourceTreeModel(this.networkManager); |
+ WebInspector.resourceTreeModel = this.resourceTreeModel; |
+ this.debuggerModel = new WebInspector.DebuggerModel(); |
+ WebInspector.debuggerModel = this.debuggerModel; |
+ this.runtimeModel = new WebInspector.RuntimeModel(this.resourceTreeModel); |
+ WebInspector.runtimeModel = this.runtimeModel; |
+ |
+ //we can't name it domAgent, because it clashes with function, WebInspector.DOMAgent should be renamed to DOMModel |
+ this._domAgent = new WebInspector.DOMAgent(); |
+ WebInspector.domAgent = this._domAgent; |
+ this.workerManager = new WebInspector.WorkerManager(this.canInspectWorkers); |
+ WebInspector.workerManager = this.workerManager; |
+ |
+ if (callback) |
+ callback(this); |
+ }, |
+ |
+ __proto__: Protocol.Agents.prototype |
+} |
+ |
+/** |
+ * @constructor |
+ */ |
+WebInspector.TargetManager = function() |
+{ |
+ /** @type {!Array.<!WebInspector.Target>} */ |
+ this._targets = []; |
+} |
+ |
+WebInspector.TargetManager.prototype = { |
+ |
+ /** |
+ * @param {!InspectorBackendClass.Connection} connection |
+ * @param {function(!WebInspector.Target)=} callback |
+ */ |
+ createTarget: function(connection, callback) |
+ { |
+ var newTarget = new WebInspector.Target(connection, callback); |
+ this._targets.push(newTarget); |
+ } |
+ |
+} |