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
3 // found in the LICENSE file.
5 cr.define('options', function() {
6 /** @const */ var OptionsPage = options.OptionsPage;
9 * Encapsulated handling of the Bluetooth options page.
12 function BluetoothOptions() {
13 OptionsPage.call(this,
15 loadTimeData.getString('bluetoothOptionsPageTabTitle'),
19 cr.addSingletonGetter(BluetoothOptions);
21 BluetoothOptions.prototype = {
22 __proto__: OptionsPage.prototype,
25 * The list of available (unpaired) bluetooth devices.
26 * @type {DeletableItemList}
32 initializePage: function() {
33 OptionsPage.prototype.initializePage.call(this);
34 this.createDeviceList_();
36 $('bluetooth-add-device-cancel-button').onclick = function(event) {
37 chrome.send('stopBluetoothDeviceDiscovery');
38 OptionsPage.closeOverlay();
42 $('bluetooth-add-device-apply-button').onclick = function(event) {
43 var device = self.deviceList_.selectedItem;
44 var address = device.address;
45 chrome.send('stopBluetoothDeviceDiscovery');
46 OptionsPage.closeOverlay();
47 device.pairing = 'bluetoothStartConnecting';
48 options.BluetoothPairing.showDialog(device);
49 chrome.send('updateBluetoothDevice', [address, 'connect']);
52 $('bluetooth-unpaired-devices-list').addEventListener('change',
54 var item = $('bluetooth-unpaired-devices-list').selectedItem;
55 // The "bluetooth-add-device-apply-button" should be enabled for devices
56 // that can be paired or remembered. Devices not supporting pairing will
57 // be just remembered and later reported as "item.paired" = true. The
58 // button should be disabled in any other case:
59 // * No item is selected (item is undefined).
60 // * Paired devices (item.paired is true) are already paired and a new
61 // pairing attempt will fail. Paired devices could appear in this list
62 // shortly after the pairing initiated in another window finishes.
63 // * "Connecting" devices (item.connecting is true) are in the process
64 // of a pairing or connection. Another attempt to pair before the
65 // ongoing pair finishes will fail, so the button should be disabled.
66 var disabled = !item || item.paired || item.connecting;
67 $('bluetooth-add-device-apply-button').disabled = disabled;
72 * Creates, decorates and initializes the bluetooth device list.
75 createDeviceList_: function() {
76 this.deviceList_ = $('bluetooth-unpaired-devices-list');
77 options.system.bluetooth.BluetoothDeviceList.decorate(this.deviceList_);
82 * Automatically start the device discovery process if the
83 * "Add device" dialog is visible.
85 BluetoothOptions.updateDiscovery = function() {
86 var page = BluetoothOptions.getInstance();
87 if (page && page.visible)
88 chrome.send('findBluetoothDevices');
93 BluetoothOptions: BluetoothOptions