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/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 domain_ = method.substr(0, pos); | 47 domain_ = method.substr(0, pos); |
48 } | 48 } |
49 | 49 |
50 DevToolsProtocol::Command::~Command() { | 50 DevToolsProtocol::Command::~Command() { |
51 } | 51 } |
52 | 52 |
53 std::string DevToolsProtocol::Command::Serialize() { | 53 std::string DevToolsProtocol::Command::Serialize() { |
54 DictionaryValue command; | 54 DictionaryValue command; |
55 command.SetInteger(kIdParam, id_); | 55 command.SetInteger(kIdParam, id_); |
56 command.SetString(kMethodParam, method_); | 56 command.SetString(kMethodParam, method_); |
57 if (params_.get()) | 57 if (params_) |
58 command.Set(kParamsParam, params_->DeepCopy()); | 58 command.Set(kParamsParam, params_->DeepCopy()); |
59 | 59 |
60 std::string json_command; | 60 std::string json_command; |
61 base::JSONWriter::Write(&command, &json_command); | 61 base::JSONWriter::Write(&command, &json_command); |
62 return json_command; | 62 return json_command; |
63 } | 63 } |
64 | 64 |
65 scoped_ptr<DevToolsProtocol::Response> | 65 scoped_ptr<DevToolsProtocol::Response> |
66 DevToolsProtocol::Command::SuccessResponse(DictionaryValue* result) { | 66 DevToolsProtocol::Command::SuccessResponse(DictionaryValue* result) { |
67 return scoped_ptr<DevToolsProtocol::Response>( | 67 return scoped_ptr<DevToolsProtocol::Response>( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 if (id_ != kNoId) | 101 if (id_ != kNoId) |
102 response.SetInteger(kIdParam, id_); | 102 response.SetInteger(kIdParam, id_); |
103 | 103 |
104 if (error_code_) { | 104 if (error_code_) { |
105 DictionaryValue* error_object = new DictionaryValue(); | 105 DictionaryValue* error_object = new DictionaryValue(); |
106 response.Set(kErrorParam, error_object); | 106 response.Set(kErrorParam, error_object); |
107 error_object->SetInteger(kErrorCodeParam, error_code_); | 107 error_object->SetInteger(kErrorCodeParam, error_code_); |
108 if (!error_message_.empty()) | 108 if (!error_message_.empty()) |
109 error_object->SetString(kErrorMessageParam, error_message_); | 109 error_object->SetString(kErrorMessageParam, error_message_); |
110 } else if (result_.get()) { | 110 } else if (result_) { |
111 response.Set(kResultParam, result_->DeepCopy()); | 111 response.Set(kResultParam, result_->DeepCopy()); |
112 } | 112 } |
113 | 113 |
114 std::string json_response; | 114 std::string json_response; |
115 base::JSONWriter::Write(&response, &json_response); | 115 base::JSONWriter::Write(&response, &json_response); |
116 return json_response; | 116 return json_response; |
117 } | 117 } |
118 | 118 |
119 DevToolsProtocol::Response::Response(int id, DictionaryValue* result) | 119 DevToolsProtocol::Response::Response(int id, DictionaryValue* result) |
120 : id_(id), | 120 : id_(id), |
(...skipping 17 matching lines...) Expand all Loading... |
138 DictionaryValue* params) | 138 DictionaryValue* params) |
139 : Message(method, params) { | 139 : Message(method, params) { |
140 } | 140 } |
141 | 141 |
142 DevToolsProtocol::Notification::~Notification() { | 142 DevToolsProtocol::Notification::~Notification() { |
143 } | 143 } |
144 | 144 |
145 std::string DevToolsProtocol::Notification::Serialize() { | 145 std::string DevToolsProtocol::Notification::Serialize() { |
146 DictionaryValue notification; | 146 DictionaryValue notification; |
147 notification.SetString(kMethodParam, method_); | 147 notification.SetString(kMethodParam, method_); |
148 if (params_.get()) | 148 if (params_) |
149 notification.Set(kParamsParam, params_->DeepCopy()); | 149 notification.Set(kParamsParam, params_->DeepCopy()); |
150 | 150 |
151 std::string json_notification; | 151 std::string json_notification; |
152 base::JSONWriter::Write(¬ification, &json_notification); | 152 base::JSONWriter::Write(¬ification, &json_notification); |
153 return json_notification; | 153 return json_notification; |
154 } | 154 } |
155 | 155 |
156 DevToolsProtocol::Handler::~Handler() { | 156 DevToolsProtocol::Handler::~Handler() { |
157 } | 157 } |
158 | 158 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 Response response(0, kErrorParseError, error_message); | 257 Response response(0, kErrorParseError, error_message); |
258 if (error_response) | 258 if (error_response) |
259 *error_response = response.Serialize(); | 259 *error_response = response.Serialize(); |
260 return NULL; | 260 return NULL; |
261 } | 261 } |
262 | 262 |
263 return static_cast<DictionaryValue*>(message.release()); | 263 return static_cast<DictionaryValue*>(message.release()); |
264 } | 264 } |
265 | 265 |
266 } // namespace content | 266 } // namespace content |
OLD | NEW |