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

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

Powered by Google App Engine
This is Rietveld 408576698