Index: headless/lib/browser/domain_h.template |
diff --git a/headless/lib/browser/domain_h.template b/headless/lib/browser/domain_h.template |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4e3b363aab3f5fb5d9dd3ad1310ad1a7063188ef |
--- /dev/null |
+++ b/headless/lib/browser/domain_h.template |
@@ -0,0 +1,77 @@ |
+// This file is generated |
+ |
+// 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 HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style | upper}}_H_ |
+#define HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style | upper}}_H_ |
+ |
+#include "base/callback.h" |
+#include "base/values.h" |
+#include "headless/public/domains/types.h" |
+#include "headless/public/headless_export.h" |
+#include "headless/public/internal/message_dispatcher.h" |
+ |
+namespace headless { |
+namespace {{domain.domain | camelcase_to_hacker_style}} { |
+ |
+{% if domain.description %} |
+// {{domain.description}} |
+{% endif %} |
+class HEADLESS_EXPORT Domain { |
+ public: |
+ Domain(internal::MessageDispatcher* dispatcher); |
+ ~Domain(); |
+ |
+ {# Generate methods for each command. #} |
+ {% for command in domain.commands %} |
+ {# Skip redirected commands. #} |
+ {% if "redirect" in command %}{% continue %}{% endif %} |
+ {% set method_name = command.name | to_title_case %} |
+ {% if command.description %} |
+ // {{ command.description }} |
+ {% endif %} |
+ {% if "parameters" in command and "returns" in command %} |
+ void {{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback = base::Callback<void(std::unique_ptr<{{method_name}}Result>)>()); |
+ {% elif "parameters" in command %} |
+ void {{method_name}}(std::unique_ptr<{{method_name}}Params> params, base::Callback<void()> callback = base::Callback<void()>()); |
+ {% elif "returns" in command %} |
+ void {{method_name}}(base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback = base::Callback<void(std::unique_ptr<{{method_name}}Result>)>()); |
+ {% else %} |
+ void {{method_name}}(base::Callback<void()> callback = base::Callback<void()>()); |
+ {% endif %} |
+ {# Generate convenience methods that take the required parameters directly. #} |
+ {% if not "parameters" in command %}{% continue %}{% endif %} |
+ void {{method_name}}({##} |
+ {% for parameter in command.parameters -%} |
+ {% if parameter.get("optional", False) -%} |
+ {% break %} |
+ {% endif %} |
+ {% if not loop.first %}, {% endif %} |
+{{resolve_type(parameter).pass_type}} {{parameter.name -}} |
+ {% endfor %} |
+ {% if "parameters" in command and not command.parameters[0].get("optional", False) %}, {% endif %}{# -#} |
+ {% if "returns" in command -%} |
+ base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback = base::Callback<void(std::unique_ptr<{{method_name}}Result>)>(){##} |
+ {% else -%} |
+ base::Callback<void()> callback = base::Callback<void()>(){##} |
+ {% endif %}); |
+ {% endfor %} |
+ private: |
+ {# Generate response handlers for commands that need them. #} |
+ {% for command in domain.commands %} |
+ {% if not "returns" in command %}{% continue %}{% endif %} |
+ {% set method_name = command.name | to_title_case %} |
+ static void Handle{{method_name}}Response(base::Callback<void(std::unique_ptr<{{method_name}}Result>)> callback, const base::Value& response); |
+ {% endfor %} |
+ |
+ internal::MessageDispatcher* dispatcher_; // Not owned. |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Domain); |
+}; |
+ |
+} // namespace {{domain.domain | camelcase_to_hacker_style}} |
+} // namespace headless |
+ |
+#endif // HEADLESS_PUBLIC_DOMAINS_{{domain.domain | camelcase_to_hacker_style | upper}}_H_ |