OLD | NEW |
---|---|
(Empty) | |
1 /* | |
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. | |
5 */ | |
6 | |
7 Protocol = {}; | |
8 Protocol.Agents = function(){}; | |
9 | |
10 /** | |
11 * @constructor | |
12 * @extends {Protocol.Agents} | |
13 * @param {!InspectorBackendClass.Connection} connection | |
14 * @param {function(!WebInspector.Target)=} callback | |
15 */ | |
16 WebInspector.Target = function(connection, callback) | |
17 { | |
18 Protocol.Agents.call(this); | |
19 this._connection = connection; | |
20 this.canScreenCast = false; | |
21 this.canInspectWorkers = false; | |
22 | |
23 this._generateProtocolAgentsMethods(); | |
24 | |
25 this.pageAgent().canScreencast(this._initializeCapability.bind(this, "canScr eencast", null)); | |
26 this.workerAgent().canInspectWorkers(this._initializeCapability.bind(this, " canInspectWorkers", this._loadedWithCapabilities.bind(this, callback))); | |
27 | |
28 // In case of loading as a web page with no bindings / harness, kick off ini tialization manually. | |
29 if (InspectorFrontendHost.isStub) { | |
30 // give a chance to add listeners of WebInspector.Target.Events.TargetIs Ready | |
31 setTimeout(this._loadedWithCapabilities.bind(this, callback), 0); | |
32 } | |
33 } | |
34 | |
35 WebInspector.Target.prototype = { | |
36 | |
37 _generateProtocolAgentsMethods: function() | |
vsevik
2014/03/06 14:49:45
Can we generate them on prototype instead?
sergeyv
2014/03/06 16:18:34
Done.
| |
38 { | |
39 var domains = this._connection.domains(); | |
40 | |
41 for (var i = 0; i < domains.length; ++i) { | |
42 var upperCaseLength = 0; | |
43 while (upperCaseLength < domains[i].length && domains[i][upperCaseLe ngth].toLowerCase() !== domains[i][upperCaseLength]) | |
44 ++upperCaseLength; | |
45 | |
46 var methodName = domains[i].substr(0, upperCaseLength).toLowerCase() + domains[i].slice(upperCaseLength) + "Agent"; | |
47 this[methodName] = this._connection.agent.bind(this._connection, dom ains[i]); | |
48 } | |
49 | |
50 }, | |
51 | |
52 _initializeCapability: function(name, callback, error, result) | |
53 { | |
54 this[name] = result; | |
55 if (callback) | |
56 callback(); | |
57 }, | |
58 | |
59 /** | |
60 * @param {function(!WebInspector.Target)=} callback | |
61 */ | |
62 _loadedWithCapabilities: function(callback) | |
63 { | |
64 this.consoleModel = new WebInspector.ConsoleModel(); | |
65 //This and similar lines are needed for compatibility | |
66 WebInspector.console = this.consoleModel; | |
67 this.networkManager = new WebInspector.NetworkManager(); | |
68 WebInspector.networkManager = this.networkManager; | |
69 this.resourceTreeModel = new WebInspector.ResourceTreeModel(this.network Manager); | |
70 WebInspector.resourceTreeModel = this.resourceTreeModel; | |
71 this.debuggerModel = new WebInspector.DebuggerModel(); | |
72 WebInspector.debuggerModel = this.debuggerModel; | |
73 this.runtimeModel = new WebInspector.RuntimeModel(this.resourceTreeModel ); | |
74 WebInspector.runtimeModel = this.runtimeModel; | |
75 | |
76 //we can't name it domAgent, because it clashes with function, WebInspec tor.DOMAgent should be renamed to DOMModel | |
77 this._domAgent = new WebInspector.DOMAgent(); | |
78 WebInspector.domAgent = this._domAgent; | |
79 this.workerManager = new WebInspector.WorkerManager(this.canInspectWorke rs); | |
80 WebInspector.workerManager = this.workerManager; | |
81 | |
82 if (callback) | |
83 callback(this); | |
84 }, | |
85 | |
86 __proto__: Protocol.Agents.prototype | |
87 } | |
88 | |
89 /** | |
90 * @constructor | |
91 */ | |
92 WebInspector.TargetManager = function() | |
93 { | |
94 /** @type {!Array.<!WebInspector.Target>} */ | |
95 this._targets = []; | |
96 } | |
97 | |
98 WebInspector.TargetManager.prototype = { | |
99 | |
100 /** | |
101 * @param {!InspectorBackendClass.Connection} connection | |
102 * @param {function(!WebInspector.Target)=} callback | |
103 */ | |
104 createTarget: function(connection, callback) | |
105 { | |
106 var newTarget = new WebInspector.Target(connection, callback); | |
107 this._targets.push(newTarget); | |
108 } | |
109 | |
110 } | |
OLD | NEW |