DevTools: generate frontend and backend interfaces under domains.
BUG=580337
Review-Url: https://codereview.chromium.org/2008183002
Cr-Original-Commit-Position: refs/heads/master@{#395966}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 237eccb244b101ec748ca1c1d3225a8af27f9a63
diff --git a/BackendCallback.h b/BackendCallback.h
new file mode 100644
index 0000000..55ea20f
--- /dev/null
+++ b/BackendCallback.h
@@ -0,0 +1,23 @@
+// 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 BackendCallback_h
+#define BackendCallback_h
+
+#include "platform/PlatformExport.h"
+#include "platform/inspector_protocol/ErrorSupport.h"
+
+namespace blink {
+namespace protocol {
+
+class PLATFORM_EXPORT BackendCallback {
+public:
+ virtual ~BackendCallback() { }
+ virtual void sendFailure(const ErrorString&) = 0;
+};
+
+} // namespace platform
+} // namespace blink
+
+#endif // !defined(BackendCallback_h)
diff --git a/Backend_h.template b/Backend_h.template
index 4d6ac71..c1f3cb6 100644
--- a/Backend_h.template
+++ b/Backend_h.template
@@ -7,71 +7,67 @@
#ifndef {{class_name}}_h
#define {{class_name}}_h
+#include "platform/inspector_protocol/BackendCallback.h"
+#include "platform/inspector_protocol/ErrorSupport.h"
#include "platform/inspector_protocol/TypeBuilder.h"
namespace blink {
namespace protocol {
-class FrontendChannel;
-class BackendImplWeakPtr;
+{% for domain in api.domains %}
+
+namespace {{domain.domain}} {
class PLATFORM_EXPORT Backend {
public:
- class PLATFORM_EXPORT CallbackBase {
- public:
- virtual ~CallbackBase() { }
- virtual void sendFailure(const ErrorString&) = 0;
- };
-{% for domain in api.domains %}
-
- class PLATFORM_EXPORT {{domain.domain}} {
- public:
{% for command in domain.commands %}
{% if "redirect" in command %}{% continue %}{% endif %}
{% if ("handlers" in command) and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %}
{% if "async" in command %}
- class PLATFORM_EXPORT {{command.name | to_title_case}}Callback : public CallbackBase {
- public:
- virtual void sendSuccess(
+ class PLATFORM_EXPORT {{command.name | to_title_case}}Callback : public BackendCallback {
+ public:
+ virtual void sendSuccess(
{%- for parameter in command.returns -%}
{%- if "optional" in parameter -%}
- const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}}
+ const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}}
{%- else -%}
{{resolve_type(parameter).pass_type}} {{parameter.name}}
{%- endif -%}
{%- if not loop.last -%}, {% endif -%}
{%- endfor -%}
- ) = 0;
- };
+ ) = 0;
+ };
{% endif %}
- virtual void {{command.name}}(ErrorString*
+ virtual void {{command.name}}(ErrorString*
{%- for parameter in command.parameters -%}
{%- if "optional" in parameter -%}
- , const Maybe<{{resolve_type(parameter).raw_type}}>& in_{{parameter.name}}
+ , const Maybe<{{resolve_type(parameter).raw_type}}>& in_{{parameter.name}}
{%- else -%}
- , {{resolve_type(parameter).pass_type}} in_{{parameter.name}}
+ , {{resolve_type(parameter).pass_type}} in_{{parameter.name}}
{%- endif -%}
{%- endfor -%}
{%- if "async" in command -%}
- , std::unique_ptr<{{command.name | to_title_case}}Callback> callback
+ , std::unique_ptr<{{command.name | to_title_case}}Callback> callback
{%- else -%}
{%- for parameter in command.returns -%}
{%- 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 -%}
- ) = 0;
+ ) = 0;
{% endfor %}
- protected:
- virtual ~{{domain.domain}}() { }
- };
-{% endfor %}
+protected:
+ virtual ~Backend() { }
};
+} // namespace {{domain.domain}}
+
+{% endfor %}
+
} // namespace protocol
} // namespace blink
diff --git a/Dispatcher_cpp.template b/Dispatcher_cpp.template
index 595541f..4f87072 100644
--- a/Dispatcher_cpp.template
+++ b/Dispatcher_cpp.template
@@ -77,7 +77,7 @@
void sendResponse(int callId, const ErrorString& invocationError, ErrorSupport* errors, std::unique_ptr<protocol::DictionaryValue> result);
{% for domain in api.domains %}
- virtual void registerAgent(blink::protocol::Backend::{{domain.domain}}* agent) { DCHECK(!m_{{domain.domain | lower}}Agent); m_{{domain.domain | lower}}Agent = agent; }
+ virtual void registerAgent(blink::protocol::{{domain.domain}}::Backend* agent) { DCHECK(!m_{{domain.domain | lower}}Agent); m_{{domain.domain | lower}}Agent = agent; }
{% endfor %}
private:
@@ -97,7 +97,7 @@
FrontendChannel* m_frontendChannel;
{% for domain in api.domains %}
- Backend::{{domain.domain}}* m_{{domain.domain | lower}}Agent;
+ {{domain.domain}}::Backend* m_{{domain.domain | lower}}Agent;
{% endfor %}
void sendResponse(int callId, ErrorString invocationError, std::unique_ptr<protocol::DictionaryValue> result)
@@ -117,7 +117,7 @@
protocol::HashSet<DispatcherImplWeakPtr*> m_weakPtrs;
};
-class PLATFORM_EXPORT DispatcherCallbackBase : public protocol::Backend::CallbackBase {
+class PLATFORM_EXPORT DispatcherCallbackBase : public protocol::BackendCallback {
public:
DispatcherCallbackBase(std::unique_ptr<DispatcherImplWeakPtr> backendImpl, int callId)
: m_backendImpl(std::move(backendImpl)), m_callId(callId) { }
@@ -153,7 +153,7 @@
{% if "async" in command %}
-class PLATFORM_EXPORT {{domain.domain}}{{command.name | to_title_case}}Callback : public Backend::{{domain.domain}}::{{command.name | to_title_case}}Callback, public DispatcherCallbackBase {
+class PLATFORM_EXPORT {{domain.domain}}{{command.name | to_title_case}}Callback : public {{domain.domain}}::Backend::{{command.name | to_title_case}}Callback, public DispatcherCallbackBase {
public:
{{domain.domain}}{{command.name | to_title_case}}Callback(std::unique_ptr<DispatcherImplWeakPtr> backendImpl, int callId)
: DispatcherCallbackBase(std::move(backendImpl), callId) { }
diff --git a/Dispatcher_h.template b/Dispatcher_h.template
index 28c6425..a76ca10 100644
--- a/Dispatcher_h.template
+++ b/Dispatcher_h.template
@@ -21,23 +21,8 @@
static std::unique_ptr<Dispatcher> create(FrontendChannel* frontendChannel);
virtual ~Dispatcher() { }
- class PLATFORM_EXPORT CallbackBase {
- public:
- CallbackBase(std::unique_ptr<DispatcherImplWeakPtr> backendImpl, int callId);
- virtual ~CallbackBase();
- void sendFailure(const ErrorString&);
- void dispose();
-
- protected:
- void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMessage, const ErrorString& invocationError);
-
- private:
- std::unique_ptr<DispatcherImplWeakPtr> m_backendImpl;
- int m_callId;
- };
-
{% for domain in api.domains %}
- virtual void registerAgent(blink::protocol::Backend::{{domain.domain}}*) = 0;
+ virtual void registerAgent(blink::protocol::{{domain.domain}}::Backend*) = 0;
{% endfor %}
virtual void clearFrontend() = 0;
diff --git a/ErrorSupport.h b/ErrorSupport.h
index 98a3340..aee4c0e 100644
--- a/ErrorSupport.h
+++ b/ErrorSupport.h
@@ -12,6 +12,8 @@
namespace blink {
namespace protocol {
+using ErrorString = String16;
+
class PLATFORM_EXPORT ErrorSupport {
public:
ErrorSupport();
diff --git a/Frontend_cpp.template b/Frontend_cpp.template
index e2c8791..f32601f 100644
--- a/Frontend_cpp.template
+++ b/Frontend_cpp.template
@@ -18,11 +18,16 @@
{% endfor %}
{
}
-
{% for domain in api.domains %}
+
+{{domain.domain}}::Frontend* {{domain.domain}}::Frontend::from(protocol::Frontend* frontend)
+{
+ return &(frontend->m_{{domain.domain | lower}});
+}
{% for event in domain.events %}
{% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% continue %}{% endif %}
-void Frontend::{{domain.domain}}::{{event.name}}(
+
+void {{domain.domain}}::Frontend::{{event.name}}(
{%- for parameter in event.parameters %}
{% if "optional" in parameter -%}
const Maybe<{{resolve_type(parameter).raw_type}}>&
diff --git a/Frontend_h.template b/Frontend_h.template
index b116ed5..c29e8e8 100644
--- a/Frontend_h.template
+++ b/Frontend_h.template
@@ -7,47 +7,54 @@
#ifndef {{class_name}}_h
#define {{class_name}}_h
-
#include "platform/inspector_protocol/FrontendChannel.h"
#include "platform/inspector_protocol/TypeBuilder.h"
namespace blink {
namespace protocol {
+class PLATFORM_EXPORT Frontend;
+
+{% for domain in api.domains %}
+
+namespace {{domain.domain}} {
+
+class PLATFORM_EXPORT Frontend {
+public:
+ static Frontend* from(protocol::Frontend* frontend);
+ Frontend(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChannel) { }
+ {% for event in domain.events %}
+ {% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% continue %}{% endif %}
+ void {{event.name}}(
+ {%- for parameter in event.parameters -%}
+ {%- if "optional" in parameter -%}
+ const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>()
+ {%- else -%}
+ {{resolve_type(parameter).pass_type}} {{parameter.name}}
+ {%- endif -%}{%- if not loop.last -%}, {% endif -%}
+ {%- endfor -%}
+ );
+ {% endfor %}
+
+ void flush() { m_frontendChannel->flushProtocolNotifications(); }
+private:
+ FrontendChannel* m_frontendChannel;
+};
+
+} // namespace {{domain.domain}}
+{% endfor %}
+
class PLATFORM_EXPORT Frontend {
public:
Frontend(FrontendChannel*);
FrontendChannel* channel() { return m_frontendChannel; }
-{% for domain in api.domains %}
-
- class PLATFORM_EXPORT {{domain.domain}} {
- public:
- static {{domain.domain}}* from(Frontend* frontend) { return &(frontend->m_{{domain.domain | lower}}) ;}
- {{domain.domain}}(FrontendChannel* frontendChannel) : m_frontendChannel(frontendChannel) { }
- {% for event in domain.events %}
- {% if "handlers" in event and not ("renderer" in event["handlers"]) %}{% continue %}{% endif %}
- void {{event.name}}(
- {%- for parameter in event.parameters -%}
- {%- if "optional" in parameter -%}
- const Maybe<{{resolve_type(parameter).raw_type}}>& {{parameter.name}} = Maybe<{{resolve_type(parameter).raw_type}}>()
- {%- else -%}
- {{resolve_type(parameter).pass_type}} {{parameter.name}}
- {%- endif -%}{%- if not loop.last -%}, {% endif -%}
- {%- endfor -%}
- );
- {% endfor %}
-
- void flush() { m_frontendChannel->flushProtocolNotifications(); }
- private:
- FrontendChannel* m_frontendChannel;
- };
-{% endfor %}
-
private:
FrontendChannel* m_frontendChannel;
+
+public:
{% for domain in api.domains %}
- {{domain.domain}} m_{{domain.domain | lower}};
+ {{domain.domain}}::Frontend m_{{domain.domain | lower}};
{% endfor %}
};
diff --git a/Object.cpp b/Object.cpp
new file mode 100644
index 0000000..7bb007d
--- /dev/null
+++ b/Object.cpp
@@ -0,0 +1,35 @@
+// Copyright 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.
+
+#include "platform/inspector_protocol/Object.h"
+
+namespace blink {
+namespace protocol {
+
+std::unique_ptr<Object> Object::parse(protocol::Value* value, ErrorSupport* errors)
+{
+ protocol::DictionaryValue* object = DictionaryValue::cast(value);
+ if (!object) {
+ errors->addError("object expected");
+ return nullptr;
+ }
+ return wrapUnique(new Object(wrapUnique(static_cast<DictionaryValue*>(object->clone().release()))));
+}
+
+std::unique_ptr<protocol::DictionaryValue> Object::serialize() const
+{
+ return DictionaryValue::cast(m_object->clone());
+}
+
+std::unique_ptr<Object> Object::clone() const
+{
+ return wrapUnique(new Object(DictionaryValue::cast(m_object->clone())));
+}
+
+Object::Object(std::unique_ptr<protocol::DictionaryValue> object) : m_object(std::move(object)) { }
+
+Object::~Object() { }
+
+} // namespace protocol
+} // namespace blink
diff --git a/Object.h b/Object.h
new file mode 100644
index 0000000..6f1c0c4
--- /dev/null
+++ b/Object.h
@@ -0,0 +1,30 @@
+// Copyright 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 Object_h
+#define Object_h
+
+#include "platform/PlatformExport.h"
+#include "platform/inspector_protocol/ErrorSupport.h"
+#include "platform/inspector_protocol/Values.h"
+
+namespace blink {
+namespace protocol {
+
+class PLATFORM_EXPORT Object {
+public:
+ static std::unique_ptr<Object> parse(protocol::Value*, ErrorSupport*);
+ ~Object();
+
+ std::unique_ptr<protocol::DictionaryValue> serialize() const;
+ std::unique_ptr<Object> clone() const;
+private:
+ explicit Object(std::unique_ptr<protocol::DictionaryValue>);
+ std::unique_ptr<protocol::DictionaryValue> m_object;
+};
+
+} // namespace platform
+} // namespace blink
+
+#endif // !defined(Object_h)
diff --git a/TypeBuilder_cpp.template b/TypeBuilder_cpp.template
index d80473a..7864402 100644
--- a/TypeBuilder_cpp.template
+++ b/TypeBuilder_cpp.template
@@ -9,29 +9,6 @@
namespace blink {
namespace protocol {
-std::unique_ptr<Object> Object::parse(protocol::Value* value, ErrorSupport* errors)
-{
- protocol::DictionaryValue* object = DictionaryValue::cast(value);
- if (!object) {
- errors->addError("object expected");
- return nullptr;
- }
- return wrapUnique(new Object(wrapUnique(static_cast<DictionaryValue*>(object->clone().release()))));
-}
-
-std::unique_ptr<protocol::DictionaryValue> Object::serialize() const
-{
- return DictionaryValue::cast(m_object->clone());
-}
-
-std::unique_ptr<Object> Object::clone() const
-{
- return wrapUnique(new Object(DictionaryValue::cast(m_object->clone())));
-}
-
-Object::Object(std::unique_ptr<protocol::DictionaryValue> object) : m_object(std::move(object)) { }
-Object::~Object() { }
-
// ------------- Enum values from types.
{% for domain in api.domains %}
diff --git a/TypeBuilder_h.template b/TypeBuilder_h.template
index 75f6704..c649009 100644
--- a/TypeBuilder_h.template
+++ b/TypeBuilder_h.template
@@ -11,6 +11,7 @@
#include "platform/inspector_protocol/Array.h"
#include "platform/inspector_protocol/ErrorSupport.h"
#include "platform/inspector_protocol/Maybe.h"
+#include "platform/inspector_protocol/Object.h"
#include "platform/inspector_protocol/String16.h"
#include "platform/inspector_protocol/Values.h"
#include "platform/inspector_protocol/ValueConversions.h"
@@ -20,20 +21,6 @@
namespace blink {
namespace protocol {
-using ErrorString = String16;
-
-class PLATFORM_EXPORT Object {
-public:
- static std::unique_ptr<Object> parse(protocol::Value* value, ErrorSupport* errors);
- ~Object();
-
- std::unique_ptr<protocol::DictionaryValue> serialize() const;
- std::unique_ptr<Object> clone() const;
-private:
- Object(std::unique_ptr<protocol::DictionaryValue> object);
- std::unique_ptr<protocol::DictionaryValue> m_object;
-};
-
{% for domain in api.domains %}
// ------------- Forward declarations and typedefs.