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

Roll inspector_protocol to 460186cff1f0eead0d418626e7e75f52105182b2.

See
https://chromium.googlesource.com/deps/inspector_protocol/+/460186cff1f0eead0d418626e7e75f52105182b2

Bug: chromium:891377
Change-Id: I10332e68fb33f8bc06a489162171c52675373536
Reviewed-on: https://chromium-review.googlesource.com/c/1297591
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56922}
parent e3e017ef
......@@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 5768a449acc0407bf55aef535b18d710df2a14f2
Revision: 460186cff1f0eead0d418626e7e75f52105182b2
License: BSD
License File: LICENSE
Security Critical: no
......
......@@ -168,6 +168,11 @@ def compare_types(context, kind, type_1, type_2, types_map_1, types_map_2, depth
base_type_1 = type_1["type"]
base_type_2 = type_2["type"]
# Binary and string have the same wire representation in JSON.
if ((base_type_1 == "string" and base_type_2 == "binary") or
(base_type_2 == "string" and base_type_1 == "binary")):
return
if base_type_1 != base_type_2:
errors.append("%s: %s base type mismatch, '%s' vs '%s'" % (context, kind, base_type_1, base_type_2))
elif base_type_1 == "object":
......
......@@ -266,6 +266,21 @@ def create_string_type_definition():
}
def create_binary_type_definition():
# pylint: disable=W0622
return {
"return_type": "Binary",
"pass_type": "const Binary&",
"to_pass_type": "%s",
"to_raw_type": "%s",
"to_rvalue": "%s",
"type": "Binary",
"raw_type": "Binary",
"raw_pass_type": "const Binary&",
"raw_return_type": "Binary",
}
def create_primitive_type_definition(type):
# pylint: disable=W0622
typedefs = {
......@@ -443,8 +458,10 @@ class Protocol(object):
self.type_definitions["boolean"] = create_primitive_type_definition("boolean")
self.type_definitions["object"] = create_object_type_definition()
self.type_definitions["any"] = create_any_type_definition()
self.type_definitions["binary"] = create_binary_type_definition()
for domain in self.json_api["domains"]:
self.type_definitions[domain["domain"] + ".string"] = create_string_type_definition()
self.type_definitions[domain["domain"] + ".binary"] = create_binary_type_definition()
if not ("types" in domain):
continue
for type in domain["types"]:
......@@ -457,6 +474,8 @@ class Protocol(object):
self.type_definitions[type_name] = self.resolve_type(type)
elif type["type"] == domain["domain"] + ".string":
self.type_definitions[type_name] = create_string_type_definition()
elif type["type"] == domain["domain"] + ".binary":
self.type_definitions[type_name] = create_binary_type_definition()
else:
self.type_definitions[type_name] = create_primitive_type_definition(type["type"])
......
......@@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import collections
import json
import os.path
......@@ -12,19 +13,22 @@ import sys
import pdl
def main(argv):
if len(argv) < 2:
sys.stderr.write("Usage: %s <protocol.pdl> <protocol.json>\n" % sys.argv[0])
return 1
file_name = os.path.normpath(argv[0])
parser = argparse.ArgumentParser(description=(
"Converts from .pdl to .json by invoking the pdl Python module."))
parser.add_argument('--map_binary_to_string', type=bool,
help=('If set, binary in the .pdl is mapped to a '
'string in .json. Client code will have to '
'base64 decode the string to get the payload.'))
parser.add_argument("pdl_file", help="The .pdl input file to parse.")
parser.add_argument("json_file", help="The .json output file write.")
args = parser.parse_args(argv)
file_name = os.path.normpath(args.pdl_file)
input_file = open(file_name, "r")
pdl_string = input_file.read()
protocol = pdl.loads(pdl_string, file_name)
protocol = pdl.loads(pdl_string, file_name, args.map_binary_to_string)
input_file.close()
output_file = open(argv[0].replace('.pdl', '.json'), 'wb')
json.dump(protocol, output_file, indent=4, separators=(',', ': '))
output_file.close()
output_file = open(os.path.normpath(argv[1]), 'wb')
output_file = open(os.path.normpath(args.json_file), 'wb')
json.dump(protocol, output_file, indent=4, separators=(',', ': '))
output_file.close()
......
......@@ -246,10 +246,6 @@ bool UberDispatcher::parseCommand(Value* parsedMessage, int* outCallId, String*
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInvalidRequest, "Message must have string 'method' property", nullptr);
return false;
}
std::unordered_map<String, String>::iterator redirectIt = m_redirects.find(method);
if (redirectIt != m_redirects.end())
method = redirectIt->second;
if (outMethod)
*outMethod = method;
return true;
......@@ -268,13 +264,21 @@ protocol::DispatcherBase* UberDispatcher::findDispatcher(const String& method) {
return it->second.get();
}
bool UberDispatcher::canDispatch(const String& method)
bool UberDispatcher::canDispatch(const String& in_method)
{
String method = in_method;
auto redirectIt = m_redirects.find(method);
if (redirectIt != m_redirects.end())
method = redirectIt->second;
return !!findDispatcher(method);
}
void UberDispatcher::dispatch(int callId, const String& method, std::unique_ptr<Value> parsedMessage, const String& rawMessage)
void UberDispatcher::dispatch(int callId, const String& in_method, std::unique_ptr<Value> parsedMessage, const String& rawMessage)
{
String method = in_method;
auto redirectIt = m_redirects.find(method);
if (redirectIt != m_redirects.end())
method = redirectIt->second;
protocol::DispatcherBase* dispatcher = findDispatcher(method);
if (!dispatcher) {
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
......
......@@ -116,6 +116,15 @@ public:
using MaybeBase::operator=;
};
template<>
class Maybe<Binary> : public MaybeBase<Binary> {
public:
Maybe() { }
Maybe(Binary value) : MaybeBase(value) { }
Maybe(Maybe&& other) IP_NOEXCEPT : MaybeBase(std::move(other)) {}
using MaybeBase::operator=;
};
{% for namespace in config.protocol.namespace %}
} // namespace {{namespace}}
{% endfor %}
......
......@@ -16,12 +16,12 @@ namespace {{namespace}} {
class {{config.lib.export_macro}} Object {
public:
static std::unique_ptr<Object> fromValue(protocol::Value*, ErrorSupport*);
explicit Object(std::unique_ptr<protocol::DictionaryValue>);
~Object();
std::unique_ptr<protocol::DictionaryValue> toValue() const;
std::unique_ptr<Object> clone() const;
private:
explicit Object(std::unique_ptr<protocol::DictionaryValue>);
std::unique_ptr<protocol::DictionaryValue> m_object;
};
......
......@@ -99,6 +99,28 @@ struct ValueConversions<String> {
}
};
template<>
struct ValueConversions<Binary> {
static Binary fromValue(protocol::Value* value, ErrorSupport* errors)
{
String result;
bool success = value ? value->asString(&result) : false;
if (!success) {
errors->addError("string value expected");
return Binary();
}
Binary out = Binary::fromBase64(result, &success);
if (!success)
errors->addError("base64 decoding error");
return out;
}
static std::unique_ptr<protocol::Value> toValue(const Binary& value)
{
return StringValue::create(value.toBase64());
}
};
template<>
struct ValueConversions<Value> {
static std::unique_ptr<Value> fromValue(protocol::Value* value, ErrorSupport* errors)
......
......@@ -10,18 +10,21 @@ import sys
description = ''
primitiveTypes = ['integer', 'number', 'boolean', 'string', 'object', 'any', 'array']
primitiveTypes = ['integer', 'number', 'boolean', 'string', 'object', 'any', 'array', 'binary']
def assignType(item, type, isArray=False):
if isArray:
def assignType(item, type, is_array=False, map_binary_to_string=False):
if is_array:
item['type'] = 'array'
item['items'] = collections.OrderedDict()
assignType(item['items'], type)
assignType(item['items'], type, False, map_binary_to_string)
return
if type == 'enum':
type = 'string'
if map_binary_to_string and type == 'binary':
type = 'string'
if type in primitiveTypes:
item['type'] = type
else:
......@@ -42,7 +45,7 @@ def createItem(d, experimental, deprecated, name=None):
return result
def parse(data, file_name):
def parse(data, file_name, map_binary_to_string=False):
protocol = collections.OrderedDict()
protocol['version'] = collections.OrderedDict()
protocol['domains'] = []
......@@ -88,7 +91,7 @@ def parse(data, file_name):
if 'types' not in domain:
domain['types'] = []
item = createItem({'id': match.group(3)}, match.group(1), match.group(2))
assignType(item, match.group(5), match.group(4))
assignType(item, match.group(5), match.group(4), map_binary_to_string)
domain['types'].append(item)
continue
......@@ -115,7 +118,7 @@ def parse(data, file_name):
param = createItem({}, match.group(1), match.group(2), match.group(6))
if match.group(3):
param['optional'] = True
assignType(param, match.group(5), match.group(4))
assignType(param, match.group(5), match.group(4), map_binary_to_string)
if match.group(5) == 'enum':
enumliterals = param['enum'] = []
subitems.append(param)
......@@ -161,7 +164,7 @@ def parse(data, file_name):
return protocol
def loads(data, file_name):
def loads(data, file_name, map_binary_to_string=False):
if file_name.endswith(".pdl"):
return parse(data, file_name)
return parse(data, file_name, map_binary_to_string)
return json.loads(data)
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