Commit 0b0ff239 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

[DevTools] Add binary type support for headless.

This adds support for protocol::Binary to the headless
client API generator, so that the headless shell may
take advantage of fields in the protocol that are
marked binary.

My overall WIP change is in here, and happy to explain more:
https://chromium-review.googlesource.com/c/chromium/src/+/1244719

Bug: chromium:891377
Change-Id: I4e46d4b94ad019be62a9a31867d956b00d718adf
Reviewed-on: https://chromium-review.googlesource.com/c/1285356Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600480}
parent 4f7ead10
...@@ -230,6 +230,21 @@ def CreateStringTypeDefinition(): ...@@ -230,6 +230,21 @@ def CreateStringTypeDefinition():
} }
def CreateBinaryTypeDefinition():
return {
'js_type': 'string',
'return_type': 'protocol::Binary',
'pass_type': 'const protocol::Binary&',
'to_pass_type': '%s',
'to_raw_type': '%s',
'to_raw_return_type': '%s',
'type': 'protocol::Binary',
'raw_type': 'protocol::Binary',
'raw_pass_type': 'const protocol::Binary&',
'raw_return_type': 'protocol::Binary',
}
def CreatePrimitiveTypeDefinition(type): def CreatePrimitiveTypeDefinition(type):
typedefs = { typedefs = {
'number': 'double', 'number': 'double',
...@@ -260,6 +275,7 @@ type_definitions['number'] = CreatePrimitiveTypeDefinition('number') ...@@ -260,6 +275,7 @@ type_definitions['number'] = CreatePrimitiveTypeDefinition('number')
type_definitions['integer'] = CreatePrimitiveTypeDefinition('integer') type_definitions['integer'] = CreatePrimitiveTypeDefinition('integer')
type_definitions['boolean'] = CreatePrimitiveTypeDefinition('boolean') type_definitions['boolean'] = CreatePrimitiveTypeDefinition('boolean')
type_definitions['string'] = CreateStringTypeDefinition() type_definitions['string'] = CreateStringTypeDefinition()
type_definitions['binary'] = CreateBinaryTypeDefinition()
type_definitions['object'] = CreateObjectTypeDefinition() type_definitions['object'] = CreateObjectTypeDefinition()
type_definitions['any'] = CreateAnyTypeDefinition() type_definitions['any'] = CreateAnyTypeDefinition()
...@@ -304,6 +320,9 @@ def CreateTypeDefinitions(json_api): ...@@ -304,6 +320,9 @@ def CreateTypeDefinitions(json_api):
elif type['type'] == 'string': elif type['type'] == 'string':
type_definitions[domain['domain'] + '.' + type['id']] = ( type_definitions[domain['domain'] + '.' + type['id']] = (
CreateStringTypeDefinition()) CreateStringTypeDefinition())
elif type['type'] == 'binary':
type_definitions[domain['domain'] + '.' + type['id']] = (
CreateBinaryTypeDefinition())
else: else:
type_definitions[domain['domain'] + '.' + type['id']] = ( type_definitions[domain['domain'] + '.' + type['id']] = (
CreatePrimitiveTypeDefinition(type['type'])) CreatePrimitiveTypeDefinition(type['type']))
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/values.h" #include "base/values.h"
#include "headless/lib/browser/protocol/protocol_string.h"
{% for domain_name in domain.dependencies %} {% for domain_name in domain.dependencies %}
#include "headless/public/devtools/domains/types_{{domain_name | camelcase_to_hacker_style}}.h" #include "headless/public/devtools/domains/types_{{domain_name | camelcase_to_hacker_style}}.h"
{% endfor %} {% endfor %}
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/optional.h" #include "base/optional.h"
#include "base/values.h" #include "base/values.h"
#include "headless/lib/browser/protocol/protocol_string.h"
{% for domain_name in domain.dependencies %} {% for domain_name in domain.dependencies %}
#include "headless/public/devtools/internal/types_forward_declarations_{{domain_name | camelcase_to_hacker_style}}.h" #include "headless/public/devtools/internal/types_forward_declarations_{{domain_name | camelcase_to_hacker_style}}.h"
{% endfor %} {% endfor %}
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include "headless/lib/browser/protocol/protocol_string.h"
#include "headless/public/util/error_reporter.h" #include "headless/public/util/error_reporter.h"
namespace headless { namespace headless {
...@@ -72,6 +73,11 @@ std::unique_ptr<base::Value> ToValue(const std::vector<T>& vector_of_values) { ...@@ -72,6 +73,11 @@ std::unique_ptr<base::Value> ToValue(const std::vector<T>& vector_of_values) {
return std::move(result); return std::move(result);
} }
template <>
inline std::unique_ptr<base::Value> ToValue(const protocol::Binary& value) {
return ToValue(value.toBase64());
}
// FromValue specializations for basic types. // FromValue specializations for basic types.
template <> template <>
struct FromValue<bool> { struct FromValue<bool> {
...@@ -146,6 +152,23 @@ struct FromValue<std::unique_ptr<T>> { ...@@ -146,6 +152,23 @@ struct FromValue<std::unique_ptr<T>> {
} }
}; };
template <>
struct FromValue<protocol::Binary> {
static protocol::Binary Parse(const base::Value& value,
ErrorReporter* errors) {
if (!value.is_string()) {
errors->AddError("string value expected");
return protocol::Binary();
}
bool success = false;
protocol::Binary out =
protocol::Binary::fromBase64(value.GetString(), &success);
if (!success)
errors->AddError("base64 decoding error");
return out;
}
};
template <typename T> template <typename T>
struct FromValue<std::vector<T>> { struct FromValue<std::vector<T>> {
static std::vector<T> Parse(const base::Value& value, ErrorReporter* errors) { static std::vector<T> Parse(const base::Value& value, ErrorReporter* errors) {
......
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