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

Side by Side 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: Try and fix python test Created 3 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview Generated DevTools bindings for the {{domain.domain}} Domain.
7 * Note bindings are not generated for experimental commands and events, if you
8 * need to use one of those you must use the
9 * <code>chromium.DevTools.Connection</code> class directly.
10 *
11 * TODO(alexclarke): Consider generating bindings for experimental stuff too.
12 */
13 'use strict';
14
15 goog.module('chromium.DevTools.{{domain.domain}}');
16 const Connection = goog.require('chromium.DevTools.Connection');
17 {% for domain_name in domain.js_dependencies %}
18 const {{domain_name}} = goog.require('chromium.DevTools.{{domain_name}}');
19 {% endfor %}
20 {% for forward_declaration in domain.js_forward_declarations %}
21 goog.forwardDeclare('chromium.DevTools.{{forward_declaration}}');
22 {% endfor %}
23
24 /**
25 * Bindings for the {{domain.domain}} DevTools Domain.
26 */
27 class {{domain.domain}} {
28 /**
29 * @param {!Connection} connection The DevTools connection.
30 */
31 constructor(connection) {
32 /** @private {!Connection} */
33 this.connection_ = connection;
34 };
35 {# Generate non-experimental commands. #}
36 {% for command in domain.commands %}
37 {% if command.experimental %}{% continue %}{% endif %}
38 {% set method_name = command.name | sanitize_literal | to_title_case %}
39 {% if command.parameters|length > 0 %}
40 {% set param_name = 'params' %}
41 {% set param_type = '{' + domain.domain + '.' + method_name + 'Params}' %}
42 {% else %}
43 {% set param_name = 'opt_params' %}
44 {% set param_type = '{' + domain.domain + '.' + method_name + 'Params=}' %}
45 {% endif %}
46 {% set result_type = '{!Promise<' + domain.domain + '.' + method_name + 'Resul t>}' %}
47
48 /**
49 {% if command.description %}
50 * {{ command.description }}
51 {% endif %}
52 * @param {{param_type}} {{param_name}}
53 * @return {{result_type}}
54 */
55 {{method_name}}({{param_name}}) {
56 return /** @type {{result_type}} **/(
57 this.connection_.sendDevToolsMessage('{{domain.domain}}.{{command.name}} ',
58 {{param_name}}));
59 }
60 {% endfor %}
61
62 {# Generate non-experimental events. #}
63 {% for event in domain.events %}
64 {% if event.experimental %}{% continue %}{% endif %}
65 {% set param_type = '{!function(!' + domain.domain + '.' + event.name | to_tit le_case + 'Params)}' %}
66
67 /**
68 {% if event.description %}
69 * {{ event.description }}
70 {% endif %}
71 * @param {{param_type}} listener
72 */
73 On{{event.name | to_title_case}}(listener) {
74 this.connection_.addEventListener(
75 '{{domain.domain}}.{{event.name}}', /** @type {!function(!Object): undef ined} */ (listener));
76 }
77 {% endfor %}
78 }
79
80 {# Generate enums. #}
81 {% for type in domain.types %}
82 {% if not "enum" in type %}{% continue %}{% endif %}
83 /**
84 {% if type.description %}
85 * {{type.description}}
86 *
87 {% endif %}
88 * @enum {string}
89 */
90 {{domain.domain}}.{{type.id}} = {
91 {% for literal in type.enum %}
92 {{ literal | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_styl e | upper }}: "{{ literal }}"{{',' if not loop.last}}
93 {% endfor %}
94 };
95
96 {% endfor %}
97
98 {# Generate types. #}
99 {% for type in domain.types %}
100 {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
101 /**
102 {% if type.description %}
103 * {{type.description}}
104 *
105 {% endif %}
106 {% for property in type.properties %}
107 {% if property.description %}
108 * {{property.name}}: {{property.description}}
109 {% endif %}
110 {% endfor %}
111 *
112 {% if type.properties %}
113 * @typedef {{ '{{' }}
114 {% for property in type.properties %}
115 {% if property.optional %}
116 * {{property.name}}: ({{ short_form(resolve_type(property).js_type) }}|undefi ned){% if not loop.last %},{% endif %}
117
118 {% else %}
119 * {{property.name}}: {{ short_form(resolve_type(property).js_type) }}{% if no t loop.last %}, {% endif %}
120
121 {% endif %}
122 {% endfor %}
123 * {{ '}}' }}
124 {% else %}
125 * @typedef {undefined}
126 {% endif %}
127 */
128 {{domain.domain}}.{{type.id}};
129
130
131 {% endfor %}
132
133 exports = {{domain.domain}};
OLDNEW
« no previous file with comments | « headless/lib/browser/devtools_api/devtools_connection.js ('k') | headless/lib/headless_browsertest_resource_ids » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698