| 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 <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 Notification(const std::string& method, | 120 Notification(const std::string& method, |
| 121 base::DictionaryValue* params); | 121 base::DictionaryValue* params); |
| 122 | 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(Notification); | 123 DISALLOW_COPY_AND_ASSIGN(Notification); |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 class CONTENT_EXPORT Handler { | 126 class CONTENT_EXPORT Handler { |
| 127 public: | 127 public: |
| 128 typedef base::Callback<scoped_refptr<DevToolsProtocol::Response>( | 128 typedef base::Callback<scoped_refptr<DevToolsProtocol::Response>( |
| 129 scoped_refptr<DevToolsProtocol::Command> command)> CommandHandler; | 129 scoped_refptr<DevToolsProtocol::Command> command)> CommandHandler; |
| 130 typedef base::Callback<void( | |
| 131 scoped_refptr<DevToolsProtocol::Notification> notification)> | |
| 132 NotificationHandler; | |
| 133 | 130 |
| 134 virtual ~Handler(); | 131 virtual ~Handler(); |
| 135 | 132 |
| 136 virtual scoped_refptr<DevToolsProtocol::Response> HandleCommand( | 133 virtual scoped_refptr<DevToolsProtocol::Response> HandleCommand( |
| 137 scoped_refptr<DevToolsProtocol::Command> command); | 134 scoped_refptr<DevToolsProtocol::Command> command); |
| 138 | 135 |
| 139 virtual void HandleNotification( | |
| 140 scoped_refptr<DevToolsProtocol::Notification> notification); | |
| 141 | |
| 142 void SetNotifier(const Notifier& notifier); | 136 void SetNotifier(const Notifier& notifier); |
| 143 | 137 |
| 144 protected: | 138 protected: |
| 145 Handler(); | 139 Handler(); |
| 146 | 140 |
| 147 void RegisterCommandHandler(const std::string& command, | 141 void RegisterCommandHandler(const std::string& command, |
| 148 const CommandHandler& handler); | 142 const CommandHandler& handler); |
| 149 | 143 |
| 150 void RegisterNotificationHandler(const std::string& notification, | |
| 151 const NotificationHandler& handler); | |
| 152 | |
| 153 // Sends notification to the client. Takes ownership of |params|. | 144 // Sends notification to the client. Takes ownership of |params|. |
| 154 void SendNotification(const std::string& method, | 145 void SendNotification(const std::string& method, |
| 155 base::DictionaryValue* params); | 146 base::DictionaryValue* params); |
| 156 | 147 |
| 157 void SendAsyncResponse(scoped_refptr<DevToolsProtocol::Response> response); | 148 void SendAsyncResponse(scoped_refptr<DevToolsProtocol::Response> response); |
| 158 | 149 |
| 159 // Sends message to client, the caller is presumed to properly | 150 // Sends message to client, the caller is presumed to properly |
| 160 // format the message. | 151 // format the message. |
| 161 void SendRawMessage(const std::string& message); | 152 void SendRawMessage(const std::string& message); |
| 162 | 153 |
| 163 private: | 154 private: |
| 164 typedef std::map<std::string, CommandHandler> CommandHandlers; | 155 typedef std::map<std::string, CommandHandler> CommandHandlers; |
| 165 typedef std::map<std::string, NotificationHandler> NotificationHandlers; | |
| 166 | 156 |
| 167 Notifier notifier_; | 157 Notifier notifier_; |
| 168 CommandHandlers command_handlers_; | 158 CommandHandlers command_handlers_; |
| 169 NotificationHandlers notification_handlers_; | |
| 170 | 159 |
| 171 DISALLOW_COPY_AND_ASSIGN(Handler); | 160 DISALLOW_COPY_AND_ASSIGN(Handler); |
| 172 }; | 161 }; |
| 173 | 162 |
| 174 CONTENT_EXPORT static base::DictionaryValue* ParseMessage( | 163 CONTENT_EXPORT static base::DictionaryValue* ParseMessage( |
| 175 const std::string& json, | 164 const std::string& json, |
| 176 std::string* error_response); | 165 std::string* error_response); |
| 177 | 166 |
| 178 CONTENT_EXPORT static scoped_refptr<Command> ParseCommand( | 167 CONTENT_EXPORT static scoped_refptr<Command> ParseCommand( |
| 179 const std::string& json, | 168 const std::string& json, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 197 static scoped_refptr<Notification> CreateNotification( | 186 static scoped_refptr<Notification> CreateNotification( |
| 198 const std::string& method, base::DictionaryValue* params); | 187 const std::string& method, base::DictionaryValue* params); |
| 199 | 188 |
| 200 DevToolsProtocol() {} | 189 DevToolsProtocol() {} |
| 201 ~DevToolsProtocol() {} | 190 ~DevToolsProtocol() {} |
| 202 }; | 191 }; |
| 203 | 192 |
| 204 } // namespace content | 193 } // namespace content |
| 205 | 194 |
| 206 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ | 195 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_PROTOCOL_H_ |
| OLD | NEW |