Chromium Code Reviews| 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 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 base::DictionaryValue notification; | 111 base::DictionaryValue notification; |
| 112 notification.SetString("method", method_); | 112 notification.SetString("method", method_); |
| 113 if (params_.get()) | 113 if (params_.get()) |
| 114 notification.Set("params", params_->DeepCopy()); | 114 notification.Set("params", params_->DeepCopy()); |
| 115 | 115 |
| 116 std::string json_notification; | 116 std::string json_notification; |
| 117 base::JSONWriter::Write(¬ification, &json_notification); | 117 base::JSONWriter::Write(¬ification, &json_notification); |
| 118 return json_notification; | 118 return json_notification; |
| 119 } | 119 } |
| 120 | 120 |
| 121 DevToolsProtocol::Handler::~Handler() { | |
| 122 } | |
| 123 | |
| 124 DevToolsProtocol::Handler::Handler(const Notifier& notifier) | |
|
pfeldman
2013/02/13 17:38:24
Method definition order should match the declarati
kkania
2013/02/13 19:17:19
Done.
| |
| 125 : notifier_(notifier) { | |
| 126 } | |
| 127 | |
| 128 scoped_ptr<DevToolsProtocol::Response> | |
| 129 DevToolsProtocol::Handler::HandleCommand( | |
| 130 DevToolsProtocol::Command* command) { | |
| 131 CommandHandlers::iterator it = command_handlers_.find(command->method()); | |
| 132 if (it == command_handlers_.end()) | |
| 133 return scoped_ptr<DevToolsProtocol::Response>(); | |
| 134 return (it->second).Run(command); | |
| 135 } | |
| 136 | |
| 137 void DevToolsProtocol::Handler::RegisterCommandHandler( | |
| 138 const std::string& command, | |
| 139 const CommandHandler& handler) { | |
| 140 command_handlers_[command] = handler; | |
| 141 } | |
| 142 | |
| 143 void DevToolsProtocol::Handler::SendNotification( | |
| 144 const std::string& method, | |
| 145 base::DictionaryValue* params) { | |
| 146 DevToolsProtocol::Notification notification(method, params); | |
| 147 notifier_.Run(notification.Serialize()); | |
| 148 } | |
| 149 | |
| 121 // static | 150 // static |
| 122 DevToolsProtocol::Command* DevToolsProtocol::ParseCommand( | 151 DevToolsProtocol::Command* DevToolsProtocol::ParseCommand( |
| 123 const std::string& json, | 152 const std::string& json, |
| 124 std::string* error_response) { | 153 std::string* error_response) { |
| 125 int parse_error_code; | 154 int parse_error_code; |
| 126 std::string error_message; | 155 std::string error_message; |
| 127 scoped_ptr<base::Value> command( | 156 scoped_ptr<base::Value> command( |
| 128 base::JSONReader::ReadAndReturnError( | 157 base::JSONReader::ReadAndReturnError( |
| 129 json, 0, &parse_error_code, &error_message)); | 158 json, 0, &parse_error_code, &error_message)); |
| 130 | 159 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 157 } | 186 } |
| 158 | 187 |
| 159 std::string domain = method.substr(0, pos); | 188 std::string domain = method.substr(0, pos); |
| 160 | 189 |
| 161 base::DictionaryValue* params = NULL; | 190 base::DictionaryValue* params = NULL; |
| 162 command_dict->GetDictionary("params", ¶ms); | 191 command_dict->GetDictionary("params", ¶ms); |
| 163 return new Command(id, domain, method, params ? params->DeepCopy() : NULL); | 192 return new Command(id, domain, method, params ? params->DeepCopy() : NULL); |
| 164 } | 193 } |
| 165 | 194 |
| 166 } // namespace content | 195 } // namespace content |
| OLD | NEW |