Commit 4371c7d5 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Switch to AppendString8EntryToCBORMap.

Change-Id: I78a34f2375794dae7aa7b6fb9f8ae0a45c193b1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574953Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652625}
parent ff61827c
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
#include "content/public/browser/devtools_manager_delegate.h" #include "content/public/browser/devtools_manager_delegate.h"
#include "third_party/inspector_protocol/encoding/encoding.h" #include "third_party/inspector_protocol/encoding/encoding.h"
namespace cbor = inspector_protocol_encoding::cbor;
using inspector_protocol_encoding::SpanFrom; using inspector_protocol_encoding::SpanFrom;
using inspector_protocol_encoding::cbor::IsCBORMessage; using inspector_protocol_encoding::Status;
namespace content { namespace content {
...@@ -150,7 +151,7 @@ bool DevToolsSession::DispatchProtocolMessage(const std::string& message) { ...@@ -150,7 +151,7 @@ bool DevToolsSession::DispatchProtocolMessage(const std::string& message) {
// TODO(dgozman): revisit the proxy delegate. // TODO(dgozman): revisit the proxy delegate.
if (proxy_delegate_) { if (proxy_delegate_) {
if (client_->UsesBinaryProtocol()) { if (client_->UsesBinaryProtocol()) {
DCHECK(IsCBORMessage(SpanFrom(message))); DCHECK(cbor::IsCBORMessage(SpanFrom(message)));
proxy_delegate_->SendMessageToBackend( proxy_delegate_->SendMessageToBackend(
this, ConvertCBORToJSON(SpanFrom(message))); this, ConvertCBORToJSON(SpanFrom(message)));
return true; return true;
...@@ -168,7 +169,7 @@ bool DevToolsSession::DispatchProtocolMessage(const std::string& message) { ...@@ -168,7 +169,7 @@ bool DevToolsSession::DispatchProtocolMessage(const std::string& message) {
if (client_->UsesBinaryProtocol()) { if (client_->UsesBinaryProtocol()) {
// If the client uses the binary protocol, then |message| is already // If the client uses the binary protocol, then |message| is already
// CBOR (it comes from the client). // CBOR (it comes from the client).
DCHECK(IsCBORMessage(SpanFrom(message))); DCHECK(cbor::IsCBORMessage(SpanFrom(message)));
} else { } else {
converted_cbor_message = ConvertJSONToCBOR(SpanFrom(message)); converted_cbor_message = ConvertJSONToCBOR(SpanFrom(message));
message_to_send = &converted_cbor_message; message_to_send = &converted_cbor_message;
...@@ -288,7 +289,7 @@ static void SendProtocolResponseOrNotification( ...@@ -288,7 +289,7 @@ static void SendProtocolResponseOrNotification(
return; return;
} }
std::string cbor = message->serialize(/*binary=*/true); std::string cbor = message->serialize(/*binary=*/true);
DCHECK(IsCBORMessage(SpanFrom(cbor))); DCHECK(cbor::IsCBORMessage(SpanFrom(cbor)));
client->DispatchProtocolMessage( client->DispatchProtocolMessage(
agent_host, agent_host,
client->UsesBinaryProtocol() ? cbor : ConvertCBORToJSON(SpanFrom(cbor))); client->UsesBinaryProtocol() ? cbor : ConvertCBORToJSON(SpanFrom(cbor)));
...@@ -329,7 +330,7 @@ static void DispatchProtocolResponseOrNotification( ...@@ -329,7 +330,7 @@ static void DispatchProtocolResponseOrNotification(
} }
std::string cbor(reinterpret_cast<const char*>(message->data.data()), std::string cbor(reinterpret_cast<const char*>(message->data.data()),
message->data.size()); message->data.size());
DCHECK(IsCBORMessage(SpanFrom(cbor))); DCHECK(cbor::IsCBORMessage(SpanFrom(cbor)));
client->DispatchProtocolMessage( client->DispatchProtocolMessage(
agent_host, agent_host,
client->UsesBinaryProtocol() ? cbor : ConvertCBORToJSON(SpanFrom(cbor))); client->UsesBinaryProtocol() ? cbor : ConvertCBORToJSON(SpanFrom(cbor)));
...@@ -364,7 +365,7 @@ void DevToolsSession::DispatchOnClientHost(const std::string& message) { ...@@ -364,7 +365,7 @@ void DevToolsSession::DispatchOnClientHost(const std::string& message) {
// Or it comes from another devtools_session, in which case it may be CBOR // 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. // already. We auto-detect and convert to what the client wants as needed.
inspector_protocol_encoding::span<uint8_t> bytes = SpanFrom(message); inspector_protocol_encoding::span<uint8_t> bytes = SpanFrom(message);
bool is_cbor_message = IsCBORMessage(bytes); bool is_cbor_message = cbor::IsCBORMessage(bytes);
if (client_->UsesBinaryProtocol()) { if (client_->UsesBinaryProtocol()) {
client_->DispatchProtocolMessage( client_->DispatchProtocolMessage(
agent_host_, is_cbor_message ? message : ConvertJSONToCBOR(bytes)); agent_host_, is_cbor_message ? message : ConvertJSONToCBOR(bytes));
...@@ -437,12 +438,16 @@ void DevToolsSession::SendMessageFromChildSession(const std::string& session_id, ...@@ -437,12 +438,16 @@ void DevToolsSession::SendMessageFromChildSession(const std::string& session_id,
// |this| may be deleted at this point. // |this| may be deleted at this point.
return; return;
} }
DCHECK(IsCBORMessage(SpanFrom(message))); DCHECK(cbor::IsCBORMessage(SpanFrom(message)));
std::string patched; std::string patched(message);
bool patched_ok = protocol::AppendStringValueToMapBinary( Status status = cbor::AppendString8EntryToCBORMap(
message, kSessionId, session_id, &patched); SpanFrom(kSessionId), SpanFrom(session_id), &patched);
if (!patched_ok) if (!status.ok()) {
LOG(ERROR) << "cbor::AppendString8EntryToCBORMap error "
<< static_cast<uint32_t>(status.error) << " position "
<< static_cast<uint32_t>(status.pos);
return; return;
}
client_->DispatchProtocolMessage(agent_host_, client_->DispatchProtocolMessage(agent_host_,
client_->UsesBinaryProtocol() client_->UsesBinaryProtocol()
? patched ? patched
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment