OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 Oobe HID detection screen implementation. | 6 * @fileoverview Oobe HID detection screen implementation. |
7 */ | 7 */ |
8 | 8 |
9 login.createScreen('HIDDetectionScreen', 'hid-detection', function() { | 9 login.createScreen('HIDDetectionScreen', 'hid-detection', function() { |
| 10 var CONTEXT_KEY_KEYBOARD_STATE = 'keyboard-state'; |
| 11 var CONTEXT_KEY_MOUSE_STATE = 'mouse-state'; |
| 12 var CONTEXT_KEY_KEYBOARD_PINCODE = 'keyboard-pincode'; |
| 13 var CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE = 'entered-part-pincode'; |
| 14 var CONTEXT_KEY_MOUSE_DEVICE_NAME = 'mouse-device-name'; |
| 15 var CONTEXT_KEY_KEYBOARD_DEVICE_NAME = 'keyboard-device-name'; |
| 16 var CONTEXT_KEY_KEYBOARD_LABEL = 'keyboard-device-label'; |
| 17 var CONTEXT_KEY_CONTINUE_BUTTON_ENABLED = 'continue-button-enabled'; |
| 18 |
10 return { | 19 return { |
11 EXTERNAL_API: [ | |
12 'setPointingDeviceState', | |
13 'setKeyboardDeviceState', | |
14 ], | |
15 | 20 |
16 /** | 21 /** |
17 * Enumeration of possible states during pairing. The value associated with | 22 * Enumeration of possible states during pairing. The value associated with |
18 * each state maps to a localized string in the global variable | 23 * each state maps to a localized string in the global variable |
19 * |loadTimeData|. | 24 * |loadTimeData|. |
20 * @enum {string} | 25 * @enum {string} |
21 */ | 26 */ |
22 PAIRING: { | 27 PAIRING: { |
23 STARTUP: 'bluetoothStartConnecting', | 28 STARTUP: 'bluetoothStartConnecting', |
24 REMOTE_PIN_CODE: 'bluetoothRemotePinCode', | 29 REMOTE_PIN_CODE: 'bluetoothRemotePinCode', |
25 REMOTE_PASSKEY: 'bluetoothRemotePasskey', | |
26 CONNECT_FAILED: 'bluetoothConnectFailed', | 30 CONNECT_FAILED: 'bluetoothConnectFailed', |
27 CANCELED: 'bluetoothPairingCanceled', | 31 CANCELED: 'bluetoothPairingCanceled', |
28 // Pairing dismissed (succeeded or canceled). | 32 // Pairing dismissed (succeeded or canceled). |
29 DISMISSED: 'bluetoothPairingDismissed' | 33 DISMISSED: 'bluetoothPairingDismissed' |
30 }, | 34 }, |
31 | 35 |
32 /** | 36 /** @override */ |
33 * Button to move to usual OOBE flow after detection. | 37 decorate: function() { |
34 * @private | 38 var self = this; |
35 */ | 39 |
36 continueButton_: null, | 40 this.context.addObserver( |
| 41 CONTEXT_KEY_MOUSE_STATE, |
| 42 function(stateId) { |
| 43 if (stateId === undefined) |
| 44 return; |
| 45 self.setDeviceBlockState_('hid-mouse-block', stateId); |
| 46 } |
| 47 ); |
| 48 this.context.addObserver( |
| 49 CONTEXT_KEY_KEYBOARD_STATE, |
| 50 function(stateId) { |
| 51 if (stateId === undefined) |
| 52 return; |
| 53 self.setDeviceBlockState_('hid-keyboard-block', stateId); |
| 54 if (stateId == 'paired') { |
| 55 $('hid-keyboard-label-paired').textContent = self.context.get( |
| 56 CONTEXT_KEY_KEYBOARD_LABEL, ''); |
| 57 } else if (stateId == 'pairing') { |
| 58 $('hid-keyboard-label-pairing').textContent = self.context.get( |
| 59 CONTEXT_KEY_KEYBOARD_LABEL, ''); |
| 60 } else if (stateId == 'connected') { |
| 61 } |
| 62 } |
| 63 ); |
| 64 this.context.addObserver( |
| 65 CONTEXT_KEY_KEYBOARD_PINCODE, |
| 66 function(pincode) { |
| 67 self.setPincodeKeysState_(-1); |
| 68 if (!pincode) { |
| 69 $('hid-keyboard-pincode').classList.remove('show-pincode'); |
| 70 return; |
| 71 } |
| 72 if (self.context.get(CONTEXT_KEY_KEYBOARD_STATE, '') != 'pairing') |
| 73 return; |
| 74 $('hid-keyboard-pincode').classList.add('show-pincode'); |
| 75 for (var i = 0, len = pincode.length; i < len; i++) { |
| 76 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); |
| 77 pincodeSymbol.textContent = pincode[i]; |
| 78 } |
| 79 announceAccessibleMessage( |
| 80 self.context.get(CONTEXT_KEY_KEYBOARD_LABEL, '') + ' ' + pincode + |
| 81 ' ' + loadTimeData.getString('hidDetectionBTEnterKey')); |
| 82 } |
| 83 ); |
| 84 this.context.addObserver( |
| 85 CONTEXT_KEY_KEYBOARD_ENTERED_PART_PINCODE, |
| 86 function(entered_part) { |
| 87 if (self.context.get(CONTEXT_KEY_KEYBOARD_STATE, '') != 'pairing') |
| 88 return; |
| 89 if (entered_part >= 0) |
| 90 self.setPincodeKeysState_(entered_part); |
| 91 } |
| 92 ); |
| 93 this.context.addObserver( |
| 94 CONTEXT_KEY_CONTINUE_BUTTON_ENABLED, |
| 95 function(enabled) { |
| 96 $('hid-continue-button').disabled = !enabled; |
| 97 } |
| 98 ); |
| 99 }, |
37 | 100 |
38 /** | 101 /** |
39 * Buttons in oobe wizard's button strip. | 102 * Buttons in oobe wizard's button strip. |
40 * @type {array} Array of Buttons. | 103 * @type {array} Array of Buttons. |
41 */ | 104 */ |
42 get buttons() { | 105 get buttons() { |
43 var buttons = []; | 106 var buttons = []; |
44 var continueButton = this.ownerDocument.createElement('button'); | 107 var continueButton = this.ownerDocument.createElement('button'); |
45 continueButton.id = 'hid-continue-button'; | 108 continueButton.id = 'hid-continue-button'; |
46 continueButton.textContent = loadTimeData.getString( | 109 continueButton.textContent = loadTimeData.getString( |
47 'hidDetectionContinue'); | 110 'hidDetectionContinue'); |
48 continueButton.addEventListener('click', function(e) { | 111 continueButton.addEventListener('click', function(e) { |
49 chrome.send('HIDDetectionOnContinue'); | 112 chrome.send('HIDDetectionOnContinue'); |
50 e.stopPropagation(); | 113 e.stopPropagation(); |
51 }); | 114 }); |
52 buttons.push(continueButton); | 115 buttons.push(continueButton); |
53 this.continueButton_ = continueButton; | |
54 | 116 |
55 return buttons; | 117 return buttons; |
56 }, | 118 }, |
57 | 119 |
58 /** | 120 /** |
59 * Returns a control which should receive an initial focus. | 121 * Returns a control which should receive an initial focus. |
60 */ | 122 */ |
61 get defaultControl() { | 123 get defaultControl() { |
62 return this.continueButton_; | 124 return $('hid-continue-button'); |
63 }, | 125 }, |
64 | 126 |
65 /** | 127 /** |
66 * Sets a device-block css class to reflect device state of searching, | 128 * Sets a device-block css class to reflect device state of searching, |
67 * connected, pairing or paired (for BT devices). | 129 * connected, pairing or paired (for BT devices). |
68 * @param {blockId} id one of 'hid-mouse-block' or 'hid-keyboard-block'. | 130 * @param {blockId} id one of 'hid-mouse-block' or 'hid-keyboard-block'. |
69 * @param {state} one of 'searching', 'connected', 'pairing', 'paired', | 131 * @param {state} one of 'searching', 'connected', 'pairing', 'paired', |
70 * @private | 132 * @private |
71 */ | 133 */ |
72 setDeviceBlockState_: function(blockId, state) { | 134 setDeviceBlockState_: function(blockId, state) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (i < entered) | 168 if (i < entered) |
107 pincodeSymbol.classList.add('key-typed'); | 169 pincodeSymbol.classList.add('key-typed'); |
108 else if (i == entered) | 170 else if (i == entered) |
109 pincodeSymbol.classList.add('key-next'); | 171 pincodeSymbol.classList.add('key-next'); |
110 else if (entered != -1) | 172 else if (entered != -1) |
111 pincodeSymbol.classList.add('key-untyped'); | 173 pincodeSymbol.classList.add('key-untyped'); |
112 } | 174 } |
113 }, | 175 }, |
114 | 176 |
115 /** | 177 /** |
116 * Sets state for keyboard-block. | |
117 * @param {data} dict with parameters. | |
118 */ | |
119 setKeyboardDeviceState: function(data) { | |
120 if (data === undefined || !('state' in data)) | |
121 return; | |
122 var state = data['state']; | |
123 this.setDeviceBlockState_('hid-keyboard-block', state); | |
124 if (state == 'paired') | |
125 $('hid-keyboard-label-paired').textContent = data['keyboard-label']; | |
126 else if (state == 'pairing') { | |
127 $('hid-keyboard-label-pairing').textContent = data['keyboard-label']; | |
128 if (data['pairing-state'] == this.PAIRING.REMOTE_PIN_CODE || | |
129 data['pairing-state'] == this.PAIRING.REMOTE_PASSKEY) { | |
130 this.setPincodeKeysState_(-1); | |
131 for (var i = 0, len = data['pincode'].length; i < len; i++) { | |
132 var pincodeSymbol = $('hid-keyboard-pincode-sym-' + (i + 1)); | |
133 pincodeSymbol.textContent = data['pincode'][i]; | |
134 } | |
135 announceAccessibleMessage( | |
136 data['keyboard-label'] + ' ' + data['pincode'] + ' ' + | |
137 loadTimeData.getString('hidDetectionBTEnterKey')); | |
138 } | |
139 } else if (state == 'update') { | |
140 if ('keysEntered' in data) { | |
141 this.setPincodeKeysState_(data['keysEntered']); | |
142 } | |
143 } | |
144 }, | |
145 | |
146 /** | |
147 * Event handler that is invoked just before the screen in shown. | 178 * Event handler that is invoked just before the screen in shown. |
148 * @param {Object} data Screen init payload. | 179 * @param {Object} data Screen init payload. |
149 */ | 180 */ |
150 onBeforeShow: function(data) { | 181 onBeforeShow: function(data) { |
151 $('hid-continue-button').disabled = true; | 182 $('hid-continue-button').disabled = true; |
152 this.setDeviceBlockState_('hid-mouse-block', 'searching'); | 183 this.setDeviceBlockState_('hid-mouse-block', 'searching'); |
153 this.setDeviceBlockState_('hid-keyboard-block', 'searching'); | 184 this.setDeviceBlockState_('hid-keyboard-block', 'searching'); |
154 }, | 185 }, |
155 }; | 186 }; |
156 }); | 187 }); |
OLD | NEW |