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

Side by Side Diff: chrome/browser/resources/options/chromeos/bluetooth_pair_device_overlay.js

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 /** 5 /**
6 * Enumeration of possible states during pairing. The value associated with 6 * Enumeration of possible states during pairing. The value associated with
7 * each state maps to a localized string in the global variable 7 * each state maps to a localized string in the global variable
8 * |loadTimeData|. 8 * |loadTimeData|.
9 * @enum {string} 9 * @enum {string}
10 */ 10 */
11 var BluetoothPairingEventType = { 11 var BluetoothPairingEventType = {
12 CONNECTING: 'bluetoothStartConnecting', 12 CONNECTING: 'bluetoothStartConnecting',
13 ENTER_PIN_CODE: 'bluetoothEnterPinCode', 13 ENTER_PIN_CODE: 'bluetoothEnterPinCode',
14 ENTER_PASSKEY: 'bluetoothEnterPasskey', 14 ENTER_PASSKEY: 'bluetoothEnterPasskey',
15 REMOTE_PIN_CODE: 'bluetoothRemotePinCode', 15 REMOTE_PIN_CODE: 'bluetoothRemotePinCode',
16 REMOTE_PASSKEY: 'bluetoothRemotePasskey', 16 REMOTE_PASSKEY: 'bluetoothRemotePasskey',
17 CONFIRM_PASSKEY: 'bluetoothConfirmPasskey', 17 CONFIRM_PASSKEY: 'bluetoothConfirmPasskey',
18 CONNECT_FAILED: 'bluetoothConnectFailed', 18 CONNECT_FAILED: 'bluetoothConnectFailed',
19 CANCELED: 'bluetoothPairingCanceled', 19 CANCELED: 'bluetoothPairingCanceled',
20 DISMISSED: 'bluetoothPairingDismissed', // pairing dismissed (succeeded or 20 DISMISSED: 'bluetoothPairingDismissed', // pairing dismissed (succeeded or
21 // canceled). 21 // canceled).
22 NOOP: '' // Update device but do not show or update the dialog. 22 NOOP: '' // Update device but do not show or update the dialog.
23 }; 23 };
24 24
25 /** 25 /**
26 * @typedef {{pairing: (BluetoothPairingEventType|undefined), 26 * @typedef {{pairing: (BluetoothPairingEventType|undefined),
27 * device: !chrome.bluetooth.Device, 27 * device: !chrome.bluetooth.Device,
28 * pincode: (string|undefined), 28 * pincode: (string|undefined),
29 * passkey: (number|undefined), 29 * passkey: (number|undefined),
30 * enteredKey: (number|undefined)}} 30 * enteredKey: (number|undefined)}}
31 */ 31 */
(...skipping 28 matching lines...) Expand all
60 60
61 cr.define('options', function() { 61 cr.define('options', function() {
62 /** @const */ var Page = cr.ui.pageManager.Page; 62 /** @const */ var Page = cr.ui.pageManager.Page;
63 /** @const */ var PageManager = cr.ui.pageManager.PageManager; 63 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
64 64
65 /** 65 /**
66 * List of IDs for conditionally visible elements in the dialog. 66 * List of IDs for conditionally visible elements in the dialog.
67 * @type {Array<string>} 67 * @type {Array<string>}
68 * @const 68 * @const
69 */ 69 */
70 var ELEMENTS = ['bluetooth-pairing-passkey-display', 70 var ELEMENTS = [
71 'bluetooth-pairing-passkey-entry', 71 'bluetooth-pairing-passkey-display', 'bluetooth-pairing-passkey-entry',
72 'bluetooth-pairing-pincode-entry', 72 'bluetooth-pairing-pincode-entry', 'bluetooth-pair-device-connect-button',
73 'bluetooth-pair-device-connect-button', 73 'bluetooth-pair-device-cancel-button',
74 'bluetooth-pair-device-cancel-button', 74 'bluetooth-pair-device-accept-button',
75 'bluetooth-pair-device-accept-button', 75 'bluetooth-pair-device-reject-button',
76 'bluetooth-pair-device-reject-button', 76 'bluetooth-pair-device-dismiss-button'
77 'bluetooth-pair-device-dismiss-button']; 77 ];
78 78
79 /** 79 /**
80 * Encapsulated handling of the Bluetooth device pairing page. 80 * Encapsulated handling of the Bluetooth device pairing page.
81 * @constructor 81 * @constructor
82 * @extends {cr.ui.pageManager.Page} 82 * @extends {cr.ui.pageManager.Page}
83 */ 83 */
84 function BluetoothPairing() { 84 function BluetoothPairing() {
85 Page.call(this, 'bluetoothPairing', 85 Page.call(
86 loadTimeData.getString('bluetoothOptionsPageTabTitle'), 86 this, 'bluetoothPairing',
87 'bluetooth-pairing'); 87 loadTimeData.getString('bluetoothOptionsPageTabTitle'),
88 'bluetooth-pairing');
88 } 89 }
89 90
90 cr.addSingletonGetter(BluetoothPairing); 91 cr.addSingletonGetter(BluetoothPairing);
91 92
92 BluetoothPairing.prototype = { 93 BluetoothPairing.prototype = {
93 __proto__: Page.prototype, 94 __proto__: Page.prototype,
94 95
95 /** 96 /**
96 * Device pairing event. 97 * Device pairing event.
97 * @type {?BluetoothPairingEvent} 98 * @type {?BluetoothPairingEvent}
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 var filtered = value.replace(/[^0-9]/g, ''); 170 var filtered = value.replace(/[^0-9]/g, '');
170 if (filtered != value) 171 if (filtered != value)
171 inputField.value = filtered; 172 inputField.value = filtered;
172 $('bluetooth-pair-device-connect-button').disabled = 173 $('bluetooth-pair-device-connect-button').disabled =
173 inputField.value.length == 0; 174 inputField.value.length == 0;
174 }; 175 };
175 $('bluetooth-pincode').oninput = function() { 176 $('bluetooth-pincode').oninput = function() {
176 $('bluetooth-pair-device-connect-button').disabled = 177 $('bluetooth-pair-device-connect-button').disabled =
177 $('bluetooth-pincode').value.length == 0; 178 $('bluetooth-pincode').value.length == 0;
178 }; 179 };
179 $('bluetooth-passkey').addEventListener('keydown', 180 $('bluetooth-passkey')
180 this.keyDownEventHandler_.bind(this)); 181 .addEventListener('keydown', this.keyDownEventHandler_.bind(this));
181 $('bluetooth-pincode').addEventListener('keydown', 182 $('bluetooth-pincode')
182 this.keyDownEventHandler_.bind(this)); 183 .addEventListener('keydown', this.keyDownEventHandler_.bind(this));
183 $('bluetooth-pairing-close-button').addEventListener('click', 184 $('bluetooth-pairing-close-button')
184 this.onClose_.bind(this)); 185 .addEventListener('click', this.onClose_.bind(this));
185 }, 186 },
186 187
187 /** @override */ 188 /** @override */
188 didClosePage: function() { 189 didClosePage: function() {
189 if (this.event_ && 190 if (this.event_ &&
190 this.event_.pairing != BluetoothPairingEventType.DISMISSED && 191 this.event_.pairing != BluetoothPairingEventType.DISMISSED &&
191 this.event_.pairing != BluetoothPairingEventType.CONNECT_FAILED) { 192 this.event_.pairing != BluetoothPairingEventType.CONNECT_FAILED) {
192 this.event_.pairing = BluetoothPairingEventType.CANCELED; 193 this.event_.pairing = BluetoothPairingEventType.CANCELED;
193 var options = { 194 var options = {
194 device: this.event_.device, 195 device: this.event_.device,
195 response: chrome.bluetoothPrivate.PairingResponse.CANCEL 196 response: chrome.bluetoothPrivate.PairingResponse.CANCEL
196 }; 197 };
197 chrome.bluetoothPrivate.setPairingResponse(options); 198 chrome.bluetoothPrivate.setPairingResponse(options);
198 } 199 }
199 }, 200 },
200 201
201 /** 202 /**
202 * Override to prevent showing the overlay if the Bluetooth device details 203 * Override to prevent showing the overlay if the Bluetooth device details
203 * have not been specified. Prevents showing an empty dialog if the user 204 * have not been specified. Prevents showing an empty dialog if the user
204 * quits and restarts Chrome while in the process of pairing with a device. 205 * quits and restarts Chrome while in the process of pairing with a device.
205 * @return {boolean} True if the overlay can be displayed. 206 * @return {boolean} True if the overlay can be displayed.
206 */ 207 */
207 canShowPage: function() { 208 canShowPage: function() {
208 return !!(this.event_ && this.event_.device.address && 209 return !!(
209 this.event_.pairing); 210 this.event_ && this.event_.device.address && this.event_.pairing);
210 }, 211 },
211 212
212 /** 213 /**
213 * Sets input focus on the passkey or pincode field if appropriate. 214 * Sets input focus on the passkey or pincode field if appropriate.
214 */ 215 */
215 didShowPage: function() { 216 didShowPage: function() {
216 if (!$('bluetooth-pincode').hidden) 217 if (!$('bluetooth-pincode').hidden)
217 $('bluetooth-pincode').focus(); 218 $('bluetooth-pincode').focus();
218 else if (!$('bluetooth-passkey').hidden) 219 else if (!$('bluetooth-passkey').hidden)
219 $('bluetooth-passkey').focus(); 220 $('bluetooth-passkey').focus();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 } 269 }
269 } 270 }
270 271
271 // Update the pairing instructions. 272 // Update the pairing instructions.
272 var instructionsEl = assert($('bluetooth-pairing-instructions')); 273 var instructionsEl = assert($('bluetooth-pairing-instructions'));
273 this.clearElement_(instructionsEl); 274 this.clearElement_(instructionsEl);
274 this.dismissible_ = opt_notDismissible !== true; 275 this.dismissible_ = opt_notDismissible !== true;
275 var message = loadTimeData.getString(this.event_.pairing); 276 var message = loadTimeData.getString(this.event_.pairing);
276 assert(typeof this.event_.device.name == 'string'); 277 assert(typeof this.event_.device.name == 'string');
277 message = message.replace( 278 message = message.replace(
278 '%1', /** @type {string} */(this.event_.device.name)); 279 '%1', /** @type {string} */ (this.event_.device.name));
279 instructionsEl.textContent = message; 280 instructionsEl.textContent = message;
280 281
281 // Update visibility of dialog elements. 282 // Update visibility of dialog elements.
282 if (this.event_.passkey) { 283 if (this.event_.passkey) {
283 this.updatePasskey_(String(this.event_.passkey)); 284 this.updatePasskey_(String(this.event_.passkey));
284 if (this.event_.pairing == BluetoothPairingEventType.CONFIRM_PASSKEY) { 285 if (this.event_.pairing == BluetoothPairingEventType.CONFIRM_PASSKEY) {
285 // Confirming a match between displayed passkeys. 286 // Confirming a match between displayed passkeys.
286 this.displayElements_(['bluetooth-pairing-passkey-display', 287 this.displayElements_([
287 'bluetooth-pair-device-accept-button', 288 'bluetooth-pairing-passkey-display',
288 'bluetooth-pair-device-reject-button']); 289 'bluetooth-pair-device-accept-button',
290 'bluetooth-pair-device-reject-button'
291 ]);
289 $('bluetooth-pair-device-accept-button').disabled = false; 292 $('bluetooth-pair-device-accept-button').disabled = false;
290 } else { 293 } else {
291 // Remote entering a passkey. 294 // Remote entering a passkey.
292 this.displayElements_(['bluetooth-pairing-passkey-display', 295 this.displayElements_([
293 'bluetooth-pair-device-cancel-button']); 296 'bluetooth-pairing-passkey-display',
297 'bluetooth-pair-device-cancel-button'
298 ]);
294 } 299 }
295 } else if (this.event_.pincode) { 300 } else if (this.event_.pincode) {
296 this.updatePasskey_(String(this.event_.pincode)); 301 this.updatePasskey_(String(this.event_.pincode));
297 this.displayElements_(['bluetooth-pairing-passkey-display', 302 this.displayElements_([
298 'bluetooth-pair-device-cancel-button']); 303 'bluetooth-pairing-passkey-display',
299 } else if (this.event_.pairing == 304 'bluetooth-pair-device-cancel-button'
300 BluetoothPairingEventType.ENTER_PIN_CODE) { 305 ]);
306 } else if (
307 this.event_.pairing == BluetoothPairingEventType.ENTER_PIN_CODE) {
301 // Prompting the user to enter a PIN code. 308 // Prompting the user to enter a PIN code.
302 this.displayElements_(['bluetooth-pairing-pincode-entry', 309 this.displayElements_([
303 'bluetooth-pair-device-connect-button', 310 'bluetooth-pairing-pincode-entry',
304 'bluetooth-pair-device-cancel-button']); 311 'bluetooth-pair-device-connect-button',
312 'bluetooth-pair-device-cancel-button'
313 ]);
305 $('bluetooth-pincode').value = ''; 314 $('bluetooth-pincode').value = '';
306 } else if (this.event_.pairing == 315 } else if (
307 BluetoothPairingEventType.ENTER_PASSKEY) { 316 this.event_.pairing == BluetoothPairingEventType.ENTER_PASSKEY) {
308 // Prompting the user to enter a passkey. 317 // Prompting the user to enter a passkey.
309 this.displayElements_(['bluetooth-pairing-passkey-entry', 318 this.displayElements_([
310 'bluetooth-pair-device-connect-button', 319 'bluetooth-pairing-passkey-entry',
311 'bluetooth-pair-device-cancel-button']); 320 'bluetooth-pair-device-connect-button',
321 'bluetooth-pair-device-cancel-button'
322 ]);
312 $('bluetooth-passkey').value = ''; 323 $('bluetooth-passkey').value = '';
313 } else if (this.event_.pairing == BluetoothPairingEventType.CONNECTING) { 324 } else if (this.event_.pairing == BluetoothPairingEventType.CONNECTING) {
314 // Starting the pairing process. 325 // Starting the pairing process.
315 this.displayElements_(['bluetooth-pair-device-cancel-button']); 326 this.displayElements_(['bluetooth-pair-device-cancel-button']);
316 } else { 327 } else {
317 // Displaying an error message. 328 // Displaying an error message.
318 this.displayElements_(['bluetooth-pair-device-dismiss-button']); 329 this.displayElements_(['bluetooth-pair-device-dismiss-button']);
319 } 330 }
320 // User is required to enter a passkey or pincode before the connect 331 // User is required to enter a passkey or pincode before the connect
321 // button can be enabled. The 'oninput' methods for the input fields 332 // button can be enabled. The 'oninput' methods for the input fields
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 390
380 /** 391 /**
381 * Formats an element for displaying the passkey or PIN code. 392 * Formats an element for displaying the passkey or PIN code.
382 * @param {string} key Passkey or PIN to display. 393 * @param {string} key Passkey or PIN to display.
383 */ 394 */
384 updatePasskey_: function(key) { 395 updatePasskey_: function(key) {
385 var passkeyEl = assert($('bluetooth-pairing-passkey-display')); 396 var passkeyEl = assert($('bluetooth-pairing-passkey-display'));
386 var keyClass = 397 var keyClass =
387 (this.event_.pairing == BluetoothPairingEventType.REMOTE_PASSKEY || 398 (this.event_.pairing == BluetoothPairingEventType.REMOTE_PASSKEY ||
388 this.event_.pairing == BluetoothPairingEventType.REMOTE_PIN_CODE) ? 399 this.event_.pairing == BluetoothPairingEventType.REMOTE_PIN_CODE) ?
389 'bluetooth-keyboard-button' : 400 'bluetooth-keyboard-button' :
390 'bluetooth-passkey-char'; 401 'bluetooth-passkey-char';
391 this.clearElement_(passkeyEl); 402 this.clearElement_(passkeyEl);
392 // Passkey should always have 6 digits. 403 // Passkey should always have 6 digits.
393 key = '000000'.substring(0, 6 - key.length) + key; 404 key = '000000'.substring(0, 6 - key.length) + key;
394 var progress = this.event_.enteredKey; 405 var progress = this.event_.enteredKey;
395 for (var i = 0; i < key.length; i++) { 406 for (var i = 0; i < key.length; i++) {
396 var keyEl = document.createElement('span'); 407 var keyEl = document.createElement('span');
397 keyEl.textContent = key.charAt(i); 408 keyEl.textContent = key.charAt(i);
398 keyEl.className = keyClass; 409 keyEl.className = keyClass;
399 if (progress != undefined) { 410 if (progress != undefined) {
400 if (i < progress) 411 if (i < progress)
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 /** 533 /**
523 * Connect request completion callback. 534 * Connect request completion callback.
524 * @param {string} address 535 * @param {string} address
525 * @param {chrome.bluetoothPrivate.ConnectResultType} result 536 * @param {chrome.bluetoothPrivate.ConnectResultType} result
526 */ 537 */
527 BluetoothPairing.connectCompleted_ = function(address, result) { 538 BluetoothPairing.connectCompleted_ = function(address, result) {
528 var message; 539 var message;
529 if (chrome.runtime.lastError) { 540 if (chrome.runtime.lastError) {
530 var errorMessage = chrome.runtime.lastError.message; 541 var errorMessage = chrome.runtime.lastError.message;
531 if (errorMessage != 'Connect failed') { 542 if (errorMessage != 'Connect failed') {
532 console.error('bluetoothPrivate.connect: Unexpected error for: ' + 543 console.error(
533 address + ': ' + errorMessage); 544 'bluetoothPrivate.connect: Unexpected error for: ' + address +
545 ': ' + errorMessage);
534 } 546 }
535 } 547 }
536 switch (result) { 548 switch (result) {
537 case chrome.bluetoothPrivate.ConnectResultType.SUCCESS: 549 case chrome.bluetoothPrivate.ConnectResultType.SUCCESS:
538 case chrome.bluetoothPrivate.ConnectResultType.ALREADY_CONNECTED: 550 case chrome.bluetoothPrivate.ConnectResultType.ALREADY_CONNECTED:
539 BluetoothPairing.dismissDialog(); 551 BluetoothPairing.dismissDialog();
540 return; 552 return;
541 case chrome.bluetoothPrivate.ConnectResultType.UNKNOWN_ERROR: 553 case chrome.bluetoothPrivate.ConnectResultType.UNKNOWN_ERROR:
542 message = 'bluetoothConnectUnknownError'; 554 message = 'bluetoothConnectUnknownError';
543 break; 555 break;
(...skipping 30 matching lines...) Expand all
574 var overlay = PageManager.getTopmostVisiblePage(); 586 var overlay = PageManager.getTopmostVisiblePage();
575 var dialog = BluetoothPairing.getInstance(); 587 var dialog = BluetoothPairing.getInstance();
576 if (overlay == dialog && dialog.dismissible_) { 588 if (overlay == dialog && dialog.dismissible_) {
577 if (dialog.event_) 589 if (dialog.event_)
578 dialog.event_.pairing = BluetoothPairingEventType.DISMISSED; 590 dialog.event_.pairing = BluetoothPairingEventType.DISMISSED;
579 PageManager.closeOverlay(); 591 PageManager.closeOverlay();
580 } 592 }
581 }; 593 };
582 594
583 // Export 595 // Export
584 return { 596 return {BluetoothPairing: BluetoothPairing};
585 BluetoothPairing: BluetoothPairing
586 };
587 }); 597 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698