Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2429)

Unified Diff: chrome/browser/resources/chromeos/emulator/bluetooth_settings.js

Issue 1258783009: Add functionality to Bluetooth settings UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..26c5490ae36562e7c68f34056246e783f3deda4d 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';
- this.classValue = 0;
- this.isPairable = true;
+
+ // The uint32 value of the selected device class.
+ this.classValue = 0x104;
+
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>
*/
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,39 @@ 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.
+ * @return {boolean} Whether the PIN/passkey input field should be shown.
+ */
+ showAuthToken: function(pairMethod) {
+ return pairMethod && pairMethod != 'None';
+ },
+
+ /**
+ * 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.
+ devices[i].class = this.getTextForDeviceClass(devices[i]['classValue']);
+ 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 +131,69 @@ 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;
+
+ device.class = this.getTextForDeviceClass(device['classValue']);
+ 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;

Powered by Google App Engine
This is Rietveld 408576698