0

[DevTools] Fixes for running the browser_tests and the headless_browsertests

This is for --enable-internal-devtools-binary-protocol.
In DevToolsSession, handle messages to proxy delegates correctly.
In HeadlessDevToolsSession, check the switch when parsing messages.

I've also uploaded a patch that hardcodes the flag so that the
bots can try it with the flag enabled.
https://chromium-review.googlesource.com/c/chromium/src/+/1542299

Change-Id: I7d2515849571f0e5465afe0528d72a6f35d1fcf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1541862
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645455}
This commit is contained in:
Johannes Henkel
2019-03-28 19:45:12 +00:00
committed by Commit Bot
parent 8a8caf5ca8
commit 8934ec60db
2 changed files with 35 additions and 11 deletions
content/browser/devtools
headless/lib/browser/protocol

@ -141,6 +141,18 @@ void DevToolsSession::MojoConnectionDestroyed() {
// The client of the devtools session will call this method to send a message
// to handlers / agents that the session is connected with.
bool DevToolsSession::DispatchProtocolMessage(const std::string& message) {
// If the session is in proxy mode, then |message| will be sent to
// an external session, so it needs to be sent as JSON.
// TODO(dgozman): revisit the proxy delegate.
if (proxy_delegate_) {
if (client_->UsesBinaryProtocol()) {
DCHECK(IsCBOR(message));
proxy_delegate_->SendMessageToBackend(this, ConvertCBORToJSON(message));
return true;
}
proxy_delegate_->SendMessageToBackend(this, message);
return true;
}
std::string converted_cbor_message;
const std::string* message_to_send = &message;
if (EnableInternalDevToolsBinaryProtocol()) {
@ -153,15 +165,6 @@ bool DevToolsSession::DispatchProtocolMessage(const std::string& message) {
message_to_send = &converted_cbor_message;
}
}
if (proxy_delegate_) {
// TODO(dgozman): revisit the proxy delegate.
// TODO(johannes): Should we send CBOR to an external backend? Maybe not!
// Revisit this when EnableInternalDevToolsBinaryProtocol() is on
// unconditionally. Note: we assume that child sessions are not forwarding.
proxy_delegate_->SendMessageToBackend(this, *message_to_send);
return true;
}
std::unique_ptr<protocol::DictionaryValue> value =
protocol::DictionaryValue::cast(protocol::StringUtil::parseMessage(
message, client_->UsesBinaryProtocol()));
@ -345,7 +348,20 @@ void DevToolsSession::DispatchProtocolNotification(
}
void DevToolsSession::DispatchOnClientHost(const std::string& message) {
client_->DispatchProtocolMessage(agent_host_, message);
if (!EnableInternalDevToolsBinaryProtocol()) {
client_->DispatchProtocolMessage(agent_host_, message);
return;
}
// |message| either comes from a web socket, in which case it's JSON.
// Or it comes from another devtools_session, in which case it may be CBOR
// already. We auto-detect and convert to what the client wants as needed.
if (client_->UsesBinaryProtocol()) {
client_->DispatchProtocolMessage(
agent_host_, IsCBOR(message) ? message : ConvertJSONToCBOR(message));
} else {
client_->DispatchProtocolMessage(
agent_host_, !IsCBOR(message) ? message : ConvertCBORToJSON(message));
}
// |this| may be deleted at this point.
}

@ -4,8 +4,10 @@
#include "headless/lib/browser/protocol/headless_devtools_session.h"
#include "base/command_line.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_agent_host_client.h"
#include "content/public/common/content_switches.h"
#include "headless/lib/browser/protocol/browser_handler.h"
#include "headless/lib/browser/protocol/headless_handler.h"
#include "headless/lib/browser/protocol/page_handler.h"
@ -13,6 +15,11 @@
namespace headless {
namespace protocol {
static bool EnableInternalDevToolsBinaryProtocol() {
static bool enabled = base::CommandLine::ForCurrentProcess()->HasSwitch(
::switches::kEnableInternalDevToolsBinaryProtocol);
return enabled;
}
HeadlessDevToolsSession::HeadlessDevToolsSession(
base::WeakPtr<HeadlessBrowserImpl> browser,
@ -53,7 +60,8 @@ void HeadlessDevToolsSession::HandleCommand(
std::string unused;
std::unique_ptr<protocol::DictionaryValue> value =
protocol::DictionaryValue::cast(protocol::StringUtil::parseMessage(
message, client_->UsesBinaryProtocol()));
message, client_->UsesBinaryProtocol() ||
EnableInternalDevToolsBinaryProtocol()));
if (!dispatcher_->parseCommand(value.get(), &call_id, &unused))
return;
pending_commands_[call_id] = std::move(callback);