Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/protocol/devtools_protocol_client.h" | 5 #include "content/browser/devtools/protocol/devtools_protocol_client.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 const DevToolsCommandId DevToolsProtocolClient::kNoId = -1; | 33 const DevToolsCommandId DevToolsProtocolClient::kNoId = -1; |
| 34 | 34 |
| 35 DevToolsProtocolClient::DevToolsProtocolClient( | 35 DevToolsProtocolClient::DevToolsProtocolClient( |
| 36 const RawMessageCallback& raw_message_callback) | 36 const RawMessageCallback& raw_message_callback) |
| 37 : raw_message_callback_(raw_message_callback) { | 37 : raw_message_callback_(raw_message_callback) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 DevToolsProtocolClient::~DevToolsProtocolClient() { | 40 DevToolsProtocolClient::~DevToolsProtocolClient() { |
| 41 } | 41 } |
| 42 | 42 |
| 43 void DevToolsProtocolClient::SendRawMessage(const std::string& message) { | 43 void DevToolsProtocolClient::SendRawMessage(int session_id, |
| 44 raw_message_callback_.Run(message); | 44 const std::string& message) { |
| 45 raw_message_callback_.Run(session_id, message); | |
| 45 } | 46 } |
| 46 | 47 |
| 47 void DevToolsProtocolClient::SendMessage(const base::DictionaryValue& message) { | 48 void DevToolsProtocolClient::SendMessage(int session_id, |
| 49 const base::DictionaryValue& message) { | |
| 48 std::string json_message; | 50 std::string json_message; |
| 49 base::JSONWriter::Write(message, &json_message); | 51 base::JSONWriter::Write(message, &json_message); |
| 50 SendRawMessage(json_message); | 52 SendRawMessage(session_id, json_message); |
| 51 } | 53 } |
| 52 | 54 |
| 53 void DevToolsProtocolClient::SendNotification( | 55 void DevToolsProtocolClient::SendNotification( |
| 54 const std::string& method, | 56 const std::string& method, |
| 55 scoped_ptr<base::DictionaryValue> params) { | 57 scoped_ptr<base::DictionaryValue> params) { |
| 56 base::DictionaryValue notification; | 58 base::DictionaryValue notification; |
| 57 notification.SetString(kMethodParam, method); | 59 notification.SetString(kMethodParam, method); |
| 58 if (params) | 60 if (params) |
| 59 notification.Set(kParamsParam, params.release()); | 61 notification.Set(kParamsParam, params.release()); |
| 60 | 62 |
| 61 SendMessage(notification); | 63 SendMessage(0, notification); |
| 62 } | 64 } |
| 63 | 65 |
| 64 void DevToolsProtocolClient::SendSuccess( | 66 void DevToolsProtocolClient::SendSuccess( |
| 67 int session_id, | |
| 65 DevToolsCommandId command_id, | 68 DevToolsCommandId command_id, |
| 66 scoped_ptr<base::DictionaryValue> params) { | 69 scoped_ptr<base::DictionaryValue> params) { |
| 70 // TODO: pass | |
|
dgozman
2015/11/06 22:57:27
remove
kozy
2015/11/07 01:54:44
Done.
| |
| 67 base::DictionaryValue response; | 71 base::DictionaryValue response; |
| 68 response.SetInteger(kIdParam, command_id); | 72 response.SetInteger(kIdParam, command_id); |
| 69 | 73 |
| 70 response.Set(kResultParam, | 74 response.Set(kResultParam, |
| 71 params ? params.release() : new base::DictionaryValue()); | 75 params ? params.release() : new base::DictionaryValue()); |
| 72 | 76 |
| 73 SendMessage(response); | 77 SendMessage(session_id, response); |
| 74 } | 78 } |
| 75 | 79 |
| 76 bool DevToolsProtocolClient::SendError(DevToolsCommandId command_id, | 80 bool DevToolsProtocolClient::SendError(int session_id, |
| 81 DevToolsCommandId command_id, | |
| 77 const Response& response) { | 82 const Response& response) { |
| 83 // TODO: ! | |
|
dgozman
2015/11/06 22:57:27
remove
kozy
2015/11/07 01:54:43
Done.
| |
| 78 if (response.status() == kStatusOk || | 84 if (response.status() == kStatusOk || |
| 79 response.status() == kStatusFallThrough) { | 85 response.status() == kStatusFallThrough) { |
| 80 return false; | 86 return false; |
| 81 } | 87 } |
| 82 base::DictionaryValue dict; | 88 base::DictionaryValue dict; |
| 83 if (command_id == kNoId) | 89 if (command_id == kNoId) |
| 84 dict.Set(kIdParam, base::Value::CreateNullValue()); | 90 dict.Set(kIdParam, base::Value::CreateNullValue()); |
| 85 else | 91 else |
| 86 dict.SetInteger(kIdParam, command_id); | 92 dict.SetInteger(kIdParam, command_id); |
| 87 | 93 |
| 88 base::DictionaryValue* error_object = new base::DictionaryValue(); | 94 base::DictionaryValue* error_object = new base::DictionaryValue(); |
| 89 error_object->SetInteger(kErrorCodeParam, response.status()); | 95 error_object->SetInteger(kErrorCodeParam, response.status()); |
| 90 if (!response.message().empty()) | 96 if (!response.message().empty()) |
| 91 error_object->SetString(kErrorMessageParam, response.message()); | 97 error_object->SetString(kErrorMessageParam, response.message()); |
| 92 | 98 |
| 93 dict.Set(kErrorParam, error_object); | 99 dict.Set(kErrorParam, error_object); |
| 94 SendMessage(dict); | 100 SendMessage(session_id, dict); |
| 95 return true; | 101 return true; |
| 96 } | 102 } |
| 97 | 103 |
| 98 typedef DevToolsProtocolClient::Response Response; | 104 typedef DevToolsProtocolClient::Response Response; |
| 99 | 105 |
| 100 Response Response::FallThrough() { | 106 Response Response::FallThrough() { |
| 101 return Response(kStatusFallThrough); | 107 return Response(kStatusFallThrough); |
| 102 } | 108 } |
| 103 | 109 |
| 104 Response Response::OK() { | 110 Response Response::OK() { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 133 Response::Response(int status) | 139 Response::Response(int status) |
| 134 : status_(status) { | 140 : status_(status) { |
| 135 } | 141 } |
| 136 | 142 |
| 137 Response::Response(int status, const std::string& message) | 143 Response::Response(int status, const std::string& message) |
| 138 : status_(status), | 144 : status_(status), |
| 139 message_(message) { | 145 message_(message) { |
| 140 } | 146 } |
| 141 | 147 |
| 142 } // namespace content | 148 } // namespace content |
| OLD | NEW |