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 Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
8 | 8 |
9 /** | 9 /** |
10 * Encapsulated handling of the Bluetooth options page. | 10 * Encapsulated handling of the Bluetooth options page. |
11 * @constructor | 11 * @constructor |
12 * @extends {cr.ui.pageManager.Page} | 12 * @extends {cr.ui.pageManager.Page} |
13 */ | 13 */ |
14 function BluetoothOptions() { | 14 function BluetoothOptions() { |
15 Page.call(this, 'bluetooth', | 15 Page.call( |
16 loadTimeData.getString('bluetoothOptionsPageTabTitle'), | 16 this, 'bluetooth', |
17 'bluetooth-options'); | 17 loadTimeData.getString('bluetoothOptionsPageTabTitle'), |
| 18 'bluetooth-options'); |
18 } | 19 } |
19 | 20 |
20 cr.addSingletonGetter(BluetoothOptions); | 21 cr.addSingletonGetter(BluetoothOptions); |
21 | 22 |
22 BluetoothOptions.prototype = { | 23 BluetoothOptions.prototype = { |
23 __proto__: Page.prototype, | 24 __proto__: Page.prototype, |
24 | 25 |
25 /** | 26 /** |
26 * The list of available (unpaired) bluetooth devices. | 27 * The list of available (unpaired) bluetooth devices. |
27 * @type {options.DeletableItemList} | 28 * @type {options.DeletableItemList} |
28 * @private | 29 * @private |
29 */ | 30 */ |
30 deviceList_: null, | 31 deviceList_: null, |
31 | 32 |
32 /** @override */ | 33 /** @override */ |
33 initializePage: function() { | 34 initializePage: function() { |
34 Page.prototype.initializePage.call(this); | 35 Page.prototype.initializePage.call(this); |
35 this.createDeviceList_(); | 36 this.createDeviceList_(); |
36 | 37 |
37 $('bluetooth-add-device-cancel-button').onclick = function(event) { | 38 $('bluetooth-add-device-cancel-button').onclick = function(event) { |
38 PageManager.closeOverlay(); | 39 PageManager.closeOverlay(); |
39 }; | 40 }; |
40 | 41 |
41 var self = this; | 42 var self = this; |
42 $('bluetooth-add-device-apply-button').onclick = function(event) { | 43 $('bluetooth-add-device-apply-button').onclick = function(event) { |
43 chrome.send('coreOptionsUserMetricsAction', | 44 chrome.send( |
44 ['Options_BluetoothConnectNewDevice']); | 45 'coreOptionsUserMetricsAction', |
| 46 ['Options_BluetoothConnectNewDevice']); |
45 var device = self.deviceList_.selectedItem; | 47 var device = self.deviceList_.selectedItem; |
46 PageManager.closeOverlay(); | 48 PageManager.closeOverlay(); |
47 options.BluetoothPairing.connect(device, true); | 49 options.BluetoothPairing.connect(device, true); |
48 }; | 50 }; |
49 | 51 |
50 $('bluetooth-unpaired-devices-list').addEventListener('change', | 52 $('bluetooth-unpaired-devices-list') |
51 function() { | 53 .addEventListener('change', function() { |
52 var item = $('bluetooth-unpaired-devices-list').selectedItem; | 54 var item = $('bluetooth-unpaired-devices-list').selectedItem; |
53 // The "bluetooth-add-device-apply-button" should be enabled for devices | 55 // The "bluetooth-add-device-apply-button" should be enabled for |
54 // that can be paired or remembered. Devices not supporting pairing will | 56 // devices that can be paired or remembered. Devices not supporting |
55 // be just remembered and later reported as "item.paired" = true. The | 57 // pairing will be just remembered and later reported as |
56 // button should be disabled in any other case: | 58 // "item.paired" = true. The button should be disabled in any other |
57 // * No item is selected (item is undefined). | 59 // case: * No item is selected (item is undefined). * Paired devices |
58 // * Paired devices (item.paired is true) are already paired and a new | 60 // (item.paired is true) are already paired and a new |
59 // pairing attempt will fail. Paired devices could appear in this list | 61 // pairing attempt will fail. Paired devices could appear in this |
60 // shortly after the pairing initiated in another window finishes. | 62 // list shortly after the pairing initiated in another window |
61 // * "Connecting" devices (item.connecting is true) are in the process | 63 // finishes. |
62 // of a pairing or connection. Another attempt to pair before the | 64 // * "Connecting" devices (item.connecting is true) are in the |
63 // ongoing pair finishes will fail, so the button should be disabled. | 65 // process |
64 var disabled = !item || item.paired || item.connecting; | 66 // of a pairing or connection. Another attempt to pair before the |
65 $('bluetooth-add-device-apply-button').disabled = disabled; | 67 // ongoing pair finishes will fail, so the button should be |
66 }); | 68 // disabled. |
| 69 var disabled = !item || item.paired || item.connecting; |
| 70 $('bluetooth-add-device-apply-button').disabled = disabled; |
| 71 }); |
67 }, | 72 }, |
68 | 73 |
69 /** @override */ | 74 /** @override */ |
70 didShowPage: function() { | 75 didShowPage: function() { |
71 chrome.bluetooth.startDiscovery(function() { | 76 chrome.bluetooth.startDiscovery(function() { |
72 if (chrome.runtime.lastError) { | 77 if (chrome.runtime.lastError) { |
73 console.error( | 78 console.error( |
74 'Unexpected error calling bluetooth.startDiscovery: ' + | 79 'Unexpected error calling bluetooth.startDiscovery: ' + |
75 chrome.runtime.lastError.message); | 80 chrome.runtime.lastError.message); |
76 } | 81 } |
77 }); | 82 }); |
78 BluetoothOptions.updateDiscoveryState(true); | 83 BluetoothOptions.updateDiscoveryState(true); |
79 }, | 84 }, |
80 | 85 |
81 /** @override */ | 86 /** @override */ |
82 didClosePage: function() { | 87 didClosePage: function() { |
83 chrome.bluetooth.stopDiscovery(function() { | 88 chrome.bluetooth.stopDiscovery(function() { |
84 // The page may get closed before discovery started, so ignore any | 89 // The page may get closed before discovery started, so ignore any |
85 // 'Failed to stop discovery' errors. | 90 // 'Failed to stop discovery' errors. |
86 if (chrome.runtime.lastError && | 91 if (chrome.runtime.lastError && |
87 chrome.runtime.lastError.message != 'Failed to stop discovery') { | 92 chrome.runtime.lastError.message != 'Failed to stop discovery') { |
88 console.log( | 93 console.log( |
89 'Unexpected error calling bluetooth.stopDiscovery: ' + | 94 'Unexpected error calling bluetooth.stopDiscovery: ' + |
90 chrome.runtime.lastError.message); | 95 chrome.runtime.lastError.message); |
91 | |
92 } | 96 } |
93 }); | 97 }); |
94 }, | 98 }, |
95 | 99 |
96 /** | 100 /** |
97 * Creates, decorates and initializes the bluetooth device list. | 101 * Creates, decorates and initializes the bluetooth device list. |
98 * @private | 102 * @private |
99 */ | 103 */ |
100 createDeviceList_: function() { | 104 createDeviceList_: function() { |
101 var deviceList = $('bluetooth-unpaired-devices-list'); | 105 var deviceList = $('bluetooth-unpaired-devices-list'); |
102 options.system.bluetooth.BluetoothDeviceList.decorate(deviceList); | 106 options.system.bluetooth.BluetoothDeviceList.decorate(deviceList); |
103 this.deviceList_ = assertInstanceof(deviceList, | 107 this.deviceList_ = |
104 options.DeletableItemList); | 108 assertInstanceof(deviceList, options.DeletableItemList); |
105 } | 109 } |
106 }; | 110 }; |
107 | 111 |
108 /** | 112 /** |
109 * Updates the dialog to show that device discovery has stopped. Updates the | 113 * Updates the dialog to show that device discovery has stopped. Updates the |
110 * label text and hides/unhides the spinner. based on discovery state. | 114 * label text and hides/unhides the spinner. based on discovery state. |
111 */ | 115 */ |
112 BluetoothOptions.updateDiscoveryState = function(discovering) { | 116 BluetoothOptions.updateDiscoveryState = function(discovering) { |
113 $('bluetooth-scanning-label').hidden = !discovering; | 117 $('bluetooth-scanning-label').hidden = !discovering; |
114 $('bluetooth-scanning-icon').hidden = !discovering; | 118 $('bluetooth-scanning-icon').hidden = !discovering; |
115 $('bluetooth-scan-stopped-label').hidden = discovering; | 119 $('bluetooth-scan-stopped-label').hidden = discovering; |
116 }; | 120 }; |
117 | 121 |
118 /** | 122 /** |
119 * If the "Add device" dialog is visible, dismiss it. | 123 * If the "Add device" dialog is visible, dismiss it. |
120 */ | 124 */ |
121 BluetoothOptions.dismissOverlay = function() { | 125 BluetoothOptions.dismissOverlay = function() { |
122 var page = BluetoothOptions.getInstance(); | 126 var page = BluetoothOptions.getInstance(); |
123 if (page && page.visible) | 127 if (page && page.visible) |
124 PageManager.closeOverlay(); | 128 PageManager.closeOverlay(); |
125 }; | 129 }; |
126 | 130 |
127 // Export | 131 // Export |
128 return { | 132 return {BluetoothOptions: BluetoothOptions}; |
129 BluetoothOptions: BluetoothOptions | |
130 }; | |
131 }); | 133 }); |
OLD | NEW |