OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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. |
| 4 |
| 5 cr.define('oobe', function() { |
| 6 /** |
| 7 * Creates a new oobe screen div. |
| 8 * @constructor |
| 9 * @extends {HTMLDivElement} |
| 10 */ |
| 11 var OAuthEnrollmentScreen = cr.ui.define('div'); |
| 12 |
| 13 /** |
| 14 * Registers with Oobe. |
| 15 */ |
| 16 OAuthEnrollmentScreen.register = function() { |
| 17 var screen = $('oauth-enrollment'); |
| 18 OAuthEnrollmentScreen.decorate(screen); |
| 19 Oobe.getInstance().registerScreen(screen); |
| 20 window.addEventListener('message', |
| 21 screen.onMessage_.bind(screen), false); |
| 22 }; |
| 23 |
| 24 /** |
| 25 * Switches between the different steps in the enrollment flow. |
| 26 * @param screen {string} the steps to show, one of "signin", "working", |
| 27 * "error", "success". |
| 28 */ |
| 29 OAuthEnrollmentScreen.showStep = function(step) { |
| 30 $('oauth-enrollment').showStep(step); |
| 31 }; |
| 32 |
| 33 /** |
| 34 * Sets an error message and switches to the error screen. |
| 35 * @param message {string} the error message. |
| 36 * @param retry {bool} whether the retry link should be shown. |
| 37 */ |
| 38 OAuthEnrollmentScreen.showError = function(message, retry) { |
| 39 $('oauth-enrollment').showError(message, retry); |
| 40 }; |
| 41 |
| 42 OAuthEnrollmentScreen.prototype = { |
| 43 __proto__: HTMLDivElement.prototype, |
| 44 |
| 45 /** |
| 46 * URL to load in the sign in frame. |
| 47 */ |
| 48 signin_url_ : null, |
| 49 |
| 50 /** |
| 51 * Enrollment steps with names and buttons to show. |
| 52 */ |
| 53 steps_ : [ |
| 54 { name: 'signin', |
| 55 button: 'cancel' }, |
| 56 { name: 'working', |
| 57 button: 'cancel' }, |
| 58 { name: 'error', |
| 59 button: 'cancel' }, |
| 60 { name: 'success', |
| 61 button: 'done' } |
| 62 ], |
| 63 |
| 64 /** @inheritDoc */ |
| 65 decorate: function() { |
| 66 // TODO(altimofeev): add accelerators for the Enterprise Enrollment |
| 67 // screen. |
| 68 }, |
| 69 |
| 70 /** |
| 71 * Header text of the screen. |
| 72 * @type {string} |
| 73 */ |
| 74 get header() { |
| 75 return localStrings.getString('oauthEnrollScreenTitle'); |
| 76 }, |
| 77 |
| 78 /** |
| 79 * Buttons in oobe wizard's button strip. |
| 80 * @type {array} Array of Buttons. |
| 81 */ |
| 82 get buttons() { |
| 83 var buttons = []; |
| 84 |
| 85 var cancelButton = this.ownerDocument.createElement('button'); |
| 86 cancelButton.id = 'oauth-enroll-button-cancel'; |
| 87 cancelButton.textContent = |
| 88 localStrings.getString('oauthEnrollCancel'); |
| 89 cancelButton.addEventListener('click', function(e) { |
| 90 chrome.send('oauthEnrollClose', []); |
| 91 }); |
| 92 buttons.push(cancelButton); |
| 93 |
| 94 var doneButton = this.ownerDocument.createElement('button'); |
| 95 doneButton.id = 'oauth-enroll-button-done'; |
| 96 doneButton.hidden = true; |
| 97 doneButton.textContent = |
| 98 localStrings.getString('oauthEnrollDone'); |
| 99 doneButton.addEventListener('click', function(e) { |
| 100 chrome.send('oauthEnrollClose', []); |
| 101 }); |
| 102 buttons.push(doneButton); |
| 103 |
| 104 return buttons; |
| 105 }, |
| 106 |
| 107 /** |
| 108 * Event handler that is invoked just before the frame is shown. |
| 109 * @param data {dictionary} Screen init payload, contains the signin frame |
| 110 * URL. |
| 111 */ |
| 112 onBeforeShow: function(data) { |
| 113 this.signin_url_ = data.signin_url; |
| 114 $('oauth-enroll-signin-frame').contentWindow.location.href = |
| 115 this.signin_url_; |
| 116 this.showStep('signin'); |
| 117 }, |
| 118 |
| 119 /** |
| 120 * Switches between the different steps in the enrollment flow. |
| 121 * @param screen {string} the steps to show, one of "signin", "working", |
| 122 * "error", "success". |
| 123 */ |
| 124 showStep: function(step) { |
| 125 $('oauth-enroll-button-cancel').hidden = true; |
| 126 $('oauth-enroll-button-done').hidden = true; |
| 127 for (var i = 0; i < this.steps_.length; i++) { |
| 128 var the_step = this.steps_[i]; |
| 129 var active = (the_step.name == step); |
| 130 $('oauth-enroll-step-' + the_step.name).hidden = !active; |
| 131 if (active) { |
| 132 $('oauth-enroll-button-' + the_step.button).hidden = false; |
| 133 } |
| 134 } |
| 135 }, |
| 136 |
| 137 /** |
| 138 * Sets an error message and switches to the error screen. |
| 139 * @param message {string} the error message. |
| 140 * @param retry {bool} whether the retry link should be shown. |
| 141 */ |
| 142 showError: function(message, retry) { |
| 143 $('oauth-enroll-error-message').textContent = message; |
| 144 $('oauth-enroll-error-retry').hidden = !retry; |
| 145 this.showStep('error'); |
| 146 }, |
| 147 |
| 148 /** |
| 149 * Checks if a given HTML5 message comes from the URL loaded into the signin |
| 150 * frame. |
| 151 * @param m {object} HTML5 message. |
| 152 * @type {bool} whether the message comes from the signin frame. |
| 153 */ |
| 154 isSigninMessage_: function(m) { |
| 155 return this.signin_url_ != null && |
| 156 this.signin_url_.indexOf(m.origin) == 0 && |
| 157 m.source == $('oauth-enroll-signin-frame').contentWindow; |
| 158 }, |
| 159 |
| 160 /** |
| 161 * Event handler for HTML5 messages. |
| 162 * @param m {object} HTML5 message. |
| 163 */ |
| 164 onMessage_: function(m) { |
| 165 var msg = m.data; |
| 166 if (msg.method == 'completeLogin' && this.isSigninMessage_(m)) { |
| 167 chrome.send('oauthEnrollCompleteLogin', [ msg.email, msg.password ]); |
| 168 } |
| 169 } |
| 170 }; |
| 171 |
| 172 return { |
| 173 OAuthEnrollmentScreen: OAuthEnrollmentScreen |
| 174 }; |
| 175 }); |
OLD | NEW |