Roll third_party/inspector_protocol to cf45a6e89b17cdc9eeacdef4c003fcc55f7ec2a0
This roll includes one change: "[inspector_protocol] support fall through and moveable Maybe" [1]. [1] https://codereview.chromium.org/2468923002/ BUG=none R=dgozman@chromium.org Review-Url: https://codereview.chromium.org/2469063002 Cr-Commit-Position: refs/heads/master@{#40687}
This commit is contained in:
parent
b19abf5371
commit
d5055bc932
@ -1,7 +1,6 @@
|
||||
setBreakpointByUrl error: undefined
|
||||
setBreakpoint error: {
|
||||
"code": -32602,
|
||||
"message": "Invalid request",
|
||||
"message": "Invalid parameters",
|
||||
"data": "location: object expected"
|
||||
}
|
||||
|
||||
|
@ -329,6 +329,11 @@ def resolve_type(protocol, prop):
|
||||
return protocol.type_definitions[prop["type"]]
|
||||
|
||||
|
||||
def new_style(domain):
|
||||
domains = []
|
||||
return domain["domain"] in domains
|
||||
|
||||
|
||||
def join_arrays(dict, keys):
|
||||
result = []
|
||||
for key in keys:
|
||||
@ -339,7 +344,7 @@ def join_arrays(dict, keys):
|
||||
|
||||
def has_disable(commands):
|
||||
for command in commands:
|
||||
if command["name"] == "disable":
|
||||
if command["name"] == "disable" and (not ("handlers" in command) or "renderer" in command["handlers"]):
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -421,6 +426,7 @@ def main():
|
||||
"type_definition": functools.partial(type_definition, protocol),
|
||||
"has_disable": has_disable,
|
||||
"format_include": format_include,
|
||||
"new_style": new_style,
|
||||
}
|
||||
|
||||
if domain["domain"] in protocol.generate_domains:
|
||||
@ -448,7 +454,6 @@ def main():
|
||||
"ValueConversions_h.template",
|
||||
"Maybe_h.template",
|
||||
"Array_h.template",
|
||||
"BackendCallback_h.template",
|
||||
"DispatcherBase_h.template",
|
||||
"Parser_h.template",
|
||||
]
|
||||
|
2
third_party/inspector_protocol/README.v8
vendored
2
third_party/inspector_protocol/README.v8
vendored
@ -2,7 +2,7 @@ Name: inspector protocol
|
||||
Short Name: inspector_protocol
|
||||
URL: https://chromium.googlesource.com/deps/inspector_protocol/
|
||||
Version: 0
|
||||
Revision: 6c15061ecf7168e520d33633b217e029e74760a7
|
||||
Revision: cf45a6e89b17cdc9eeacdef4c003fcc55f7ec2a0
|
||||
License: BSD
|
||||
License File: LICENSE
|
||||
Security Critical: no
|
||||
|
@ -33,7 +33,6 @@ template("inspector_protocol_generate") {
|
||||
invoker.config_file,
|
||||
"$inspector_protocol_dir/lib/Allocator_h.template",
|
||||
"$inspector_protocol_dir/lib/Array_h.template",
|
||||
"$inspector_protocol_dir/lib/BackendCallback_h.template",
|
||||
"$inspector_protocol_dir/lib/Collections_h.template",
|
||||
"$inspector_protocol_dir/lib/DispatcherBase_cpp.template",
|
||||
"$inspector_protocol_dir/lib/DispatcherBase_h.template",
|
||||
|
@ -7,7 +7,6 @@
|
||||
'inspector_protocol_files': [
|
||||
'lib/Allocator_h.template',
|
||||
'lib/Array_h.template',
|
||||
'lib/BackendCallback_h.template',
|
||||
'lib/Collections_h.template',
|
||||
'lib/DispatcherBase_cpp.template',
|
||||
'lib/DispatcherBase_h.template',
|
||||
|
@ -1,24 +0,0 @@
|
||||
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef {{"_".join(config.protocol.namespace)}}_BackendCallback_h
|
||||
#define {{"_".join(config.protocol.namespace)}}_BackendCallback_h
|
||||
|
||||
//#include "Forward.h"
|
||||
|
||||
{% for namespace in config.protocol.namespace %}
|
||||
namespace {{namespace}} {
|
||||
{% endfor %}
|
||||
|
||||
class {{config.lib.export_macro}} BackendCallback {
|
||||
public:
|
||||
virtual ~BackendCallback() { }
|
||||
virtual void sendFailure(const ErrorString&) = 0;
|
||||
};
|
||||
|
||||
{% for namespace in config.protocol.namespace %}
|
||||
} // namespace {{namespace}}
|
||||
{% endfor %}
|
||||
|
||||
#endif // !defined({{"_".join(config.protocol.namespace)}}_BackendCallback_h)
|
@ -10,7 +10,45 @@ namespace {{namespace}} {
|
||||
{% endfor %}
|
||||
|
||||
// static
|
||||
const char DispatcherBase::kInvalidRequest[] = "Invalid request";
|
||||
DispatchResponse DispatchResponse::OK()
|
||||
{
|
||||
DispatchResponse result;
|
||||
result.m_status = kSuccess;
|
||||
result.m_errorCode = kParseError;
|
||||
return result;
|
||||
}
|
||||
|
||||
// static
|
||||
DispatchResponse DispatchResponse::Error(const String& error)
|
||||
{
|
||||
DispatchResponse result;
|
||||
result.m_status = kError;
|
||||
result.m_errorCode = kServerError;
|
||||
result.m_errorMessage = error;
|
||||
return result;
|
||||
}
|
||||
|
||||
// static
|
||||
DispatchResponse DispatchResponse::InternalError()
|
||||
{
|
||||
DispatchResponse result;
|
||||
result.m_status = kError;
|
||||
result.m_errorCode = kInternalError;
|
||||
result.m_errorMessage = "Internal error";
|
||||
return result;
|
||||
}
|
||||
|
||||
// static
|
||||
DispatchResponse DispatchResponse::FallThrough()
|
||||
{
|
||||
DispatchResponse result;
|
||||
result.m_status = kFallThrough;
|
||||
result.m_errorCode = kParseError;
|
||||
return result;
|
||||
}
|
||||
|
||||
// static
|
||||
const char DispatcherBase::kInvalidParamsString[] = "Invalid parameters";
|
||||
|
||||
DispatcherBase::WeakPtr::WeakPtr(DispatcherBase* dispatcher) : m_dispatcher(dispatcher) { }
|
||||
|
||||
@ -31,11 +69,11 @@ void DispatcherBase::Callback::dispose()
|
||||
m_backendImpl = nullptr;
|
||||
}
|
||||
|
||||
void DispatcherBase::Callback::sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const ErrorString& invocationError)
|
||||
void DispatcherBase::Callback::sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const DispatchResponse& response)
|
||||
{
|
||||
if (!m_backendImpl || !m_backendImpl->get())
|
||||
return;
|
||||
m_backendImpl->get()->sendResponse(m_callId, invocationError, nullptr, std::move(partialMessage));
|
||||
m_backendImpl->get()->sendResponse(m_callId, response, std::move(partialMessage));
|
||||
m_backendImpl = nullptr;
|
||||
}
|
||||
|
||||
@ -64,10 +102,10 @@ bool DispatcherBase::getCommandName(const String& message, String* result)
|
||||
return true;
|
||||
}
|
||||
|
||||
void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError, ErrorSupport* errors, std::unique_ptr<protocol::DictionaryValue> result)
|
||||
void DispatcherBase::sendResponse(int callId, const DispatchResponse& response, std::unique_ptr<protocol::DictionaryValue> result)
|
||||
{
|
||||
if (invocationError.length() || (errors && errors->hasErrors())) {
|
||||
reportProtocolError(callId, ServerError, invocationError, errors);
|
||||
if (response.status() == DispatchResponse::kError) {
|
||||
reportProtocolError(callId, response.errorCode(), response.errorMessage(), nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -78,24 +116,18 @@ void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError
|
||||
m_frontendChannel->sendProtocolResponse(callId, responseMessage->toJSONString());
|
||||
}
|
||||
|
||||
void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError, std::unique_ptr<protocol::DictionaryValue> result)
|
||||
void DispatcherBase::sendResponse(int callId, const DispatchResponse& response)
|
||||
{
|
||||
sendResponse(callId, invocationError, nullptr, std::move(result));
|
||||
sendResponse(callId, response, DictionaryValue::create());
|
||||
}
|
||||
|
||||
void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError)
|
||||
{
|
||||
sendResponse(callId, invocationError, nullptr, DictionaryValue::create());
|
||||
}
|
||||
|
||||
static void reportProtocolErrorTo(FrontendChannel* frontendChannel, int callId, DispatcherBase::CommonErrorCode code, const String& errorMessage, ErrorSupport* errors)
|
||||
static void reportProtocolErrorTo(FrontendChannel* frontendChannel, int callId, DispatchResponse::ErrorCode code, const String& errorMessage, ErrorSupport* errors)
|
||||
{
|
||||
if (!frontendChannel)
|
||||
return;
|
||||
std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create();
|
||||
error->setInteger("code", code);
|
||||
error->setString("message", errorMessage);
|
||||
DCHECK(error);
|
||||
if (errors && errors->hasErrors())
|
||||
error->setString("data", errors->errors());
|
||||
std::unique_ptr<protocol::DictionaryValue> message = DictionaryValue::create();
|
||||
@ -104,7 +136,19 @@ static void reportProtocolErrorTo(FrontendChannel* frontendChannel, int callId,
|
||||
frontendChannel->sendProtocolResponse(callId, message->toJSONString());
|
||||
}
|
||||
|
||||
void DispatcherBase::reportProtocolError(int callId, CommonErrorCode code, const String& errorMessage, ErrorSupport* errors)
|
||||
static void reportProtocolErrorTo(FrontendChannel* frontendChannel, DispatchResponse::ErrorCode code, const String& errorMessage)
|
||||
{
|
||||
if (!frontendChannel)
|
||||
return;
|
||||
std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create();
|
||||
error->setInteger("code", code);
|
||||
error->setString("message", errorMessage);
|
||||
std::unique_ptr<protocol::DictionaryValue> message = DictionaryValue::create();
|
||||
message->setObject("error", std::move(error));
|
||||
frontendChannel->sendProtocolNotification(message->toJSONString());
|
||||
}
|
||||
|
||||
void DispatcherBase::reportProtocolError(int callId, DispatchResponse::ErrorCode code, const String& errorMessage, ErrorSupport* errors)
|
||||
{
|
||||
reportProtocolErrorTo(m_frontendChannel, callId, code, errorMessage, errors);
|
||||
}
|
||||
@ -132,38 +176,46 @@ void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco
|
||||
m_dispatchers[name] = std::move(dispatcher);
|
||||
}
|
||||
|
||||
void UberDispatcher::dispatch(std::unique_ptr<Value> parsedMessage)
|
||||
DispatchResponse::Status UberDispatcher::dispatch(std::unique_ptr<Value> parsedMessage)
|
||||
{
|
||||
if (!parsedMessage)
|
||||
return;
|
||||
if (!parsedMessage) {
|
||||
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kParseError, "Message must be a valid JSON");
|
||||
return DispatchResponse::kError;
|
||||
}
|
||||
std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(std::move(parsedMessage));
|
||||
if (!messageObject)
|
||||
return;
|
||||
if (!messageObject) {
|
||||
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must be an object");
|
||||
return DispatchResponse::kError;
|
||||
}
|
||||
|
||||
int callId = 0;
|
||||
protocol::Value* callIdValue = messageObject->get("id");
|
||||
bool success = callIdValue && callIdValue->asInteger(&callId);
|
||||
if (!success)
|
||||
return;
|
||||
if (!success) {
|
||||
reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must have integer 'id' porperty");
|
||||
return DispatchResponse::kError;
|
||||
}
|
||||
|
||||
protocol::Value* methodValue = messageObject->get("method");
|
||||
String method;
|
||||
success = methodValue && methodValue->asString(&method);
|
||||
if (!success)
|
||||
return;
|
||||
if (!success) {
|
||||
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInvalidRequest, "Message must have string 'method' porperty", nullptr);
|
||||
return DispatchResponse::kError;
|
||||
}
|
||||
|
||||
size_t dotIndex = method.find(".");
|
||||
if (dotIndex == StringUtil::kNotFound) {
|
||||
reportProtocolErrorTo(m_frontendChannel, callId, DispatcherBase::MethodNotFound, "'" + method + "' wasn't found", nullptr);
|
||||
return;
|
||||
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
|
||||
return DispatchResponse::kError;
|
||||
}
|
||||
String domain = StringUtil::substring(method, 0, dotIndex);
|
||||
auto it = m_dispatchers.find(domain);
|
||||
if (it == m_dispatchers.end()) {
|
||||
reportProtocolErrorTo(m_frontendChannel, callId, DispatcherBase::MethodNotFound, "'" + method + "' wasn't found", nullptr);
|
||||
return;
|
||||
reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
|
||||
return DispatchResponse::kError;
|
||||
}
|
||||
it->second->dispatch(callId, method, std::move(messageObject));
|
||||
return it->second->dispatch(callId, method, std::move(messageObject));
|
||||
}
|
||||
|
||||
UberDispatcher::~UberDispatcher() = default;
|
||||
|
@ -5,7 +5,6 @@
|
||||
#ifndef {{"_".join(config.protocol.namespace)}}_DispatcherBase_h
|
||||
#define {{"_".join(config.protocol.namespace)}}_DispatcherBase_h
|
||||
|
||||
//#include "BackendCallback.h"
|
||||
//#include "Collections.h"
|
||||
//#include "ErrorSupport.h"
|
||||
//#include "Forward.h"
|
||||
@ -17,10 +16,44 @@ namespace {{namespace}} {
|
||||
|
||||
class WeakPtr;
|
||||
|
||||
class {{config.lib.export_macro}} DispatchResponse {
|
||||
public:
|
||||
enum Status {
|
||||
kSuccess = 0,
|
||||
kError = 1,
|
||||
kFallThrough = 2,
|
||||
kAsync = 3
|
||||
};
|
||||
|
||||
enum ErrorCode {
|
||||
kParseError = -32700,
|
||||
kInvalidRequest = -32600,
|
||||
kMethodNotFound = -32601,
|
||||
kInvalidParams = -32602,
|
||||
kInternalError = -32603,
|
||||
kServerError = -32000,
|
||||
};
|
||||
|
||||
Status status() const { return m_status; }
|
||||
const String& errorMessage() const { return m_errorMessage; }
|
||||
ErrorCode errorCode() const { return m_errorCode; }
|
||||
bool isSuccess() const { return m_status == kSuccess; }
|
||||
|
||||
static DispatchResponse OK();
|
||||
static DispatchResponse Error(const String&);
|
||||
static DispatchResponse InternalError();
|
||||
static DispatchResponse FallThrough();
|
||||
|
||||
private:
|
||||
Status m_status;
|
||||
String m_errorMessage;
|
||||
ErrorCode m_errorCode;
|
||||
};
|
||||
|
||||
class {{config.lib.export_macro}} DispatcherBase {
|
||||
PROTOCOL_DISALLOW_COPY(DispatcherBase);
|
||||
public:
|
||||
static const char kInvalidRequest[];
|
||||
static const char kInvalidParamsString[];
|
||||
class {{config.lib.export_macro}} WeakPtr {
|
||||
public:
|
||||
explicit WeakPtr(DispatcherBase*);
|
||||
@ -32,14 +65,14 @@ public:
|
||||
DispatcherBase* m_dispatcher;
|
||||
};
|
||||
|
||||
class {{config.lib.export_macro}} Callback : public protocol::BackendCallback {
|
||||
class {{config.lib.export_macro}} Callback {
|
||||
public:
|
||||
Callback(std::unique_ptr<WeakPtr> backendImpl, int callId);
|
||||
virtual ~Callback();
|
||||
void dispose();
|
||||
|
||||
protected:
|
||||
void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const ErrorString& invocationError);
|
||||
void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const DispatchResponse& response);
|
||||
|
||||
private:
|
||||
std::unique_ptr<WeakPtr> m_backendImpl;
|
||||
@ -49,24 +82,14 @@ public:
|
||||
explicit DispatcherBase(FrontendChannel*);
|
||||
virtual ~DispatcherBase();
|
||||
|
||||
enum CommonErrorCode {
|
||||
ParseError = -32700,
|
||||
InvalidRequest = -32600,
|
||||
MethodNotFound = -32601,
|
||||
InvalidParams = -32602,
|
||||
InternalError = -32603,
|
||||
ServerError = -32000,
|
||||
};
|
||||
|
||||
static bool getCommandName(const String& message, String* result);
|
||||
|
||||
virtual void dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) = 0;
|
||||
virtual DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) = 0;
|
||||
|
||||
void sendResponse(int callId, const ErrorString&, ErrorSupport*, std::unique_ptr<protocol::DictionaryValue> result);
|
||||
void sendResponse(int callId, const ErrorString&, std::unique_ptr<protocol::DictionaryValue> result);
|
||||
void sendResponse(int callId, const ErrorString&);
|
||||
void sendResponse(int callId, const DispatchResponse&, std::unique_ptr<protocol::DictionaryValue> result);
|
||||
void sendResponse(int callId, const DispatchResponse&);
|
||||
|
||||
void reportProtocolError(int callId, CommonErrorCode, const String& errorMessage, ErrorSupport* errors);
|
||||
void reportProtocolError(int callId, DispatchResponse::ErrorCode, const String& errorMessage, ErrorSupport* errors);
|
||||
void clearFrontend();
|
||||
|
||||
std::unique_ptr<WeakPtr> weakPtr();
|
||||
@ -81,7 +104,7 @@ class {{config.lib.export_macro}} UberDispatcher {
|
||||
public:
|
||||
explicit UberDispatcher(FrontendChannel*);
|
||||
void registerBackend(const String& name, std::unique_ptr<protocol::DispatcherBase>);
|
||||
void dispatch(std::unique_ptr<Value> message);
|
||||
DispatchResponse::Status dispatch(std::unique_ptr<Value> message);
|
||||
FrontendChannel* channel() { return m_frontendChannel; }
|
||||
virtual ~UberDispatcher();
|
||||
|
||||
|
@ -19,12 +19,14 @@ namespace {{namespace}} {
|
||||
|
||||
template<typename T> class Array;
|
||||
class DictionaryValue;
|
||||
class DispatchResponse;
|
||||
using ErrorString = String;
|
||||
class ErrorSupport;
|
||||
class FundamentalValue;
|
||||
class ListValue;
|
||||
template<typename T> class Maybe;
|
||||
class Object;
|
||||
using Response = DispatchResponse;
|
||||
class SerializedValue;
|
||||
class StringValue;
|
||||
class UberDispatcher;
|
||||
|
@ -16,6 +16,7 @@ class Maybe {
|
||||
public:
|
||||
Maybe() : m_value() { }
|
||||
Maybe(std::unique_ptr<T> value) : m_value(std::move(value)) { }
|
||||
Maybe(Maybe&& other) : m_value(std::move(other.m_value)) { }
|
||||
void operator=(std::unique_ptr<T> value) { m_value = std::move(value); }
|
||||
T* fromJust() const { DCHECK(m_value); return m_value.get(); }
|
||||
T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defaultValue; }
|
||||
@ -30,6 +31,7 @@ class MaybeBase {
|
||||
public:
|
||||
MaybeBase() : m_isJust(false) { }
|
||||
MaybeBase(T value) : m_isJust(true), m_value(value) { }
|
||||
MaybeBase(MaybeBase&& other) : m_isJust(other.m_isJust), m_value(std::move(other.m_value)) { }
|
||||
void operator=(T value) { m_value = value; m_isJust = true; }
|
||||
T fromJust() const { DCHECK(m_isJust); return m_value; }
|
||||
T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; }
|
||||
@ -46,6 +48,7 @@ class Maybe<bool> : public MaybeBase<bool> {
|
||||
public:
|
||||
Maybe() { }
|
||||
Maybe(bool value) : MaybeBase(value) { }
|
||||
Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
|
||||
using MaybeBase::operator=;
|
||||
};
|
||||
|
||||
@ -54,6 +57,7 @@ class Maybe<int> : public MaybeBase<int> {
|
||||
public:
|
||||
Maybe() { }
|
||||
Maybe(int value) : MaybeBase(value) { }
|
||||
Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
|
||||
using MaybeBase::operator=;
|
||||
};
|
||||
|
||||
@ -62,6 +66,7 @@ class Maybe<double> : public MaybeBase<double> {
|
||||
public:
|
||||
Maybe() { }
|
||||
Maybe(double value) : MaybeBase(value) { }
|
||||
Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
|
||||
using MaybeBase::operator=;
|
||||
};
|
||||
|
||||
@ -70,6 +75,7 @@ class Maybe<String> : public MaybeBase<String> {
|
||||
public:
|
||||
Maybe() { }
|
||||
Maybe(const String& value) : MaybeBase(value) { }
|
||||
Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
|
||||
using MaybeBase::operator=;
|
||||
};
|
||||
|
||||
|
@ -150,7 +150,11 @@ const char* {{ literal | to_title_case}} = "{{literal}}";
|
||||
void Frontend::{{event.name}}(
|
||||
{%- for parameter in event.parameters %}
|
||||
{% if "optional" in parameter -%}
|
||||
{%- if new_style(domain) -%}
|
||||
Maybe<{{resolve_type(parameter).raw_type}}>
|
||||
{%- else -%}
|
||||
const Maybe<{{resolve_type(parameter).raw_type}}>&
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{{resolve_type(parameter).pass_type}}
|
||||
{%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%}
|
||||
@ -192,32 +196,32 @@ public:
|
||||
{% endfor %}
|
||||
}
|
||||
~DispatcherImpl() override { }
|
||||
void 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;
|
||||
|
||||
protected:
|
||||
using CallHandler = void (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>;
|
||||
DispatchMap m_dispatchMap;
|
||||
|
||||
{% for command in domain.commands %}
|
||||
{% if "redirect" in command %}{% continue %}{% endif %}
|
||||
{% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %}
|
||||
void {{command.name}}(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
|
||||
DispatchResponse::Status {{command.name}}(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
|
||||
{% endfor %}
|
||||
|
||||
Backend* m_backend;
|
||||
};
|
||||
|
||||
void DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
|
||||
DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
|
||||
{
|
||||
protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
|
||||
if (it == m_dispatchMap.end()) {
|
||||
reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't found", nullptr);
|
||||
return;
|
||||
reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
|
||||
return DispatchResponse::kError;
|
||||
}
|
||||
|
||||
protocol::ErrorSupport errors;
|
||||
(this->*(it->second))(callId, std::move(messageObject), &errors);
|
||||
return (this->*(it->second))(callId, std::move(messageObject), &errors);
|
||||
}
|
||||
|
||||
{% for command in domain.commands %}
|
||||
@ -231,14 +235,18 @@ public:
|
||||
: DispatcherBase::Callback(std::move(backendImpl), callId) { }
|
||||
|
||||
void sendSuccess(
|
||||
{%- for parameter in command.returns -%}
|
||||
{%- if "optional" in parameter -%}
|
||||
{%- for parameter in command.returns -%}
|
||||
{%- if "optional" in parameter -%}
|
||||
{%- if new_style(domain) -%}
|
||||
Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}}
|
||||
{%- else -%}
|
||||
const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}}
|
||||
{%- else -%}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{{resolve_type(parameter).pass_type}} {{parameter.name}}
|
||||
{%- endif -%}
|
||||
{%- if not loop.last -%}, {% endif -%}
|
||||
{%- endfor -%}) override
|
||||
{%- endif -%}
|
||||
{%- if not loop.last -%}, {% endif -%}
|
||||
{%- endfor -%}) override
|
||||
{
|
||||
std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
|
||||
{% for parameter in command.returns %}
|
||||
@ -249,19 +257,26 @@ public:
|
||||
resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % parameter.name}}));
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
sendIfActive(std::move(resultObject), ErrorString());
|
||||
sendIfActive(std::move(resultObject), DispatchResponse::OK());
|
||||
}
|
||||
|
||||
{% if new_style(domain) %}
|
||||
void sendFailure(const DispatchResponse& response) override
|
||||
{
|
||||
DCHECK(response.status() == DispatchResponse::kError);
|
||||
sendIfActive(nullptr, response);
|
||||
}
|
||||
{% else %}
|
||||
void sendFailure(const ErrorString& error) override
|
||||
{
|
||||
DCHECK(error.length());
|
||||
sendIfActive(nullptr, error);
|
||||
sendIfActive(nullptr, DispatchResponse::Error(error));
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
};
|
||||
{% endif %}
|
||||
|
||||
void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
|
||||
DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
|
||||
{
|
||||
{% if "parameters" in command %}
|
||||
// Prepare input parameters.
|
||||
@ -282,15 +297,12 @@ void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValu
|
||||
{% endfor %}
|
||||
errors->pop();
|
||||
if (errors->hasErrors()) {
|
||||
reportProtocolError(callId, InvalidParams, kInvalidRequest, errors);
|
||||
return;
|
||||
reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
|
||||
return DispatchResponse::kError;
|
||||
}
|
||||
{% endif %}
|
||||
{% if "async" in command %}
|
||||
std::unique_ptr<{{command.name | to_title_case}}CallbackImpl> callback(new {{command.name | to_title_case}}CallbackImpl(weakPtr(), callId));
|
||||
{% elif "returns" in command %}
|
||||
{% if "returns" in command and not ("async" in command) %}
|
||||
// Declare output parameters.
|
||||
std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
|
||||
{% for property in command.returns %}
|
||||
{% if "optional" in property %}
|
||||
Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}};
|
||||
@ -300,24 +312,40 @@ void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValu
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
|
||||
{% if not("async" in command) %}
|
||||
std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
|
||||
{% if not new_style(domain) %}
|
||||
ErrorString error;
|
||||
m_backend->{{command.name}}(&error
|
||||
{%- else %}
|
||||
DispatchResponse response = m_backend->{{command.name}}(
|
||||
{%- endif -%}
|
||||
{%- for property in command.parameters -%}
|
||||
{%- if not loop.first or not new_style(domain) -%}, {% endif -%}
|
||||
{%- if "optional" in property -%}
|
||||
, in_{{property.name}}
|
||||
{%- if new_style(domain) -%}
|
||||
std::move(in_{{property.name}})
|
||||
{%- else -%}
|
||||
in_{{property.name}}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
, {{resolve_type(property).to_pass_type % ("in_" + property.name)}}
|
||||
{{resolve_type(property).to_pass_type % ("in_" + property.name)}}
|
||||
{%- endif -%}
|
||||
{%- endfor %}
|
||||
{%- if "returns" in command %}
|
||||
{%- for property in command.returns -%}
|
||||
, &out_{{property.name}}
|
||||
{%- if not loop.first or command.parameters or not new_style(domain) -%}, {% endif -%}
|
||||
&out_{{property.name}}
|
||||
{%- endfor %}
|
||||
{% endif %});
|
||||
{% if "returns" in command and not("async" in command) %}
|
||||
if (!error.length()) {
|
||||
{% if not new_style(domain) %}
|
||||
DispatchResponse response = error.length() ? DispatchResponse::Error(error) : DispatchResponse::OK();
|
||||
{% endif %}
|
||||
{% if "returns" in command %}
|
||||
if (response.status() == DispatchResponse::kFallThrough)
|
||||
return response.status();
|
||||
std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
|
||||
if (response.status() == DispatchResponse::kSuccess) {
|
||||
{% for parameter in command.returns %}
|
||||
{% if "optional" in parameter %}
|
||||
if (out_{{parameter.name}}.isJust())
|
||||
@ -328,21 +356,30 @@ void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValu
|
||||
{% endfor %}
|
||||
}
|
||||
if (weak->get())
|
||||
weak->get()->sendResponse(callId, error, std::move(result));
|
||||
weak->get()->sendResponse(callId, response, std::move(result));
|
||||
{% else %}
|
||||
if (weak->get())
|
||||
weak->get()->sendResponse(callId, error);
|
||||
weak->get()->sendResponse(callId, response);
|
||||
{% endif %}
|
||||
{%- else %}
|
||||
return response.status();
|
||||
{% else %}
|
||||
std::unique_ptr<{{command.name | to_title_case}}CallbackImpl> callback(new {{command.name | to_title_case}}CallbackImpl(weakPtr(), callId));
|
||||
m_backend->{{command.name}}(
|
||||
{%- for property in command.parameters -%}
|
||||
{%- if not loop.first -%}, {% endif -%}
|
||||
{%- if "optional" in property -%}
|
||||
in_{{property.name}},
|
||||
{%- if new_style(domain) -%}
|
||||
std::move(in_{{property.name}})
|
||||
{%- else -%}
|
||||
in_{{property.name}}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{{resolve_type(property).to_pass_type % ("in_" + property.name)}},
|
||||
{{resolve_type(property).to_pass_type % ("in_" + property.name)}}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- if command.parameters -%}, {% endif -%}
|
||||
std::move(callback));
|
||||
return DispatchResponse::kAsync;
|
||||
{% endif %}
|
||||
}
|
||||
{% endfor %}
|
||||
|
@ -191,41 +191,59 @@ public:
|
||||
{% if "redirect" in command %}{% continue %}{% endif %}
|
||||
{% if ("handlers" in command) and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %}
|
||||
{% if "async" in command %}
|
||||
class {{config.protocol.export_macro}} {{command.name | to_title_case}}Callback : public BackendCallback {
|
||||
class {{config.protocol.export_macro}} {{command.name | to_title_case}}Callback {
|
||||
public:
|
||||
virtual void sendSuccess(
|
||||
{%- for parameter in command.returns -%}
|
||||
{%- if "optional" in parameter -%}
|
||||
{%- for parameter in command.returns -%}
|
||||
{%- if "optional" in parameter -%}
|
||||
{%- if new_style(domain) -%}
|
||||
Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}}
|
||||
{%- else -%}
|
||||
const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}}
|
||||
{%- else -%}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{{resolve_type(parameter).pass_type}} {{parameter.name}}
|
||||
{%- endif -%}
|
||||
{%- if not loop.last -%}, {% endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
{%- if not loop.last -%}, {% endif -%}
|
||||
{%- endfor -%}
|
||||
) = 0;
|
||||
{% if new_style(domain) %}
|
||||
virtual void sendFailure(const DispatchResponse&) = 0;
|
||||
{% else %}
|
||||
virtual void sendFailure(const ErrorString&) = 0;
|
||||
{% endif %}
|
||||
};
|
||||
{% endif %}
|
||||
{%- if not("async" in command) and new_style(domain) %}
|
||||
virtual DispatchResponse {{command.name}}(
|
||||
{%- else %}
|
||||
virtual void {{command.name}}(
|
||||
{%- if not("async" in command) -%}
|
||||
{%- endif %}
|
||||
{%- if not("async" in command) and not new_style(domain) -%}
|
||||
ErrorString*
|
||||
{%- endif -%}
|
||||
{%- for parameter in command.parameters -%}
|
||||
{%- if (not loop.first) or not("async" in command) -%}, {% endif -%}
|
||||
{%- if "optional" in parameter -%}
|
||||
const Maybe<{{resolve_type(parameter).raw_type}}>& in_{{parameter.name}}
|
||||
{%- if (not loop.first) or (not ("async" in command) and not new_style(domain)) -%}, {% endif -%}
|
||||
{%- if "optional" in parameter -%}
|
||||
{%- if new_style(domain) -%}
|
||||
Maybe<{{resolve_type(parameter).raw_type}}> in_{{parameter.name}}
|
||||
{%- else -%}
|
||||
{{resolve_type(parameter).pass_type}} in_{{parameter.name}}
|
||||
const Maybe<{{resolve_type(parameter).raw_type}}>& in_{{parameter.name}}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{{resolve_type(parameter).pass_type}} in_{{parameter.name}}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- if "async" in command -%}
|
||||
{%- if command.parameters -%}, {% endif -%}
|
||||
{%- if command.parameters -%}, {% endif -%}
|
||||
std::unique_ptr<{{command.name | to_title_case}}Callback> callback
|
||||
{%- else -%}
|
||||
{%- for parameter in command.returns -%}
|
||||
{%- if (not loop.first) or command.parameters or not new_style(domain) -%}, {% endif -%}
|
||||
{%- if "optional" in parameter -%}
|
||||
, Maybe<{{resolve_type(parameter).raw_type}}>* out_{{parameter.name}}
|
||||
Maybe<{{resolve_type(parameter).raw_type}}>* out_{{parameter.name}}
|
||||
{%- else -%}
|
||||
, {{resolve_type(parameter).type}}* out_{{parameter.name}}
|
||||
{{resolve_type(parameter).type}}* out_{{parameter.name}}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
@ -233,8 +251,26 @@ public:
|
||||
{% endfor %}
|
||||
|
||||
{% if not has_disable(domain.commands) %}
|
||||
{% if new_style(domain) %}
|
||||
virtual DispatchResponse disable()
|
||||
{
|
||||
return DispatchResponse::OK();
|
||||
}
|
||||
{% else %}
|
||||
virtual void disable(ErrorString*) { }
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
// TODO(dgozman): remove once all domains migrated.
|
||||
static void disableMe(Backend* backend)
|
||||
{
|
||||
{% if new_style(domain) %}
|
||||
backend->disable();
|
||||
{% else %}
|
||||
ErrorString error;
|
||||
backend->disable(&error);
|
||||
{% endif %}
|
||||
}
|
||||
};
|
||||
|
||||
// ------------- Frontend interface.
|
||||
@ -247,7 +283,11 @@ public:
|
||||
void {{event.name}}(
|
||||
{%- for parameter in event.parameters -%}
|
||||
{%- if "optional" in parameter -%}
|
||||
{%- if new_style(domain) -%}
|
||||
Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>()
|
||||
{%- else -%}
|
||||
const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>()
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{{resolve_type(parameter).pass_type}} {{parameter.name}}
|
||||
{%- endif -%}{%- if not loop.last -%}, {% endif -%}
|
||||
|
Loading…
Reference in New Issue
Block a user