OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 login.createScreen('OAuthEnrollmentScreen', 'oauth-enrollment', function() { | 5 login.createScreen('OAuthEnrollmentScreen', 'oauth-enrollment', function() { |
6 /* Code which is embedded inside of the webview. See below for details. | 6 /* Code which is embedded inside of the webview. See below for details. |
7 /** @const */ var INJECTED_WEBVIEW_SCRIPT = String.raw` | 7 /** @const */ var INJECTED_WEBVIEW_SCRIPT = String.raw` |
8 (function() { | 8 (function() { |
9 // <include src="../keyboard/keyboard_utils.js"> | 9 // <include src="../keyboard/keyboard_utils.js"> |
10 keyboard.initializeKeyboardFlow(true); | 10 keyboard.initializeKeyboardFlow(true); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 * The current step. This is the last value passed to showStep(). | 44 * The current step. This is the last value passed to showStep(). |
45 */ | 45 */ |
46 currentStep_: null, | 46 currentStep_: null, |
47 | 47 |
48 /** | 48 /** |
49 * We block esc, back button and cancel button until gaia is loaded to | 49 * We block esc, back button and cancel button until gaia is loaded to |
50 * prevent multiple cancel events. | 50 * prevent multiple cancel events. |
51 */ | 51 */ |
52 isCancelDisabled_: null, | 52 isCancelDisabled_: null, |
53 | 53 |
54 get isCancelDisabled() { return this.isCancelDisabled_; }, | 54 get isCancelDisabled() { |
| 55 return this.isCancelDisabled_; |
| 56 }, |
55 set isCancelDisabled(disabled) { | 57 set isCancelDisabled(disabled) { |
56 this.isCancelDisabled_ = disabled; | 58 this.isCancelDisabled_ = disabled; |
57 }, | 59 }, |
58 | 60 |
59 isManualEnrollment_: undefined, | 61 isManualEnrollment_: undefined, |
60 | 62 |
61 /** | 63 /** |
62 * An element containg navigation buttons. | 64 * An element containg navigation buttons. |
63 */ | 65 */ |
64 navigation_: undefined, | 66 navigation_: undefined, |
(...skipping 27 matching lines...) Expand all Loading... |
92 /** @override */ | 94 /** @override */ |
93 decorate: function() { | 95 decorate: function() { |
94 this.navigation_ = $('oauth-enroll-navigation'); | 96 this.navigation_ = $('oauth-enroll-navigation'); |
95 this.offlineAdUi_ = $('oauth-enroll-ad-join-ui'); | 97 this.offlineAdUi_ = $('oauth-enroll-ad-join-ui'); |
96 | 98 |
97 this.authenticator_ = | 99 this.authenticator_ = |
98 new cr.login.Authenticator($('oauth-enroll-auth-view')); | 100 new cr.login.Authenticator($('oauth-enroll-auth-view')); |
99 | 101 |
100 // Establish an initial messaging between content script and | 102 // Establish an initial messaging between content script and |
101 // host script so that content script can message back. | 103 // host script so that content script can message back. |
102 $('oauth-enroll-auth-view').addEventListener('loadstop', | 104 $('oauth-enroll-auth-view').addEventListener('loadstop', function(e) { |
103 function(e) { | 105 e.target.contentWindow.postMessage( |
104 e.target.contentWindow.postMessage( | 106 'initialMessage', $('oauth-enroll-auth-view').src); |
105 'initialMessage', $('oauth-enroll-auth-view').src); | 107 }); |
106 }); | |
107 | 108 |
108 // When we get the advancing focus command message from injected content | 109 // When we get the advancing focus command message from injected content |
109 // script, we can execute it on host script context. | 110 // script, we can execute it on host script context. |
110 window.addEventListener('message', | 111 window.addEventListener('message', function(e) { |
111 function(e) { | 112 if (e.data == 'forwardFocus') |
112 if (e.data == 'forwardFocus') | 113 keyboard.onAdvanceFocus(false); |
113 keyboard.onAdvanceFocus(false); | 114 else if (e.data == 'backwardFocus') |
114 else if (e.data == 'backwardFocus') | 115 keyboard.onAdvanceFocus(true); |
115 keyboard.onAdvanceFocus(true); | 116 }); |
116 }); | |
117 | 117 |
118 this.authenticator_.addEventListener('ready', | 118 this.authenticator_.addEventListener( |
119 (function() { | 119 'ready', (function() { |
120 if (this.currentStep_ != STEP_SIGNIN) | 120 if (this.currentStep_ != STEP_SIGNIN) |
121 return; | 121 return; |
122 this.isCancelDisabled = false; | 122 this.isCancelDisabled = false; |
123 chrome.send('frameLoadingCompleted'); | 123 chrome.send('frameLoadingCompleted'); |
124 }).bind(this)); | 124 }).bind(this)); |
125 | 125 |
126 this.authenticator_.addEventListener('authCompleted', | 126 this.authenticator_.addEventListener( |
| 127 'authCompleted', |
127 (function(e) { | 128 (function(e) { |
128 var detail = e.detail; | 129 var detail = e.detail; |
129 if (!detail.email || !detail.authCode) { | 130 if (!detail.email || !detail.authCode) { |
130 this.showError( | 131 this.showError( |
131 loadTimeData.getString('fatalEnrollmentError'), | 132 loadTimeData.getString('fatalEnrollmentError'), false); |
132 false); | |
133 return; | 133 return; |
134 } | 134 } |
135 chrome.send('oauthEnrollCompleteLogin', [detail.email, | 135 chrome.send( |
136 detail.authCode]); | 136 'oauthEnrollCompleteLogin', [detail.email, detail.authCode]); |
137 }).bind(this)); | 137 }).bind(this)); |
138 | 138 |
139 this.offlineAdUi_.addEventListener('authCompleted', function(e) { | 139 this.offlineAdUi_.addEventListener('authCompleted', function(e) { |
140 this.offlineAdUi_.disabled = true; | 140 this.offlineAdUi_.disabled = true; |
141 this.activeDirectoryMachine_ = e.detail.machinename; | 141 this.activeDirectoryMachine_ = e.detail.machinename; |
142 this.activeDirectoryUsername_ = e.detail.username; | 142 this.activeDirectoryUsername_ = e.detail.username; |
143 chrome.send('oauthEnrollAdCompleteLogin', | 143 chrome.send( |
| 144 'oauthEnrollAdCompleteLogin', |
144 [e.detail.machinename, e.detail.username, e.detail.password]); | 145 [e.detail.machinename, e.detail.username, e.detail.password]); |
145 }.bind(this)); | 146 }.bind(this)); |
146 | 147 |
147 this.authenticator_.addEventListener('authFlowChange', | 148 this.authenticator_.addEventListener( |
148 (function(e) { | 149 'authFlowChange', (function(e) { |
149 var isSAML = this.authenticator_.authFlow == | 150 var isSAML = this.authenticator_.authFlow == |
150 cr.login.Authenticator.AuthFlow.SAML; | 151 cr.login.Authenticator.AuthFlow.SAML; |
151 if (isSAML) { | 152 if (isSAML) { |
152 $('oauth-saml-notice-message').textContent = | 153 $('oauth-saml-notice-message').textContent = |
153 loadTimeData.getStringF('samlNotice', | 154 loadTimeData.getStringF( |
154 this.authenticator_.authDomain); | 155 'samlNotice', |
155 } | 156 this.authenticator_.authDomain); |
156 this.classList.toggle('saml', isSAML); | 157 } |
157 if (Oobe.getInstance().currentScreen == this) | 158 this.classList.toggle('saml', isSAML); |
158 Oobe.getInstance().updateScreenSize(this); | 159 if (Oobe.getInstance().currentScreen == this) |
159 this.lastBackMessageValue_ = false; | 160 Oobe.getInstance().updateScreenSize(this); |
160 this.updateControlsState(); | 161 this.lastBackMessageValue_ = false; |
161 }).bind(this)); | 162 this.updateControlsState(); |
| 163 }).bind(this)); |
162 | 164 |
163 this.authenticator_.addEventListener('backButton', | 165 this.authenticator_.addEventListener( |
164 (function(e) { | 166 'backButton', (function(e) { |
165 this.lastBackMessageValue_ = !!e.detail; | 167 this.lastBackMessageValue_ = !!e.detail; |
166 $('oauth-enroll-auth-view').focus(); | 168 $('oauth-enroll-auth-view').focus(); |
167 this.updateControlsState(); | 169 this.updateControlsState(); |
168 }).bind(this)); | 170 }).bind(this)); |
169 | 171 |
170 this.authenticator_.addEventListener('dialogShown', | 172 this.authenticator_.addEventListener( |
171 (function(e) { | 173 'dialogShown', (function(e) { |
172 this.navigation_.disabled = true; | 174 this.navigation_.disabled = true; |
173 }).bind(this)); | 175 }).bind(this)); |
174 | 176 |
175 this.authenticator_.addEventListener('dialogHidden', | 177 this.authenticator_.addEventListener( |
176 (function(e) { | 178 'dialogHidden', (function(e) { |
177 this.navigation_.disabled = false; | 179 this.navigation_.disabled = false; |
178 }).bind(this)); | 180 }).bind(this)); |
179 | 181 |
180 this.authenticator_.insecureContentBlockedCallback = | 182 this.authenticator_.insecureContentBlockedCallback = |
181 (function(url) { | 183 (function(url) { |
182 this.showError( | 184 this.showError( |
183 loadTimeData.getStringF('insecureURLEnrollmentError', url), | 185 loadTimeData.getStringF('insecureURLEnrollmentError', url), |
184 false); | 186 false); |
185 }).bind(this); | 187 }).bind(this); |
186 | 188 |
187 this.authenticator_.missingGaiaInfoCallback = | 189 this.authenticator_.missingGaiaInfoCallback = |
188 (function() { | 190 (function() { |
189 this.showError( | 191 this.showError( |
190 loadTimeData.getString('fatalEnrollmentError'), | 192 loadTimeData.getString('fatalEnrollmentError'), false); |
191 false); | |
192 }).bind(this); | 193 }).bind(this); |
193 | 194 |
194 $('oauth-enroll-error-card').addEventListener('buttonclick', | 195 $('oauth-enroll-error-card') |
195 this.doRetry_.bind(this)); | 196 .addEventListener('buttonclick', this.doRetry_.bind(this)); |
196 function doneCallback() { | 197 function doneCallback() { |
197 chrome.send('oauthEnrollClose', ['done']); | 198 chrome.send('oauthEnrollClose', ['done']); |
198 } | 199 } |
199 | 200 |
200 $('oauth-enroll-attribute-prompt-error-card').addEventListener( | 201 $('oauth-enroll-attribute-prompt-error-card') |
201 'buttonclick', doneCallback); | 202 .addEventListener('buttonclick', doneCallback); |
202 $('oauth-enroll-success-card').addEventListener( | 203 $('oauth-enroll-success-card') |
203 'buttonclick', doneCallback); | 204 .addEventListener('buttonclick', doneCallback); |
204 $('oauth-enroll-abe-success-card').addEventListener( | 205 $('oauth-enroll-abe-success-card') |
205 'buttonclick', doneCallback); | 206 .addEventListener('buttonclick', doneCallback); |
206 $('oauth-enroll-active-directory-join-error-card').addEventListener( | 207 $('oauth-enroll-active-directory-join-error-card') |
207 'buttonclick', function() { | 208 .addEventListener('buttonclick', function() { |
208 this.showStep(STEP_AD_JOIN); | 209 this.showStep(STEP_AD_JOIN); |
209 }.bind(this)); | 210 }.bind(this)); |
210 | 211 |
211 this.navigation_.addEventListener('close', this.cancel.bind(this)); | 212 this.navigation_.addEventListener('close', this.cancel.bind(this)); |
212 this.navigation_.addEventListener('refresh', this.cancel.bind(this)); | 213 this.navigation_.addEventListener('refresh', this.cancel.bind(this)); |
213 | 214 |
214 this.navigation_.addEventListener('back', function() { | 215 this.navigation_.addEventListener('back', function() { |
215 this.navigation_.backVisible = false; | 216 this.navigation_.backVisible = false; |
216 if (this.currentStep_ == STEP_SIGNIN) | 217 if (this.currentStep_ == STEP_SIGNIN) |
217 $('oauth-enroll-auth-view').back(); | 218 $('oauth-enroll-auth-view').back(); |
218 }.bind(this)); | 219 }.bind(this)); |
219 | 220 |
220 $('oauth-enroll-attribute-prompt-card').addEventListener('submit', | 221 $('oauth-enroll-attribute-prompt-card') |
221 this.onAttributesSubmitted.bind(this)); | 222 .addEventListener('submit', this.onAttributesSubmitted.bind(this)); |
222 | 223 |
223 $('oauth-enroll-learn-more-link').addEventListener('click', | 224 $('oauth-enroll-learn-more-link') |
224 function(event) { | 225 .addEventListener('click', function(event) { |
225 chrome.send('oauthEnrollOnLearnMore'); | 226 chrome.send('oauthEnrollOnLearnMore'); |
226 }); | 227 }); |
227 | 228 |
228 $('oauth-enroll-skip-button').addEventListener('click', | 229 $('oauth-enroll-skip-button') |
229 this.onSkipButtonClicked.bind(this)); | 230 .addEventListener('click', this.onSkipButtonClicked.bind(this)); |
230 }, | 231 }, |
231 | 232 |
232 /** | 233 /** |
233 * Header text of the screen. | 234 * Header text of the screen. |
234 * @type {string} | 235 * @type {string} |
235 */ | 236 */ |
236 get header() { | 237 get header() { |
237 return loadTimeData.getString('oauthEnrollScreenTitle'); | 238 return loadTimeData.getString('oauthEnrollScreenTitle'); |
238 }, | 239 }, |
239 | 240 |
240 /** | 241 /** |
241 * Event handler that is invoked just before the frame is shown. | 242 * Event handler that is invoked just before the frame is shown. |
242 * @param {Object} data Screen init payload, contains the signin frame | 243 * @param {Object} data Screen init payload, contains the signin frame |
243 * URL. | 244 * URL. |
244 */ | 245 */ |
245 onBeforeShow: function(data) { | 246 onBeforeShow: function(data) { |
246 if (Oobe.getInstance().forceKeyboardFlow) { | 247 if (Oobe.getInstance().forceKeyboardFlow) { |
247 // We run the tab remapping logic inside of the webview so that the | 248 // We run the tab remapping logic inside of the webview so that the |
248 // simulated tab events will use the webview tab-stops. Simulated tab | 249 // simulated tab events will use the webview tab-stops. Simulated tab |
249 // events created from the webui treat the entire webview as one tab | 250 // events created from the webui treat the entire webview as one tab |
250 // stop. Real tab events do not do this. See crbug.com/543865. | 251 // stop. Real tab events do not do this. See crbug.com/543865. |
251 $('oauth-enroll-auth-view').addContentScripts([{ | 252 $('oauth-enroll-auth-view').addContentScripts([{ |
252 name: 'injectedTabHandler', | 253 name: 'injectedTabHandler', |
253 matches: ['http://*/*', 'https://*/*'], | 254 matches: ['http://*/*', 'https://*/*'], |
254 js: { code: INJECTED_WEBVIEW_SCRIPT }, | 255 js: {code: INJECTED_WEBVIEW_SCRIPT}, |
255 run_at: 'document_start' | 256 run_at: 'document_start' |
256 }]); | 257 }]); |
257 } | 258 } |
258 | 259 |
259 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.ENROLLMENT; | 260 $('login-header-bar').signinUIState = SIGNIN_UI_STATE.ENROLLMENT; |
260 $('progress-dots').hidden = true; | 261 $('progress-dots').hidden = true; |
261 this.classList.remove('saml'); | 262 this.classList.remove('saml'); |
262 | 263 |
263 var gaiaParams = {}; | 264 var gaiaParams = {}; |
264 gaiaParams.gaiaUrl = data.gaiaUrl; | 265 gaiaParams.gaiaUrl = data.gaiaUrl; |
265 gaiaParams.clientId = data.clientId; | 266 gaiaParams.clientId = data.clientId; |
266 gaiaParams.gaiaPath = 'embedded/setup/chromeos'; | 267 gaiaParams.gaiaPath = 'embedded/setup/chromeos'; |
267 gaiaParams.isNewGaiaFlow = true; | 268 gaiaParams.isNewGaiaFlow = true; |
268 gaiaParams.needPassword = false; | 269 gaiaParams.needPassword = false; |
269 if (data.management_domain) { | 270 if (data.management_domain) { |
270 gaiaParams.enterpriseDomain = data.management_domain; | 271 gaiaParams.enterpriseDomain = data.management_domain; |
271 gaiaParams.emailDomain = data.management_domain; | 272 gaiaParams.emailDomain = data.management_domain; |
272 } | 273 } |
273 gaiaParams.flow = data.flow; | 274 gaiaParams.flow = data.flow; |
274 this.authenticator_.load(cr.login.Authenticator.AuthMode.DEFAULT, | 275 this.authenticator_.load( |
275 gaiaParams); | 276 cr.login.Authenticator.AuthMode.DEFAULT, gaiaParams); |
276 | 277 |
277 var modes = ['manual', 'forced', 'recovery']; | 278 var modes = ['manual', 'forced', 'recovery']; |
278 for (var i = 0; i < modes.length; ++i) { | 279 for (var i = 0; i < modes.length; ++i) { |
279 this.classList.toggle('mode-' + modes[i], | 280 this.classList.toggle( |
280 data.enrollment_mode == modes[i]); | 281 'mode-' + modes[i], data.enrollment_mode == modes[i]); |
281 } | 282 } |
282 this.isManualEnrollment_ = data.enrollment_mode === 'manual'; | 283 this.isManualEnrollment_ = data.enrollment_mode === 'manual'; |
283 this.isCancelDisabled = true; | 284 this.isCancelDisabled = true; |
284 this.navigation_.disabled = false; | 285 this.navigation_.disabled = false; |
285 | 286 |
286 this.showStep(data.attestationBased ? STEP_WORKING : STEP_SIGNIN); | 287 this.showStep(data.attestationBased ? STEP_WORKING : STEP_SIGNIN); |
287 }, | 288 }, |
288 | 289 |
289 onBeforeHide: function() { | 290 onBeforeHide: function() { |
290 this.activeDirectoryMachine_ = null; | 291 this.activeDirectoryMachine_ = null; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } else if (step == STEP_ABE_SUCCESS) { | 342 } else if (step == STEP_ABE_SUCCESS) { |
342 $('oauth-enroll-abe-success-card').submitButton.focus(); | 343 $('oauth-enroll-abe-success-card').submitButton.focus(); |
343 } else if (step == STEP_ATTRIBUTE_PROMPT) { | 344 } else if (step == STEP_ATTRIBUTE_PROMPT) { |
344 $('oauth-enroll-asset-id').focus(); | 345 $('oauth-enroll-asset-id').focus(); |
345 } else if (step == STEP_ATTRIBUTE_PROMPT_ERROR) { | 346 } else if (step == STEP_ATTRIBUTE_PROMPT_ERROR) { |
346 $('oauth-enroll-attribute-prompt-error-card').submitButton.focus(); | 347 $('oauth-enroll-attribute-prompt-error-card').submitButton.focus(); |
347 } else if (step == STEP_ACTIVE_DIRECTORY_JOIN_ERROR) { | 348 } else if (step == STEP_ACTIVE_DIRECTORY_JOIN_ERROR) { |
348 $('oauth-enroll-active-directory-join-error-card').submitButton.focus(); | 349 $('oauth-enroll-active-directory-join-error-card').submitButton.focus(); |
349 } else if (step == STEP_AD_JOIN) { | 350 } else if (step == STEP_AD_JOIN) { |
350 this.offlineAdUi_.disabled = false; | 351 this.offlineAdUi_.disabled = false; |
351 this.offlineAdUi_.setUser(this.activeDirectoryUsername_, | 352 this.offlineAdUi_.setUser( |
352 this.activeDirectoryMachine_); | 353 this.activeDirectoryUsername_, this.activeDirectoryMachine_); |
353 this.offlineAdUi_.setInvalid(ACTIVE_DIRECTORY_ERROR_STATE.NONE); | 354 this.offlineAdUi_.setInvalid(ACTIVE_DIRECTORY_ERROR_STATE.NONE); |
354 } | 355 } |
355 | 356 |
356 this.currentStep_ = step; | 357 this.currentStep_ = step; |
357 this.lastBackMessageValue_ = false; | 358 this.lastBackMessageValue_ = false; |
358 this.updateControlsState(); | 359 this.updateControlsState(); |
359 }, | 360 }, |
360 | 361 |
361 /** | 362 /** |
362 * Sets an error message and switches to the error screen. | 363 * Sets an error message and switches to the error screen. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 */ | 410 */ |
410 onSkipButtonClicked: function() { | 411 onSkipButtonClicked: function() { |
411 this.showStep(STEP_SUCCESS); | 412 this.showStep(STEP_SUCCESS); |
412 }, | 413 }, |
413 | 414 |
414 /** | 415 /** |
415 * Uploads the device attributes to server. This goes to C++ side through | 416 * Uploads the device attributes to server. This goes to C++ side through |
416 * |chrome| and launches the device attribute update negotiation. | 417 * |chrome| and launches the device attribute update negotiation. |
417 */ | 418 */ |
418 onAttributesSubmitted: function() { | 419 onAttributesSubmitted: function() { |
419 chrome.send('oauthEnrollAttributes', | 420 chrome.send( |
420 [$('oauth-enroll-asset-id').value, | 421 'oauthEnrollAttributes', |
421 $('oauth-enroll-location').value]); | 422 [$('oauth-enroll-asset-id').value, $('oauth-enroll-location').value]); |
422 }, | 423 }, |
423 | 424 |
424 /** | 425 /** |
425 * Returns true if we are at the begging of enrollment flow (i.e. the email | 426 * Returns true if we are at the begging of enrollment flow (i.e. the email |
426 * page). | 427 * page). |
427 * | 428 * |
428 * @type {boolean} | 429 * @type {boolean} |
429 */ | 430 */ |
430 isAtTheBeginning: function() { | 431 isAtTheBeginning: function() { |
431 return !this.navigation_.backVisible && this.currentStep_ == STEP_SIGNIN; | 432 return !this.navigation_.backVisible && this.currentStep_ == STEP_SIGNIN; |
432 }, | 433 }, |
433 | 434 |
434 /** | 435 /** |
435 * Updates visibility of navigation buttons. | 436 * Updates visibility of navigation buttons. |
436 */ | 437 */ |
437 updateControlsState: function() { | 438 updateControlsState: function() { |
438 this.navigation_.backVisible = this.currentStep_ == STEP_SIGNIN && | 439 this.navigation_.backVisible = |
439 this.lastBackMessageValue_; | 440 this.currentStep_ == STEP_SIGNIN && this.lastBackMessageValue_; |
440 this.navigation_.refreshVisible = this.isAtTheBeginning() && | 441 this.navigation_.refreshVisible = |
441 !this.isManualEnrollment_; | 442 this.isAtTheBeginning() && !this.isManualEnrollment_; |
442 this.navigation_.closeVisible = | 443 this.navigation_.closeVisible = |
443 (this.currentStep_ == STEP_SIGNIN || | 444 (this.currentStep_ == STEP_SIGNIN || |
444 this.currentStep_ == STEP_ERROR || | 445 this.currentStep_ == STEP_ERROR || |
445 this.currentStep_ == STEP_ACTIVE_DIRECTORY_JOIN_ERROR || | 446 this.currentStep_ == STEP_ACTIVE_DIRECTORY_JOIN_ERROR || |
446 this.currentStep_ == STEP_AD_JOIN) && | 447 this.currentStep_ == STEP_AD_JOIN) && |
447 !this.navigation_.refreshVisible; | 448 !this.navigation_.refreshVisible; |
448 $('login-header-bar').updateUI_(); | 449 $('login-header-bar').updateUI_(); |
449 } | 450 } |
450 }; | 451 }; |
451 }); | 452 }); |
OLD | NEW |