Skip to content

Commit 5dffb59

Browse files
pavelfeldmanCommit Bot
authored andcommitted
DevTools: roll third_party/inspector_protocol, wire binary operation.
Bug: chromium:929862 Change-Id: I8c23be1d22f70d1143d570050514c36ecfb30fc7 Reviewed-on: https://chromium-review.googlesource.com/c/1466003 Reviewed-by: Alexei Filippov <alph@chromium.org> Commit-Queue: Pavel Feldman <pfeldman@chromium.org> Commit-Queue: Alexei Filippov <alph@chromium.org> Cr-Commit-Position: refs/heads/master@{#59541}
1 parent ba78fef commit 5dffb59

18 files changed

Lines changed: 262 additions & 91 deletions

src/inspector/custom-preview.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ bool substituteObjectTags(int sessionId, const String16& groupName,
120120
return false;
121121
}
122122
v8::Local<v8::Value> jsonWrapper;
123-
String16 serialized = wrapper->serialize();
123+
String16 serialized = wrapper->toJSON();
124124
if (!v8::JSON::Parse(context, toV8String(isolate, serialized))
125125
.ToLocal(&jsonWrapper)) {
126126
reportError(context, tryCatch, "cannot wrap value");

src/inspector/injected-script.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ Response InjectedScript::resolveCallArgument(
585585
if (callArgument->hasValue() || callArgument->hasUnserializableValue()) {
586586
String16 value;
587587
if (callArgument->hasValue()) {
588-
value = "(" + callArgument->getValue(nullptr)->serialize() + ")";
588+
value = "(" + callArgument->getValue(nullptr)->toJSONString() + ")";
589589
} else {
590590
String16 unserializableValue = callArgument->getUnserializableValue("");
591591
// Protect against potential identifier resolution for NaN and Infinity.

src/inspector/string-util.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ std::unique_ptr<protocol::Value> StringUtil::parseJSON(const String16& string) {
122122
static_cast<int>(string.length()));
123123
}
124124

125+
// static
126+
std::unique_ptr<protocol::Value> StringUtil::parseProtocolMessage(
127+
const ProtocolMessage& message) {
128+
return parseJSON(message.json);
129+
}
130+
131+
// static
132+
ProtocolMessage StringUtil::jsonToMessage(String message) {
133+
ProtocolMessage result;
134+
result.json = std::move(message);
135+
return result;
136+
}
137+
138+
// static
139+
ProtocolMessage StringUtil::binaryToMessage(std::vector<uint8_t> message) {
140+
ProtocolMessage result;
141+
result.binary = std::move(message);
142+
return result;
143+
}
144+
125145
// static
126146
void StringUtil::builderAppendQuotedString(StringBuilder& builder,
127147
const String& str) {

src/inspector/string-util.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class Value;
2222

2323
using String = v8_inspector::String16;
2424
using StringBuilder = v8_inspector::String16Builder;
25+
struct ProtocolMessage {
26+
String json;
27+
std::vector<uint8_t> binary;
28+
};
2529

2630
class StringUtil {
2731
public:
@@ -59,6 +63,10 @@ class StringUtil {
5963
}
6064
static std::unique_ptr<protocol::Value> parseJSON(const String16& json);
6165
static std::unique_ptr<protocol::Value> parseJSON(const StringView& json);
66+
static std::unique_ptr<protocol::Value> parseProtocolMessage(
67+
const ProtocolMessage&);
68+
static ProtocolMessage jsonToMessage(String message);
69+
static ProtocolMessage binaryToMessage(std::vector<uint8_t> message);
6270
};
6371

6472
// A read-only sequence of uninterpreted bytes with reference-counted storage.
@@ -101,6 +109,19 @@ class StringBufferImpl : public StringBuffer {
101109
DISALLOW_COPY_AND_ASSIGN(StringBufferImpl);
102110
};
103111

112+
class BinaryStringBuffer : public StringBuffer {
113+
public:
114+
explicit BinaryStringBuffer(std::vector<uint8_t> data)
115+
: m_data(std::move(data)), m_string(m_data.data(), m_data.size()) {}
116+
const StringView& string() override { return m_string; }
117+
118+
private:
119+
std::vector<uint8_t> m_data;
120+
StringView m_string;
121+
122+
DISALLOW_COPY_AND_ASSIGN(BinaryStringBuffer);
123+
};
124+
104125
String16 debuggerIdToString(const std::pair<int64_t, int64_t>& debuggerId);
105126
String16 stackTraceIdToString(uintptr_t id);
106127

src/inspector/v8-inspector-session-impl.cc

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,41 +137,53 @@ namespace {
137137
class MessageBuffer : public StringBuffer {
138138
public:
139139
static std::unique_ptr<MessageBuffer> create(
140-
std::unique_ptr<protocol::Serializable> message) {
140+
std::unique_ptr<protocol::Serializable> message, bool binary) {
141141
return std::unique_ptr<MessageBuffer>(
142-
new MessageBuffer(std::move(message)));
142+
new MessageBuffer(std::move(message), binary));
143143
}
144144

145145
const StringView& string() override {
146146
if (!m_serialized) {
147-
m_serialized = StringBuffer::create(toStringView(m_message->serialize()));
147+
if (m_binary) {
148+
// Encode binary response as an 8bit string buffer.
149+
m_serialized.reset(
150+
new BinaryStringBuffer(m_message->serializeToBinary()));
151+
} else {
152+
m_serialized =
153+
StringBuffer::create(toStringView(m_message->serializeToJSON()));
154+
}
148155
m_message.reset(nullptr);
149156
}
150157
return m_serialized->string();
151158
}
152159

153160
private:
154-
explicit MessageBuffer(std::unique_ptr<protocol::Serializable> message)
155-
: m_message(std::move(message)) {}
161+
explicit MessageBuffer(std::unique_ptr<protocol::Serializable> message,
162+
bool binary)
163+
: m_message(std::move(message)), m_binary(binary) {}
156164

157165
std::unique_ptr<protocol::Serializable> m_message;
158166
std::unique_ptr<StringBuffer> m_serialized;
167+
bool m_binary;
159168
};
160169

161170
} // namespace
162171

163172
void V8InspectorSessionImpl::sendProtocolResponse(
164173
int callId, std::unique_ptr<protocol::Serializable> message) {
165-
m_channel->sendResponse(callId, MessageBuffer::create(std::move(message)));
174+
m_channel->sendResponse(
175+
callId, MessageBuffer::create(std::move(message), use_binary_protocol_));
166176
}
167177

168178
void V8InspectorSessionImpl::sendProtocolNotification(
169179
std::unique_ptr<protocol::Serializable> message) {
170-
m_channel->sendNotification(MessageBuffer::create(std::move(message)));
180+
m_channel->sendNotification(
181+
MessageBuffer::create(std::move(message), use_binary_protocol_));
171182
}
172183

173-
void V8InspectorSessionImpl::fallThrough(int callId, const String16& method,
174-
const String16& message) {
184+
void V8InspectorSessionImpl::fallThrough(
185+
int callId, const String16& method,
186+
const protocol::ProtocolMessage& message) {
175187
// There's no other layer to handle the command.
176188
UNREACHABLE();
177189
}
@@ -316,19 +328,28 @@ void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) {
316328

317329
void V8InspectorSessionImpl::dispatchProtocolMessage(
318330
const StringView& message) {
331+
bool binary_protocol =
332+
message.is8Bit() && message.length() && message.characters8()[0] == 0xDA;
333+
if (binary_protocol) use_binary_protocol_ = true;
319334
int callId;
335+
std::unique_ptr<protocol::Value> parsed_message;
336+
if (binary_protocol) {
337+
parsed_message = protocol::Value::parseBinary(
338+
message.characters8(), static_cast<unsigned>(message.length()));
339+
} else {
340+
parsed_message = protocol::StringUtil::parseJSON(message);
341+
}
320342
String16 method;
321-
std::unique_ptr<protocol::Value> parsedMessage =
322-
protocol::StringUtil::parseJSON(message);
323-
if (m_dispatcher.parseCommand(parsedMessage.get(), &callId, &method)) {
343+
if (m_dispatcher.parseCommand(parsed_message.get(), &callId, &method)) {
324344
// Pass empty string instead of the actual message to save on a conversion.
325345
// We're allowed to do so because fall-through is not implemented.
326-
m_dispatcher.dispatch(callId, method, std::move(parsedMessage), "");
346+
m_dispatcher.dispatch(callId, method, std::move(parsed_message),
347+
protocol::ProtocolMessage());
327348
}
328349
}
329350

330351
std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON() {
331-
String16 json = m_state->serialize();
352+
String16 json = m_state->toJSONString();
332353
return StringBufferImpl::adopt(json);
333354
}
334355

src/inspector/v8-inspector-session-impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class V8InspectorSessionImpl : public V8InspectorSession,
102102
void sendProtocolNotification(
103103
std::unique_ptr<protocol::Serializable> message) override;
104104
void fallThrough(int callId, const String16& method,
105-
const String16& message) override;
105+
const protocol::ProtocolMessage& message) override;
106106
void flushProtocolNotifications() override;
107107

108108
int m_contextGroupId;
@@ -122,6 +122,7 @@ class V8InspectorSessionImpl : public V8InspectorSession,
122122
std::unique_ptr<V8SchemaAgentImpl> m_schemaAgent;
123123
std::vector<std::unique_ptr<V8InspectorSession::Inspectable>>
124124
m_inspectedObjects;
125+
bool use_binary_protocol_ = false;
125126

126127
DISALLOW_COPY_AND_ASSIGN(V8InspectorSessionImpl);
127128
};

third_party/inspector_protocol/README.v8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Name: inspector protocol
22
Short Name: inspector_protocol
33
URL: https://chromium.googlesource.com/deps/inspector_protocol/
44
Version: 0
5-
Revision: 8515c2a1c5c016646b61221586cd4e5839f425ee
5+
Revision: e8a0de7351b5d72aadde777e2ad9b412d1431ffa
66
License: BSD
77
License File: LICENSE
88
Security Critical: no

third_party/inspector_protocol/lib/DispatcherBase_cpp.template

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ DispatcherBase::WeakPtr::~WeakPtr()
7070
m_dispatcher->m_weakPtrs.erase(this);
7171
}
7272

73-
DispatcherBase::Callback::Callback(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, const String& method, const String& message)
73+
DispatcherBase::Callback::Callback(std::unique_ptr<DispatcherBase::WeakPtr> backendImpl, int callId, const String& method, const ProtocolMessage& message)
7474
: m_backendImpl(std::move(backendImpl))
7575
, m_callId(callId)
7676
, m_method(method)
@@ -142,18 +142,14 @@ public:
142142
return std::unique_ptr<ProtocolError>(new ProtocolError(code, errorMessage));
143143
}
144144

145-
String serialize() override
145+
String serializeToJSON() override
146146
{
147-
std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create();
148-
error->setInteger("code", m_code);
149-
error->setString("message", m_errorMessage);
150-
if (m_data.length())
151-
error->setString("data", m_data);
152-
std::unique_ptr<protocol::DictionaryValue> message = DictionaryValue::create();
153-
message->setObject("error", std::move(error));
154-
if (m_hasCallId)
155-
message->setInteger("id", m_callId);
156-
return message->serialize();
147+
return serialize()->serializeToJSON();
148+
}
149+
150+
std::vector<uint8_t> serializeToBinary() override
151+
{
152+
return serialize()->serializeToBinary();
157153
}
158154

159155
~ProtocolError() override {}
@@ -165,6 +161,19 @@ private:
165161
{
166162
}
167163

164+
std::unique_ptr<DictionaryValue> serialize() {
165+
std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create();
166+
error->setInteger("code", m_code);
167+
error->setString("message", m_errorMessage);
168+
if (m_data.length())
169+
error->setString("data", m_data);
170+
std::unique_ptr<protocol::DictionaryValue> message = DictionaryValue::create();
171+
message->setObject("error", std::move(error));
172+
if (m_hasCallId)
173+
message->setInteger("id", m_callId);
174+
return message;
175+
}
176+
168177
DispatchResponse::ErrorCode m_code;
169178
String m_errorMessage;
170179
String m_data;
@@ -275,7 +284,7 @@ bool UberDispatcher::canDispatch(const String& in_method)
275284
return !!findDispatcher(method);
276285
}
277286

278-
void UberDispatcher::dispatch(int callId, const String& in_method, std::unique_ptr<Value> parsedMessage, const String& rawMessage)
287+
void UberDispatcher::dispatch(int callId, const String& in_method, std::unique_ptr<Value> parsedMessage, const ProtocolMessage& rawMessage)
279288
{
280289
String method = in_method;
281290
auto redirectIt = m_redirects.find(method);
@@ -304,18 +313,32 @@ std::unique_ptr<InternalResponse> InternalResponse::createNotification(const Str
304313
return std::unique_ptr<InternalResponse>(new InternalResponse(0, notification, std::move(params)));
305314
}
306315

307-
String InternalResponse::serialize()
316+
String InternalResponse::serializeToJSON()
317+
{
318+
std::unique_ptr<DictionaryValue> result = DictionaryValue::create();
319+
std::unique_ptr<Serializable> params(m_params ? std::move(m_params) : DictionaryValue::create());
320+
if (m_notification.length()) {
321+
result->setString("method", m_notification);
322+
result->setValue("params", SerializedValue::fromJSON(params->serializeToJSON()));
323+
} else {
324+
result->setInteger("id", m_callId);
325+
result->setValue("result", SerializedValue::fromJSON(params->serializeToJSON()));
326+
}
327+
return result->serializeToJSON();
328+
}
329+
330+
std::vector<uint8_t> InternalResponse::serializeToBinary()
308331
{
309332
std::unique_ptr<DictionaryValue> result = DictionaryValue::create();
310333
std::unique_ptr<Serializable> params(m_params ? std::move(m_params) : DictionaryValue::create());
311334
if (m_notification.length()) {
312335
result->setString("method", m_notification);
313-
result->setValue("params", SerializedValue::create(params->serialize()));
336+
result->setValue("params", SerializedValue::fromBinary(params->serializeToBinary()));
314337
} else {
315338
result->setInteger("id", m_callId);
316-
result->setValue("result", SerializedValue::create(params->serialize()));
339+
result->setValue("result", SerializedValue::fromBinary(params->serializeToBinary()));
317340
}
318-
return result->serialize();
341+
return result->serializeToBinary();
319342
}
320343

321344
InternalResponse::InternalResponse(int callId, const String& notification, std::unique_ptr<Serializable> params)

0 commit comments

Comments
 (0)