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