| 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 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 scoped_ptr<base::DictionaryValue> | 45 scoped_ptr<base::DictionaryValue> |
| 46 DevToolsProtocol::CreateInvalidParamsResponse(int command_id, | 46 DevToolsProtocol::CreateInvalidParamsResponse(int command_id, |
| 47 const std::string& param) { | 47 const std::string& param) { |
| 48 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | 48 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); |
| 49 base::DictionaryValue* error_object = new base::DictionaryValue(); | 49 base::DictionaryValue* error_object = new base::DictionaryValue(); |
| 50 response->Set(kErrorParam, error_object); | 50 response->Set(kErrorParam, error_object); |
| 51 error_object->SetInteger(kErrorCodeParam, kErrorInvalidParams); | 51 error_object->SetInteger(kErrorCodeParam, kErrorInvalidParams); |
| 52 error_object->SetString(kErrorMessageParam, | 52 error_object->SetString(kErrorMessageParam, |
| 53 base::StringPrintf("Missing or invalid '%s' parameter", param.c_str())); | 53 base::StringPrintf("Missing or invalid '%s' parameter", param.c_str())); |
| 54 | 54 |
| 55 return response.Pass(); | 55 return response; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // static | 58 // static |
| 59 scoped_ptr<base::DictionaryValue> | 59 scoped_ptr<base::DictionaryValue> |
| 60 DevToolsProtocol::CreateSuccessResponse( | 60 DevToolsProtocol::CreateSuccessResponse( |
| 61 int command_id, | 61 int command_id, |
| 62 scoped_ptr<base::DictionaryValue> result) { | 62 scoped_ptr<base::DictionaryValue> result) { |
| 63 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); | 63 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); |
| 64 response->SetInteger(kIdParam, command_id); | 64 response->SetInteger(kIdParam, command_id); |
| 65 response->Set(kResultParam, | 65 response->Set(kResultParam, |
| 66 result ? result.release() : new base::DictionaryValue()); | 66 result ? result.release() : new base::DictionaryValue()); |
| 67 | 67 |
| 68 return response.Pass(); | 68 return response; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // static | 71 // static |
| 72 bool DevToolsProtocol::ParseCommand(base::DictionaryValue* command, | 72 bool DevToolsProtocol::ParseCommand(base::DictionaryValue* command, |
| 73 int* command_id, | 73 int* command_id, |
| 74 std::string* method, | 74 std::string* method, |
| 75 base::DictionaryValue** params) { | 75 base::DictionaryValue** params) { |
| 76 if (!command) | 76 if (!command) |
| 77 return false; | 77 return false; |
| 78 | 78 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 if (!dict->GetInteger(kIdParam, command_id)) | 125 if (!dict->GetInteger(kIdParam, command_id)) |
| 126 return false; | 126 return false; |
| 127 | 127 |
| 128 *error_code = 0; | 128 *error_code = 0; |
| 129 base::DictionaryValue* error_dict = nullptr; | 129 base::DictionaryValue* error_dict = nullptr; |
| 130 if (dict->GetDictionary(kErrorParam, &error_dict)) | 130 if (dict->GetDictionary(kErrorParam, &error_dict)) |
| 131 error_dict->GetInteger(kErrorCodeParam, error_code); | 131 error_dict->GetInteger(kErrorCodeParam, error_code); |
| 132 return true; | 132 return true; |
| 133 } | 133 } |
| OLD | NEW |