Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1011)

Unified Diff: content/browser/devtools/devtools_protocol_handler.cc

Issue 1437993003: Revert of [DevTools] Filter any messages from previous sessions in DevToolsAgentHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 9f69cfba3421a99b0a91eaffe0f615c919c28996..86ccd8e5d2d05830c5a9ada8be073fbf4f68104b 100644
--- a/content/browser/devtools/devtools_protocol_handler.cc
+++ b/content/browser/devtools/devtools_protocol_handler.cc
@@ -7,7 +7,6 @@
#include "base/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
-#include "content/browser/devtools/devtools_agent_host_impl.h"
#include "content/browser/devtools/devtools_manager.h"
#include "content/public/browser/devtools_manager_delegate.h"
@@ -37,35 +36,35 @@
} // namespace
DevToolsProtocolHandler::DevToolsProtocolHandler(
- DevToolsAgentHostImpl* agent_host)
- : agent_host_(agent_host), client_(agent_host), dispatcher_(agent_host) {}
+ DevToolsAgentHost* agent_host, const Notifier& notifier)
+ : agent_host_(agent_host),
+ client_(notifier),
+ dispatcher_(notifier) {
+}
DevToolsProtocolHandler::~DevToolsProtocolHandler() {
}
-void DevToolsProtocolHandler::HandleMessage(int session_id,
- const std::string& message) {
- scoped_ptr<base::DictionaryValue> command = ParseCommand(session_id, message);
+void DevToolsProtocolHandler::HandleMessage(const std::string& message) {
+ scoped_ptr<base::DictionaryValue> command = ParseCommand(message);
if (!command)
return;
- if (PassCommandToDelegate(session_id, command.get()))
+ if (PassCommandToDelegate(command.get()))
return;
- HandleCommand(session_id, command.Pass());
+ HandleCommand(command.Pass());
}
-bool DevToolsProtocolHandler::HandleOptionalMessage(int session_id,
- const std::string& message,
- int* call_id) {
- scoped_ptr<base::DictionaryValue> command = ParseCommand(session_id, message);
+bool DevToolsProtocolHandler::HandleOptionalMessage(
+ const std::string& message, int* call_id) {
+ scoped_ptr<base::DictionaryValue> command = ParseCommand(message);
if (!command)
return true;
- if (PassCommandToDelegate(session_id, command.get()))
+ if (PassCommandToDelegate(command.get()))
return true;
- return HandleOptionalCommand(session_id, command.Pass(), call_id);
+ return HandleOptionalCommand(command.Pass(), call_id);
}
bool DevToolsProtocolHandler::PassCommandToDelegate(
- int session_id,
base::DictionaryValue* command) {
DevToolsManagerDelegate* delegate =
DevToolsManager::GetInstance()->delegate();
@@ -75,41 +74,41 @@
scoped_ptr<base::DictionaryValue> response(
delegate->HandleCommand(agent_host_, command));
if (response) {
- client_.SendMessage(session_id, *response);
+ std::string json_response;
+ base::JSONWriter::Write(*response, &json_response);
+ client_.SendRawMessage(json_response);
return true;
}
return false;
}
-scoped_ptr<base::DictionaryValue> DevToolsProtocolHandler::ParseCommand(
- int session_id,
- const std::string& message) {
+scoped_ptr<base::DictionaryValue>
+DevToolsProtocolHandler::ParseCommand(const std::string& message) {
scoped_ptr<base::Value> value = base::JSONReader::Read(message);
if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) {
- client_.SendError(
- DevToolsCommandId(DevToolsCommandId::kNoId, session_id),
- Response(kStatusParseError, "Message must be in JSON format"));
+ client_.SendError(DevToolsProtocolClient::kNoId,
+ 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 call_id = DevToolsCommandId::kNoId;
- bool ok = command->GetInteger(kIdParam, &call_id) && call_id >= 0;
+ int id = DevToolsProtocolClient::kNoId;
+ bool ok = command->GetInteger(kIdParam, &id) && id >= 0;
if (!ok) {
- client_.SendError(DevToolsCommandId(call_id, session_id),
- Response(kStatusInvalidRequest,
- "The type of 'id' property must be number"));
+ client_.SendError(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(DevToolsCommandId(call_id, session_id),
- Response(kStatusInvalidRequest,
- "The type of 'method' property must be string"));
+ client_.SendError(id,
+ Response(kStatusInvalidRequest,
+ "The type of 'method' property must be string"));
return nullptr;
}
@@ -117,39 +116,34 @@
}
void DevToolsProtocolHandler::HandleCommand(
- int session_id,
scoped_ptr<base::DictionaryValue> command) {
- int call_id = DevToolsCommandId::kNoId;
+ int id = DevToolsProtocolClient::kNoId;
std::string method;
- command->GetInteger(kIdParam, &call_id);
+ command->GetInteger(kIdParam, &id);
command->GetString(kMethodParam, &method);
DevToolsProtocolDispatcher::CommandHandler command_handler(
dispatcher_.FindCommandHandler(method));
if (command_handler.is_null()) {
- client_.SendError(DevToolsCommandId(call_id, session_id),
- Response(kStatusNoSuchMethod, "No such method"));
+ client_.SendError(id, Response(kStatusNoSuchMethod, "No such method"));
return;
}
bool result =
- command_handler.Run(DevToolsCommandId(call_id, session_id),
- TakeDictionary(command.get(), kParamsParam));
+ command_handler.Run(id, TakeDictionary(command.get(), kParamsParam));
DCHECK(result);
}
bool DevToolsProtocolHandler::HandleOptionalCommand(
- int session_id,
- scoped_ptr<base::DictionaryValue> command,
- int* call_id) {
- *call_id = DevToolsCommandId::kNoId;
+ scoped_ptr<base::DictionaryValue> command, int* call_id) {
+ *call_id = DevToolsProtocolClient::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(DevToolsCommandId(*call_id, session_id),
- TakeDictionary(command.get(), kParamsParam));
+ return command_handler.Run(
+ *call_id, TakeDictionary(command.get(), kParamsParam));
}
return false;
}
« no previous file with comments | « content/browser/devtools/devtools_protocol_handler.h ('k') | content/browser/devtools/forwarding_agent_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698