Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/debugger/devtools_browser_target.h" | |
| 6 | |
| 7 #include "base/json/json_reader.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/values.h" | |
| 11 | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 DevToolsBrowserTarget::DevToolsBrowserTarget(int connection_id) | |
| 16 : connection_id_(connection_id) { | |
| 17 } | |
| 18 | |
| 19 DevToolsBrowserTarget::~DevToolsBrowserTarget() { | |
| 20 } | |
| 21 | |
| 22 void DevToolsBrowserTarget::RegisterHandler(const std::string& domain, | |
| 23 Handler* handler) { | |
| 24 handlers_[domain] = handler; | |
| 25 } | |
| 26 | |
| 27 base::Value* DevToolsBrowserTarget::OnWebSocketMessage( | |
| 28 int connection_id, const std::string& data) { | |
| 29 scoped_ptr<base::Value> command(base::JSONReader::Read(data)); | |
| 30 int request_id; | |
| 31 std::string domain; | |
| 32 std::string method; | |
| 33 base::DictionaryValue* params = NULL; | |
| 34 if (command && command->IsType(base::Value::TYPE_DICTIONARY)) { | |
|
pfeldman
2012/12/14 10:39:33
Fast return otherwise.
bulach
2012/12/14 16:03:52
Done.
| |
| 35 base::DictionaryValue* command_dict; | |
| 36 command->GetAsDictionary(&command_dict); | |
| 37 command_dict->GetInteger("id", &request_id); | |
| 38 command_dict->GetString("method", &method); | |
| 39 command_dict->GetDictionary("params", ¶ms); | |
| 40 } | |
| 41 size_t pos = method.find("."); | |
| 42 if (pos != std::string::npos) | |
|
pfeldman
2012/12/14 10:39:33
Return "error" response that has request id and er
bulach
2012/12/14 16:03:52
Done.
| |
| 43 domain = method.substr(0, pos); | |
| 44 if (domain.empty() || handlers_.find(domain) == handlers_.end()) | |
| 45 return NULL; | |
| 46 base::Value* domain_response = handlers_[domain]->OnProtocolCommand( | |
| 47 connection_id, request_id, method, params); | |
| 48 base::DictionaryValue* response = new base::DictionaryValue(); | |
| 49 response->SetInteger("id", request_id); | |
| 50 response->Set("response", domain_response); | |
| 51 return response; | |
| 52 } | |
| 53 | |
| 54 } // namespace content | |
| OLD | NEW |