| OLD | NEW |
| 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var OptionsPage = options.OptionsPage; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
| 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
| 7 | 8 |
| 8 /** | 9 /** |
| 9 * Enumeration of possible states during pairing. The value associated with | 10 * Enumeration of possible states during pairing. The value associated with |
| 10 * each state maps to a localized string in the global variable | 11 * each state maps to a localized string in the global variable |
| 11 * |loadTimeData|. | 12 * |loadTimeData|. |
| 12 * @enum {string} | 13 * @enum {string} |
| 13 */ | 14 */ |
| 14 var PAIRING = { | 15 var PAIRING = { |
| 15 STARTUP: 'bluetoothStartConnecting', | 16 STARTUP: 'bluetoothStartConnecting', |
| 16 ENTER_PIN_CODE: 'bluetoothEnterPinCode', | 17 ENTER_PIN_CODE: 'bluetoothEnterPinCode', |
| (...skipping 19 matching lines...) Expand all Loading... |
| 36 'bluetooth-pair-device-cancel-button', | 37 'bluetooth-pair-device-cancel-button', |
| 37 'bluetooth-pair-device-accept-button', | 38 'bluetooth-pair-device-accept-button', |
| 38 'bluetooth-pair-device-reject-button', | 39 'bluetooth-pair-device-reject-button', |
| 39 'bluetooth-pair-device-dismiss-button']; | 40 'bluetooth-pair-device-dismiss-button']; |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * Encapsulated handling of the Bluetooth device pairing page. | 43 * Encapsulated handling of the Bluetooth device pairing page. |
| 43 * @constructor | 44 * @constructor |
| 44 */ | 45 */ |
| 45 function BluetoothPairing() { | 46 function BluetoothPairing() { |
| 46 OptionsPage.call(this, | 47 Page.call(this, 'bluetoothPairing', |
| 47 'bluetoothPairing', | 48 loadTimeData.getString('bluetoothOptionsPageTabTitle'), |
| 48 loadTimeData.getString('bluetoothOptionsPageTabTitle'), | 49 'bluetooth-pairing'); |
| 49 'bluetooth-pairing'); | |
| 50 } | 50 } |
| 51 | 51 |
| 52 cr.addSingletonGetter(BluetoothPairing); | 52 cr.addSingletonGetter(BluetoothPairing); |
| 53 | 53 |
| 54 BluetoothPairing.prototype = { | 54 BluetoothPairing.prototype = { |
| 55 __proto__: OptionsPage.prototype, | 55 __proto__: Page.prototype, |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * Description of the bluetooth device. | 58 * Description of the bluetooth device. |
| 59 * @type {{name: string, | 59 * @type {{name: string, |
| 60 * address: string, | 60 * address: string, |
| 61 * paired: boolean, | 61 * paired: boolean, |
| 62 * connected: boolean, | 62 * connected: boolean, |
| 63 * connecting: boolean, | 63 * connecting: boolean, |
| 64 * connectable: boolean, | 64 * connectable: boolean, |
| 65 * pairing: string|undefined, | 65 * pairing: string|undefined, |
| 66 * passkey: number|undefined, | 66 * passkey: number|undefined, |
| 67 * pincode: string|undefined, | 67 * pincode: string|undefined, |
| 68 * entered: number|undefined}} | 68 * entered: number|undefined}} |
| 69 * @private. | 69 * @private |
| 70 */ | 70 */ |
| 71 device_: null, | 71 device_: null, |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Can the dialog be programmatically dismissed. | 74 * Can the dialog be programmatically dismissed. |
| 75 * @type {boolean} | 75 * @type {boolean} |
| 76 */ | 76 */ |
| 77 dismissible_: true, | 77 dismissible_: true, |
| 78 | 78 |
| 79 /** @override */ | 79 /** @override */ |
| 80 initializePage: function() { | 80 initializePage: function() { |
| 81 OptionsPage.prototype.initializePage.call(this); | 81 Page.prototype.initializePage.call(this); |
| 82 var self = this; | 82 var self = this; |
| 83 $('bluetooth-pair-device-cancel-button').onclick = function() { | 83 $('bluetooth-pair-device-cancel-button').onclick = function() { |
| 84 OptionsPage.closeOverlay(); | 84 PageManager.closeOverlay(); |
| 85 }; | 85 }; |
| 86 $('bluetooth-pair-device-reject-button').onclick = function() { | 86 $('bluetooth-pair-device-reject-button').onclick = function() { |
| 87 chrome.send('updateBluetoothDevice', | 87 chrome.send('updateBluetoothDevice', |
| 88 [self.device_.address, 'reject']); | 88 [self.device_.address, 'reject']); |
| 89 self.device_.pairing = PAIRING.DISMISSED; | 89 self.device_.pairing = PAIRING.DISMISSED; |
| 90 OptionsPage.closeOverlay(); | 90 PageManager.closeOverlay(); |
| 91 }; | 91 }; |
| 92 $('bluetooth-pair-device-connect-button').onclick = function() { | 92 $('bluetooth-pair-device-connect-button').onclick = function() { |
| 93 var args = [self.device_.address, 'connect']; | 93 var args = [self.device_.address, 'connect']; |
| 94 var passkey = self.device_.passkey; | 94 var passkey = self.device_.passkey; |
| 95 if (passkey) | 95 if (passkey) |
| 96 args.push(String(passkey)); | 96 args.push(String(passkey)); |
| 97 else if (!$('bluetooth-pairing-passkey-entry').hidden) | 97 else if (!$('bluetooth-pairing-passkey-entry').hidden) |
| 98 args.push($('bluetooth-passkey').value); | 98 args.push($('bluetooth-passkey').value); |
| 99 else if (!$('bluetooth-pairing-pincode-entry').hidden) | 99 else if (!$('bluetooth-pairing-pincode-entry').hidden) |
| 100 args.push($('bluetooth-pincode').value); | 100 args.push($('bluetooth-pincode').value); |
| 101 chrome.send('updateBluetoothDevice', args); | 101 chrome.send('updateBluetoothDevice', args); |
| 102 // Prevent sending a 'connect' command twice. | 102 // Prevent sending a 'connect' command twice. |
| 103 $('bluetooth-pair-device-connect-button').disabled = true; | 103 $('bluetooth-pair-device-connect-button').disabled = true; |
| 104 }; | 104 }; |
| 105 $('bluetooth-pair-device-accept-button').onclick = function() { | 105 $('bluetooth-pair-device-accept-button').onclick = function() { |
| 106 chrome.send('updateBluetoothDevice', | 106 chrome.send('updateBluetoothDevice', |
| 107 [self.device_.address, 'accept']); | 107 [self.device_.address, 'accept']); |
| 108 // Prevent sending a 'accept' command twice. | 108 // Prevent sending a 'accept' command twice. |
| 109 $('bluetooth-pair-device-accept-button').disabled = true; | 109 $('bluetooth-pair-device-accept-button').disabled = true; |
| 110 }; | 110 }; |
| 111 $('bluetooth-pair-device-dismiss-button').onclick = function() { | 111 $('bluetooth-pair-device-dismiss-button').onclick = function() { |
| 112 OptionsPage.closeOverlay(); | 112 PageManager.closeOverlay(); |
| 113 }; | 113 }; |
| 114 $('bluetooth-passkey').oninput = function() { | 114 $('bluetooth-passkey').oninput = function() { |
| 115 var inputField = $('bluetooth-passkey'); | 115 var inputField = $('bluetooth-passkey'); |
| 116 var value = inputField.value; | 116 var value = inputField.value; |
| 117 // Note that using <input type="number"> is insufficient to restrict | 117 // Note that using <input type="number"> is insufficient to restrict |
| 118 // the input as it allows negative numbers and does not limit the | 118 // the input as it allows negative numbers and does not limit the |
| 119 // number of charactes typed even if a range is set. Furthermore, | 119 // number of charactes typed even if a range is set. Furthermore, |
| 120 // it sometimes produces strange repaint artifacts. | 120 // it sometimes produces strange repaint artifacts. |
| 121 var filtered = value.replace(/[^0-9]/g, ''); | 121 var filtered = value.replace(/[^0-9]/g, ''); |
| 122 if (filtered != value) | 122 if (filtered != value) |
| 123 inputField.value = filtered; | 123 inputField.value = filtered; |
| 124 $('bluetooth-pair-device-connect-button').disabled = | 124 $('bluetooth-pair-device-connect-button').disabled = |
| 125 inputField.value.length == 0; | 125 inputField.value.length == 0; |
| 126 } | 126 }; |
| 127 $('bluetooth-pincode').oninput = function() { | 127 $('bluetooth-pincode').oninput = function() { |
| 128 $('bluetooth-pair-device-connect-button').disabled = | 128 $('bluetooth-pair-device-connect-button').disabled = |
| 129 $('bluetooth-pincode').value.length == 0; | 129 $('bluetooth-pincode').value.length == 0; |
| 130 } | 130 }; |
| 131 $('bluetooth-passkey').addEventListener('keydown', | 131 $('bluetooth-passkey').addEventListener('keydown', |
| 132 this.keyDownEventHandler_.bind(this)); | 132 this.keyDownEventHandler_.bind(this)); |
| 133 $('bluetooth-pincode').addEventListener('keydown', | 133 $('bluetooth-pincode').addEventListener('keydown', |
| 134 this.keyDownEventHandler_.bind(this)); | 134 this.keyDownEventHandler_.bind(this)); |
| 135 }, | 135 }, |
| 136 | 136 |
| 137 /** @override */ | 137 /** @override */ |
| 138 didClosePage: function() { | 138 didClosePage: function() { |
| 139 if (this.device_.pairing != PAIRING.DISMISSED && | 139 if (this.device_.pairing != PAIRING.DISMISSED && |
| 140 this.device_.pairing != PAIRING.CONNECT_FAILED) { | 140 this.device_.pairing != PAIRING.CONNECT_FAILED) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 }, | 318 }, |
| 319 }; | 319 }; |
| 320 | 320 |
| 321 /** | 321 /** |
| 322 * Configures the device pairing instructions and displays the pairing | 322 * Configures the device pairing instructions and displays the pairing |
| 323 * overlay. | 323 * overlay. |
| 324 * @param {Object} device Description of the Bluetooth device. | 324 * @param {Object} device Description of the Bluetooth device. |
| 325 */ | 325 */ |
| 326 BluetoothPairing.showDialog = function(device) { | 326 BluetoothPairing.showDialog = function(device) { |
| 327 BluetoothPairing.getInstance().update(device); | 327 BluetoothPairing.getInstance().update(device); |
| 328 OptionsPage.showPageByName('bluetoothPairing', false); | 328 PageManager.showPageByName('bluetoothPairing', false); |
| 329 }; | 329 }; |
| 330 | 330 |
| 331 /** | 331 /** |
| 332 * Displays a message from the Bluetooth adapter. | 332 * Displays a message from the Bluetooth adapter. |
| 333 * @param {{string: label, | 333 * @param {Object} data Data for constructing the message. |
| 334 * string: address} data Data for constructing the message. | 334 * @param {string} data.message Name of message to show. |
| 335 * @param {string} data.address Device address. |
| 335 */ | 336 */ |
| 336 BluetoothPairing.showMessage = function(data) { | 337 BluetoothPairing.showMessage = function(data) { |
| 337 var name = data.address; | 338 var name = data.address; |
| 338 if (name.length == 0) | 339 if (name.length == 0) |
| 339 return; | 340 return; |
| 340 var dialog = BluetoothPairing.getInstance(); | 341 var dialog = BluetoothPairing.getInstance(); |
| 341 if (dialog.device_ && name == dialog.device_.address && | 342 if (dialog.device_ && name == dialog.device_.address && |
| 342 dialog.device_.pairing == PAIRING.CANCELED) { | 343 dialog.device_.pairing == PAIRING.CANCELED) { |
| 343 // Do not show any error message after cancelation of the pairing. | 344 // Do not show any error message after cancelation of the pairing. |
| 344 return; | 345 return; |
| 345 } | 346 } |
| 346 | 347 |
| 347 var list = $('bluetooth-paired-devices-list'); | 348 var list = $('bluetooth-paired-devices-list'); |
| 348 if (list) { | 349 if (list) { |
| 349 var index = list.find(name); | 350 var index = list.find(name); |
| 350 if (index == undefined) { | 351 if (index == undefined) { |
| 351 list = $('bluetooth-unpaired-devices-list'); | 352 list = $('bluetooth-unpaired-devices-list'); |
| 352 index = list.find(name); | 353 index = list.find(name); |
| 353 } | 354 } |
| 354 if (index != undefined) { | 355 if (index != undefined) { |
| 355 var entry = list.dataModel.item(index); | 356 var entry = list.dataModel.item(index); |
| 356 if (entry && entry.name) | 357 if (entry && entry.name) |
| 357 name = entry.name; | 358 name = entry.name; |
| 358 } | 359 } |
| 359 } | 360 } |
| 360 BluetoothPairing.showDialog({name: name, | 361 BluetoothPairing.showDialog({name: name, |
| 361 address: data.address, | 362 address: data.address, |
| 362 pairing: data.label, | 363 pairing: data.message, |
| 363 dismissible: false}); | 364 dismissible: false}); |
| 364 }; | 365 }; |
| 365 | 366 |
| 366 /** | 367 /** |
| 367 * Closes the Bluetooth pairing dialog. | 368 * Closes the Bluetooth pairing dialog. |
| 368 */ | 369 */ |
| 369 BluetoothPairing.dismissDialog = function() { | 370 BluetoothPairing.dismissDialog = function() { |
| 370 var overlay = OptionsPage.getTopmostVisiblePage(); | 371 var overlay = PageManager.getTopmostVisiblePage(); |
| 371 var dialog = BluetoothPairing.getInstance(); | 372 var dialog = BluetoothPairing.getInstance(); |
| 372 if (overlay == dialog && dialog.dismissible_) { | 373 if (overlay == dialog && dialog.dismissible_) { |
| 373 dialog.device_.pairing = PAIRING.DISMISSED; | 374 dialog.device_.pairing = PAIRING.DISMISSED; |
| 374 OptionsPage.closeOverlay(); | 375 PageManager.closeOverlay(); |
| 375 } | 376 } |
| 376 }; | 377 }; |
| 377 | 378 |
| 378 // Export | 379 // Export |
| 379 return { | 380 return { |
| 380 BluetoothPairing: BluetoothPairing | 381 BluetoothPairing: BluetoothPairing |
| 381 }; | 382 }; |
| 382 }); | 383 }); |
| OLD | NEW |