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
3 // found in the LICENSE file.
5 login.createScreen('OAuthEnrollmentScreen', 'oauth-enrollment', function() {
6 /** @const */ var STEP_SIGNIN = 'signin';
7 /** @const */ var STEP_WORKING = 'working';
8 /** @const */ var STEP_ERROR = 'error';
9 /** @const */ var STEP_EXPLAIN = 'explain';
10 /** @const */ var STEP_SUCCESS = 'success';
14 'setIsAutoEnrollment',
21 * URL to load in the sign in frame.
26 * Whether this is a manual or auto enrollment.
28 isAutoEnrollment_: false,
31 * True if enrollment cancellation should be prevented.
33 preventCancellation_: false,
36 * Enrollment steps with names and buttons to show.
41 * Dialog to confirm that auto-enrollment should really be cancelled.
42 * This is only created the first time it's used.
47 * The current step. This is the last value passed to showStep().
52 decorate: function() {
53 window.addEventListener('message',
54 this.onMessage_.bind(this), false);
55 $('oauth-enroll-error-retry').addEventListener('click',
56 this.doRetry_.bind(this));
57 var links = document.querySelectorAll('.oauth-enroll-explain-link');
58 for (var i = 0; i < links.length; i++) {
59 links[i].addEventListener('click',
60 this.showStep.bind(this, STEP_EXPLAIN));
65 * Header text of the screen.
69 return loadTimeData.getString('oauthEnrollScreenTitle');
73 * Buttons in oobe wizard's button strip.
74 * @type {array} Array of Buttons.
79 var cancelButton = this.ownerDocument.createElement('button');
80 cancelButton.id = 'oauth-enroll-cancel-button';
81 cancelButton.textContent = loadTimeData.getString('oauthEnrollCancel');
83 cancelButton.addEventListener('click', function(e) {
84 chrome.send('oauthEnrollClose', ['cancel']);
86 buttons.push(cancelButton);
88 var tryAgainButton = this.ownerDocument.createElement('button');
89 tryAgainButton.id = 'oauth-enroll-try-again-button';
90 tryAgainButton.hidden = true;
91 tryAgainButton.textContent =
92 loadTimeData.getString('oauthEnrollRetry');
93 tryAgainButton.addEventListener('click', this.doRetry_.bind(this));
94 buttons.push(tryAgainButton);
96 var explainButton = this.ownerDocument.createElement('button');
97 explainButton.id = 'oauth-enroll-explain-button';
98 explainButton.hidden = true;
99 explainButton.textContent =
100 loadTimeData.getString('oauthEnrollExplainButton');
101 explainButton.addEventListener('click', this.doRetry_.bind(this));
102 buttons.push(explainButton);
104 var doneButton = this.ownerDocument.createElement('button');
105 doneButton.id = 'oauth-enroll-done-button';
106 doneButton.hidden = true;
107 doneButton.textContent =
108 loadTimeData.getString('oauthEnrollDone');
109 doneButton.addEventListener('click', function(e) {
110 chrome.send('oauthEnrollClose', ['done']);
112 buttons.push(doneButton);
118 * Sets the |isAutoEnrollment| flag of the OAuthEnrollmentScreen class and
120 * @param {boolean} is_auto_enrollment the new value of the flag.
122 setIsAutoEnrollment: function(is_auto_enrollment) {
123 this.isAutoEnrollment_ = is_auto_enrollment;
124 // The cancel button is not available during auto-enrollment.
125 var cancel = this.isAutoEnrollment_ ? null : 'cancel';
126 // During auto-enrollment the user must try again from the error screen.
127 var errorCancel = this.isAutoEnrollment_ ? 'try-again' : 'cancel';
140 focusButton: this.isAutoEnrollment_
154 var links = document.querySelectorAll('.oauth-enroll-explain-link');
155 for (var i = 0; i < links.length; i++) {
156 links[i].hidden = !this.isAutoEnrollment_;
161 * Event handler that is invoked just before the frame is shown.
162 * @param {Object} data Screen init payload, contains the signin frame
165 onBeforeShow: function(data) {
166 var url = data.signin_url;
167 url += '?gaiaUrl=' + encodeURIComponent(data.gaiaUrl);
168 this.signInUrl_ = url;
169 this.setIsAutoEnrollment(data.is_auto_enrollment);
170 this.preventCancellation_ = data.prevent_cancellation;
171 $('oauth-enroll-signin-frame').contentWindow.location.href =
173 if (this.preventCancellation_) {
174 $('oauth-enroll-cancel-button').textContent =
175 loadTimeData.getString('oauthEnrollCancelAutoEnrollmentGoBack');
178 this.showStep(STEP_SIGNIN);
182 * Cancels enrollment and drops the user back to the login screen.
185 if (this.isAutoEnrollment_)
188 chrome.send('oauthEnrollClose', ['cancel']);
192 * Switches between the different steps in the enrollment flow.
193 * @param {string} step the steps to show, one of "signin", "working",
194 * "error", "success".
196 showStep: function(step) {
197 this.currentStep_ = step;
198 $('oauth-enroll-cancel-button').hidden = true;
199 $('oauth-enroll-try-again-button').hidden = true;
200 $('oauth-enroll-explain-button').hidden = true;
201 $('oauth-enroll-done-button').hidden = true;
202 for (var i = 0; i < this.steps_.length; i++) {
203 var theStep = this.steps_[i];
204 var active = (theStep.name == step);
205 $('oauth-enroll-step-' + theStep.name).hidden = !active;
206 if (active && theStep.button) {
207 var button = $('oauth-enroll-' + theStep.button + '-button');
208 button.hidden = false;
209 if (theStep.focusButton)
216 * Sets an error message and switches to the error screen.
217 * @param {string} message the error message.
218 * @param {boolean} retry whether the retry link should be shown.
220 showError: function(message, retry) {
221 $('oauth-enroll-error-message').textContent = message;
222 $('oauth-enroll-error-retry').hidden = !retry || this.isAutoEnrollment_;
223 this.showStep(STEP_ERROR);
227 * Sets a progressing message and switches to the working screen.
228 * @param {string} message the progress message.
230 showWorking: function(message) {
231 $('oauth-enroll-working-message').textContent = message;
232 this.showStep(STEP_WORKING);
236 * Handler for cancellations of an enforced auto-enrollment.
238 cancelAutoEnrollment: function() {
239 // Check if this is forced enrollment flow for a kiosk app.
240 if (this.preventCancellation_)
243 // The dialog to confirm cancellation of auto-enrollment is only shown
244 // if this is an auto-enrollment, and if the user is currently in the
246 if (!this.isAutoEnrollment_ || this.currentStep_ !== STEP_EXPLAIN)
248 if (!this.confirmDialog_) {
249 this.confirmDialog_ = new cr.ui.dialogs.ConfirmDialog(document.body);
250 this.confirmDialog_.setOkLabel(
251 loadTimeData.getString('oauthEnrollCancelAutoEnrollmentConfirm'));
252 this.confirmDialog_.setCancelLabel(
253 loadTimeData.getString('oauthEnrollCancelAutoEnrollmentGoBack'));
254 this.confirmDialog_.setInitialFocusOnCancel();
256 this.confirmDialog_.show(
257 loadTimeData.getString('oauthEnrollCancelAutoEnrollmentReally'),
258 this.onConfirmCancelAutoEnrollment_.bind(this));
262 * Retries the enrollment process after an error occurred in a previous
263 * attempt. This goes to the C++ side through |chrome| first to clean up the
264 * profile, so that the next attempt is performed with a clean state.
266 doRetry_: function() {
267 chrome.send('oauthEnrollRetry');
271 * Handler for confirmation of cancellation of auto-enrollment.
273 onConfirmCancelAutoEnrollment_: function() {
274 chrome.send('oauthEnrollClose', ['autocancel']);
278 * Checks if a given HTML5 message comes from the URL loaded into the signin
280 * @param {Object} m HTML5 message.
281 * @type {boolean} whether the message comes from the signin frame.
283 isSigninMessage_: function(m) {
284 return this.signInUrl_ != null &&
285 this.signInUrl_.indexOf(m.origin) == 0 &&
286 m.source == $('oauth-enroll-signin-frame').contentWindow;
290 * Event handler for HTML5 messages.
291 * @param {Object} m HTML5 message.
293 onMessage_: function(m) {
294 if (!this.isSigninMessage_(m))
299 // 'completeLogin' for full gaia signin flow. For SAML case,
300 // 'confirmPassword' is sent after authentication. Since enrollment
301 // does not need the actual password, this is treated the same as
303 if (msg.method == 'completeLogin' || msg.method == 'confirmPassword')
304 chrome.send('oauthEnrollCompleteLogin', [msg.email]);