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 #include "content/browser/devtools/devtools_protocol.h" | 5 #include "content/browser/devtools/devtools_protocol.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 | 10 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 scoped_refptr<DevToolsProtocol::Response> | 172 scoped_refptr<DevToolsProtocol::Response> |
173 DevToolsProtocol::Handler::HandleCommand( | 173 DevToolsProtocol::Handler::HandleCommand( |
174 scoped_refptr<DevToolsProtocol::Command> command) { | 174 scoped_refptr<DevToolsProtocol::Command> command) { |
175 CommandHandlers::iterator it = command_handlers_.find(command->method()); | 175 CommandHandlers::iterator it = command_handlers_.find(command->method()); |
176 if (it == command_handlers_.end()) | 176 if (it == command_handlers_.end()) |
177 return NULL; | 177 return NULL; |
178 return (it->second).Run(command); | 178 return (it->second).Run(command); |
179 } | 179 } |
180 | 180 |
| 181 void DevToolsProtocol::Handler::HandleNotification( |
| 182 scoped_refptr<DevToolsProtocol::Notification> notification) { |
| 183 NotificationHandlers::iterator it = |
| 184 notification_handlers_.find(notification->method()); |
| 185 if (it == notification_handlers_.end()) |
| 186 return; |
| 187 (it->second).Run(notification); |
| 188 } |
| 189 |
181 void DevToolsProtocol::Handler::SetNotifier(const Notifier& notifier) { | 190 void DevToolsProtocol::Handler::SetNotifier(const Notifier& notifier) { |
182 notifier_ = notifier; | 191 notifier_ = notifier; |
183 } | 192 } |
184 | 193 |
185 DevToolsProtocol::Handler::Handler() { | 194 DevToolsProtocol::Handler::Handler() { |
186 } | 195 } |
187 | 196 |
188 void DevToolsProtocol::Handler::RegisterCommandHandler( | 197 void DevToolsProtocol::Handler::RegisterCommandHandler( |
189 const std::string& command, | 198 const std::string& command, |
190 const CommandHandler& handler) { | 199 const CommandHandler& handler) { |
191 command_handlers_[command] = handler; | 200 command_handlers_[command] = handler; |
192 } | 201 } |
193 | 202 |
| 203 void DevToolsProtocol::Handler::RegisterNotificationHandler( |
| 204 const std::string& notification, |
| 205 const NotificationHandler& handler) { |
| 206 notification_handlers_[notification] = handler; |
| 207 } |
| 208 |
194 void DevToolsProtocol::Handler::SendNotification( | 209 void DevToolsProtocol::Handler::SendNotification( |
195 const std::string& method, | 210 const std::string& method, |
196 base::DictionaryValue* params) { | 211 base::DictionaryValue* params) { |
197 scoped_refptr<DevToolsProtocol::Notification> notification = | 212 scoped_refptr<DevToolsProtocol::Notification> notification = |
198 new DevToolsProtocol::Notification(method, params); | 213 new DevToolsProtocol::Notification(method, params); |
199 SendRawMessage(notification->Serialize()); | 214 SendRawMessage(notification->Serialize()); |
200 } | 215 } |
201 | 216 |
202 void DevToolsProtocol::Handler::SendAsyncResponse( | 217 void DevToolsProtocol::Handler::SendAsyncResponse( |
203 scoped_refptr<DevToolsProtocol::Response> response) { | 218 scoped_refptr<DevToolsProtocol::Response> response) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 new Response(0, kErrorParseError, error_message); | 337 new Response(0, kErrorParseError, error_message); |
323 if (error_response) | 338 if (error_response) |
324 *error_response = response->Serialize(); | 339 *error_response = response->Serialize(); |
325 return NULL; | 340 return NULL; |
326 } | 341 } |
327 | 342 |
328 return static_cast<base::DictionaryValue*>(message.release()); | 343 return static_cast<base::DictionaryValue*>(message.release()); |
329 } | 344 } |
330 | 345 |
331 } // namespace content | 346 } // namespace content |
OLD | NEW |