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..09460a43a6f6faa1ad18708c7407e9f542a1fe68 100644 |
--- a/content/browser/devtools/devtools_protocol_handler.cc |
+++ b/content/browser/devtools/devtools_protocol_handler.cc |
@@ -36,35 +36,36 @@ scoped_ptr<base::DictionaryValue> TakeDictionary(base::DictionaryValue* dict, |
} // namespace |
DevToolsProtocolHandler::DevToolsProtocolHandler( |
- DevToolsAgentHost* agent_host, const Notifier& notifier) |
- : agent_host_(agent_host), |
- client_(notifier), |
- dispatcher_(notifier) { |
-} |
+ DevToolsAgentHost* agent_host, |
+ DevToolsProtocolDelegate* notifier) |
+ : agent_host_(agent_host), client_(notifier), dispatcher_(notifier) {} |
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,39 +77,41 @@ 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( |
+ DevToolsCommandId(DevToolsCommandId::kNoId, session_id), |
+ Response(kStatusParseError, "Message must be in JSON format")); |
return nullptr; |
} |
scoped_ptr<base::DictionaryValue> command = |
make_scoped_ptr(static_cast<base::DictionaryValue*>(value.release())); |
- int id = DevToolsProtocolClient::kNoId; |
- bool ok = command->GetInteger(kIdParam, &id) && id >= 0; |
+ int call_id = DevToolsCommandId::kNoId; |
+ bool ok = command->GetInteger(kIdParam, &call_id) && call_id >= 0; |
if (!ok) { |
- client_.SendError(id, Response(kStatusInvalidRequest, |
- "The type of 'id' property must be number")); |
+ client_.SendError(DevToolsCommandId(call_id, session_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(DevToolsCommandId(call_id, session_id), |
+ Response(kStatusInvalidRequest, |
+ "The type of 'method' property must be string")); |
return nullptr; |
} |
@@ -116,34 +119,39 @@ DevToolsProtocolHandler::ParseCommand(const std::string& message) { |
} |
void DevToolsProtocolHandler::HandleCommand( |
+ int session_id, |
scoped_ptr<base::DictionaryValue> command) { |
- int id = DevToolsProtocolClient::kNoId; |
+ int call_id = DevToolsCommandId::kNoId; |
std::string method; |
- command->GetInteger(kIdParam, &id); |
+ command->GetInteger(kIdParam, &call_id); |
command->GetString(kMethodParam, &method); |
DevToolsProtocolDispatcher::CommandHandler command_handler( |
dispatcher_.FindCommandHandler(method)); |
if (command_handler.is_null()) { |
- client_.SendError(id, Response(kStatusNoSuchMethod, "No such method")); |
+ client_.SendError(DevToolsCommandId(call_id, session_id), |
+ Response(kStatusNoSuchMethod, "No such method")); |
return; |
} |
bool result = |
- command_handler.Run(id, TakeDictionary(command.get(), kParamsParam)); |
+ command_handler.Run(DevToolsCommandId(call_id, session_id), |
+ TakeDictionary(command.get(), kParamsParam)); |
DCHECK(result); |
} |
bool DevToolsProtocolHandler::HandleOptionalCommand( |
- scoped_ptr<base::DictionaryValue> command, int* call_id) { |
- *call_id = DevToolsProtocolClient::kNoId; |
+ int session_id, |
+ scoped_ptr<base::DictionaryValue> command, |
+ int* call_id) { |
+ *call_id = DevToolsCommandId::kNoId; |
std::string method; |
command->GetInteger(kIdParam, call_id); |
command->GetString(kMethodParam, &method); |
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(DevToolsCommandId(*call_id, session_id), |
+ TakeDictionary(command.get(), kParamsParam)); |
} |
return false; |
} |