cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / emulator / audio_settings.js
blob739c21c6689f9a00afb3ab19507627ff3e53d96a
1 // Copyright 2015 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.
5 /** @enum {string} */ var AudioNodeType = {
6 HEADPHONE: 'HEADPHONE',
7 MIC: 'MIC',
8 USB: 'USB',
9 BLUETOOTH: 'BLUETOOTH',
10 HDMI: 'HDMI',
11 INTERNAL_SPEAKER: 'INTERNAL_SPEAKER',
12 INTERNAL_MIC: 'INTERNAL_MIC',
13 KEYBOARD_MIC: 'KEYBOARD_MIC',
14 AOKR: 'AOKR',
15 POST_MIX_LOOPBACK: 'POST_MIX_LOOPBACK',
16 POST_DSP_LOOPBACK: 'POST_DSP_LOOPBACK',
17 OTHER: 'OTHER',
20 /**
21 * An audio node. Based on the struct AudioNode found in audio_node.h.
22 * @constructor
24 var AudioNode = function() {
25 // Whether node will input or output audio.
26 this.isInput = false;
28 // Node ID. Set to 3000 because predefined output and input
29 // nodes use 10000's and 20000's respectively and |nodeCount| will append it.
30 this.id = '3000';
32 // Display name of the node. When this is empty, cras will automatically
33 // use |this.deviceName| as the display name.
34 this.name = '';
36 // The text label of the selected node name.
37 this.deviceName = 'New Device';
39 // Based on the AudioNodeType enum.
40 this.type = AudioNodeType.OTHER;
42 // Whether the node is active or not.
43 this.active = false;
45 // The time the node was plugged in (in seconds).
46 this.pluggedTime = 0;
49 Polymer({
50 is: 'audio-settings',
52 properties: {
53 /**
54 * An AudioNode which is currently being edited.
55 * @type {AudioNode}
57 currentEditableObject: {
58 type: Object,
59 value: function() { return {}; }
62 /**
63 * The index of the audio node which is currently being edited.
64 * This is initially set to -1 (i.e. no node selected) becuase no devices
65 * have been copied.
67 currentEditIndex: {type: Number, value: function() { return -1; }},
69 /**
70 * A counter that will auto increment everytime a new node is added
71 * or copied and used to set a new id. This allows the |AudioNode.id|
72 * to allows be unique.
74 nodeCount: {type: Number, value: function() { return 0; }},
76 /**
77 * A set of audio nodes.
78 * @type !Array<!AudioNode>
80 nodes: {type: Array, value: function() { return []; }},
82 /**
83 * A set of options for the possible audio node types.
84 * AudioNodeType |type| is based on the AudioType emumation.
85 * @type {!Array<!{name: string, type: string}>}
87 nodeTypeOptions: {
88 type: Array,
89 value: function() {
90 return [
91 {name: 'Headphones', type: AudioNodeType.HEADPHONE},
92 {name: 'Mic', type: AudioNodeType.MIC},
93 {name: 'Usb', type: AudioNodeType.USB},
94 {name: 'Bluetooth', type: AudioNodeType.BLUETOOTH},
95 {name: 'HDMI', type: AudioNodeType.HDMI},
96 {name: 'Internal Speaker', type: AudioNodeType.INTERNAL_SPEAKER},
97 {name: 'Internal Mic', type: AudioNodeType.INTERNAL_MIC},
98 {name: 'Keyboard Mic', type: AudioNodeType.KEYBOARD_MIC},
99 {name: 'Aokr', type: AudioNodeType.AOKR},
100 {name: 'Post Mix Loopback', type: AudioNodeType.POST_MIX_LOOPBACK},
101 {name: 'Post Dsp Loopback', type: AudioNodeType.POST_DSP_LOOPBACK},
102 {name: 'Other', type: AudioNodeType.OTHER}
108 * The title to be displayed in a heading element for the element.
110 title: {type: String},
113 ready: function() {
114 this.title = 'Audio';
117 initialize: function() {
118 if (!this.initialized) {
119 chrome.send('requestAudioNodes');
120 this.initialized = true;
125 * Adds a new node with default settings to the list of nodes.
127 appendNewNode: function() {
128 var newNode = new AudioNode();
129 newNode.id += this.nodeCount;
130 this.nodeCount++;
131 this.push('nodes', newNode);
135 * This adds or modifies an audio node to the AudioNodeList.
136 * @param {model: {index: number}} e Event with a model containing
137 * the index in |nodes| to add.
139 insertAudioNode: function(e) {
140 // Create a new audio node and add all the properties from |nodes[i]|.
141 var info = this.nodes[e.model.index];
142 chrome.send('insertAudioNode', [info]);
146 * This adds/modifies the audio node |nodes[currentEditIndex]| to/from the
147 * AudioNodeList.
148 * @param {model: {index: number}} e Event with a model containing
149 * the index in |nodes| to add.
151 insertEditedAudioNode: function(e) {
152 // Insert a new node or update an existing node using all the properties
153 // in |node|.
154 var node = this.nodes[this.currentEditIndex];
155 chrome.send('insertAudioNode', [node]);
159 * Removes the audio node with id |id|.
160 * @param {model: {index: number}} e Event with a model containing
161 * the index in |nodes| to add.
163 removeAudioNode: function(e) {
164 var info = this.nodes[e.model.index];
165 chrome.send('removeAudioNode', [info.id]);
169 * Called on "copy" button from the device list clicked. Creates a copy of
170 * the selected node.
171 * @param {Event} event Contains event data. |event.model.index| is the index
172 * of the item which the target is contained in.
174 copyDevice: function(event) {
175 // Create a shallow copy of the selected device.
176 var newNode = new AudioNode();
177 Object.assign(newNode, this.nodes[event.model.index]);
178 newNode.name += ' (Copy)';
179 newNode.deviceName += ' (Copy)';
180 newNode.id += this.nodeCount;
181 this.nodeCount++;
183 this.push('nodes', newNode);
187 * Shows a modal dialog to edit the selected node's properties.
188 * @param {Event} event Contains event data. |event.model.index| is the index
189 * of the item which the target is contained in.
191 showEditModal: function(event) {
192 var index = event.model.index;
193 this.currentEditIndex = index;
194 this.currentEditableObject = this.nodes[index];
195 this.$.editModal.toggle();
199 * Called by the WebUI which provides a list of nodes.
200 * @param {!Array<!AudioNode>} nodeList A list of audio nodes.
202 updateAudioNodes: function(nodeList) {
203 /** @type {!Array<!AudioNode>} */ var newNodeList = [];
204 for (var i = 0; i < nodeList.length; ++i) {
205 // Create a new audio node and add all the properties from |nodeList[i]|.
206 var node = new AudioNode();
207 Object.assign(node, nodeList[i]);
208 newNodeList.push(node);
210 this.nodes = newNodeList;