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