Commit f16b8a06 authored by dgozman's avatar dgozman Committed by Commit bot

Roll third_party/inspector_protocol to 344219890fe40130571f5a5b17f261a654e3b8cc.

This roll includes:
- [inspector_protocol] Support redirects and types whitelisting.

TBR=kozyatinskiy@chromium.org
BUG=none

Review-Url: https://codereview.chromium.org/2572643002
Cr-Commit-Position: refs/heads/master@{#438024}
parent 89636c39
...@@ -440,6 +440,12 @@ class Protocol(object): ...@@ -440,6 +440,12 @@ class Protocol(object):
return self.check_options(self.config.protocol.options, domain, event, "include_events", "exclude_events", True) return self.check_options(self.config.protocol.options, domain, event, "include_events", "exclude_events", True)
def generate_type(self, domain, typename):
if not self.config.protocol.options:
return domain in self.generate_domains
return self.check_options(self.config.protocol.options, domain, typename, "include_types", "exclude_types", True)
def is_async_command(self, domain, command): def is_async_command(self, domain, command):
if not self.config.protocol.options: if not self.config.protocol.options:
return False return False
...@@ -473,6 +479,10 @@ class Protocol(object): ...@@ -473,6 +479,10 @@ class Protocol(object):
return True return True
def is_imported_dependency(self, domain):
return domain in self.generate_domains or domain in self.imported_domains
def main(): def main():
jinja_dir, config_file, config = read_config() jinja_dir, config_file, config = read_config()
......
...@@ -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: c65b17da8a32bc6ab25b4ebbef1008f23c69e7d1 Revision: 344219890fe40130571f5a5b17f261a654e3b8cc
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -248,7 +248,13 @@ void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco ...@@ -248,7 +248,13 @@ void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco
m_dispatchers[name] = std::move(dispatcher); m_dispatchers[name] = std::move(dispatcher);
} }
DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedMessage) void UberDispatcher::setupRedirects(const HashMap<String, String>& redirects)
{
for (const auto& pair : redirects)
m_redirects[pair.first] = pair.second;
}
DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedMessage, int* outCallId, String* outMethod)
{ {
if (!parsedMessage) { if (!parsedMessage) {
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON"); reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON");
...@@ -263,6 +269,8 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM ...@@ -263,6 +269,8 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
int callId = 0; int callId = 0;
protocol::Value* callIdValue = messageObject->get("id"); protocol::Value* callIdValue = messageObject->get("id");
bool success = callIdValue && callIdValue->asInteger(&callId); bool success = callIdValue && callIdValue->asInteger(&callId);
if (outCallId)
*outCallId = callId;
if (!success) { if (!success) {
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must have integer 'id' porperty"); reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must have integer 'id' porperty");
return DispatchResponse::kError; return DispatchResponse::kError;
...@@ -271,11 +279,17 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM ...@@ -271,11 +279,17 @@ DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedM
protocol::Value* methodValue = messageObject->get("method"); protocol::Value* methodValue = messageObject->get("method");
String method; String method;
success = methodValue && methodValue->asString(&method); success = methodValue && methodValue->asString(&method);
if (outMethod)
*outMethod = method;
if (!success) { if (!success) {
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInvalidRequest, "Message must have string 'method' porperty", nullptr); reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInvalidRequest, "Message must have string 'method' porperty", nullptr);
return DispatchResponse::kError; return DispatchResponse::kError;
} }
HashMap<String, String>::iterator redirectIt = m_redirects.find(method);
if (redirectIt != m_redirects.end())
method = redirectIt->second;
size_t dotIndex = method.find("."); size_t dotIndex = method.find(".");
if (dotIndex == StringUtil::kNotFound) { if (dotIndex == StringUtil::kNotFound) {
if (m_fallThroughForNotFound) if (m_fallThroughForNotFound)
......
...@@ -113,7 +113,8 @@ class {{config.lib.export_macro}} UberDispatcher { ...@@ -113,7 +113,8 @@ class {{config.lib.export_macro}} UberDispatcher {
public: public:
explicit UberDispatcher(FrontendChannel*); explicit UberDispatcher(FrontendChannel*);
void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>); void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>);
DispatchResponse::Status dispatch(std::unique_ptr<Value> message); void setupRedirects(const HashMap<String, String>&);
DispatchResponse::Status dispatch(std::unique_ptr<Value> message, int* callId = nullptr, String* method = nullptr);
FrontendChannel* channel() { return m_frontendChannel; } FrontendChannel* channel() { return m_frontendChannel; }
bool fallThroughForNotFound() { return m_fallThroughForNotFound; } bool fallThroughForNotFound() { return m_fallThroughForNotFound; }
void setFallThroughForNotFound(bool); void setFallThroughForNotFound(bool);
...@@ -122,6 +123,7 @@ public: ...@@ -122,6 +123,7 @@ public:
private: private:
FrontendChannel* m_frontendChannel; FrontendChannel* m_frontendChannel;
bool m_fallThroughForNotFound; bool m_fallThroughForNotFound;
HashMap<String, String> m_redirects;
protocol::HashMap<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers; protocol::HashMap<String, std::unique_ptr<protocol::DispatcherBase>> m_dispatchers;
}; };
......
...@@ -19,6 +19,7 @@ const char Metainfo::domainName[] = "{{domain.domain}}"; ...@@ -19,6 +19,7 @@ const char Metainfo::domainName[] = "{{domain.domain}}";
const char Metainfo::commandPrefix[] = "{{domain.domain}}."; const char Metainfo::commandPrefix[] = "{{domain.domain}}.";
const char Metainfo::version[] = "{{domain.version}}"; const char Metainfo::version[] = "{{domain.version}}";
{% for type in domain.types %} {% for type in domain.types %}
{% if not protocol.generate_type(domain.domain, type.id) %}{% continue %} {% endif %}
{% if "enum" in type %} {% if "enum" in type %}
namespace {{type.id}}Enum { namespace {{type.id}}Enum {
...@@ -200,18 +201,23 @@ public: ...@@ -200,18 +201,23 @@ public:
, m_backend(backend) , m_backend(backend)
, m_fallThroughForNotFound(fallThroughForNotFound) { , m_fallThroughForNotFound(fallThroughForNotFound) {
{% for command in domain.commands %} {% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %} {% if "redirect" in command %}
m_redirects["{{domain.domain}}.{{command.name}}"] = "{{command.redirect}}.{{command.name}}";
{% continue %}
{% endif %}
{% if not protocol.generate_command(domain.domain, command.name) %}{% continue %}{% endif %} {% if not protocol.generate_command(domain.domain, command.name) %}{% continue %}{% endif %}
m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{{command.name}}; m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{{command.name}};
{% endfor %} {% endfor %}
} }
~DispatcherImpl() override { } ~DispatcherImpl() override { }
DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override; DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
HashMap<String, String>& redirects() { return m_redirects; }
protected: protected:
using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors); using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
using DispatchMap = protocol::HashMap<String, CallHandler>; using DispatchMap = protocol::HashMap<String, CallHandler>;
DispatchMap m_dispatchMap; DispatchMap m_dispatchMap;
HashMap<String, String> m_redirects;
{% for command in domain.commands %} {% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %} {% if "redirect" in command %}{% continue %}{% endif %}
...@@ -337,9 +343,9 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu ...@@ -337,9 +343,9 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
&out_{{parameter.name}} &out_{{parameter.name}}
{%- endfor %} {%- endfor %}
{% endif %}); {% endif %});
{% if "returns" in command %}
if (response.status() == DispatchResponse::kFallThrough) if (response.status() == DispatchResponse::kFallThrough)
return response.status(); return response.status();
{% if "returns" in command %}
std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create(); std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
if (response.status() == DispatchResponse::kSuccess) { if (response.status() == DispatchResponse::kSuccess) {
{% for parameter in command.returns %} {% for parameter in command.returns %}
...@@ -378,9 +384,11 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu ...@@ -378,9 +384,11 @@ DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu
{% endfor %} {% endfor %}
// static // static
void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
{ {
dispatcher->registerBackend("{{domain.domain}}", std::unique_ptr<protocol::DispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fallThroughForNotFound()))); std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend, uber->fallThroughForNotFound()));
uber->setupRedirects(dispatcher->redirects());
uber->registerBackend("{{domain.domain}}", std::move(dispatcher));
} }
} // {{domain.domain}} } // {{domain.domain}}
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
// For each imported domain we generate a ValueConversions struct instead of a full domain definition // For each imported domain we generate a ValueConversions struct instead of a full domain definition
// and include Domain::API version from there. // and include Domain::API version from there.
{% for name in domain.dependencies %} {% for name in domain.dependencies %}
{% if protocol.is_imported_dependency(name) %}
#include {{format_include(config.protocol.package, name)}} #include {{format_include(config.protocol.package, name)}}
{% endif %}
{% endfor %} {% endfor %}
{% if protocol.is_exported_domain(domain.domain) %} {% if protocol.is_exported_domain(domain.domain) %}
#include {{format_include(config.exported.package, domain.domain)}} #include {{format_include(config.exported.package, domain.domain)}}
...@@ -27,6 +29,7 @@ namespace {{domain.domain}} { ...@@ -27,6 +29,7 @@ namespace {{domain.domain}} {
// ------------- Forward and enum declarations. // ------------- Forward and enum declarations.
{% for type in domain.types %} {% for type in domain.types %}
{% if not protocol.generate_type(domain.domain, type.id) %}{% continue %}{% endif %}
{% if type.type == "object" %} {% if type.type == "object" %}
{% if "properties" in type %} {% if "properties" in type %}
// {{type.description}} // {{type.description}}
...@@ -41,6 +44,7 @@ using {{type.id}} = {{protocol.resolve_type(type).type}}; ...@@ -41,6 +44,7 @@ using {{type.id}} = {{protocol.resolve_type(type).type}};
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% for type in domain.types %} {% for type in domain.types %}
{% if not protocol.generate_type(domain.domain, type.id) %}{% continue %}{% endif %}
{% if "enum" in type %} {% if "enum" in type %}
namespace {{type.id}}Enum { namespace {{type.id}}Enum {
...@@ -67,6 +71,7 @@ namespace {{param.name | to_title_case}}Enum { ...@@ -67,6 +71,7 @@ namespace {{param.name | to_title_case}}Enum {
// ------------- Type and builder declarations. // ------------- Type and builder declarations.
{% for type in domain.types %} {% for type in domain.types %}
{% if not protocol.generate_type(domain.domain, type.id) %}{% continue %}{% endif %}
{% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %} {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
// {{type.description}} // {{type.description}}
......
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