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

Side by Side Diff: chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js

Issue 2218713002: MD Settings: Bluetooth polish (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clang fixes + cleanup Created 4 years, 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.exportPath('settings'); 5 cr.exportPath('settings');
6 6
7 (function() { 7 (function() {
8 8
9 var PairingEventType = chrome.bluetoothPrivate.PairingEventType; 9 var PairingEventType = chrome.bluetoothPrivate.PairingEventType;
10 10
(...skipping 11 matching lines...) Expand all
22 type: Object, 22 type: Object,
23 observer: 'adapterStateChanged_', 23 observer: 'adapterStateChanged_',
24 }, 24 },
25 25
26 /** 26 /**
27 * The ordered list of bluetooth devices. 27 * The ordered list of bluetooth devices.
28 * @type {!Array<!chrome.bluetooth.Device>} 28 * @type {!Array<!chrome.bluetooth.Device>}
29 */ 29 */
30 deviceList: { 30 deviceList: {
31 type: Array, 31 type: Array,
32 value: /** @return {Array} */ function() { return []; }, 32 value: /** @return {Array} */ function() {
33 return [];
34 },
33 }, 35 },
34 }, 36 },
35 37
36 /** @private */ 38 /** @private */
37 adapterStateChanged_: function() { 39 adapterStateChanged_: function() {
38 if (!this.adapterState.powered) 40 if (!this.adapterState.powered)
39 this.close(); 41 this.close();
40 }, 42 },
41 43
42 /** 44 /**
43 * @param {!chrome.bluetooth.Device} device 45 * @param {!chrome.bluetooth.Device} device
44 * @return {boolean} 46 * @return {boolean}
45 * @private 47 * @private
46 */ 48 */
47 deviceNotPaired_: function(device) { return !device.paired; }, 49 deviceNotPaired_: function(device) {
50 return !device.paired;
51 },
48 52
49 /** 53 /**
50 * @param {!Array<!chrome.bluetooth.Device>} deviceList
51 * @return {boolean} True if deviceList contains any unpaired devices. 54 * @return {boolean} True if deviceList contains any unpaired devices.
52 * @private 55 * @private
53 */ 56 */
54 haveDevices_: function(deviceList) { 57 haveDevices_: function(deviceList) {
55 return this.deviceList.findIndex(function(d) { return !d.paired; }) != -1; 58 return this.deviceList.findIndex(function(d) {
59 return !d.paired;
60 }) != -1;
56 }, 61 },
57 62
58 /** 63 /**
59 * @param {!{detail: {action: string, device: !chrome.bluetooth.Device}}} e 64 * @param {!{detail: {action: string, device: !chrome.bluetooth.Device}}} e
60 * @private 65 * @private
61 */ 66 */
62 onDeviceEvent_: function(e) { 67 onDeviceEvent_: function(e) {
63 this.fire('device-event', e.detail); 68 this.fire('device-event', e.detail);
64 /** @type {Event} */ (e).stopPropagation(); 69 /** @type {Event} */ (e).stopPropagation();
65 }, 70 },
(...skipping 25 matching lines...) Expand all
91 type: Array, 96 type: Array,
92 readOnly: true, 97 readOnly: true,
93 value: [0, 1, 2, 3, 4, 5], 98 value: [0, 1, 2, 3, 4, 5],
94 }, 99 },
95 }, 100 },
96 101
97 observers: [ 102 observers: [
98 'pairingChanged_(pairingDevice, pairingEvent)', 103 'pairingChanged_(pairingDevice, pairingEvent)',
99 ], 104 ],
100 105
101 /** 106 /** @private */
102 * @param {?chrome.bluetooth.Device} pairingDevice 107 pairingChanged_: function() {
103 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
104 * @private
105 */
106 pairingChanged_: function(pairingDevice, pairingEvent) {
107 // Auto-close the dialog when pairing completes. 108 // Auto-close the dialog when pairing completes.
108 if (pairingDevice && pairingDevice.connected) { 109 if (this.pairingDevice && this.pairingDevice.connected) {
109 this.close(); 110 this.close();
110 return; 111 return;
111 } 112 }
112 this.pinOrPass = ''; 113 this.pinOrPass = '';
113 }, 114 },
114 115
115 /** 116 /**
116 * @param {?chrome.bluetooth.Device} device
117 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
118 * @return {string} 117 * @return {string}
119 * @private 118 * @private
120 */ 119 */
121 getMessage_: function(device, pairingEvent) { 120 getMessage_: function() {
122 if (!device) 121 if (!this.pairingDevice)
123 return ''; 122 return '';
124 var message; 123 var message;
125 if (!pairingEvent) 124 if (!this.pairingEvent)
126 message = 'bluetoothStartConnecting'; 125 message = 'bluetoothStartConnecting';
127 else 126 else
128 message = this.getEventDesc_(pairingEvent.pairing); 127 message = this.getEventDesc_(this.pairingEvent.pairing);
129 return this.i18n(message, device.name); 128 return this.i18n(message, this.pairingDevice.name);
130 }, 129 },
131 130
132 /** 131 /**
133 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
134 * @return {boolean} 132 * @return {boolean}
135 * @private 133 * @private
136 */ 134 */
137 showEnterPincode_: function(pairingEvent) { 135 showEnterPincode_: function() {
138 return !!pairingEvent && 136 return !!this.pairingEvent &&
139 pairingEvent.pairing == PairingEventType.REQUEST_PINCODE; 137 this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE;
140 }, 138 },
141 139
142 /** 140 /**
143 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
144 * @return {boolean} 141 * @return {boolean}
145 * @private 142 * @private
146 */ 143 */
147 showEnterPasskey_: function(pairingEvent) { 144 showEnterPasskey_: function() {
148 return !!pairingEvent && 145 return !!this.pairingEvent &&
149 pairingEvent.pairing == PairingEventType.REQUEST_PASSKEY; 146 this.pairingEvent.pairing == PairingEventType.REQUEST_PASSKEY;
150 }, 147 },
151 148
152 /** 149 /**
153 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
154 * @return {boolean} 150 * @return {boolean}
155 * @private 151 * @private
156 */ 152 */
157 showDisplayPassOrPin_: function(pairingEvent) { 153 showDisplayPassOrPin_: function() {
158 if (!pairingEvent) 154 if (!this.pairingEvent)
159 return false; 155 return false;
160 var pairing = pairingEvent.pairing; 156 var pairing = this.pairingEvent.pairing;
161 return ( 157 return (
162 pairing == PairingEventType.DISPLAY_PINCODE || 158 pairing == PairingEventType.DISPLAY_PINCODE ||
163 pairing == PairingEventType.DISPLAY_PASSKEY || 159 pairing == PairingEventType.DISPLAY_PASSKEY ||
164 pairing == PairingEventType.CONFIRM_PASSKEY || 160 pairing == PairingEventType.CONFIRM_PASSKEY ||
165 pairing == PairingEventType.KEYS_ENTERED); 161 pairing == PairingEventType.KEYS_ENTERED);
166 }, 162 },
167 163
168 /** 164 /**
169 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
170 * @return {boolean} 165 * @return {boolean}
171 * @private 166 * @private
172 */ 167 */
173 showAcceptReject_: function(pairingEvent) { 168 showAcceptReject_: function() {
174 return !!pairingEvent && 169 return !!this.pairingEvent &&
175 pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY; 170 this.pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY;
176 }, 171 },
177 172
178 /** 173 /**
179 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
180 * @return {boolean} 174 * @return {boolean}
181 * @private 175 * @private
182 */ 176 */
183 showConnect_: function(pairingEvent) { 177 showConnect_: function() {
184 if (!pairingEvent) 178 if (!this.pairingEvent)
185 return false; 179 return false;
186 var pairing = pairingEvent.pairing; 180 var pairing = this.pairingEvent.pairing;
187 return pairing == PairingEventType.REQUEST_PINCODE || 181 return pairing == PairingEventType.REQUEST_PINCODE ||
188 pairing == PairingEventType.REQUEST_PASSKEY; 182 pairing == PairingEventType.REQUEST_PASSKEY;
189 }, 183 },
190 184
191 /** 185 /**
192 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
193 * @param {string} pinOrPass Unused; call is triggered when this changes.
194 * @return {boolean} 186 * @return {boolean}
195 * @private 187 * @private
196 */ 188 */
197 enableConnect_: function(pairingEvent, pinOrPass) { 189 enableConnect_: function() {
198 if (!this.showConnect_(this.pairingEvent)) 190 if (!this.showConnect_())
199 return false; 191 return false;
200 var inputId = 192 var inputId =
201 (this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE) ? 193 (this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE) ?
202 '#pincode' : 194 '#pincode' :
203 '#passkey'; 195 '#passkey';
204 var paperInput = /** @type {!PaperInputElement} */ (this.$$(inputId)); 196 var paperInput = /** @type {!PaperInputElement} */ (this.$$(inputId));
205 assert(paperInput); 197 assert(paperInput);
206 /** @type {string} */ var value = paperInput.value; 198 /** @type {string} */ var value = paperInput.value;
207 return !!value && paperInput.validate(); 199 return !!value && paperInput.validate();
208 }, 200 },
209 201
210 /** 202 /**
211 * @param {?chrome.bluetooth.Device} device
212 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
213 * @return {boolean} 203 * @return {boolean}
214 * @private 204 * @private
215 */ 205 */
216 showDismiss_: function(device, pairingEvent) { 206 showDismiss_: function() {
217 return (!!device && device.paired) || 207 return (!!this.paringDevice && this.pairingDevice.paired) ||
218 (!!pairingEvent && pairingEvent.pairing == PairingEventType.COMPLETE); 208 (!!this.pairingEvent &&
209 this.pairingEvent.pairing == PairingEventType.COMPLETE);
219 }, 210 },
220 211
221 /** @private */ 212 /** @private */
222 onAcceptTap_: function() { 213 onAcceptTap_: function() {
223 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM); 214 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM);
224 }, 215 },
225 216
226 /** @private */ 217 /** @private */
227 onConnectTap_: function() { 218 onConnectTap_: function() {
228 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM); 219 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CONFIRM);
229 }, 220 },
230 221
231 /** @private */ 222 /** @private */
232 onRejectTap_: function() { 223 onRejectTap_: function() {
233 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.REJECT); 224 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.REJECT);
234 }, 225 },
235 226
236 /** @private */ 227 /**
228 * @param {!chrome.bluetoothPrivate.PairingResponse} response
229 * @private
230 */
237 sendResponse_: function(response) { 231 sendResponse_: function(response) {
238 if (!this.pairingDevice) 232 if (!this.pairingDevice)
239 return; 233 return;
240 var options = 234 var options =
241 /** @type {!chrome.bluetoothPrivate.SetPairingResponseOptions} */ { 235 /** @type {!chrome.bluetoothPrivate.SetPairingResponseOptions} */ {
242 device: this.pairingDevice, 236 device: this.pairingDevice,
243 response: response 237 response: response
244 }; 238 };
245 if (response == chrome.bluetoothPrivate.PairingResponse.CONFIRM) { 239 if (response == chrome.bluetoothPrivate.PairingResponse.CONFIRM) {
246 var pairing = this.pairingEvent.pairing; 240 var pairing = this.pairingEvent.pairing;
(...skipping 14 matching lines...) Expand all
261 assert(eventType); 255 assert(eventType);
262 if (eventType == PairingEventType.COMPLETE || 256 if (eventType == PairingEventType.COMPLETE ||
263 eventType == PairingEventType.KEYS_ENTERED || 257 eventType == PairingEventType.KEYS_ENTERED ||
264 eventType == PairingEventType.REQUEST_AUTHORIZATION) { 258 eventType == PairingEventType.REQUEST_AUTHORIZATION) {
265 return 'bluetoothStartConnecting'; 259 return 'bluetoothStartConnecting';
266 } 260 }
267 return 'bluetooth_' + /** @type {string} */ (eventType); 261 return 'bluetooth_' + /** @type {string} */ (eventType);
268 }, 262 },
269 263
270 /** 264 /**
271 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
272 * @param {number} index 265 * @param {number} index
273 * @return {string} 266 * @return {string}
274 * @private 267 * @private
275 */ 268 */
276 getPinDigit_: function(pairingEvent, index) { 269 getPinDigit_: function(index) {
277 if (!pairingEvent) 270 if (!this.pairingEvent)
278 return ''; 271 return '';
279 var digit = '0'; 272 var digit = '0';
280 var pairing = pairingEvent.pairing; 273 var pairing = this.pairingEvent.pairing;
281 if (pairing == PairingEventType.DISPLAY_PINCODE && pairingEvent.pincode && 274 if (pairing == PairingEventType.DISPLAY_PINCODE &&
282 index < pairingEvent.pincode.length) { 275 this.pairingEvent.pincode && index < this.pairingEvent.pincode.length) {
283 digit = pairingEvent.pincode[index]; 276 digit = this.pairingEvent.pincode[index];
284 } else if ( 277 } else if (
285 pairingEvent.passkey && (pairing == PairingEventType.DISPLAY_PASSKEY || 278 this.pairingEvent.passkey &&
286 pairing == PairingEventType.KEYS_ENTERED || 279 (pairing == PairingEventType.DISPLAY_PASSKEY ||
287 pairing == PairingEventType.CONFIRM_PASSKEY)) { 280 pairing == PairingEventType.KEYS_ENTERED ||
288 var passkeyString = String(pairingEvent.passkey); 281 pairing == PairingEventType.CONFIRM_PASSKEY)) {
282 var passkeyString = String(this.pairingEvent.passkey);
289 if (index < passkeyString.length) 283 if (index < passkeyString.length)
290 digit = passkeyString[index]; 284 digit = passkeyString[index];
291 } 285 }
292 return digit; 286 return digit;
293 }, 287 },
294 288
295 /** 289 /**
296 * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent
297 * @param {number} index 290 * @param {number} index
298 * @return {string} 291 * @return {string}
299 * @private 292 * @private
300 */ 293 */
301 getPinClass_: function(pairingEvent, index) { 294 getPinClass_: function(index) {
302 if (!pairingEvent) 295 if (!this.pairingEvent)
303 return ''; 296 return '';
304 if (pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY) 297 if (this.pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY)
305 return 'confirm'; 298 return 'confirm';
306 var cssClass = 'display'; 299 var cssClass = 'display';
307 if (pairingEvent.pairing == PairingEventType.DISPLAY_PASSKEY) { 300 if (this.pairingEvent.pairing == PairingEventType.DISPLAY_PASSKEY) {
308 if (index == 0) 301 if (index == 0)
309 cssClass += ' next'; 302 cssClass += ' next';
310 else 303 else
311 cssClass += ' untyped'; 304 cssClass += ' untyped';
312 } else if ( 305 } else if (
313 pairingEvent.pairing == PairingEventType.KEYS_ENTERED && 306 this.pairingEvent.pairing == PairingEventType.KEYS_ENTERED &&
314 pairingEvent.enteredKey) { 307 this.pairingEvent.enteredKey) {
315 var enteredKey = pairingEvent.enteredKey; // 1-7 308 var enteredKey = this.pairingEvent.enteredKey; // 1-7
316 var lastKey = this.digits.length; // 6 309 var lastKey = this.digits.length; // 6
317 if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey)) 310 if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey))
318 cssClass += ' next'; 311 cssClass += ' next';
319 else if (index > enteredKey) 312 else if (index > enteredKey)
320 cssClass += ' untyped'; 313 cssClass += ' untyped';
321 } 314 }
322 return cssClass; 315 return cssClass;
323 }, 316 },
324 }; 317 };
325 318
326 Polymer({ 319 Polymer({
327 is: 'bluetooth-device-dialog', 320 is: 'bluetooth-device-dialog',
328 321
329 behaviors: [ 322 behaviors: [
330 I18nBehavior, 323 I18nBehavior,
331 settings.BluetoothAddDeviceBehavior, 324 settings.BluetoothAddDeviceBehavior,
332 settings.BluetoothPairDeviceBehavior, 325 settings.BluetoothPairDeviceBehavior,
333 ], 326 ],
334 327
335 properties: { 328 properties: {
336 /** Which version of this dialog to show (adding or pairing). */ 329 /** Which version of this dialog to show (adding or pairing). */
337 dialogId: String, 330 dialogId: String,
338 }, 331 },
339 332
333 observers: [
334 'dialogUpdated_(dialogId, pairingEvent)',
335 ],
336
340 open: function() { 337 open: function() {
341 this.pinOrPass = ''; 338 this.pinOrPass = '';
342 this.getDialog_().showModal(); 339 this.getDialog_().showModal();
343 }, 340 },
344 341
345 close: function() { 342 close: function() {
346 var dialog = this.getDialog_(); 343 var dialog = this.getDialog_();
347 if (dialog.open) 344 if (dialog.open)
348 dialog.close(); 345 dialog.close();
349 }, 346 },
350 347
348 /** @private */
349 dialogUpdated_: function() {
350 if (this.showEnterPincode_())
351 this.$$('#pincode').focus();
352 else if (this.showEnterPasskey_())
353 this.$$('#passkey').focus();
354 },
355
351 /** 356 /**
352 * @return {!CrDialogElement} 357 * @return {!CrDialogElement}
353 * @private 358 * @private
354 */ 359 */
355 getDialog_: function() { 360 getDialog_: function() {
356 return /** @type {!CrDialogElement} */ (this.$.dialog); 361 return /** @type {!CrDialogElement} */ (this.$.dialog);
357 }, 362 },
358 363
359 /** 364 /**
360 * @param {string} dialogId 365 * @param {string} dialogId
361 * @return {string} The title of for that |dialogId|. 366 * @return {string} The title of for that |dialogId|.
362 */ 367 */
363 getTitle_: function(dialogId) { 368 getTitle_: function(dialogId) {
364 if (dialogId == 'addDevice') 369 if (dialogId == 'addDevice')
365 return this.i18n('bluetoothAddDevicePageTitle'); 370 return this.i18n('bluetoothAddDevicePageTitle');
366 // Use the 'pair' title for the pairing dialog and error dialog. 371 // Use the 'pair' title for the pairing dialog and error dialog.
367 return this.i18n('bluetoothPairDevicePageTitle'); 372 return this.i18n('bluetoothPairDevicePageTitle');
368 }, 373 },
369 374
370 /** 375 /**
371 * @param {string} currentDialogType 376 * @param {string} desiredDialogType
372 * @param {string} wantedDialogType
373 * @return {boolean} 377 * @return {boolean}
374 * @private 378 * @private
375 */ 379 */
376 isDialogType_: function(currentDialogType, wantedDialogType) { 380 isDialogType_: function(desiredDialogType, currentDialogType) {
377 return currentDialogType == wantedDialogType; 381 return currentDialogType == desiredDialogType;
378 }, 382 },
379 383
380 /** @private */ 384 /** @private */
381 onCancelTap_: function() { 385 onCancelTap_: function() {
382 this.getDialog_().cancel(); 386 this.getDialog_().cancel();
383 }, 387 },
384 388
385 /** @private */ 389 /** @private */
386 onDialogCanceled_: function() { 390 onDialogCanceled_: function() {
387 if (this.dialogId == 'pairDevice') 391 if (this.dialogId == 'pairDevice')
388 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); 392 this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL);
389 }, 393 },
390 }); 394 });
391 395
392 })(); 396 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698