Index: Source/devtools/front_end/InspectorBackend.js |
diff --git a/Source/devtools/front_end/InspectorBackend.js b/Source/devtools/front_end/InspectorBackend.js |
index e8c948d194365b56897d70fd8c093da3e3ec2b88..1c790f65b636c921efd04b8ca7dbd6bbe47602c6 100644 |
--- a/Source/devtools/front_end/InspectorBackend.js |
+++ b/Source/devtools/front_end/InspectorBackend.js |
@@ -38,10 +38,49 @@ function InspectorBackendClass() |
this._dispatcherPrototypes = {}; |
this._initialized = false; |
this._enums = {}; |
+ this.initProtocolAgentsClass(); |
} |
InspectorBackendClass.prototype = { |
+ 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.
|
+ |
+ window.Protocol = {}; |
+ |
+ /** |
+ * @constructor |
+ * @param {!Object.<string, !Object>} agentsMap |
+ */ |
+ window.Protocol.Agents = function(agentsMap) { |
+ this._agentsMap = agentsMap; |
+ }; |
+ }, |
+ |
+ /** |
+ * @param {string} domain |
+ */ |
+ _addProtocolAgentsMethodIfNeeded: function(domain) |
+ { |
+ if (this._agentPrototypes[domain]) |
+ return; |
+ |
+ var upperCaseLength = 0; |
+ while (upperCaseLength < domain.length && domain[upperCaseLength].toLowerCase() !== domain[upperCaseLength]) |
+ ++upperCaseLength; |
+ |
+ var methodName = domain.substr(0, upperCaseLength).toLowerCase() + domain.slice(upperCaseLength) + "Agent"; |
+ |
+ /** |
+ * @this {Protocol.Agents} |
+ */ |
+ function agentGetter() |
+ { |
+ return this._agentsMap[domain]; |
+ } |
+ |
+ window.Protocol.Agents.prototype[methodName] = agentGetter; |
+ }, |
+ |
/** |
* @return {!InspectorBackendClass.Connection} |
*/ |
@@ -99,6 +138,7 @@ InspectorBackendClass.prototype = { |
registerCommand: function(method, signature, replyArgs, hasErrorData) |
{ |
var domainAndMethod = method.split("."); |
+ 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.
|
this._agentPrototype(domainAndMethod[0]).registerCommand(domainAndMethod[1], signature, replyArgs, hasErrorData); |
this._initialized = true; |
}, |
@@ -338,6 +378,14 @@ InspectorBackendClass.Connection.prototype = { |
}, |
/** |
+ * @return {!Object.<string, !Object>} |
+ */ |
+ agentsMap: function() |
+ { |
+ return this._agents; |
+ }, |
+ |
+ /** |
* @param {string} domain |
* @param {string} method |
* @param {?Object} params |