| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ |
| 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ |
| 7 | 7 |
| 8 #include <map> |
| 8 #include <string> | 9 #include <string> |
| 10 |
| 9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 11 #include "base/values.h" | 14 #include "base/values.h" |
| 12 | 15 |
| 13 namespace content { | 16 namespace content { |
| 14 | 17 |
| 15 // Utility classes for processing DevTools remote debugging messages. | 18 // Utility classes for processing DevTools remote debugging messages. |
| 16 // https://developers.google.com/chrome-developer-tools/docs/debugger-protocol | 19 // https://developers.google.com/chrome-developer-tools/docs/debugger-protocol |
| 17 class DevToolsProtocol { | 20 class DevToolsProtocol { |
| 18 public: | 21 public: |
| 22 typedef base::Callback<void(const std::string& message)> Notifier; |
| 23 |
| 19 // JSON RPC 2.0 spec: http://www.jsonrpc.org/specification#error_object | 24 // JSON RPC 2.0 spec: http://www.jsonrpc.org/specification#error_object |
| 20 enum Error { | 25 enum Error { |
| 21 kErrorParseError = -32700, | 26 kErrorParseError = -32700, |
| 22 kErrorInvalidRequest = -32600, | 27 kErrorInvalidRequest = -32600, |
| 23 kErrorNoSuchMethod = -32601, | 28 kErrorNoSuchMethod = -32601, |
| 24 kErrorInvalidParams = -32602, | 29 kErrorInvalidParams = -32602, |
| 25 kErrorInternalError = -32603 | 30 kErrorInternalError = -32603 |
| 26 }; | 31 }; |
| 27 | 32 |
| 28 class Response; | 33 class Response; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 93 |
| 89 std::string Serialize(); | 94 std::string Serialize(); |
| 90 | 95 |
| 91 private: | 96 private: |
| 92 std::string method_; | 97 std::string method_; |
| 93 scoped_ptr<base::DictionaryValue> params_; | 98 scoped_ptr<base::DictionaryValue> params_; |
| 94 | 99 |
| 95 DISALLOW_COPY_AND_ASSIGN(Notification); | 100 DISALLOW_COPY_AND_ASSIGN(Notification); |
| 96 }; | 101 }; |
| 97 | 102 |
| 103 class Handler { |
| 104 public: |
| 105 typedef base::Callback<scoped_ptr<DevToolsProtocol::Response>( |
| 106 DevToolsProtocol::Command* command)> CommandHandler; |
| 107 |
| 108 virtual ~Handler(); |
| 109 |
| 110 virtual scoped_ptr<DevToolsProtocol::Response> HandleCommand( |
| 111 DevToolsProtocol::Command* command); |
| 112 |
| 113 void SetNotifier(const Notifier& notifier); |
| 114 |
| 115 protected: |
| 116 Handler(); |
| 117 |
| 118 void RegisterCommandHandler(const std::string& command, |
| 119 const CommandHandler& handler); |
| 120 |
| 121 // Sends notification to the client. Takes ownership of |params|. |
| 122 void SendNotification(const std::string& method, |
| 123 base::DictionaryValue* params); |
| 124 |
| 125 private: |
| 126 typedef std::map<std::string, CommandHandler> CommandHandlers; |
| 127 |
| 128 Notifier notifier_; |
| 129 CommandHandlers command_handlers_; |
| 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(Handler); |
| 132 }; |
| 133 |
| 98 static Command* ParseCommand(const std::string& json, | 134 static Command* ParseCommand(const std::string& json, |
| 99 std::string* error_response); | 135 std::string* error_response); |
| 100 | 136 |
| 101 private: | 137 private: |
| 102 DevToolsProtocol() {} | 138 DevToolsProtocol() {} |
| 103 ~DevToolsProtocol() {} | 139 ~DevToolsProtocol() {} |
| 104 }; | 140 }; |
| 105 | 141 |
| 106 } // namespace content | 142 } // namespace content |
| 107 | 143 |
| 108 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ | 144 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ |
| OLD | NEW |