Index: chrome/browser/resources/chromeos/emulator/bluetooth_settings.js |
diff --git a/chrome/browser/resources/chromeos/emulator/bluetooth_settings.js b/chrome/browser/resources/chromeos/emulator/bluetooth_settings.js |
index e656e41984789b2ead64e450622ce8f413cb0f74..a6a95144a2064d75f5177e190e0ac95540b737cf 100644 |
--- a/chrome/browser/resources/chromeos/emulator/bluetooth_settings.js |
+++ b/chrome/browser/resources/chromeos/emulator/bluetooth_settings.js |
@@ -9,13 +9,22 @@ |
var BluetoothDevice = function() { |
this.address = ''; |
this.alias = ''; |
+ |
+ // The text label of the selected device class. |
this.class = 'Computer'; |
+ |
+ // The uint32 value of the selected device class. |
this.classValue = 0; |
- this.isPairable = true; |
+ |
this.isTrusted = true; |
this.name = ''; |
this.path = ''; |
- this.pairMethod = 'None'; |
+ |
+ // The label of the selected pairing method option. |
+ this.pairingMethod = 'None'; |
+ |
+ // The text containing a PIN key or passkey for pairing. |
+ this.pairingAuthToken = ''; |
}; |
Polymer({ |
@@ -30,13 +39,6 @@ Polymer({ |
}, |
/** |
- * Indicates whether or not the main bluetooth adapter is turned on. |
- */ |
- powerToMainAdapter: { |
- type: Boolean |
- }, |
- |
- /** |
* A set of bluetooth devices. |
* @type !Array<!BluetoothDevice> |
*/ |
@@ -49,7 +51,7 @@ Polymer({ |
* A set of options for the possible bluetooth device classes/types. |
* Object |value| attribute comes from values in the WebUI, set in |
* setDeviceClassOptions. |
- * @type !Array<! { text: string, value: int }} > |
+ * @type !Array<! {text: string, value: int} > |
*/ |
deviceClassOptions: { |
type: Array, |
@@ -59,18 +61,28 @@ Polymer({ |
{ text: 'Keyboard', value: 0x2540 }, |
{ text: 'Audio', value: 0x240408 }, |
{ text: 'Phone', value: 0x7a020c }, |
- { text: 'Computer', value: 0x100 }]; |
+ { text: 'Computer', value: 0x104 }]; |
} |
}, |
/** |
* A set of strings representing the method to be used for |
* authenticating a device during a pair request. |
- * @type !Array<!String> |
+ * @type !Array<!string> |
stevenjb
2015/07/31 16:49:33
nit: ! or ? is only needed for Object and Array ty
|
*/ |
deviceAuthenticationMethods: { |
type: Array, |
- value: function() { return ['None', 'Pin Code', 'Pass Key']; } |
+ value: function() { return ['None', 'PIN Code', 'PassKey']; } |
+ }, |
+ |
+ /** |
+ * Contains keys for all the device paths which have been discovered. Used |
+ * to look up whether or not a device is listed already. |
+ * @type {Object} |
+ */ |
+ devicePaths: { |
+ type: Object, |
+ value: function() { return {}; } |
}, |
}, |
@@ -78,9 +90,41 @@ Polymer({ |
this.title = 'Bluetooth Settings'; |
}, |
+ /** |
+ * Checks whether or not the PIN/passkey input field should be shown. |
+ * It should only be shown when the pair method is not 'None' or empty. |
+ * @param {string} pairMethod The label of the selected pair method option |
+ * for a particular device. |
stevenjb
2015/07/31 16:49:33
indent 4 spaces when continuing an @ line, i.e.:
*
|
+ * @return {boolean} Whether the PIN/passkey input field should be shown. |
+ */ |
+ showAuthToken: function(pairMethod) { |
+ return pairMethod != 'None' && pairMethod != undefined; |
+ }, |
+ |
+ /** |
+ * Called by the WebUI which provides a list of devices which are connected |
+ * to the main adapter. |
+ * @param {!Array<!BluetoothDevice>} devices A list of bluetooth devices. |
+ */ |
+ updateBluetoothInfo: function(devices) { |
+ /** @type {!Array<!BluetoothDevice>} */ var deviceList = []; |
+ |
+ for (var i = 0; i < devices.length; ++i) { |
+ // Get the label for the device class which should be selected. |
+ var selectedClass = |
+ this.getTextForDeviceClass(devices[i]['classValue']); |
+ devices[i].class = selectedClass; |
+ deviceList.push(devices[i]); |
+ this.devicePaths[devices[i]['path']] = true; |
+ } |
+ |
+ this.devices = deviceList; |
+ }, |
+ |
pairDevice: function(e) { |
var device = this.devices[e.path[2].dataIndex]; |
device.classValue = this.getValueForDeviceClass(device.class); |
+ this.devicePaths[device.path] = true; |
// Send device info to the WebUI. |
chrome.send('requestBluetoothPair', [device]); |
@@ -89,18 +133,70 @@ Polymer({ |
discoverDevice: function(e) { |
var device = this.devices[e.path[2].dataIndex]; |
device.classValue = this.getValueForDeviceClass(device.class); |
+ this.devicePaths[device.path] = true; |
// Send device info to WebUI. |
chrome.send('requestBluetoothDiscover', [device]); |
}, |
+ // Adds a new device with default settings to the list of devices. |
appendNewDevice: function() { |
this.push('devices', new BluetoothDevice()); |
}, |
- getValueForDeviceClass: function(classValue) { |
+ /** |
+ * This is called when a new device is discovered by the main adapter. |
+ * The device is only added to the view's list if it is not already in |
+ * the list (i.e. its path has not yet been recorded in |devicePaths|). |
+ * @param {BluetoothDevice} device A bluetooth device. |
+ */ |
+ addBluetoothDevice: function(device) { |
+ if (this.devicePaths[device['path']] != undefined) |
+ return; |
+ |
+ var selectedClass = this.getTextForDeviceClass(device['classValue']); |
+ device.class = selectedClass; |
+ this.push('devices', device); |
+ this.devicePaths[device['path']] = true; |
+ }, |
+ |
+ /** |
+ * Removes the bluetooth device with path |path|. |
+ * @param {string} path A bluetooth device's path. |
+ */ |
+ removeBluetoothDevice: function(path) { |
+ if (this.devicePaths[path] == undefined) |
+ return; |
+ |
+ for (var i = 0; i < this.devices.length; ++i) { |
+ if (this.devices[i].path == path) { |
+ this.splice('devices', i, 1); |
+ break; |
+ } |
+ } |
+ }, |
+ |
+ /** |
+ * Returns the text for the label that corresponds to |classValue|. |
+ * @param {number} classValue A number representing the bluetooth class |
+ * of a device. |
+ * @return {string} The label which represents |classValue|. |
+ */ |
+ getTextForDeviceClass: function(classValue) { |
+ for (var i = 0; i < this.deviceClassOptions.length; ++i) { |
+ if (this.deviceClassOptions[i].value == classValue) |
+ return this.deviceClassOptions[i].text; |
+ } |
+ }, |
+ |
+ /** |
+ * Returns the integer value which corresponds with the label |classText|. |
+ * @param {string} classText The label for a device class option. |
+ * @return {number} The value which |classText| represents. |
+ */ |
+ getValueForDeviceClass: function(classText) { |
for (var i = 0; i < this.deviceClassOptions.length; ++i) { |
- if (this.deviceClassOptions[i].text == classValue) |
+ if (this.deviceClassOptions[i].text == classText) |
return this.deviceClassOptions[i].value; |
} |
return 0; |