Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @fileoverview | 6 * @fileoverview |
| 7 * 'settings-bluetooth-page' is the settings page for managing bluetooth | 7 * 'settings-bluetooth-page' is the settings page for managing bluetooth |
| 8 * properties and devices. | 8 * properties and devices. |
| 9 * | 9 * |
| 10 * Example: | 10 * Example: |
| 11 * <core-animated-pages> | 11 * <core-animated-pages> |
| 12 * <settings-bluetooth-page> | 12 * <settings-bluetooth-page> |
| 13 * </settings-bluetooth-page> | 13 * </settings-bluetooth-page> |
| 14 * ... other pages ... | 14 * ... other pages ... |
| 15 * </core-animated-pages> | 15 * </core-animated-pages> |
| 16 * | 16 * |
| 17 * @group Chrome Settings Elements | 17 * @group Chrome Settings Elements |
| 18 * @element settings-bluetooth-page | 18 * @element settings-bluetooth-page |
| 19 */ | 19 */ |
| 20 | |
| 21 var bluetoothPage = bluetoothPage || { | |
|
michaelpg
2015/12/17 22:07:16
use cr.define?
stevenjb
2015/12/17 22:13:57
Hm, interesting question. I'm a bit reluctant to "
Dan Beam
2015/12/28 21:55:15
cr.exportPath('bluetoothPage'); seems to do someth
| |
| 22 /** | |
| 23 * Set this to provide a fake implementation for testing. | |
| 24 * @type {Bluetooth} | |
| 25 */ | |
| 26 bluetoothApiForTest: null, | |
| 27 | |
| 28 /** | |
| 29 * Set this to provide a fake implementation for testing. | |
| 30 * @type {BluetoothPrivate} | |
| 31 */ | |
| 32 bluetoothPrivateApiForTest: null, | |
| 33 }; | |
| 34 | |
| 20 Polymer({ | 35 Polymer({ |
| 21 is: 'settings-bluetooth-page', | 36 is: 'settings-bluetooth-page', |
| 22 | 37 |
| 23 behaviors: [ | 38 behaviors: [ |
| 24 I18nBehavior, | 39 I18nBehavior, |
| 25 ], | 40 ], |
| 26 | 41 |
| 27 properties: { | 42 properties: { |
| 28 /** The current active route. */ | 43 /** The current active route. */ |
| 29 currentRoute: { | 44 currentRoute: { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 40 */ | 55 */ |
| 41 deviceList: {type: Array, value: function() { return []; }}, | 56 deviceList: {type: Array, value: function() { return []; }}, |
| 42 | 57 |
| 43 /** The index of the selected device or -1 if none. */ | 58 /** The index of the selected device or -1 if none. */ |
| 44 selectedDevice: {type: Number, value: -1}, | 59 selectedDevice: {type: Number, value: -1}, |
| 45 | 60 |
| 46 /** | 61 /** |
| 47 * Interface for bluetooth calls. May be overriden by tests. | 62 * Interface for bluetooth calls. May be overriden by tests. |
| 48 * @type {Bluetooth} | 63 * @type {Bluetooth} |
| 49 */ | 64 */ |
| 50 bluetooth: { | 65 bluetooth: { |
|
michaelpg
2015/12/17 22:07:17
does this need to be a Polymer property vs. a vani
stevenjb
2015/12/17 22:13:57
It will likely get passed to subpages, so probably
| |
| 51 type: Object, | 66 type: Object, |
| 52 value: chrome.bluetooth, | 67 value: chrome.bluetooth, |
| 53 }, | 68 }, |
| 54 | 69 |
| 55 /** | 70 /** |
| 56 * Interface for bluetoothPrivate calls. May be overriden by tests. | 71 * Interface for bluetoothPrivate calls. May be overriden by tests. |
| 57 * @type {BluetoothPrivate} | 72 * @type {BluetoothPrivate} |
| 58 */ | 73 */ |
| 59 bluetoothPrivate: { | 74 bluetoothPrivate: { |
|
michaelpg
2015/12/17 22:07:17
same
| |
| 60 type: Object, | 75 type: Object, |
| 61 value: chrome.bluetoothPrivate, | 76 value: chrome.bluetoothPrivate, |
| 62 }, | 77 }, |
| 63 }, | 78 }, |
| 64 | 79 |
| 65 /** | 80 /** |
| 66 * Listener for chrome.bluetooth.onAdapterStateChanged events. | 81 * Listener for chrome.bluetooth.onAdapterStateChanged events. |
| 67 * @type {function(!chrome.bluetooth.AdapterState)|undefined} | 82 * @type {function(!chrome.bluetooth.AdapterState)|undefined} |
| 68 * @private | 83 * @private |
| 69 */ | 84 */ |
| 70 bluetoothAdapterStateChangedListener_: undefined, | 85 bluetoothAdapterStateChangedListener_: undefined, |
| 71 | 86 |
| 72 /** | 87 /** |
| 73 * Listener for chrome.bluetooth.onBluetoothDeviceAdded/Changed events. | 88 * Listener for chrome.bluetooth.onBluetoothDeviceAdded/Changed events. |
| 74 * @type {function(!chrome.bluetooth.Device)|undefined} | 89 * @type {function(!chrome.bluetooth.Device)|undefined} |
| 75 * @private | 90 * @private |
| 76 */ | 91 */ |
| 77 bluetoothDeviceUpdatedListener_: undefined, | 92 bluetoothDeviceUpdatedListener_: undefined, |
| 78 | 93 |
| 79 /** | 94 /** |
| 80 * Listener for chrome.bluetooth.onBluetoothDeviceRemoved events. | 95 * Listener for chrome.bluetooth.onBluetoothDeviceRemoved events. |
| 81 * @type {function(!chrome.bluetooth.Device)|undefined} | 96 * @type {function(!chrome.bluetooth.Device)|undefined} |
| 82 * @private | 97 * @private |
| 83 */ | 98 */ |
| 84 bluetoothDeviceRemovedListener_: undefined, | 99 bluetoothDeviceRemovedListener_: undefined, |
| 85 | 100 |
| 101 /** @override */ | |
| 102 ready: function() { | |
| 103 if (bluetoothPage.bluetoothApiForTest) | |
| 104 this.bluetooth = bluetoothPage.bluetoothApiForTest; | |
| 105 if (bluetoothPage.bluetoothPrivateApiForTest) | |
| 106 this.bluetoothPrivate = bluetoothPage.bluetoothPrivateApiForTest; | |
| 107 }, | |
| 86 | 108 |
| 87 /** @override */ | 109 /** @override */ |
| 88 attached: function() { | 110 attached: function() { |
| 89 this.bluetoothAdapterStateChangedListener_ = | 111 this.bluetoothAdapterStateChangedListener_ = |
| 90 this.onBluetoothAdapterStateChanged_.bind(this); | 112 this.onBluetoothAdapterStateChanged_.bind(this); |
| 91 this.bluetooth.onAdapterStateChanged.addListener( | 113 this.bluetooth.onAdapterStateChanged.addListener( |
| 92 this.bluetoothAdapterStateChangedListener_); | 114 this.bluetoothAdapterStateChangedListener_); |
| 93 | 115 |
| 94 this.bluetoothDeviceUpdatedListener_ = | 116 this.bluetoothDeviceUpdatedListener_ = |
| 95 this.onBluetoothDeviceUpdated_.bind(this); | 117 this.onBluetoothDeviceUpdated_.bind(this); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 /** | 246 /** |
| 225 * @param {!chrome.bluetooth.Device} device | 247 * @param {!chrome.bluetooth.Device} device |
| 226 * @return {boolean} True if |device| should be shown in the device list. | 248 * @return {boolean} True if |device| should be shown in the device list. |
| 227 * @private | 249 * @private |
| 228 */ | 250 */ |
| 229 showDeviceInList_: function(device) { | 251 showDeviceInList_: function(device) { |
| 230 return !!device.paired || !!device.connected || !!device.connecting; | 252 return !!device.paired || !!device.connected || !!device.connecting; |
| 231 }, | 253 }, |
| 232 | 254 |
| 233 /** | 255 /** |
| 234 * @param {!Array<!chrome.bluetooth.Device>} deviceList | 256 * @param {Object} deviceListChanges |
| 235 * @return {boolean} True if deviceList is not empty. | 257 * @return {boolean} True if deviceList is not empty. |
| 236 * @private | 258 * @private |
| 237 */ | 259 */ |
| 238 haveDevices_: function(deviceList) { return !!deviceList.length; }, | 260 haveDevices_: function(deviceListChanges) { |
| 261 return !!this.deviceList.length; | |
| 262 }, | |
| 239 | 263 |
| 240 /** | 264 /** |
| 241 * @param {number} selectedDevice | 265 * @param {number} selectedDevice |
| 242 * @return {boolean} True if a device is selected. | 266 * @return {boolean} True if a device is selected. |
| 243 * @private | 267 * @private |
| 244 */ | 268 */ |
| 245 haveSelectedDevice_: function(selectedDevice) { return selectedDevice >= 0; }, | 269 haveSelectedDevice_: function(selectedDevice) { return selectedDevice >= 0; }, |
| 246 | 270 |
| 247 /** @private */ | 271 /** @private */ |
| 248 onConnectTap_: function() { | 272 onConnectTap_: function() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 'Error forgetting devce: ' + device.name + ': ' + | 309 'Error forgetting devce: ' + device.name + ': ' + |
| 286 chrome.runtime.lastError.message); | 310 chrome.runtime.lastError.message); |
| 287 } | 311 } |
| 288 }); | 312 }); |
| 289 } | 313 } |
| 290 }, | 314 }, |
| 291 | 315 |
| 292 /** @private */ | 316 /** @private */ |
| 293 onAddDeviceTap_: function() {} | 317 onAddDeviceTap_: function() {} |
| 294 }); | 318 }); |
| OLD | NEW |