| 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 OptionsPage = options.OptionsPage; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Encapsulated handling of the Bluetooth options page. | 9 * Encapsulated handling of the Bluetooth options page. |
| 10 * @constructor | 10 * @constructor |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * @private | 27 * @private |
| 28 */ | 28 */ |
| 29 deviceList_: null, | 29 deviceList_: null, |
| 30 | 30 |
| 31 /** @override */ | 31 /** @override */ |
| 32 initializePage: function() { | 32 initializePage: function() { |
| 33 OptionsPage.prototype.initializePage.call(this); | 33 OptionsPage.prototype.initializePage.call(this); |
| 34 this.createDeviceList_(); | 34 this.createDeviceList_(); |
| 35 | 35 |
| 36 $('bluetooth-add-device-cancel-button').onclick = function(event) { | 36 $('bluetooth-add-device-cancel-button').onclick = function(event) { |
| 37 chrome.send('stopBluetoothDeviceDiscovery'); | |
| 38 OptionsPage.closeOverlay(); | 37 OptionsPage.closeOverlay(); |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 var self = this; | 40 var self = this; |
| 42 $('bluetooth-add-device-apply-button').onclick = function(event) { | 41 $('bluetooth-add-device-apply-button').onclick = function(event) { |
| 43 var device = self.deviceList_.selectedItem; | 42 var device = self.deviceList_.selectedItem; |
| 44 var address = device.address; | 43 var address = device.address; |
| 45 chrome.send('stopBluetoothDeviceDiscovery'); | |
| 46 OptionsPage.closeOverlay(); | 44 OptionsPage.closeOverlay(); |
| 47 device.pairing = 'bluetoothStartConnecting'; | 45 device.pairing = 'bluetoothStartConnecting'; |
| 48 options.BluetoothPairing.showDialog(device); | 46 options.BluetoothPairing.showDialog(device); |
| 49 chrome.send('updateBluetoothDevice', [address, 'connect']); | 47 chrome.send('updateBluetoothDevice', [address, 'connect']); |
| 50 }; | 48 }; |
| 51 | 49 |
| 52 $('bluetooth-unpaired-devices-list').addEventListener('change', | 50 $('bluetooth-unpaired-devices-list').addEventListener('change', |
| 53 function() { | 51 function() { |
| 54 var item = $('bluetooth-unpaired-devices-list').selectedItem; | 52 var item = $('bluetooth-unpaired-devices-list').selectedItem; |
| 55 // The "bluetooth-add-device-apply-button" should be enabled for devices | 53 // The "bluetooth-add-device-apply-button" should be enabled for devices |
| 56 // that can be paired or remembered. Devices not supporting pairing will | 54 // that can be paired or remembered. Devices not supporting pairing will |
| 57 // be just remembered and later reported as "item.paired" = true. The | 55 // be just remembered and later reported as "item.paired" = true. The |
| 58 // button should be disabled in any other case: | 56 // button should be disabled in any other case: |
| 59 // * No item is selected (item is undefined). | 57 // * No item is selected (item is undefined). |
| 60 // * Paired devices (item.paired is true) are already paired and a new | 58 // * Paired devices (item.paired is true) are already paired and a new |
| 61 // pairing attempt will fail. Paired devices could appear in this list | 59 // pairing attempt will fail. Paired devices could appear in this list |
| 62 // shortly after the pairing initiated in another window finishes. | 60 // shortly after the pairing initiated in another window finishes. |
| 63 // * "Connecting" devices (item.connecting is true) are in the process | 61 // * "Connecting" devices (item.connecting is true) are in the process |
| 64 // of a pairing or connection. Another attempt to pair before the | 62 // of a pairing or connection. Another attempt to pair before the |
| 65 // ongoing pair finishes will fail, so the button should be disabled. | 63 // ongoing pair finishes will fail, so the button should be disabled. |
| 66 var disabled = !item || item.paired || item.connecting; | 64 var disabled = !item || item.paired || item.connecting; |
| 67 $('bluetooth-add-device-apply-button').disabled = disabled; | 65 $('bluetooth-add-device-apply-button').disabled = disabled; |
| 68 }); | 66 }); |
| 69 }, | 67 }, |
| 70 | 68 |
| 69 /** @override */ |
| 70 didClosePage: function() { |
| 71 chrome.send('stopBluetoothDeviceDiscovery'); |
| 72 }, |
| 73 |
| 71 /** | 74 /** |
| 72 * Creates, decorates and initializes the bluetooth device list. | 75 * Creates, decorates and initializes the bluetooth device list. |
| 73 * @private | 76 * @private |
| 74 */ | 77 */ |
| 75 createDeviceList_: function() { | 78 createDeviceList_: function() { |
| 76 this.deviceList_ = $('bluetooth-unpaired-devices-list'); | 79 this.deviceList_ = $('bluetooth-unpaired-devices-list'); |
| 77 options.system.bluetooth.BluetoothDeviceList.decorate(this.deviceList_); | 80 options.system.bluetooth.BluetoothDeviceList.decorate(this.deviceList_); |
| 78 } | 81 } |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 /** | 84 /** |
| 82 * Automatically start the device discovery process if the | 85 * Automatically start the device discovery process if the |
| 83 * "Add device" dialog is visible. | 86 * "Add device" dialog is visible. |
| 84 */ | 87 */ |
| 85 BluetoothOptions.updateDiscovery = function() { | 88 BluetoothOptions.updateDiscovery = function() { |
| 86 var page = BluetoothOptions.getInstance(); | 89 var page = BluetoothOptions.getInstance(); |
| 87 if (page && page.visible) | 90 if (page && page.visible) |
| 88 chrome.send('findBluetoothDevices'); | 91 chrome.send('findBluetoothDevices'); |
| 89 } | 92 } |
| 90 | 93 |
| 91 // Export | 94 // Export |
| 92 return { | 95 return { |
| 93 BluetoothOptions: BluetoothOptions | 96 BluetoothOptions: BluetoothOptions |
| 94 }; | 97 }; |
| 95 }); | 98 }); |
| OLD | NEW |