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 { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 DevToolsProtocol::Response::Response(int id, int error_code) | 60 DevToolsProtocol::Response::Response(int id, int error_code) |
61 : id_(id), | 61 : id_(id), |
62 error_code_(error_code) { | 62 error_code_(error_code) { |
63 } | 63 } |
64 | 64 |
65 // static | 65 // static |
66 DevToolsProtocol::Notification* DevToolsProtocol::ParseNotification( | 66 DevToolsProtocol::Notification* DevToolsProtocol::ParseNotification( |
67 const std::string& json) { | 67 const std::string& json) { |
68 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); | 68 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); |
69 if (!value || !value->IsType(Value::TYPE_DICTIONARY)) | 69 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) |
70 return NULL; | 70 return NULL; |
71 | 71 |
72 scoped_ptr<base::DictionaryValue> dict( | 72 scoped_ptr<base::DictionaryValue> dict( |
73 static_cast<base::DictionaryValue*>(value.release())); | 73 static_cast<base::DictionaryValue*>(value.release())); |
74 | 74 |
75 std::string method; | 75 std::string method; |
76 if (!dict->GetString(kMethodParam, &method)) | 76 if (!dict->GetString(kMethodParam, &method)) |
77 return NULL; | 77 return NULL; |
78 | 78 |
79 base::DictionaryValue* params = NULL; | 79 base::DictionaryValue* params = NULL; |
80 dict->GetDictionary(kParamsParam, ¶ms); | 80 dict->GetDictionary(kParamsParam, ¶ms); |
81 return new Notification(method, params); | 81 return new Notification(method, params); |
82 } | 82 } |
83 | 83 |
84 DevToolsProtocol::Response* DevToolsProtocol::ParseResponse( | 84 DevToolsProtocol::Response* DevToolsProtocol::ParseResponse( |
85 const std::string& json) { | 85 const std::string& json) { |
86 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); | 86 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); |
87 if (!value || !value->IsType(Value::TYPE_DICTIONARY)) | 87 if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) |
88 return NULL; | 88 return NULL; |
89 | 89 |
90 scoped_ptr<base::DictionaryValue> dict( | 90 scoped_ptr<base::DictionaryValue> dict( |
91 static_cast<base::DictionaryValue*>(value.release())); | 91 static_cast<base::DictionaryValue*>(value.release())); |
92 | 92 |
93 int id; | 93 int id; |
94 if (!dict->GetInteger(kIdParam, &id)) | 94 if (!dict->GetInteger(kIdParam, &id)) |
95 return NULL; | 95 return NULL; |
96 | 96 |
97 int error_code = 0; | 97 int error_code = 0; |
98 base::DictionaryValue* error_dict = NULL; | 98 base::DictionaryValue* error_dict = NULL; |
99 if (dict->GetDictionary(kErrorParam, &error_dict)) | 99 if (dict->GetDictionary(kErrorParam, &error_dict)) |
100 error_dict->GetInteger(kErrorCodeParam, &error_code); | 100 error_dict->GetInteger(kErrorCodeParam, &error_code); |
101 return new Response(id, error_code); | 101 return new Response(id, error_code); |
102 } | 102 } |
OLD | NEW |