| Index: headless/lib/browser/domain_h.template
|
| diff --git a/headless/lib/browser/domain_h.template b/headless/lib/browser/domain_h.template
|
| index bf53d0ee6c8eef7a0fc57a55f9a5d48f9838c6fd..e5180fbe6fd5e54010b26b400f244c7c1d971b00 100644
|
| --- a/headless/lib/browser/domain_h.template
|
| +++ b/headless/lib/browser/domain_h.template
|
| @@ -14,19 +14,73 @@
|
| #include "headless/public/headless_export.h"
|
| #include "headless/public/internal/message_dispatcher.h"
|
|
|
| +{# Macro for defining a member function for a given command. #}
|
| +{% macro command_decl(command) %}
|
| + {% 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 "parameters" in command %}
|
| + 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 | camelcase_to_hacker_style -}}
|
| + {% 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 %});
|
| + {% endif %}
|
| +{% endmacro %}
|
| +
|
| namespace headless {
|
| namespace {{domain.domain | camelcase_to_hacker_style}} {
|
| +class ExperimentalDomain;
|
| +class ExperimentalObserver;
|
| {% if "events" in domain %}
|
| -class Observer {
|
| +
|
| +class HEADLESS_EXPORT ExperimentalObserver {
|
| public:
|
| - virtual ~Observer() {}
|
| + virtual ~ExperimentalObserver() {}
|
| {% for event in domain.events %}
|
| + {% if event.description %}
|
| + // {{event.description}}
|
| + {% endif %}
|
| virtual void On{{event.name | to_title_case}}({# -#}
|
| {% if "parameters" in event %}{# -#}
|
| const {{event.name | to_title_case}}Params& params{# -#}
|
| {% endif %}) {}
|
| {% endfor %}
|
| };
|
| +
|
| +class HEADLESS_EXPORT Observer : public ExperimentalObserver {
|
| + public:
|
| + virtual ~Observer() {}
|
| + {% for event in domain.events %}
|
| + {% if event.description %}
|
| + // {% if event.hidden %}Experimental: {% endif %}{{event.description}}
|
| + {% endif %}
|
| + virtual void On{{event.name | to_title_case}}({# -#}
|
| + {% if "parameters" in event %}{# -#}
|
| + const {{event.name | to_title_case}}Params& params{# -#}
|
| + {% endif %}) {% if event.hidden %}final {% endif %}{}
|
| + {% endfor %}
|
| +};
|
| {% endif %}
|
|
|
| {% if domain.description %}
|
| @@ -34,9 +88,6 @@ class Observer {
|
| {% endif %}
|
| class HEADLESS_EXPORT Domain {
|
| public:
|
| - Domain(internal::MessageDispatcher* dispatcher);
|
| - ~Domain();
|
| -
|
| {% if "events" in domain %}
|
| // Add or remove an observer. |observer| must be removed before being
|
| // destroyed.
|
| @@ -44,41 +95,22 @@ class HEADLESS_EXPORT Domain {
|
| void RemoveObserver(Observer* observer);
|
| {% endif %}
|
|
|
| + // Return the experimental interface for this domain. Note that experimental
|
| + // commands may be changed or removed at any time.
|
| + ExperimentalDomain* GetExperimental();
|
| +
|
| {# 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 | camelcase_to_hacker_style -}}
|
| - {% 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 %});
|
| + {# Skip hidden commands. #}
|
| + {% if command.hidden %}{% continue %}{% endif %}
|
| +{{ command_decl(command) }}
|
| {% endfor %}
|
| - private:
|
| + protected:
|
| + Domain(internal::MessageDispatcher* dispatcher);
|
| + ~Domain();
|
| +
|
| {# Generate response handlers for commands that need them. #}
|
| {% for command in domain.commands %}
|
| {% if not "returns" in command %}{% continue %}{% endif %}
|
| @@ -96,12 +128,38 @@ class HEADLESS_EXPORT Domain {
|
|
|
| internal::MessageDispatcher* dispatcher_; // Not owned.
|
| {% if "events" in domain %}
|
| - base::ObserverList<Observer> observers_;
|
| + base::ObserverList<ExperimentalObserver> observers_;
|
| {% endif %}
|
|
|
| + private:
|
| DISALLOW_COPY_AND_ASSIGN(Domain);
|
| };
|
|
|
| +class ExperimentalDomain : public Domain {
|
| + public:
|
| + ExperimentalDomain(internal::MessageDispatcher* dispatcher);
|
| + ~ExperimentalDomain();
|
| +
|
| + {% if "events" in domain %}
|
| + // Add or remove an observer. |observer| must be removed before being
|
| + // destroyed.
|
| + void AddObserver(ExperimentalObserver* observer);
|
| + void RemoveObserver(ExperimentalObserver* observer);
|
| + {% endif %}
|
| +
|
| + {# Generate methods for each experimental command. #}
|
| + {% for command in domain.commands %}
|
| + {# Skip redirected commands. #}
|
| + {% if "redirect" in command %}{% continue %}{% endif %}
|
| + {# Skip non-hidden commands. #}
|
| + {% if not command.hidden %}{% continue %}{% endif %}
|
| +{{ command_decl(command) }}
|
| + {% endfor %}
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ExperimentalDomain);
|
| +};
|
| +
|
| } // namespace {{domain.domain | camelcase_to_hacker_style}}
|
| } // namespace headless
|
|
|
|
|