blob: 4f18227c1764fd604b3b3d919971cd7e83331c29 [file] [log] [blame]
// 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.
{# Changes to the generated API must be reflected in the externs too. #}
/**
* @fileoverview Generated DevTools bindings for the {{domain.domain}} Domain.
*/
'use strict';
goog.provide('chromium.DevTools.Experimental{{domain.domain}}');
goog.provide('chromium.DevTools.{{domain.domain}}');
goog.require('chromium.DevTools.Connection');
{% for domain_name in domain.js_dependencies %}
goog.require('chromium.DevTools.{{domain_name}}');
{% endfor %}
{% for forward_declaration in domain.js_forward_declarations %}
goog.forwardDeclare('chromium.DevTools.{{forward_declaration}}');
{% endfor %}
goog.scope(function() {
const Connection = chromium.DevTools.Connection;
{% for domain_name in domain.js_dependencies %}
const {{domain_name}} = chromium.DevTools.{{domain_name}};
{% endfor %}
/**
* Experimental bindings for the {{domain.domain}} DevTools Domain. Note these
* are subject to change without warning. Use at your own risk.
* @param {!Connection} connection The DevTools connection.
* @constructor
*/
chromium.DevTools.Experimental{{domain.domain}} = function(connection) {
/** @private {!Connection} */
this.connection_ = connection;
}
const Experimental{{domain.domain}} = chromium.DevTools.Experimental{{domain.domain}};
/**
* Removes an event listener.
*
* @param {number} id The id of the event listener to remove.
* @return {boolean} Whether the event listener was actually removed.
*/
Experimental{{domain.domain}}.prototype.removeEventListener = function(id) {
return this.connection_.removeEventListener(id);
}
/**
* Bindings for the {{domain.domain}} DevTools Domain.
* @param {!Connection} connection The DevTools connection.
* @constructor
*/
chromium.DevTools.{{domain.domain}} = function(connection) {
/** @private {!Connection} */
this.connection_ = connection;
/** @type {!Experimental{{domain.domain}}} */
this.experimental = new Experimental{{domain.domain}}(connection);
}
const {{domain.domain}} = chromium.DevTools.{{domain.domain}};
/**
* Removes an event listener.
*
* @param {number} id The id of the event listener to remove.
* @return {boolean} Whether the event listener was actually removed.
*/
{{domain.domain}}.prototype.removeEventListener = function(id) {
return this.connection_.removeEventListener(id);
}
{# Generate enums. #}
{% for type in domain.types %}
{% if not "enum" in type %}{% continue %}{% endif %}
/**
{% if type.description %}
* {{type.description.replace('\n', '\n * ')}}
*
{% 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 %}
{# Generate types. #}
{% for type in domain.types %}
{% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %}
/**
{% if type.description %}
* {{type.description.replace('\n', '\n * ')}}
*
{% endif %}
{% for property in type.properties %}
{% if property.description %}
* {{property.name}}: {{property.description.replace('\n', '\n * ')}}
{% endif %}
{% endfor %}
*
{% if type.properties %}
* @typedef {{ '{{' }}
{% for property in type.properties %}
{% if property.optional %}
* {{property.name}}: ({{ short_form(resolve_type(property).js_type) }}|undefined){{',' if not loop.last}}
{% else %}
* {{property.name}}: {{ short_form(resolve_type(property).js_type) }}{{',' if not loop.last}}
{% endif %}
{% endfor %}
* {{ '}}' }}
{% else %}
* @typedef {undefined}
{% endif %}
*/
{{domain.domain}}.{{type.id}};
{% endfor %}
{# Generate all commands for Experimental Domain. #}
{% for command in domain.commands %}
{% set method_name = command.name | sanitize_literal %}
{% set title_case_method_name = method_name | to_title_case %}
{% set result_type = '{!Promise<' + domain.domain + '.' + title_case_method_name + 'Result>}' %}
/**
{% if command.description %}
* {{ command.description.replace('\n', '\n * ') }}
*
{% endif %}
{% if command.parameters|length > 0 %}
{% if command.parameters_required %}
* @param {{ '{' + domain.domain + '.' + title_case_method_name + 'Params}' }} params
{% else %}
* @param {{ '{' + domain.domain + '.' + title_case_method_name + 'Params=}' }} opt_params
{% endif %}
{% endif %}
* @return {{result_type}}
*/
{% if command.parameters|length > 0 %}
{% if command.parameters_required %}
Experimental{{domain.domain}}.prototype.{{method_name}} = function(params) {
return this.connection_.sendDevToolsMessage('{{domain.domain}}.{{command.name}}', params);
};
{% else %}
Experimental{{domain.domain}}.prototype.{{method_name}} = function(opt_params) {
return this.connection_.sendDevToolsMessage('{{domain.domain}}.{{command.name}}', opt_params || {});
};
{% endif %}
{% else %}
Experimental{{domain.domain}}.prototype.{{method_name}} = function() {
return this.connection_.sendDevToolsMessage('{{domain.domain}}.{{command.name}}', {});
};
{% endif %}
{% endfor %}
{# Generate all events Experimental Domain. #}
{% for event in domain.events %}
{% if event.parameters|length > 0 %}
{% set param_type = '{!function(!' + domain.domain + '.' + event.name | to_title_case + 'Params)}' %}
{% else %}
{% set param_type = '{!function()}' %}
{% endif %}
/**
{% if event.description %}
* {{ event.description.replace('\n', '\n * ') }}
*
{% endif %}
* @param {{param_type}} listener
* @return {number} The id of this event listener.
*/
Experimental{{domain.domain}}.prototype.on{{event.name | to_title_case}} = function(listener) {
return this.connection_.addEventListener(
'{{domain.domain}}.{{event.name}}', /** @type {!function(!Object): undefined} */ (listener));
};
{% endfor %}
{# Generate non-Experimental commands. #}
{% for command in domain.commands %}
{% if command.Experimental %}{% continue %}{% endif %}
{% set method_name = command.name | sanitize_literal %}
{% set title_case_method_name = method_name | to_title_case %}
{% set result_type = '{!Promise<' + domain.domain + '.' + title_case_method_name + 'Result>}' %}
/**
{% if command.description %}
* {{ command.description.replace('\n', '\n * ') }}
*
{% endif %}
{% if command.parameters|length > 0 %}
{% if command.parameters_required %}
* @param {{ '{' + domain.domain + '.' + title_case_method_name + 'Params}' }} params
{% else %}
* @param {{ '{' + domain.domain + '.' + title_case_method_name + 'Params=}' }} opt_params
{% endif %}
{% endif %}
* @return {{result_type}}
*/
{% if command.parameters|length > 0 %}
{% if command.parameters_required %}
{{domain.domain}}.prototype.{{method_name}} = function(params) {
return this.connection_.sendDevToolsMessage('{{domain.domain}}.{{command.name}}', params);
};
{% else %}
{{domain.domain}}.prototype.{{method_name}} = function(opt_params) {
return this.connection_.sendDevToolsMessage('{{domain.domain}}.{{command.name}}', opt_params || {});
};
{% endif %}
{% else %}
{{domain.domain}}.prototype.{{method_name}} = function() {
return this.connection_.sendDevToolsMessage('{{domain.domain}}.{{command.name}}', {});
};
{% endif %}
{% endfor %}
{# Generate non-Experimental events. #}
{% for event in domain.events %}
{% if event.Experimental %}{% continue %}{% endif %}
{% if event.parameters|length > 0 %}
{% set param_type = '{!function(!' + domain.domain + '.' + event.name | to_title_case + 'Params)}' %}
{% else %}
{% set param_type = '{!function()}' %}
{% endif %}
/**
{% if event.description %}
* {{ event.description.replace('\n', '\n * ') }}
*
{% endif %}
* @param {{param_type}} listener
* @return {number} The id of this event listener.
*/
{{domain.domain}}.prototype.on{{event.name | to_title_case}} = function(listener) {
return this.connection_.addEventListener(
'{{domain.domain}}.{{event.name}}', /** @type {!function(!Object): undefined} */ (listener));
};
{% endfor %}
}); // goog.scope