Chromium Code Reviews| Index: content/browser/devtools/devtools_protocol_handler.cc |
| diff --git a/content/browser/devtools/devtools_protocol_handler.cc b/content/browser/devtools/devtools_protocol_handler.cc |
| index 86ccd8e5d2d05830c5a9ada8be073fbf4f68104b..67eff9710b0e638629d8a01561a84f084cacd0ca 100644 |
| --- a/content/browser/devtools/devtools_protocol_handler.cc |
| +++ b/content/browser/devtools/devtools_protocol_handler.cc |
| @@ -45,26 +45,29 @@ DevToolsProtocolHandler::DevToolsProtocolHandler( |
| DevToolsProtocolHandler::~DevToolsProtocolHandler() { |
| } |
| -void DevToolsProtocolHandler::HandleMessage(const std::string& message) { |
| - scoped_ptr<base::DictionaryValue> command = ParseCommand(message); |
| +void DevToolsProtocolHandler::HandleMessage(int session_id, |
| + const std::string& message) { |
| + scoped_ptr<base::DictionaryValue> command = ParseCommand(session_id, message); |
| if (!command) |
| return; |
| - if (PassCommandToDelegate(command.get())) |
| + if (PassCommandToDelegate(session_id, command.get())) |
| return; |
| - HandleCommand(command.Pass()); |
| + HandleCommand(session_id, command.Pass()); |
| } |
| -bool DevToolsProtocolHandler::HandleOptionalMessage( |
| - const std::string& message, int* call_id) { |
| - scoped_ptr<base::DictionaryValue> command = ParseCommand(message); |
| +bool DevToolsProtocolHandler::HandleOptionalMessage(int session_id, |
| + const std::string& message, |
| + int* call_id) { |
| + scoped_ptr<base::DictionaryValue> command = ParseCommand(session_id, message); |
| if (!command) |
| return true; |
| - if (PassCommandToDelegate(command.get())) |
| + if (PassCommandToDelegate(session_id, command.get())) |
| return true; |
| - return HandleOptionalCommand(command.Pass(), call_id); |
| + return HandleOptionalCommand(session_id, command.Pass(), call_id); |
| } |
| bool DevToolsProtocolHandler::PassCommandToDelegate( |
| + int session_id, |
| base::DictionaryValue* command) { |
| DevToolsManagerDelegate* delegate = |
| DevToolsManager::GetInstance()->delegate(); |
| @@ -76,20 +79,21 @@ bool DevToolsProtocolHandler::PassCommandToDelegate( |
| if (response) { |
| std::string json_response; |
| base::JSONWriter::Write(*response, &json_response); |
| - client_.SendRawMessage(json_response); |
| + client_.SendRawMessage(session_id, json_response); |
| return true; |
| } |
| return false; |
| } |
| -scoped_ptr<base::DictionaryValue> |
| -DevToolsProtocolHandler::ParseCommand(const std::string& message) { |
| +scoped_ptr<base::DictionaryValue> DevToolsProtocolHandler::ParseCommand( |
| + int session_id, |
| + const std::string& message) { |
| scoped_ptr<base::Value> value = base::JSONReader::Read(message); |
| if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) { |
| - client_.SendError(DevToolsProtocolClient::kNoId, |
| - Response(kStatusParseError, |
| - "Message must be in JSON format")); |
| + client_.SendError( |
| + session_id, DevToolsProtocolClient::kNoId, |
| + Response(kStatusParseError, "Message must be in JSON format")); |
| return nullptr; |
| } |
| @@ -98,17 +102,18 @@ DevToolsProtocolHandler::ParseCommand(const std::string& message) { |
| int id = DevToolsProtocolClient::kNoId; |
|
dgozman
2015/11/06 22:57:27
nit: let's rename to command_id
kozy
2015/11/07 01:54:43
Done.
|
| bool ok = command->GetInteger(kIdParam, &id) && id >= 0; |
| if (!ok) { |
| - client_.SendError(id, Response(kStatusInvalidRequest, |
| - "The type of 'id' property must be number")); |
| + client_.SendError(session_id, id, |
| + Response(kStatusInvalidRequest, |
| + "The type of 'id' property must be number")); |
| return nullptr; |
| } |
| std::string method; |
| ok = command->GetString(kMethodParam, &method); |
| if (!ok) { |
| - client_.SendError(id, |
| - Response(kStatusInvalidRequest, |
| - "The type of 'method' property must be string")); |
| + client_.SendError(session_id, id, |
| + Response(kStatusInvalidRequest, |
| + "The type of 'method' property must be string")); |
| return nullptr; |
| } |
| @@ -116,6 +121,7 @@ DevToolsProtocolHandler::ParseCommand(const std::string& message) { |
| } |
| void DevToolsProtocolHandler::HandleCommand( |
| + int session_id, |
| scoped_ptr<base::DictionaryValue> command) { |
| int id = DevToolsProtocolClient::kNoId; |
| std::string method; |
| @@ -124,17 +130,20 @@ void DevToolsProtocolHandler::HandleCommand( |
| DevToolsProtocolDispatcher::CommandHandler command_handler( |
| dispatcher_.FindCommandHandler(method)); |
| if (command_handler.is_null()) { |
| - client_.SendError(id, Response(kStatusNoSuchMethod, "No such method")); |
| + client_.SendError(session_id, id, |
| + Response(kStatusNoSuchMethod, "No such method")); |
| return; |
| } |
| - bool result = |
| - command_handler.Run(id, TakeDictionary(command.get(), kParamsParam)); |
| + bool result = command_handler.Run( |
| + session_id, id, TakeDictionary(command.get(), kParamsParam)); |
| DCHECK(result); |
| } |
| bool DevToolsProtocolHandler::HandleOptionalCommand( |
| - scoped_ptr<base::DictionaryValue> command, int* call_id) { |
| + int session_id, |
| + scoped_ptr<base::DictionaryValue> command, |
| + int* call_id) { |
| *call_id = DevToolsProtocolClient::kNoId; |
| std::string method; |
| command->GetInteger(kIdParam, call_id); |
| @@ -142,8 +151,8 @@ bool DevToolsProtocolHandler::HandleOptionalCommand( |
| DevToolsProtocolDispatcher::CommandHandler command_handler( |
| dispatcher_.FindCommandHandler(method)); |
| if (!command_handler.is_null()) { |
| - return command_handler.Run( |
| - *call_id, TakeDictionary(command.get(), kParamsParam)); |
| + return command_handler.Run(session_id, *call_id, |
| + TakeDictionary(command.get(), kParamsParam)); |
| } |
| return false; |
| } |