Commit b8f9bad8 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Roll inspector_protocol (Chromium)

"Remove the JSON parser and revamp Value::parseBinary."
Upstream review: https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/2026351

"Add JsonEncoder tests for lone surrogates"
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/2017303

In addition to the upstream changes, this PR includes the necessary
tweaks to the blink inspector (now taking the detour via
CBOR to parse Javascript).

New Revision: 0e0a1995497511008864546c094e885f3f1e13a3

Change-Id: I1449d3a76c6a946a8bc321dd8d0cb111ce1bf303
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2021290Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738228}
parent 63099e25
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "third_party/blink/renderer/core/page/chrome_client.h" #include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/platform/keyboard_codes.h" #include "third_party/blink/renderer/platform/keyboard_codes.h"
#include "third_party/inspector_protocol/crdtp/json.h"
namespace blink { namespace blink {
...@@ -436,8 +437,21 @@ int ScreenshotTool::GetDataResourceId() { ...@@ -436,8 +437,21 @@ int ScreenshotTool::GetDataResourceId() {
} }
void ScreenshotTool::Dispatch(const String& message) { void ScreenshotTool::Dispatch(const String& message) {
if (message.IsEmpty())
return;
std::vector<uint8_t> cbor;
if (message.Is8Bit()) {
crdtp::json::ConvertJSONToCBOR(
crdtp::span<uint8_t>(message.Characters8(), message.length()), &cbor);
} else {
crdtp::json::ConvertJSONToCBOR(
crdtp::span<uint16_t>(
reinterpret_cast<const uint16_t*>(message.Characters16()),
message.length()),
&cbor);
}
std::unique_ptr<protocol::Value> value = std::unique_ptr<protocol::Value> value =
protocol::StringUtil::parseJSON(message); protocol::Value::parseBinary(cbor.data(), cbor.size());
if (!value) if (!value)
return; return;
protocol::ErrorSupport errors; protocol::ErrorSupport errors;
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#include "third_party/blink/renderer/platform/transforms/transformation_matrix.h" #include "third_party/blink/renderer/platform/transforms/transformation_matrix.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h" #include "third_party/blink/renderer/platform/wtf/text/base64.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/inspector_protocol/crdtp/json.h"
#include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkRefCnt.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -537,8 +538,19 @@ Response InspectorLayerTreeAgent::snapshotCommandLog( ...@@ -537,8 +538,19 @@ Response InspectorLayerTreeAgent::snapshotCommandLog(
if (!response.isSuccess()) if (!response.isSuccess())
return response; return response;
protocol::ErrorSupport errors; protocol::ErrorSupport errors;
std::unique_ptr<protocol::Value> log_value = protocol::StringUtil::parseJSON( const String& json = snapshot->SnapshotCommandLog()->ToJSONString();
snapshot->SnapshotCommandLog()->ToJSONString()); std::vector<uint8_t> cbor;
if (json.Is8Bit()) {
crdtp::json::ConvertJSONToCBOR(
crdtp::span<uint8_t>(json.Characters8(), json.length()), &cbor);
} else {
crdtp::json::ConvertJSONToCBOR(
crdtp::span<uint16_t>(
reinterpret_cast<const uint16_t*>(json.Characters16()),
json.length()),
&cbor);
}
auto log_value = protocol::Value::parseBinary(cbor.data(), cbor.size());
*command_log = protocol::ValueConversions< *command_log = protocol::ValueConversions<
protocol::Array<protocol::DictionaryValue>>::fromValue(log_value.get(), protocol::Array<protocol::DictionaryValue>>::fromValue(log_value.get(),
&errors); &errors);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/inspector_protocol/crdtp/json.h"
namespace blink { namespace blink {
...@@ -14,7 +15,18 @@ using protocol::ListValue; ...@@ -14,7 +15,18 @@ using protocol::ListValue;
using protocol::Value; using protocol::Value;
static std::unique_ptr<protocol::Value> ParseJSON(const String& string) { static std::unique_ptr<protocol::Value> ParseJSON(const String& string) {
return protocol::StringUtil::parseJSON(string); std::vector<uint8_t> cbor;
if (string.Is8Bit()) {
crdtp::json::ConvertJSONToCBOR(
crdtp::span<uint8_t>(string.Characters8(), string.length()), &cbor);
} else {
crdtp::json::ConvertJSONToCBOR(
crdtp::span<uint16_t>(
reinterpret_cast<const uint16_t*>(string.Characters16()),
string.length()),
&cbor);
}
return protocol::Value::parseBinary(cbor.data(), cbor.size());
} }
TEST(ProtocolParserTest, Reading) { TEST(ProtocolParserTest, Reading) {
......
...@@ -44,21 +44,6 @@ String ToCoreString(std::unique_ptr<v8_inspector::StringBuffer> buffer) { ...@@ -44,21 +44,6 @@ String ToCoreString(std::unique_ptr<v8_inspector::StringBuffer> buffer) {
} }
namespace protocol { namespace protocol {
// static
std::unique_ptr<protocol::Value> StringUtil::parseJSON(const String& string) {
if (string.IsNull())
return nullptr;
if (string.Is8Bit()) {
return parseJSONCharacters(
reinterpret_cast<const uint8_t*>(string.Characters8()),
string.length());
}
return parseJSONCharacters(
reinterpret_cast<const uint16_t*>(string.Characters16()),
string.length());
}
// static // static
String StringUtil::fromUTF16LE(const uint16_t* data, size_t length) { String StringUtil::fromUTF16LE(const uint16_t* data, size_t length) {
// Chromium doesn't support big endian architectures, so it's OK to cast here. // Chromium doesn't support big endian architectures, so it's OK to cast here.
......
...@@ -36,9 +36,6 @@ CORE_EXPORT String ToCoreString(const v8_inspector::StringView&); ...@@ -36,9 +36,6 @@ CORE_EXPORT String ToCoreString(const v8_inspector::StringView&);
CORE_EXPORT String ToCoreString(std::unique_ptr<v8_inspector::StringBuffer>); CORE_EXPORT String ToCoreString(std::unique_ptr<v8_inspector::StringBuffer>);
namespace protocol { namespace protocol {
class Value;
using String = WTF::String; using String = WTF::String;
using StringBuilder = WTF::StringBuilder; using StringBuilder = WTF::StringBuilder;
...@@ -79,7 +76,6 @@ class CORE_EXPORT StringUtil { ...@@ -79,7 +76,6 @@ class CORE_EXPORT StringUtil {
static String builderToString(StringBuilder& builder) { static String builderToString(StringBuilder& builder) {
return builder.ToString(); return builder.ToString();
} }
static std::unique_ptr<protocol::Value> parseJSON(const String&);
static String fromUTF8(const uint8_t* data, size_t length) { static String fromUTF8(const uint8_t* data, size_t length) {
return String::FromUTF8(reinterpret_cast<const char*>(data), length); return String::FromUTF8(reinterpret_cast<const char*>(data), length);
......
...@@ -2,7 +2,7 @@ Name: inspector protocol ...@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/ URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0 Version: 0
Revision: 607bfb87bdc389997abf6ae3b7e08027856b886e Revision: 0e0a1995497511008864546c094e885f3f1e13a3
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: yes Security Critical: yes
......
...@@ -102,7 +102,7 @@ to be stable. ...@@ -102,7 +102,7 @@ to be stable.
## crdtp_test_platform ## crdtp_test_platform
This platform library is only used by the tests. Upstream, it's setup to This platform library is only used by the tests. Upstream, it's setup to
use mini_chromium and gtest. Downstream, Chromium uses it's //base libraries, use mini_chromium and gtest. Downstream, Chromium uses its //base libraries,
and V8 uses theirs; and a small amount of tweaking is needed in each code and V8 uses theirs; and a small amount of tweaking is needed in each code
base - e.g., Chromium, V8, and google3 each place `#include` declarations into base - e.g., Chromium, V8, and google3 each place `#include` declarations into
test_platform.h that are specific to their code base, and they have their test_platform.h that are specific to their code base, and they have their
......
...@@ -81,6 +81,32 @@ TEST(JsonEncoder, NotAContinuationByte) { ...@@ -81,6 +81,32 @@ TEST(JsonEncoder, NotAContinuationByte) {
EXPECT_EQ("\"Hello\"", out); // "Hello" shows we restarted at 'H'. EXPECT_EQ("\"Hello\"", out); // "Hello" shows we restarted at 'H'.
} }
TEST(JsonEncoder, EscapesLoneHighSurrogates) {
// This tests that the JSON encoder escapes lone high surrogates, i.e.
// invalid code points in the range from 0xD800 to 0xDBFF. In
// unescaped form, these cannot be represented in well-formed UTF-8 or
// UTF-16.
std::vector<uint16_t> chars = {'a', 0xd800, 'b', 0xdada, 'c', 0xdbff, 'd'};
std::string out;
Status status;
std::unique_ptr<ParserHandler> writer = NewJSONEncoder(&out, &status);
writer->HandleString16(span<uint16_t>(chars.data(), chars.size()));
EXPECT_EQ("\"a\\ud800b\\udadac\\udbffd\"", out);
}
TEST(JsonEncoder, EscapesLoneLowSurrogates) {
// This tests that the JSON encoder escapes lone low surrogates, i.e.
// invalid code points in the range from 0xDC00 to 0xDFFF. In
// unescaped form, these cannot be represented in well-formed UTF-8 or
// UTF-16.
std::vector<uint16_t> chars = {'a', 0xdc00, 'b', 0xdede, 'c', 0xdfff, 'd'};
std::string out;
Status status;
std::unique_ptr<ParserHandler> writer = NewJSONEncoder(&out, &status);
writer->HandleString16(span<uint16_t>(chars.data(), chars.size()));
EXPECT_EQ("\"a\\udc00b\\udedec\\udfffd\"", out);
}
TEST(JsonEncoder, EscapesFFFF) { TEST(JsonEncoder, EscapesFFFF) {
// This tests that the JSON encoder will escape the UTF16 input 0xffff as // This tests that the JSON encoder will escape the UTF16 input 0xffff as
// \uffff; useful to check this since it's an edge case. // \uffff; useful to check this since it's an edge case.
......
...@@ -4,21 +4,4 @@ ...@@ -4,21 +4,4 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef {{"_".join(config.protocol.namespace)}}_Parser_h // TODO(johannes): Remove Parser_h.template.
#define {{"_".join(config.protocol.namespace)}}_Parser_h
//#include "Forward.h"
//#include "Values.h"
{% for namespace in config.protocol.namespace %}
namespace {{namespace}} {
{% endfor %}
{{config.lib.export_macro}} std::unique_ptr<Value> parseJSONCharacters(const uint8_t*, unsigned);
{{config.lib.export_macro}} std::unique_ptr<Value> parseJSONCharacters(const uint16_t*, unsigned);
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
#endif // !defined({{"_".join(config.protocol.namespace)}}_Parser_h)
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