| 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 OptionsPage = options.OptionsPage; | 6 /** @const */ var OptionsPage = options.OptionsPage; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Enumeration of possible states during pairing. The value associated with | 9 * Enumeration of possible states during pairing. The value associated with |
| 10 * each state maps to a localized string in the global variable | 10 * each state maps to a localized string in the global variable |
| 11 * 'templateData'. | 11 * |loadTimeData|. |
| 12 * @enum {string} | 12 * @enum {string} |
| 13 */ | 13 */ |
| 14 var PAIRING = { | 14 var PAIRING = { |
| 15 STARTUP: 'bluetoothStartConnecting', | 15 STARTUP: 'bluetoothStartConnecting', |
| 16 ENTER_PIN_CODE: 'bluetoothEnterPinCode', | 16 ENTER_PIN_CODE: 'bluetoothEnterPinCode', |
| 17 ENTER_PASSKEY: 'bluetoothEnterPasskey', | 17 ENTER_PASSKEY: 'bluetoothEnterPasskey', |
| 18 REMOTE_PIN_CODE: 'bluetoothRemotePinCode', | 18 REMOTE_PIN_CODE: 'bluetoothRemotePinCode', |
| 19 REMOTE_PASSKEY: 'bluetoothRemotePasskey', | 19 REMOTE_PASSKEY: 'bluetoothRemotePasskey', |
| 20 CONFIRM_PASSKEY: 'bluetoothConfirmPasskey', | 20 CONFIRM_PASSKEY: 'bluetoothConfirmPasskey', |
| 21 ERROR_NO_DEVICE: 'bluetoothErrorNoDevice', | 21 ERROR_NO_DEVICE: 'bluetoothErrorNoDevice', |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 'bluetooth-pair-device-dismiss-button']; | 39 'bluetooth-pair-device-dismiss-button']; |
| 40 | 40 |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Encapsulated handling of the Bluetooth device pairing page. | 43 * Encapsulated handling of the Bluetooth device pairing page. |
| 44 * @constructor | 44 * @constructor |
| 45 */ | 45 */ |
| 46 function BluetoothPairing() { | 46 function BluetoothPairing() { |
| 47 OptionsPage.call(this, | 47 OptionsPage.call(this, |
| 48 'bluetoothPairing', | 48 'bluetoothPairing', |
| 49 templateData.bluetoothOptionsPageTabTitle, | 49 loadTimeData.getString('bluetoothOptionsPageTabTitle'), |
| 50 'bluetooth-pairing'); | 50 'bluetooth-pairing'); |
| 51 } | 51 } |
| 52 | 52 |
| 53 cr.addSingletonGetter(BluetoothPairing); | 53 cr.addSingletonGetter(BluetoothPairing); |
| 54 | 54 |
| 55 BluetoothPairing.prototype = { | 55 BluetoothPairing.prototype = { |
| 56 __proto__: OptionsPage.prototype, | 56 __proto__: OptionsPage.prototype, |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Description of the bluetooth device. | 59 * Description of the bluetooth device. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 update: function(device) { | 161 update: function(device) { |
| 162 this.device_ = {}; | 162 this.device_ = {}; |
| 163 for (key in device) | 163 for (key in device) |
| 164 this.device_[key] = device[key]; | 164 this.device_[key] = device[key]; |
| 165 // Update the pairing instructions. | 165 // Update the pairing instructions. |
| 166 var instructionsEl = $('bluetooth-pairing-instructions'); | 166 var instructionsEl = $('bluetooth-pairing-instructions'); |
| 167 this.clearElement_(instructionsEl); | 167 this.clearElement_(instructionsEl); |
| 168 this.dismissible_ = ('dismissible' in device) ? | 168 this.dismissible_ = ('dismissible' in device) ? |
| 169 device.dimissible : true; | 169 device.dimissible : true; |
| 170 | 170 |
| 171 var message = templateData[device.pairing]; | 171 var message = loadTimeData.getString('device.pairing'); |
| 172 message = message.replace('%1', this.device_.name); | 172 message = message.replace('%1', this.device_.name); |
| 173 instructionsEl.textContent = message; | 173 instructionsEl.textContent = message; |
| 174 | 174 |
| 175 // Update visibility of dialog elements. | 175 // Update visibility of dialog elements. |
| 176 if (this.device_.passkey) { | 176 if (this.device_.passkey) { |
| 177 this.updatePasskey_(); | 177 this.updatePasskey_(); |
| 178 if (this.device_.pairing == PAIRING.CONFIRM_PASSKEY) { | 178 if (this.device_.pairing == PAIRING.CONFIRM_PASSKEY) { |
| 179 // Confirming a match between displayed passkeys. | 179 // Confirming a match between displayed passkeys. |
| 180 this.displayElements_(['bluetooth-pairing-passkey-display', | 180 this.displayElements_(['bluetooth-pairing-passkey-display', |
| 181 'bluetooth-pair-device-accept-button', | 181 'bluetooth-pair-device-accept-button', |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 for (var i = 0; i < key.length; i++) { | 271 for (var i = 0; i < key.length; i++) { |
| 272 var keyEl = document.createElement('span'); | 272 var keyEl = document.createElement('span'); |
| 273 keyEl.textContent = key.charAt(i); | 273 keyEl.textContent = key.charAt(i); |
| 274 keyEl.className = keyClass; | 274 keyEl.className = keyClass; |
| 275 if (i < progress) | 275 if (i < progress) |
| 276 keyEl.classList.add('key-typed'); | 276 keyEl.classList.add('key-typed'); |
| 277 passkeyEl.appendChild(keyEl); | 277 passkeyEl.appendChild(keyEl); |
| 278 } | 278 } |
| 279 if (this.device_.pairing == PAIRING.REMOTE_PASSKEY) { | 279 if (this.device_.pairing == PAIRING.REMOTE_PASSKEY) { |
| 280 // Add enter key. | 280 // Add enter key. |
| 281 var label = templateData['bluetoothEnterKey']; | 281 var label = loadTimeData.getString('bluetoothEnterKey'); |
| 282 var keyEl = document.createElement('span'); | 282 var keyEl = document.createElement('span'); |
| 283 keyEl.textContent = label; | 283 keyEl.textContent = label; |
| 284 keyEl.className = keyClass; | 284 keyEl.className = keyClass; |
| 285 keyEl.id = 'bluetooth-enter-key'; | 285 keyEl.id = 'bluetooth-enter-key'; |
| 286 passkeyEl.appendChild(keyEl); | 286 passkeyEl.appendChild(keyEl); |
| 287 } | 287 } |
| 288 passkeyEl.hidden = false; | 288 passkeyEl.hidden = false; |
| 289 }, | 289 }, |
| 290 | 290 |
| 291 /** | 291 /** |
| 292 * Formats an element for displaying the PIN code. | 292 * Formats an element for displaying the PIN code. |
| 293 */ | 293 */ |
| 294 updatePinCode_: function() { | 294 updatePinCode_: function() { |
| 295 var passkeyEl = $('bluetooth-pairing-passkey-display'); | 295 var passkeyEl = $('bluetooth-pairing-passkey-display'); |
| 296 var keyClass = this.device_.pairing == PAIRING.REMOTE_PIN_CODE ? | 296 var keyClass = this.device_.pairing == PAIRING.REMOTE_PIN_CODE ? |
| 297 'bluetooth-keyboard-button' : 'bluetooth-passkey-char'; | 297 'bluetooth-keyboard-button' : 'bluetooth-passkey-char'; |
| 298 this.clearElement_(passkeyEl); | 298 this.clearElement_(passkeyEl); |
| 299 var key = String(this.device_.pincode); | 299 var key = String(this.device_.pincode); |
| 300 for (var i = 0; i < key.length; i++) { | 300 for (var i = 0; i < key.length; i++) { |
| 301 var keyEl = document.createElement('span'); | 301 var keyEl = document.createElement('span'); |
| 302 keyEl.textContent = key.charAt(i); | 302 keyEl.textContent = key.charAt(i); |
| 303 keyEl.className = keyClass; | 303 keyEl.className = keyClass; |
| 304 keyEl.classList.add('key-pin'); | 304 keyEl.classList.add('key-pin'); |
| 305 passkeyEl.appendChild(keyEl); | 305 passkeyEl.appendChild(keyEl); |
| 306 } | 306 } |
| 307 if (this.device_.pairing == PAIRING.REMOTE_PIN_CODE) { | 307 if (this.device_.pairing == PAIRING.REMOTE_PIN_CODE) { |
| 308 // Add enter key. | 308 // Add enter key. |
| 309 var label = templateData['bluetoothEnterKey']; | 309 var label = loadTimeData.getString('bluetoothEnterKey'); |
| 310 var keyEl = document.createElement('span'); | 310 var keyEl = document.createElement('span'); |
| 311 keyEl.textContent = label; | 311 keyEl.textContent = label; |
| 312 keyEl.className = keyClass; | 312 keyEl.className = keyClass; |
| 313 keyEl.classList.add('key-pin'); | 313 keyEl.classList.add('key-pin'); |
| 314 keyEl.id = 'bluetooth-enter-key'; | 314 keyEl.id = 'bluetooth-enter-key'; |
| 315 passkeyEl.appendChild(keyEl); | 315 passkeyEl.appendChild(keyEl); |
| 316 } | 316 } |
| 317 passkeyEl.hidden = false; | 317 passkeyEl.hidden = false; |
| 318 }, | 318 }, |
| 319 }; | 319 }; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 var dialog = BluetoothPairing.getInstance(); | 362 var dialog = BluetoothPairing.getInstance(); |
| 363 if (overlay == dialog && dialog.dismissible_) | 363 if (overlay == dialog && dialog.dismissible_) |
| 364 OptionsPage.closeOverlay(); | 364 OptionsPage.closeOverlay(); |
| 365 }; | 365 }; |
| 366 | 366 |
| 367 // Export | 367 // Export |
| 368 return { | 368 return { |
| 369 BluetoothPairing: BluetoothPairing | 369 BluetoothPairing: BluetoothPairing |
| 370 }; | 370 }; |
| 371 }); | 371 }); |
| OLD | NEW |