OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 */ | 33 */ |
34 function InspectorBackendClass() | 34 function InspectorBackendClass() |
35 { | 35 { |
36 this._connection = null; | |
37 this._agentPrototypes = {}; | 36 this._agentPrototypes = {}; |
38 this._dispatcherPrototypes = {}; | 37 this._dispatcherPrototypes = {}; |
39 this._initialized = false; | 38 this._initialized = false; |
40 this._enums = {}; | |
41 this._initProtocolAgentsConstructor(); | 39 this._initProtocolAgentsConstructor(); |
42 } | 40 } |
43 | 41 |
44 InspectorBackendClass._DevToolsErrorCode = -32000; | 42 InspectorBackendClass._DevToolsErrorCode = -32000; |
45 | 43 |
46 /** | 44 /** |
47 * @param {string} error | 45 * @param {string} error |
48 * @param {!Object} messageObject | 46 * @param {!Object} messageObject |
49 */ | 47 */ |
50 InspectorBackendClass.reportProtocolError = function(error, messageObject) | 48 InspectorBackendClass.reportProtocolError = function(error, messageObject) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 */ | 91 */ |
94 function registerDispatcher(dispatcher) | 92 function registerDispatcher(dispatcher) |
95 { | 93 { |
96 this.registerDispatcher(domain, dispatcher) | 94 this.registerDispatcher(domain, dispatcher) |
97 } | 95 } |
98 | 96 |
99 window.Protocol.Agents.prototype["register" + domain + "Dispatcher"] = r
egisterDispatcher; | 97 window.Protocol.Agents.prototype["register" + domain + "Dispatcher"] = r
egisterDispatcher; |
100 }, | 98 }, |
101 | 99 |
102 /** | 100 /** |
103 * @return {!InspectorBackendClass.Connection} | |
104 */ | |
105 connection: function() | |
106 { | |
107 if (!this._connection) | |
108 throw "Main connection was not initialized"; | |
109 return this._connection; | |
110 }, | |
111 | |
112 /** | |
113 * @param {!InspectorBackendClass.MainConnection} connection | |
114 */ | |
115 setConnection: function(connection) | |
116 { | |
117 this._connection = connection; | |
118 | |
119 this._connection.registerAgentsOn(window); | |
120 for (var type in this._enums) { | |
121 var domainAndMethod = type.split("."); | |
122 window[domainAndMethod[0] + "Agent"][domainAndMethod[1]] = this._enu
ms[type]; | |
123 } | |
124 }, | |
125 | |
126 /** | |
127 * @param {string} domain | 101 * @param {string} domain |
128 * @return {!InspectorBackendClass.AgentPrototype} | 102 * @return {!InspectorBackendClass.AgentPrototype} |
129 */ | 103 */ |
130 _agentPrototype: function(domain) | 104 _agentPrototype: function(domain) |
131 { | 105 { |
132 if (!this._agentPrototypes[domain]) { | 106 if (!this._agentPrototypes[domain]) { |
133 this._agentPrototypes[domain] = new InspectorBackendClass.AgentProto
type(domain); | 107 this._agentPrototypes[domain] = new InspectorBackendClass.AgentProto
type(domain); |
134 this._addAgentGetterMethodToProtocolAgentsPrototype(domain); | 108 this._addAgentGetterMethodToProtocolAgentsPrototype(domain); |
135 } | 109 } |
136 | 110 |
(...skipping 23 matching lines...) Expand all Loading... |
160 this._agentPrototype(domainAndMethod[0]).registerCommand(domainAndMethod
[1], signature, replyArgs, hasErrorData); | 134 this._agentPrototype(domainAndMethod[0]).registerCommand(domainAndMethod
[1], signature, replyArgs, hasErrorData); |
161 this._initialized = true; | 135 this._initialized = true; |
162 }, | 136 }, |
163 | 137 |
164 /** | 138 /** |
165 * @param {string} type | 139 * @param {string} type |
166 * @param {!Object} values | 140 * @param {!Object} values |
167 */ | 141 */ |
168 registerEnum: function(type, values) | 142 registerEnum: function(type, values) |
169 { | 143 { |
170 this._enums[type] = values; | 144 var domainAndMethod = type.split("."); |
| 145 var agentName = domainAndMethod[0] + "Agent"; |
| 146 if (!window[agentName]) |
| 147 window[agentName] = {}; |
| 148 |
| 149 window[agentName][domainAndMethod[1]] = values; |
171 this._initialized = true; | 150 this._initialized = true; |
172 }, | 151 }, |
173 | 152 |
174 /** | 153 /** |
175 * @param {string} eventName | 154 * @param {string} eventName |
176 * @param {!Object} params | 155 * @param {!Object} params |
177 */ | 156 */ |
178 registerEvent: function(eventName, params) | 157 registerEvent: function(eventName, params) |
179 { | 158 { |
180 var domain = eventName.split(".")[0]; | 159 var domain = eventName.split(".")[0]; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 this._agents[domain] = Object.create(agentPrototypes[domain]); | 338 this._agents[domain] = Object.create(agentPrototypes[domain]); |
360 this._agents[domain].setConnection(this); | 339 this._agents[domain].setConnection(this); |
361 } | 340 } |
362 | 341 |
363 for (var domain in dispatcherPrototypes) | 342 for (var domain in dispatcherPrototypes) |
364 this._dispatchers[domain] = Object.create(dispatcherPrototypes[domai
n]); | 343 this._dispatchers[domain] = Object.create(dispatcherPrototypes[domai
n]); |
365 | 344 |
366 }, | 345 }, |
367 | 346 |
368 /** | 347 /** |
369 * @param {!Object} object | |
370 */ | |
371 registerAgentsOn: function(object) | |
372 { | |
373 for (var domain in this._agents) | |
374 object[domain + "Agent"] = {}; | |
375 }, | |
376 | |
377 /** | |
378 * @return {number} | 348 * @return {number} |
379 */ | 349 */ |
380 nextMessageId: function() | 350 nextMessageId: function() |
381 { | 351 { |
382 return this._lastMessageId++; | 352 return this._lastMessageId++; |
383 }, | 353 }, |
384 | 354 |
385 /** | 355 /** |
386 * @param {string} domain | 356 * @param {string} domain |
387 * @return {!InspectorBackendClass.AgentPrototype} | 357 * @return {!InspectorBackendClass.AgentPrototype} |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 } | 1019 } |
1050 } | 1020 } |
1051 | 1021 |
1052 InspectorBackendClass.Options = { | 1022 InspectorBackendClass.Options = { |
1053 dumpInspectorTimeStats: false, | 1023 dumpInspectorTimeStats: false, |
1054 dumpInspectorProtocolMessages: false, | 1024 dumpInspectorProtocolMessages: false, |
1055 suppressRequestErrors: false | 1025 suppressRequestErrors: false |
1056 } | 1026 } |
1057 | 1027 |
1058 InspectorBackend = new InspectorBackendClass(); | 1028 InspectorBackend = new InspectorBackendClass(); |
OLD | NEW |