Skip to content

Commit 744b49e

Browse files
alexkozyCommit Bot
authored andcommitted
Roll third_party/inspector_protocol to 8cb7a4f50ff7d5b1b7f2e5df0542dc577c88bdc3
This roll includes: - [inspector_protocol] fixed compatibility with latest jinja 2.9.6 - [inspector_protocol] removed unused variable - Follow up on alph's review comments. - Provide default escape implementation for latin and wide strings. - Allow escaping utf8 strings in embedders that operate std::string. - Upload inspector_protocol changes to Gerrit by default - [inspector_protocol] Fix building with non-ASCII paths - [inspector_protocol] added StringUtil::toDouble method as requirement - Add const char* overloads to ErrorSupport BUG=chromium:743313 [email protected] Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: Ic81a62c638bf592ae65c84055d53d926e50715ac Reviewed-on: https://chromium-review.googlesource.com/713538 Reviewed-by: Dmitry Gozman <[email protected]> Commit-Queue: Aleksey Kozyatinskiy <[email protected]> Cr-Commit-Position: refs/heads/master@{#48477}
1 parent a445b97 commit 744b49e

12 files changed

Lines changed: 103 additions & 35 deletions

src/inspector/string-util.cc

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

124+
// static
125+
void StringUtil::builderAppendQuotedString(StringBuilder& builder,
126+
const String& str) {
127+
builder.append('"');
128+
if (!str.isEmpty()) {
129+
escapeWideStringForJSON(
130+
reinterpret_cast<const uint16_t*>(str.characters16()),
131+
static_cast<int>(str.length()), &builder);
132+
}
133+
builder.append('"');
134+
}
135+
124136
} // namespace protocol
125137

126138
// static

src/inspector/string-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class StringUtil {
4949
static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
5050
builder.append(s, len);
5151
}
52+
static void builderAppendQuotedString(StringBuilder&, const String&);
5253
static void builderReserve(StringBuilder& builder, size_t capacity) {
5354
builder.reserveCapacity(capacity);
5455
}

third_party/inspector_protocol/CodeGenerator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ def init_defaults(config_tuple, path, defaults):
5959
jinja_dir = arg_options.jinja_dir
6060
if not jinja_dir:
6161
raise Exception("jinja directory must be specified")
62+
jinja_dir = jinja_dir.decode('utf8')
6263
output_base = arg_options.output_base
6364
if not output_base:
6465
raise Exception("Base output directory must be specified")
66+
output_base = output_base.decode('utf8')
6567
config_file = arg_options.config
6668
if not config_file:
6769
raise Exception("Config file name must be specified")
70+
config_file = config_file.decode('utf8')
6871
config_base = os.path.dirname(config_file)
6972
config_values = arg_options.config_value
7073
if not config_values:
@@ -440,6 +443,12 @@ def generate_event(self, domain, event):
440443
return self.check_options(self.config.protocol.options, domain, event, "include_events", "exclude_events", True)
441444

442445

446+
def generate_type(self, domain, typename):
447+
if not self.config.protocol.options:
448+
return domain in self.generate_domains
449+
return self.check_options(self.config.protocol.options, domain, typename, "include_types", "exclude_types", True)
450+
451+
443452
def is_async_command(self, domain, command):
444453
if not self.config.protocol.options:
445454
return False
@@ -473,6 +482,10 @@ def generate_disable(self, domain):
473482
return True
474483

475484

485+
def is_imported_dependency(self, domain):
486+
return domain in self.generate_domains or domain in self.imported_domains
487+
488+
476489
def main():
477490
jinja_dir, config_file, config = read_config()
478491

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: 1a7cbe8ba8fa0d622586f549a97c73d9b52efbea
5+
Revision: 8cb7a4f50ff7d5b1b7f2e5df0542dc577c88bdc3
66
License: BSD
77
License File: LICENSE
88
Security Critical: no

third_party/inspector_protocol/lib/DispatcherBase_cpp.template

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,13 @@ void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco
248248
m_dispatchers[name] = std::move(dispatcher);
249249
}
250250

251-
DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedMessage)
251+
void UberDispatcher::setupRedirects(const HashMap<String, String>& redirects)
252+
{
253+
for (const auto& pair : redirects)
254+
m_redirects[pair.first] = pair.second;
255+
}
256+
257+
DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedMessage, int* outCallId, String* outMethod)
252258
{
253259
if (!parsedMessage) {
254260
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON");
@@ -263,6 +269,8 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
263269
int callId = 0;
264270
protocol::Value* callIdValue = messageObject->get("id");
265271
bool success = callIdValue && callIdValue->asInteger(&callId);
272+
if (outCallId)
273+
*outCallId = callId;
266274
if (!success) {
267275
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must have integer 'id' porperty");
268276
return DispatchResponse::kError;
@@ -271,11 +279,17 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
271279
protocol::Value* methodValue = messageObject->get("method");
272280
String method;
273281
success = methodValue && methodValue->asString(&method);
282+
if (outMethod)
283+
*outMethod = method;
274284
if (!success) {
275285
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInvalidRequest, "Message must have string 'method' porperty", nullptr);
276286
return DispatchResponse::kError;
277287
}
278288

289+
HashMap<String, String>::iterator redirectIt = m_redirects.find(method);
290+
if (redirectIt != m_redirects.end())
291+
method = redirectIt->second;
292+
279293
size_t dotIndex = StringUtil::find(method, ".");
280294
if (dotIndex == StringUtil::kNotFound) {
281295
if (m_fallThroughForNotFound)

third_party/inspector_protocol/lib/DispatcherBase_h.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ class {{config.lib.export_macro}} UberDispatcher {
113113
public:
114114
explicit UberDispatcher(FrontendChannel*);
115115
void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>);
116-
DispatchResponse::Status dispatch(std::unique_ptr<Value> message);
116+
void setupRedirects(const HashMap<String, String>&);
117+
DispatchResponse::Status dispatch(std::unique_ptr<Value> message, int* callId = nullptr, String* method = nullptr);
117118
FrontendChannel* channel() { return m_frontendChannel; }
118119
bool fallThroughForNotFound() { return m_fallThroughForNotFound; }
119120
void setFallThroughForNotFound(bool);
@@ -122,6 +123,7 @@ public:
122123
private:
123124
FrontendChannel* m_frontendChannel;
124125
bool m_fallThroughForNotFound;
126+
HashMap<String, String> m_redirects;
125127
protocol::HashMap<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers;
126128
};
127129

third_party/inspector_protocol/lib/ErrorSupport_cpp.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ namespace {{namespace}} {
1111
ErrorSupport::ErrorSupport() { }
1212
ErrorSupport::~ErrorSupport() { }
1313

14+
void ErrorSupport::setName(const char* name)
15+
{
16+
setName(String(name));
17+
}
18+
1419
void ErrorSupport::setName(const String& name)
1520
{
1621
DCHECK(m_path.size());
@@ -27,6 +32,11 @@ void ErrorSupport::pop()
2732
m_path.pop_back();
2833
}
2934

35+
void ErrorSupport::addError(const char* error)
36+
{
37+
addError(String(error));
38+
}
39+
3040
void ErrorSupport::addError(const String& error)
3141
{
3242
StringBuilder builder;

third_party/inspector_protocol/lib/ErrorSupport_h.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ public:
1717
~ErrorSupport();
1818

1919
void push();
20+
void setName(const char*);
2021
void setName(const String&);
2122
void pop();
23+
void addError(const char*);
2224
void addError(const String&);
2325
bool hasErrors();
2426
String errors();

third_party/inspector_protocol/lib/Values_cpp.template

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,22 @@ void appendUnsignedAsHex(uint16_t number, StringBuilder* dst)
4242
}
4343
}
4444

45-
void escapeStringForJSON(const String& str, StringBuilder* dst)
46-
{
47-
for (unsigned i = 0; i < str.length(); ++i) {
48-
uint16_t c = str[i];
49-
if (!escapeChar(c, dst)) {
50-
if (c < 32 || c > 126 || c == '<' || c == '>') {
51-
// 1. Escaping <, > to prevent script execution.
52-
// 2. Technically, we could also pass through c > 126 as UTF8, but this
53-
// is also optional. It would also be a pain to implement here.
54-
appendUnsignedAsHex(c, dst);
55-
} else {
56-
StringUtil::builderAppend(*dst, c);
57-
}
45+
template <typename Char>
46+
void escapeStringForJSONInternal(const Char* str, unsigned len,
47+
StringBuilder* dst)
48+
{
49+
for (unsigned i = 0; i < len; ++i) {
50+
Char c = str[i];
51+
if (escapeChar(c, dst))
52+
continue;
53+
if (c < 32 || c > 126) {
54+
appendUnsignedAsHex(c, dst);
55+
} else {
56+
StringUtil::builderAppend(*dst, c);
5857
}
5958
}
6059
}
6160

62-
void doubleQuoteStringForJSON(const String& str, StringBuilder* dst)
63-
{
64-
StringUtil::builderAppend(*dst, '"');
65-
escapeStringForJSON(str, dst);
66-
StringUtil::builderAppend(*dst, '"');
67-
}
68-
6961
} // anonymous namespace
7062

7163
bool Value::asBoolean(bool*) const
@@ -181,7 +173,7 @@ bool StringValue::asString(String* output) const
181173
void StringValue::writeJSON(StringBuilder* output) const
182174
{
183175
DCHECK(type() == TypeString);
184-
doubleQuoteStringForJSON(m_stringValue, output);
176+
StringUtil::builderAppendQuotedString(*output, m_stringValue);
185177
}
186178

187179
std::unique_ptr<Value> StringValue::clone() const
@@ -336,7 +328,7 @@ void DictionaryValue::writeJSON(StringBuilder* output) const
336328
CHECK(it != m_data.end());
337329
if (i)
338330
StringUtil::builderAppend(*output, ',');
339-
doubleQuoteStringForJSON(it->first, output);
331+
StringUtil::builderAppendQuotedString(*output, it->first);
340332
StringUtil::builderAppend(*output, ':');
341333
it->second->writeJSON(output);
342334
}
@@ -402,6 +394,16 @@ protocol::Value* ListValue::at(size_t index)
402394
return m_data[index].get();
403395
}
404396

397+
void escapeLatinStringForJSON(const uint8_t* str, unsigned len, StringBuilder* dst)
398+
{
399+
escapeStringForJSONInternal<uint8_t>(str, len, dst);
400+
}
401+
402+
void escapeWideStringForJSON(const uint16_t* str, unsigned len, StringBuilder* dst)
403+
{
404+
escapeStringForJSONInternal<uint16_t>(str, len, dst);
405+
}
406+
405407
{% for namespace in config.protocol.namespace %}
406408
} // namespace {{namespace}}
407409
{% endfor %}

third_party/inspector_protocol/lib/Values_h.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ private:
239239
std::vector<std::unique_ptr<Value>> m_data;
240240
};
241241

242+
void escapeLatinStringForJSON(const uint8_t* str, unsigned len, StringBuilder* dst);
243+
void escapeWideStringForJSON(const uint16_t* str, unsigned len, StringBuilder* dst);
244+
242245
{% for namespace in config.protocol.namespace %}
243246
} // namespace {{namespace}}
244247
{% endfor %}

0 commit comments

Comments
 (0)