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 20 matching lines...) Expand all Loading... | |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 */ | 33 */ |
34 function InspectorBackendClass() | 34 function InspectorBackendClass() |
35 { | 35 { |
36 this._connection = null; | 36 this._connection = null; |
37 this._agentPrototypes = {}; | 37 this._agentPrototypes = {}; |
38 this._dispatcherPrototypes = {}; | 38 this._dispatcherPrototypes = {}; |
39 this._initialized = false; | 39 this._initialized = false; |
40 this._enums = {}; | 40 this._enums = {}; |
41 this.initProtocolAgentsClass(); | |
41 } | 42 } |
42 | 43 |
43 InspectorBackendClass.prototype = { | 44 InspectorBackendClass.prototype = { |
44 | 45 |
46 initProtocolAgentsClass: function() { | |
vsevik
2014/03/06 16:30:08
{ on the next line.
This method should be private.
sergeyv
2014/03/06 16:45:37
Done.
| |
47 | |
48 window.Protocol = {}; | |
49 | |
50 /** | |
51 * @constructor | |
52 * @param {!Object.<string, !Object>} agentsMap | |
53 */ | |
54 window.Protocol.Agents = function(agentsMap) { | |
55 this._agentsMap = agentsMap; | |
56 }; | |
57 }, | |
58 | |
59 /** | |
60 * @param {string} domain | |
61 */ | |
62 _addProtocolAgentsMethodIfNeeded: function(domain) | |
63 { | |
64 if (this._agentPrototypes[domain]) | |
65 return; | |
66 | |
67 var upperCaseLength = 0; | |
68 while (upperCaseLength < domain.length && domain[upperCaseLength].toLowe rCase() !== domain[upperCaseLength]) | |
69 ++upperCaseLength; | |
70 | |
71 var methodName = domain.substr(0, upperCaseLength).toLowerCase() + domai n.slice(upperCaseLength) + "Agent"; | |
72 | |
73 /** | |
74 * @this {Protocol.Agents} | |
75 */ | |
76 function agentGetter() | |
77 { | |
78 return this._agentsMap[domain]; | |
79 } | |
80 | |
81 window.Protocol.Agents.prototype[methodName] = agentGetter; | |
82 }, | |
83 | |
45 /** | 84 /** |
46 * @return {!InspectorBackendClass.Connection} | 85 * @return {!InspectorBackendClass.Connection} |
47 */ | 86 */ |
48 connection: function() | 87 connection: function() |
49 { | 88 { |
50 if (!this._connection) | 89 if (!this._connection) |
51 throw "Main connection was not initialized"; | 90 throw "Main connection was not initialized"; |
52 return this._connection; | 91 return this._connection; |
53 }, | 92 }, |
54 | 93 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 | 131 |
93 /** | 132 /** |
94 * @param {string} method | 133 * @param {string} method |
95 * @param {!Array.<!Object>} signature | 134 * @param {!Array.<!Object>} signature |
96 * @param {!Array.<string>} replyArgs | 135 * @param {!Array.<string>} replyArgs |
97 * @param {boolean} hasErrorData | 136 * @param {boolean} hasErrorData |
98 */ | 137 */ |
99 registerCommand: function(method, signature, replyArgs, hasErrorData) | 138 registerCommand: function(method, signature, replyArgs, hasErrorData) |
100 { | 139 { |
101 var domainAndMethod = method.split("."); | 140 var domainAndMethod = method.split("."); |
141 this._addProtocolAgentsMethodIfNeeded(domainAndMethod[0]); | |
vsevik
2014/03/06 16:30:08
You could move this call to _agentPrototype and ge
sergeyv
2014/03/06 16:45:37
Done.
| |
102 this._agentPrototype(domainAndMethod[0]).registerCommand(domainAndMethod [1], signature, replyArgs, hasErrorData); | 142 this._agentPrototype(domainAndMethod[0]).registerCommand(domainAndMethod [1], signature, replyArgs, hasErrorData); |
103 this._initialized = true; | 143 this._initialized = true; |
104 }, | 144 }, |
105 | 145 |
106 /** | 146 /** |
107 * @param {string} type | 147 * @param {string} type |
108 * @param {!Object} values | 148 * @param {!Object} values |
109 */ | 149 */ |
110 registerEnum: function(type, values) | 150 registerEnum: function(type, values) |
111 { | 151 { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 /** | 371 /** |
332 * @param {string} domain | 372 * @param {string} domain |
333 * @return {!InspectorBackendClass.AgentPrototype} | 373 * @return {!InspectorBackendClass.AgentPrototype} |
334 */ | 374 */ |
335 agent: function(domain) | 375 agent: function(domain) |
336 { | 376 { |
337 return this._agents[domain]; | 377 return this._agents[domain]; |
338 }, | 378 }, |
339 | 379 |
340 /** | 380 /** |
381 * @return {!Object.<string, !Object>} | |
382 */ | |
383 agentsMap: function() | |
384 { | |
385 return this._agents; | |
386 }, | |
387 | |
388 /** | |
341 * @param {string} domain | 389 * @param {string} domain |
342 * @param {string} method | 390 * @param {string} method |
343 * @param {?Object} params | 391 * @param {?Object} params |
344 * @param {?function(*)} callback | 392 * @param {?function(*)} callback |
345 * @private | 393 * @private |
346 */ | 394 */ |
347 _wrapCallbackAndSendMessageObject: function(domain, method, params, callback ) | 395 _wrapCallbackAndSendMessageObject: function(domain, method, params, callback ) |
348 { | 396 { |
349 var messageObject = {}; | 397 var messageObject = {}; |
350 messageObject.method = method; | 398 messageObject.method = method; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 } | 755 } |
708 | 756 |
709 } | 757 } |
710 | 758 |
711 InspectorBackendClass.Options = { | 759 InspectorBackendClass.Options = { |
712 dumpInspectorTimeStats: false, | 760 dumpInspectorTimeStats: false, |
713 dumpInspectorProtocolMessages: false | 761 dumpInspectorProtocolMessages: false |
714 } | 762 } |
715 | 763 |
716 InspectorBackend = new InspectorBackendClass(); | 764 InspectorBackend = new InspectorBackendClass(); |
OLD | NEW |