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 "chrome/browser/devtools/devtools_protocol.h" | 5 #include "chrome/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 { | 10 namespace { |
11 const char kIdParam[] = "id"; | 11 const char kIdParam[] = "id"; |
12 const char kMethodParam[] = "method"; | 12 const char kMethodParam[] = "method"; |
13 const char kParamsParam[] = "params"; | 13 const char kParamsParam[] = "params"; |
| 14 const char kErrorParam[] = "error"; |
| 15 const char kErrorCodeParam[] = "code"; |
14 } // namespace | 16 } // namespace |
15 | 17 |
16 DevToolsProtocol::Message::~Message() { | 18 DevToolsProtocol::Message::~Message() { |
17 } | 19 } |
18 | 20 |
19 DevToolsProtocol::Message::Message(const std::string& method, | 21 DevToolsProtocol::Message::Message(const std::string& method, |
20 base::DictionaryValue* params) | 22 base::DictionaryValue* params) |
21 : method_(method), | 23 : method_(method), |
22 params_(params ? params->DeepCopy() : NULL) { | 24 params_(params ? params->DeepCopy() : NULL) { |
23 } | 25 } |
(...skipping 21 matching lines...) Expand all Loading... |
45 } | 47 } |
46 | 48 |
47 DevToolsProtocol::Notification::~Notification() { | 49 DevToolsProtocol::Notification::~Notification() { |
48 } | 50 } |
49 | 51 |
50 DevToolsProtocol::Notification::Notification(const std::string& method, | 52 DevToolsProtocol::Notification::Notification(const std::string& method, |
51 base::DictionaryValue* params) | 53 base::DictionaryValue* params) |
52 : Message(method, params) { | 54 : Message(method, params) { |
53 } | 55 } |
54 | 56 |
| 57 DevToolsProtocol::Response::~Response() { |
| 58 } |
| 59 |
| 60 DevToolsProtocol::Response::Response(int id, int error_code) |
| 61 : id_(id), |
| 62 error_code_(error_code) { |
| 63 } |
| 64 |
55 // static | 65 // static |
56 DevToolsProtocol::Notification* DevToolsProtocol::ParseNotification( | 66 DevToolsProtocol::Notification* DevToolsProtocol::ParseNotification( |
57 const std::string& json) { | 67 const std::string& json) { |
58 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); | 68 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); |
59 if (!value || !value->IsType(Value::TYPE_DICTIONARY)) | 69 if (!value || !value->IsType(Value::TYPE_DICTIONARY)) |
60 return NULL; | 70 return NULL; |
61 | 71 |
62 scoped_ptr<base::DictionaryValue> dict( | 72 scoped_ptr<base::DictionaryValue> dict( |
63 static_cast<base::DictionaryValue*>(value.release())); | 73 static_cast<base::DictionaryValue*>(value.release())); |
64 | 74 |
65 std::string method; | 75 std::string method; |
66 if (!dict->GetString(kMethodParam, &method)) | 76 if (!dict->GetString(kMethodParam, &method)) |
67 return NULL; | 77 return NULL; |
68 | 78 |
69 base::DictionaryValue* params = NULL; | 79 base::DictionaryValue* params = NULL; |
70 dict->GetDictionary(kParamsParam, ¶ms); | 80 dict->GetDictionary(kParamsParam, ¶ms); |
71 return new Notification(method, params); | 81 return new Notification(method, params); |
72 } | 82 } |
| 83 |
| 84 DevToolsProtocol::Response* DevToolsProtocol::ParseResponse( |
| 85 const std::string& json) { |
| 86 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); |
| 87 if (!value || !value->IsType(Value::TYPE_DICTIONARY)) |
| 88 return NULL; |
| 89 |
| 90 scoped_ptr<base::DictionaryValue> dict( |
| 91 static_cast<base::DictionaryValue*>(value.release())); |
| 92 |
| 93 int id; |
| 94 if (!dict->GetInteger(kIdParam, &id)) |
| 95 return NULL; |
| 96 |
| 97 int error_code = 0; |
| 98 base::DictionaryValue* error_dict = NULL; |
| 99 if (dict->GetDictionary(kErrorParam, &error_dict)) |
| 100 error_dict->GetInteger(kErrorCodeParam, &error_code); |
| 101 return new Response(id, error_code); |
| 102 } |
OLD | NEW |