Commit d5055bc9 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

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}
parent b19abf53
setBreakpointByUrl error: undefined setBreakpointByUrl error: undefined
setBreakpoint error: { setBreakpoint error: {
"code": -32602, "code": -32602,
"message": "Invalid request", "message": "Invalid parameters",
"data": "location: object expected" "data": "location: object expected"
} }
...@@ -329,6 +329,11 @@ def resolve_type(protocol, prop): ...@@ -329,6 +329,11 @@ def resolve_type(protocol, prop):
return protocol.type_definitions[prop["type"]] return protocol.type_definitions[prop["type"]]
def new_style(domain):
domains = []
return domain["domain"] in domains
def join_arrays(dict, keys): def join_arrays(dict, keys):
result = [] result = []
for key in keys: for key in keys:
...@@ -339,7 +344,7 @@ def join_arrays(dict, keys): ...@@ -339,7 +344,7 @@ def join_arrays(dict, keys):
def has_disable(commands): def has_disable(commands):
for command in 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 True
return False return False
...@@ -421,6 +426,7 @@ def main(): ...@@ -421,6 +426,7 @@ def main():
"type_definition": functools.partial(type_definition, protocol), "type_definition": functools.partial(type_definition, protocol),
"has_disable": has_disable, "has_disable": has_disable,
"format_include": format_include, "format_include": format_include,
"new_style": new_style,
} }
if domain["domain"] in protocol.generate_domains: if domain["domain"] in protocol.generate_domains:
...@@ -448,7 +454,6 @@ def main(): ...@@ -448,7 +454,6 @@ def main():
"ValueConversions_h.template", "ValueConversions_h.template",
"Maybe_h.template", "Maybe_h.template",
"Array_h.template", "Array_h.template",
"BackendCallback_h.template",
"DispatcherBase_h.template", "DispatcherBase_h.template",
"Parser_h.template", "Parser_h.template",
] ]
......
...@@ -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: 6c15061ecf7168e520d33633b217e029e74760a7 Revision: cf45a6e89b17cdc9eeacdef4c003fcc55f7ec2a0
License: BSD License: BSD
License File: LICENSE License File: LICENSE
Security Critical: no Security Critical: no
......
...@@ -33,7 +33,6 @@ template("inspector_protocol_generate") { ...@@ -33,7 +33,6 @@ template("inspector_protocol_generate") {
invoker.config_file, invoker.config_file,
"$inspector_protocol_dir/lib/Allocator_h.template", "$inspector_protocol_dir/lib/Allocator_h.template",
"$inspector_protocol_dir/lib/Array_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/Collections_h.template",
"$inspector_protocol_dir/lib/DispatcherBase_cpp.template", "$inspector_protocol_dir/lib/DispatcherBase_cpp.template",
"$inspector_protocol_dir/lib/DispatcherBase_h.template", "$inspector_protocol_dir/lib/DispatcherBase_h.template",
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
'inspector_protocol_files': [ 'inspector_protocol_files': [
'lib/Allocator_h.template', 'lib/Allocator_h.template',
'lib/Array_h.template', 'lib/Array_h.template',
'lib/BackendCallback_h.template',
'lib/Collections_h.template', 'lib/Collections_h.template',
'lib/DispatcherBase_cpp.template', 'lib/DispatcherBase_cpp.template',
'lib/DispatcherBase_h.template', 'lib/DispatcherBase_h.template',
......
// 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}} { ...@@ -10,7 +10,45 @@ namespace {{namespace}} {
{% endfor %} {% endfor %}
// static // 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) { } DispatcherBase::WeakPtr::WeakPtr(DispatcherBase* dispatcher) : m_dispatcher(dispatcher) { }
...@@ -31,11 +69,11 @@ void DispatcherBase::Callback::dispose() ...@@ -31,11 +69,11 @@ void DispatcherBase::Callback::dispose()
m_backendImpl = nullptr; 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()) if (!m_backendImpl || !m_backendImpl->get())
return; 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; m_backendImpl = nullptr;
} }
...@@ -64,10 +102,10 @@ bool DispatcherBase::getCommandName(const String& message, String* result) ...@@ -64,10 +102,10 @@ bool DispatcherBase::getCommandName(const String& message, String* result)
return true; 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())) { if (response.status() == DispatchResponse::kError) {
reportProtocolError(callId, ServerError, invocationError, errors); reportProtocolError(callId, response.errorCode(), response.errorMessage(), nullptr);
return; return;
} }
...@@ -78,24 +116,18 @@ void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError ...@@ -78,24 +116,18 @@ void DispatcherBase::sendResponse(int callId, const ErrorString& invocationError
m_frontendChannel->sendProtocolResponse(callId, responseMessage->toJSONString()); 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) static void reportProtocolErrorTo(FrontendChannel* frontendChannel, int callId, DispatchResponse::ErrorCode code, const String& errorMessage, ErrorSupport* errors)
{
sendResponse(callId, invocationError, nullptr, DictionaryValue::create());
}
static void reportProtocolErrorTo(FrontendChannel* frontendChannel, int callId, DispatcherBase::CommonErrorCode code, const String& errorMessage, ErrorSupport* errors)
{ {
if (!frontendChannel) if (!frontendChannel)
return; return;
std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create(); std::unique_ptr<protocol::DictionaryValue> error = DictionaryValue::create();
error->setInteger("code", code); error->setInteger("code", code);
error->setString("message", errorMessage); error->setString("message", errorMessage);
DCHECK(error);
if (errors && errors->hasErrors()) if (errors && errors->hasErrors())
error->setString("data", errors->errors()); error->setString("data", errors->errors());
std::unique_ptr<protocol::DictionaryValue> message = DictionaryValue::create(); std::unique_ptr<protocol::DictionaryValue> message = DictionaryValue::create();
...@@ -104,7 +136,19 @@ static void reportProtocolErrorTo(FrontendChannel* frontendChannel, int callId, ...@@ -104,7 +136,19 @@ static void reportProtocolErrorTo(FrontendChannel* frontendChannel, int callId,
frontendChannel->sendProtocolResponse(callId, message->toJSONString()); 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); reportProtocolErrorTo(m_frontendChannel, callId, code, errorMessage, errors);
} }
...@@ -132,38 +176,46 @@ void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco ...@@ -132,38 +176,46 @@ void UberDispatcher::registerBackend(const String& name, std::unique_ptr<protoco
m_dispatchers[name] = std::move(dispatcher); 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) if (!parsedMessage) {
return; 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)); std::unique_ptr<protocol::DictionaryValue> messageObject = DictionaryValue::cast(std::move(parsedMessage));
if (!messageObject) if (!messageObject) {
return; reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must be an object");
return DispatchResponse::kError;
}
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 (!success) if (!success) {
return; reportProtocolErrorTo(m_frontendChannel, DispatchResponse::kInvalidRequest, "Message must have integer 'id' porperty");
return DispatchResponse::kError;
}
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 (!success) if (!success) {
return; reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kInvalidRequest, "Message must have string 'method' porperty", nullptr);
return DispatchResponse::kError;
}
size_t dotIndex = method.find("."); size_t dotIndex = method.find(".");
if (dotIndex == StringUtil::kNotFound) { if (dotIndex == StringUtil::kNotFound) {
reportProtocolErrorTo(m_frontendChannel, callId, DispatcherBase::MethodNotFound, "'" + method + "' wasn't found", nullptr); reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
return; return DispatchResponse::kError;
} }
String domain = StringUtil::substring(method, 0, dotIndex); String domain = StringUtil::substring(method, 0, dotIndex);
auto it = m_dispatchers.find(domain); auto it = m_dispatchers.find(domain);
if (it == m_dispatchers.end()) { if (it == m_dispatchers.end()) {
reportProtocolErrorTo(m_frontendChannel, callId, DispatcherBase::MethodNotFound, "'" + method + "' wasn't found", nullptr); reportProtocolErrorTo(m_frontendChannel, callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
return; return DispatchResponse::kError;
} }
it->second->dispatch(callId, method, std::move(messageObject)); return it->second->dispatch(callId, method, std::move(messageObject));
} }
UberDispatcher::~UberDispatcher() = default; UberDispatcher::~UberDispatcher() = default;
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef {{"_".join(config.protocol.namespace)}}_DispatcherBase_h #ifndef {{"_".join(config.protocol.namespace)}}_DispatcherBase_h
#define {{"_".join(config.protocol.namespace)}}_DispatcherBase_h #define {{"_".join(config.protocol.namespace)}}_DispatcherBase_h
//#include "BackendCallback.h"
//#include "Collections.h" //#include "Collections.h"
//#include "ErrorSupport.h" //#include "ErrorSupport.h"
//#include "Forward.h" //#include "Forward.h"
...@@ -17,10 +16,44 @@ namespace {{namespace}} { ...@@ -17,10 +16,44 @@ namespace {{namespace}} {
class WeakPtr; 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 { class {{config.lib.export_macro}} DispatcherBase {
PROTOCOL_DISALLOW_COPY(DispatcherBase); PROTOCOL_DISALLOW_COPY(DispatcherBase);
public: public:
static const char kInvalidRequest[]; static const char kInvalidParamsString[];
class {{config.lib.export_macro}} WeakPtr { class {{config.lib.export_macro}} WeakPtr {
public: public:
explicit WeakPtr(DispatcherBase*); explicit WeakPtr(DispatcherBase*);
...@@ -32,14 +65,14 @@ public: ...@@ -32,14 +65,14 @@ public:
DispatcherBase* m_dispatcher; DispatcherBase* m_dispatcher;
}; };
class {{config.lib.export_macro}} Callback : public protocol::BackendCallback { class {{config.lib.export_macro}} Callback {
public: public:
Callback(std::unique_ptr<WeakPtr> backendImpl, int callId); Callback(std::unique_ptr<WeakPtr> backendImpl, int callId);
virtual ~Callback(); virtual ~Callback();
void dispose(); void dispose();
protected: protected:
void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const ErrorString& invocationError); void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const DispatchResponse& response);
private: private:
std::unique_ptr<WeakPtr> m_backendImpl; std::unique_ptr<WeakPtr> m_backendImpl;
...@@ -49,24 +82,14 @@ public: ...@@ -49,24 +82,14 @@ public:
explicit DispatcherBase(FrontendChannel*); explicit DispatcherBase(FrontendChannel*);
virtual ~DispatcherBase(); virtual ~DispatcherBase();
enum CommonErrorCode {
ParseError = -32700,
InvalidRequest = -32600,
MethodNotFound = -32601,
InvalidParams = -32602,
InternalError = -32603,
ServerError = -32000,
};
static bool getCommandName(const String& message, String* result); 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 DispatchResponse&, std::unique_ptr<protocol::DictionaryValue> result);
void sendResponse(int callId, const ErrorString&, std::unique_ptr<protocol::DictionaryValue> result); void sendResponse(int callId, const DispatchResponse&);
void sendResponse(int callId, const ErrorString&);
void reportProtocolError(int callId, CommonErrorCode, const String& errorMessage, ErrorSupport* errors); void reportProtocolError(int callId, DispatchResponse::ErrorCode, const String& errorMessage, ErrorSupport* errors);
void clearFrontend(); void clearFrontend();
std::unique_ptr<WeakPtr> weakPtr(); std::unique_ptr<WeakPtr> weakPtr();
...@@ -81,7 +104,7 @@ class {{config.lib.export_macro}} UberDispatcher { ...@@ -81,7 +104,7 @@ 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>);
void dispatch(std::unique_ptr<Value> message); DispatchResponse::Status dispatch(std::unique_ptr<Value> message);
FrontendChannel* channel() { return m_frontendChannel; } FrontendChannel* channel() { return m_frontendChannel; }
virtual ~UberDispatcher(); virtual ~UberDispatcher();
......
...@@ -19,12 +19,14 @@ namespace {{namespace}} { ...@@ -19,12 +19,14 @@ namespace {{namespace}} {
template<typename T> class Array; template<typename T> class Array;
class DictionaryValue; class DictionaryValue;
class DispatchResponse;
using ErrorString = String; using ErrorString = String;
class ErrorSupport; class ErrorSupport;
class FundamentalValue; class FundamentalValue;
class ListValue; class ListValue;
template<typename T> class Maybe; template<typename T> class Maybe;
class Object; class Object;
using Response = DispatchResponse;
class SerializedValue; class SerializedValue;
class StringValue; class StringValue;
class UberDispatcher; class UberDispatcher;
......
...@@ -16,6 +16,7 @@ class Maybe { ...@@ -16,6 +16,7 @@ class Maybe {
public: public:
Maybe() : m_value() { } Maybe() : m_value() { }
Maybe(std::unique_ptr<T> value) : m_value(std::move(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); } void operator=(std::unique_ptr<T> value) { m_value = std::move(value); }
T* fromJust() const { DCHECK(m_value); return m_value.get(); } T* fromJust() const { DCHECK(m_value); return m_value.get(); }
T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defaultValue; } T* fromMaybe(T* defaultValue) const { return m_value ? m_value.get() : defaultValue; }
...@@ -30,6 +31,7 @@ class MaybeBase { ...@@ -30,6 +31,7 @@ class MaybeBase {
public: public:
MaybeBase() : m_isJust(false) { } MaybeBase() : m_isJust(false) { }
MaybeBase(T value) : m_isJust(true), m_value(value) { } 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; } void operator=(T value) { m_value = value; m_isJust = true; }
T fromJust() const { DCHECK(m_isJust); return m_value; } T fromJust() const { DCHECK(m_isJust); return m_value; }
T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; } T fromMaybe(const T& defaultValue) const { return m_isJust ? m_value : defaultValue; }
...@@ -46,6 +48,7 @@ class Maybe<bool> : public MaybeBase<bool> { ...@@ -46,6 +48,7 @@ class Maybe<bool> : public MaybeBase<bool> {
public: public:
Maybe() { } Maybe() { }
Maybe(bool value) : MaybeBase(value) { } Maybe(bool value) : MaybeBase(value) { }
Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
using MaybeBase::operator=; using MaybeBase::operator=;
}; };
...@@ -54,6 +57,7 @@ class Maybe<int> : public MaybeBase<int> { ...@@ -54,6 +57,7 @@ class Maybe<int> : public MaybeBase<int> {
public: public:
Maybe() { } Maybe() { }
Maybe(int value) : MaybeBase(value) { } Maybe(int value) : MaybeBase(value) { }
Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
using MaybeBase::operator=; using MaybeBase::operator=;
}; };
...@@ -62,6 +66,7 @@ class Maybe<double> : public MaybeBase<double> { ...@@ -62,6 +66,7 @@ class Maybe<double> : public MaybeBase<double> {
public: public:
Maybe() { } Maybe() { }
Maybe(double value) : MaybeBase(value) { } Maybe(double value) : MaybeBase(value) { }
Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
using MaybeBase::operator=; using MaybeBase::operator=;
}; };
...@@ -70,6 +75,7 @@ class Maybe<String> : public MaybeBase<String> { ...@@ -70,6 +75,7 @@ class Maybe<String> : public MaybeBase<String> {
public: public:
Maybe() { } Maybe() { }
Maybe(const String& value) : MaybeBase(value) { } Maybe(const String& value) : MaybeBase(value) { }
Maybe(Maybe&& other) : MaybeBase(std::move(other)) { }
using MaybeBase::operator=; using MaybeBase::operator=;
}; };
......
...@@ -150,7 +150,11 @@ const char* {{ literal | to_title_case}} = "{{literal}}"; ...@@ -150,7 +150,11 @@ const char* {{ literal | to_title_case}} = "{{literal}}";
void Frontend::{{event.name}}( void Frontend::{{event.name}}(
{%- for parameter in event.parameters %} {%- for parameter in event.parameters %}
{% if "optional" in parameter -%} {% if "optional" in parameter -%}
{%- if new_style(domain) -%}
Maybe<{{resolve_type(parameter).raw_type}}>
{%- else -%}
const Maybe<{{resolve_type(parameter).raw_type}}>& const Maybe<{{resolve_type(parameter).raw_type}}>&
{%- endif -%}
{%- else -%} {%- else -%}
{{resolve_type(parameter).pass_type}} {{resolve_type(parameter).pass_type}}
{%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%} {%- endif %} {{parameter.name}}{%- if not loop.last -%}, {% endif -%}
...@@ -192,32 +196,32 @@ public: ...@@ -192,32 +196,32 @@ public:
{% endfor %} {% endfor %}
} }
~DispatcherImpl() override { } ~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: 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>; using DispatchMap = protocol::HashMap<String, CallHandler>;
DispatchMap m_dispatchMap; DispatchMap m_dispatchMap;
{% for command in domain.commands %} {% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %} {% if "redirect" in command %}{% continue %}{% endif %}
{% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% 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 %} {% endfor %}
Backend* m_backend; 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); protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
if (it == m_dispatchMap.end()) { if (it == m_dispatchMap.end()) {
reportProtocolError(callId, MethodNotFound, "'" + method + "' wasn't found", nullptr); reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
return; return DispatchResponse::kError;
} }
protocol::ErrorSupport errors; 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 %} {% for command in domain.commands %}
...@@ -231,14 +235,18 @@ public: ...@@ -231,14 +235,18 @@ public:
: DispatcherBase::Callback(std::move(backendImpl), callId) { } : DispatcherBase::Callback(std::move(backendImpl), callId) { }
void sendSuccess( void sendSuccess(
{%- for parameter in command.returns -%} {%- for parameter in command.returns -%}
{%- if "optional" in parameter -%} {%- 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}} const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}}
{%- else -%} {%- endif -%}
{%- else -%}
{{resolve_type(parameter).pass_type}} {{parameter.name}} {{resolve_type(parameter).pass_type}} {{parameter.name}}
{%- endif -%} {%- endif -%}
{%- if not loop.last -%}, {% endif -%} {%- if not loop.last -%}, {% endif -%}
{%- endfor -%}) override {%- endfor -%}) override
{ {
std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create(); std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValue::create();
{% for parameter in command.returns %} {% for parameter in command.returns %}
...@@ -249,19 +257,26 @@ public: ...@@ -249,19 +257,26 @@ public:
resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % parameter.name}})); resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % parameter.name}}));
{% endif %} {% endif %}
{% endfor %} {% 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 void sendFailure(const ErrorString& error) override
{ {
DCHECK(error.length()); DCHECK(error.length());
sendIfActive(nullptr, error); sendIfActive(nullptr, DispatchResponse::Error(error));
} }
{% endif %}
}; };
{% 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 %} {% if "parameters" in command %}
// Prepare input parameters. // Prepare input parameters.
...@@ -282,15 +297,12 @@ void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValu ...@@ -282,15 +297,12 @@ void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValu
{% endfor %} {% endfor %}
errors->pop(); errors->pop();
if (errors->hasErrors()) { if (errors->hasErrors()) {
reportProtocolError(callId, InvalidParams, kInvalidRequest, errors); reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors);
return; return DispatchResponse::kError;
} }
{% endif %} {% endif %}
{% if "async" in command %} {% if "returns" in command and not ("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 %}
// Declare output parameters. // Declare output parameters.
std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
{% for property in command.returns %} {% for property in command.returns %}
{% if "optional" in property %} {% if "optional" in property %}
Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}}; Maybe<{{resolve_type(property).raw_type}}> out_{{property.name}};
...@@ -300,24 +312,40 @@ void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValu ...@@ -300,24 +312,40 @@ void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValu
{% endfor %} {% endfor %}
{% endif %} {% endif %}
std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
{% if not("async" in command) %} {% if not("async" in command) %}
std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
{% if not new_style(domain) %}
ErrorString error; ErrorString error;
m_backend->{{command.name}}(&error m_backend->{{command.name}}(&error
{%- else %}
DispatchResponse response = m_backend->{{command.name}}(
{%- endif -%}
{%- for property in command.parameters -%} {%- for property in command.parameters -%}
{%- if not loop.first or not new_style(domain) -%}, {% endif -%}
{%- if "optional" in property -%} {%- if "optional" in property -%}
, in_{{property.name}} {%- if new_style(domain) -%}
std::move(in_{{property.name}})
{%- else -%}
in_{{property.name}}
{%- endif -%}
{%- else -%} {%- else -%}
, {{resolve_type(property).to_pass_type % ("in_" + property.name)}} {{resolve_type(property).to_pass_type % ("in_" + property.name)}}
{%- endif -%} {%- endif -%}
{%- endfor %} {%- endfor %}
{%- if "returns" in command %} {%- if "returns" in command %}
{%- for property in command.returns -%} {%- 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 %} {%- endfor %}
{% endif %}); {% endif %});
{% if "returns" in command and not("async" in command) %} {% if not new_style(domain) %}
if (!error.length()) { 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 %} {% for parameter in command.returns %}
{% if "optional" in parameter %} {% if "optional" in parameter %}
if (out_{{parameter.name}}.isJust()) if (out_{{parameter.name}}.isJust())
...@@ -328,21 +356,30 @@ void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValu ...@@ -328,21 +356,30 @@ void DispatcherImpl::{{command.name}}(int callId, std::unique_ptr<DictionaryValu
{% endfor %} {% endfor %}
} }
if (weak->get()) if (weak->get())
weak->get()->sendResponse(callId, error, std::move(result)); weak->get()->sendResponse(callId, response, std::move(result));
{% else %} {% else %}
if (weak->get()) if (weak->get())
weak->get()->sendResponse(callId, error); weak->get()->sendResponse(callId, response);
{% endif %} {% 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}}( m_backend->{{command.name}}(
{%- for property in command.parameters -%} {%- for property in command.parameters -%}
{%- if not loop.first -%}, {% endif -%}
{%- if "optional" in property -%} {%- if "optional" in property -%}
in_{{property.name}}, {%- if new_style(domain) -%}
std::move(in_{{property.name}})
{%- else -%}
in_{{property.name}}
{%- endif -%}
{%- else -%} {%- else -%}
{{resolve_type(property).to_pass_type % ("in_" + property.name)}}, {{resolve_type(property).to_pass_type % ("in_" + property.name)}}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- if command.parameters -%}, {% endif -%}
std::move(callback)); std::move(callback));
return DispatchResponse::kAsync;
{% endif %} {% endif %}
} }
{% endfor %} {% endfor %}
......
...@@ -191,41 +191,59 @@ public: ...@@ -191,41 +191,59 @@ public:
{% if "redirect" in command %}{% continue %}{% endif %} {% if "redirect" in command %}{% continue %}{% endif %}
{% if ("handlers" in command) and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %} {% if ("handlers" in command) and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %}
{% if "async" in command %} {% 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: public:
virtual void sendSuccess( virtual void sendSuccess(
{%- for parameter in command.returns -%} {%- for parameter in command.returns -%}
{%- if "optional" in parameter -%} {%- 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}} const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}}
{%- else -%} {%- endif -%}
{%- else -%}
{{resolve_type(parameter).pass_type}} {{parameter.name}} {{resolve_type(parameter).pass_type}} {{parameter.name}}
{%- endif -%} {%- endif -%}
{%- if not loop.last -%}, {% endif -%} {%- if not loop.last -%}, {% endif -%}
{%- endfor -%} {%- endfor -%}
) = 0; ) = 0;
{% if new_style(domain) %}
virtual void sendFailure(const DispatchResponse&) = 0;
{% else %}
virtual void sendFailure(const ErrorString&) = 0;
{% endif %}
}; };
{% endif %} {% endif %}
{%- if not("async" in command) and new_style(domain) %}
virtual DispatchResponse {{command.name}}(
{%- else %}
virtual void {{command.name}}( virtual void {{command.name}}(
{%- if not("async" in command) -%} {%- endif %}
{%- if not("async" in command) and not new_style(domain) -%}
ErrorString* ErrorString*
{%- endif -%} {%- endif -%}
{%- for parameter in command.parameters -%} {%- for parameter in command.parameters -%}
{%- if (not loop.first) or not("async" in command) -%}, {% endif -%} {%- if (not loop.first) or (not ("async" in command) and not new_style(domain)) -%}, {% endif -%}
{%- if "optional" in parameter -%} {%- if "optional" in parameter -%}
const Maybe<{{resolve_type(parameter).raw_type}}>& in_{{parameter.name}} {%- if new_style(domain) -%}
Maybe<{{resolve_type(parameter).raw_type}}> in_{{parameter.name}}
{%- else -%} {%- else -%}
{{resolve_type(parameter).pass_type}} in_{{parameter.name}} const Maybe<{{resolve_type(parameter).raw_type}}>& in_{{parameter.name}}
{%- endif -%} {%- endif -%}
{%- else -%}
{{resolve_type(parameter).pass_type}} in_{{parameter.name}}
{%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- if "async" in command -%} {%- if "async" in command -%}
{%- if command.parameters -%}, {% endif -%} {%- if command.parameters -%}, {% endif -%}
std::unique_ptr<{{command.name | to_title_case}}Callback> callback std::unique_ptr<{{command.name | to_title_case}}Callback> callback
{%- else -%} {%- else -%}
{%- for parameter in command.returns -%} {%- for parameter in command.returns -%}
{%- if (not loop.first) or command.parameters or not new_style(domain) -%}, {% endif -%}
{%- if "optional" in parameter -%} {%- if "optional" in parameter -%}
, Maybe<{{resolve_type(parameter).raw_type}}>* out_{{parameter.name}} Maybe<{{resolve_type(parameter).raw_type}}>* out_{{parameter.name}}
{%- else -%} {%- else -%}
, {{resolve_type(parameter).type}}* out_{{parameter.name}} {{resolve_type(parameter).type}}* out_{{parameter.name}}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- endif -%} {%- endif -%}
...@@ -233,8 +251,26 @@ public: ...@@ -233,8 +251,26 @@ public:
{% endfor %} {% endfor %}
{% if not has_disable(domain.commands) %} {% if not has_disable(domain.commands) %}
{% if new_style(domain) %}
virtual DispatchResponse disable()
{
return DispatchResponse::OK();
}
{% else %}
virtual void disable(ErrorString*) { } virtual void disable(ErrorString*) { }
{% endif %}
{% 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. // ------------- Frontend interface.
...@@ -247,7 +283,11 @@ public: ...@@ -247,7 +283,11 @@ public:
void {{event.name}}( void {{event.name}}(
{%- for parameter in event.parameters -%} {%- for parameter in event.parameters -%}
{%- if "optional" in parameter -%} {%- 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}}>() const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>()
{%- endif -%}
{%- else -%} {%- else -%}
{{resolve_type(parameter).pass_type}} {{parameter.name}} {{resolve_type(parameter).pass_type}} {{parameter.name}}
{%- endif -%}{%- if not loop.last -%}, {% endif -%} {%- endif -%}{%- if not loop.last -%}, {% endif -%}
......
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