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

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: Make the JS better 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.require('chromium.DevTools.Connection');
16 {% for domain_name in domain.js_dependencies %}
17 goog.require('chromium.DevTools.{{domain_name}}')
18 {% endfor %}
19 goog.provide('chromium.DevTools.{{domain.domain}}');
20
21 {% for forward_declaration in domain.js_forward_declarations %}
22 goog.forwardDeclare('chromium.DevTools.{{forward_declaration}}');
23 {% endfor %}
24
25 /**
26 * @class Bindings for the {{domain.domain}} DevTools Domain.
27 * @param {!chromium.DevTools.Connection} connection The DevTools connection.
28 * @constructor
29 */
30 chromium.DevTools.{{domain.domain}} = function(connection) {
31 /**
32 * The DevTools connection.
33 *
34 * @private {!chromium.DevTools.Connection}
35 */
36 this.connection_ = connection;
37 };
38
39 goog.scope(function () {
40
41 var {{domain.domain}} = chromium.DevTools.{{domain.domain}};
42
43 {# Generate enums. #}
44 {% for type in domain.types %}
45 {% if not "enum" in type %}{% continue %}{% endif %}
46 /**
47 {% if type.description %}
48 * {{type.description}}
49 *
50 {% endif %}
51 * @enum {string}
52 */
53 {{domain.domain}}.{{type.id}} = {
54 {% for literal in type.enum %}
55 {{ literal | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_styl e | upper }}: "{{ literal }}"{{',' if not loop.last}}
56 {% endfor %}
57 };
58
59 {% endfor %}
60
61 {# Generate types. #}
62 {% for type in domain.types %}
63 {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
64 /**
65 {% if type.description %}
66 * {{type.description}}
67 *
68 {% endif %}
69 {% for property in type.properties %}
70 {% if property.description %}
71 * {{property.name}}: {{property.description}}
72 {% endif %}
73 {% endfor %}
74 *
75 {% if type.properties %}
76 * @typedef {{ '{{' }}
77 {% for property in type.properties %}
78 {% if property.optional %}
79 * {{property.name}}: ({{ resolve_type(property).js_type }}|undefined){% if no t loop.last %},{% endif %}
80
81 {% else %}
82 * {{property.name}}: {{ resolve_type(property).js_type }}{% if not loop.last %}, {% endif %}
83
84 {% endif %}
85 {% endfor %}
86 * {{ '}}' }}
87 {% else %}
88 * @typedef {undefined}
89 {% endif %}
90 */
91 {{domain.domain}}.{{type.id}};
92
93
94 {% endfor %}
95
96 {# Generate non-experimental commands. #}
97 {% for command in domain.commands %}
98 {% if command.experimental %}{% continue %}{% endif %}
99 {% set method_name = command.name | sanitize_literal | to_title_case %}
100 {% if command.parameters|length > 0 %}
101 {% set param_name = 'params' %}
102 {% set param_type = '{' + domain.domain + '.' + method_name + 'Params}' %}
103 {% else %}
104 {% set param_name = 'opt_params' %}
105 {% set param_type = '{' + domain.domain + '.' + method_name + 'Params=}' %}
106 {% endif %}
107 {% set result_type = '{!Promise<' + domain.domain + '.' + method_name + 'Resul t>}' %}
108
109 /**
110 {% if command.description %}
111 * {{ command.description }}
112 {% endif %}
113 * @param {{param_type}} {{param_name}}
114 * @return {{result_type}}
115 */
116 {{domain.domain}}.prototype.{{method_name}} = function({{param_name}}) {
117 return /** @type {{result_type}} **/(
118 this.connection_.sendDevToolsMessage('{{domain.domain}}.{{command.name}}',
119 {{param_name}}));
120 };
121
122 {% endfor %}
123
124
125 {# Generate non-experimental events. #}
126 {% for event in domain.events %}
127 {% if event.experimental %}{% continue %}{% endif %}
128 {% set param_type = '{!function(!' + domain.domain + '.' + event.name | to_tit le_case + 'Params)}' %}
129
130 /**
131 {% if event.description %}
132 * {{ event.description }}
133 {% endif %}
134 * @param {{param_type}} listener
135 */
136 {{domain.domain}}.prototype.On{{event.name | to_title_case}} = function(listener ) {
137 this.connection_.addEventListener('{{domain.domain}}.{{event.name}}',
138 /** @type {!function(!Object): undefined} * / (listener));
139 };
140 {% endfor %}
141
142 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698