Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Unified Diff: headless/lib/browser/devtools_api/domain_js.template

Issue 2902583002: Add some closureised JS bindings for DevTools for use by headless embedder (Closed)
Patch Set: Don't run the test on windows because js_binary doesn't work Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: headless/lib/browser/devtools_api/domain_js.template
diff --git a/headless/lib/browser/devtools_api/domain_js.template b/headless/lib/browser/devtools_api/domain_js.template
new file mode 100644
index 0000000000000000000000000000000000000000..d810ab2110d3dd9b095edfc80dca92addda881fc
--- /dev/null
+++ b/headless/lib/browser/devtools_api/domain_js.template
@@ -0,0 +1,127 @@
+// Copyright 2017 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.
+
+/**
+ * @fileoverview Generated DevTools bindings for the {{domain.domain}} Domain.
Sami 2017/05/24 09:16:21 How do we handle experimental things currently? Ma
alex clarke (OOO till 29th) 2017/05/24 11:38:15 I guess we should just drop them and you have to u
Sami 2017/05/25 17:53:35 Right, let's not generate anything for them now an
alex clarke (OOO till 29th) 2017/05/26 11:37:02 Done.
+ */
+'use strict';
+
+goog.require('goog.DevTools.Connection');
+{% for domain_name in domain.js_dependencies %}
+goog.require('goog.DevTools.{{domain_name}}')
+{% endfor %}
+goog.provide('goog.DevTools.{{domain.domain}}');
+
+/**
+ * @class Bindings for the {{domain.domain}} DevTools Domain.
+ * @param {!goog.DevTools.Connection} connection The DevTools connection.
+ * @constructor
+ */
+goog.DevTools.{{domain.domain}} = function(connection) {
+ /**
+ * The DevTools connection.
+ *
+ * @private {!goog.DevTools.Connection}
+ */
+ this.connection_ = connection;
+};
+
+goog.scope(function () {
+
+var {{domain.domain}} = goog.DevTools.{{domain.domain}};
+
+{% for type in domain.types %}
+{% if not "enum" in type %}{% continue %}{% endif %}
+/**
+{% if type.description %}
+ * {{type.description}}
+ *
+{% endif %}
+ * @enum {string}
+ */
+{{domain.domain}}.{{type.id}} = {
+{% for literal in type.enum %}
+ {{ literal | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_style | upper }}: "{{ literal }}"{{',' if not loop.last}}
+{% endfor %}
+};
+
+{% endfor %}
+
+{% for type in domain.types %}
+{% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
+/**
+{% if type.description %}
+ * {{type.description}}
+ *
+{% endif %}
+{% for property in type.properties %}
+{% if property.description %}
+ * {{property.name}}: {{property.description}}
+{% endif %}
+{% endfor %}
+ *
+{% if type.properties %}
+ * @typedef {{ '{{' }}
+{% for property in type.properties %}
+{% if property.optional %}
+ * {{property.name}}: ({{ resolve_type(property).js_type }}|undefined){% if not loop.last %},{% endif %}
+
+{% else %}
+ * {{property.name}}: {{ resolve_type(property).js_type }}{% if not loop.last %}, {% endif %}
+
+{% endif %}
+{% endfor %}
+ * {{ '}}' }}
+{% else %}
+ * @typedef {undefined}
+{% endif %}
+ */
+{{domain.domain}}.{{type.id}};
+
+
+{% endfor %}
+
+{% for command in domain.commands %}
+{% set method_name = command.name | sanitize_literal | to_title_case %}
+{% if command.parameters|length > 0 %}
+{% set param_name = 'params' %}
+{% set param_type = '{' + domain.domain + '.' + method_name + 'Params}' %}
+{% else %}
+{% set param_name = 'opt_params' %}
+{% set param_type = '{' + domain.domain + '.' + method_name + 'Params=}' %}
+{% endif %}
+{% set result_type = '{Promise<' + domain.domain + '.' + method_name + 'Result>}' %}
+
+/**
+{% if command.description %}
+ * {{ command.description }}
+{% endif %}
+ * @param {{param_type}} {{param_name}}
+ * @return {{result_type}}
+ */
+{{domain.domain}}.prototype.{{method_name}} = function({{param_name}}) {
+ return /** @type {{result_type}} **/(
+ this.connection_.SendDevToolsMessage('{{domain.domain}}.{{command.name}}',
+ {{param_name}}));
+};
+
+{% endfor %}
+
+
+{% for event in domain.events %}
+{% set param_type = '{!function(!' + domain.domain + '.' + event.name | to_title_case + 'Params)}' %}
+
+/**
+{% if event.description %}
+ * {{ event.description }}
+{% endif %}
+ * @param {{param_type}} listener
+ */
+{{domain.domain}}.prototype.On{{event.name | to_title_case}} = function(listener) {
+ this.connection_.AddEventListener('{{domain.domain}}.{{event.name}}',
+ /** @type {!function(!Object)} */ (listener));
+};
+{% endfor %}
+
+}); // goog.scope

Powered by Google App Engine
This is Rietveld 408576698