| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 signin screen implementation. | 6 * @fileoverview Oobe signin screen implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('login', function() { | 9 cr.define('login', function() { |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * Header text of the screen. | 46 * Header text of the screen. |
| 47 * @type {string} | 47 * @type {string} |
| 48 */ | 48 */ |
| 49 get header() { | 49 get header() { |
| 50 return localStrings.getString('signinScreenTitle'); | 50 return localStrings.getString('signinScreenTitle'); |
| 51 }, | 51 }, |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Shows/hides loading UI. |
| 55 * @param {boolean} show True to show loading UI. |
| 56 * @private |
| 57 */ |
| 58 showLoadingUI_: function(show) { |
| 59 $('gaia-loading').hidden = !show; |
| 60 $('signin-frame').hidden = show; |
| 61 $('signin-right').hidden = show; |
| 62 }, |
| 63 |
| 64 /** |
| 65 * Whether Gaia is loading. |
| 66 * @type {boolean} |
| 67 */ |
| 68 get gaiaLoading() { |
| 69 return !$('gaia-loading').hidden; |
| 70 }, |
| 71 set gaiaLoading(loading) { |
| 72 if (loading == this.gaiaLoading) |
| 73 return; |
| 74 |
| 75 this.showLoadingUI_(loading); |
| 76 }, |
| 77 |
| 78 /** |
| 54 * Event handler that is invoked just before the frame is shown. | 79 * Event handler that is invoked just before the frame is shown. |
| 55 * @param data {string} Screen init payload. Url of auth extension start | 80 * @param data {string} Screen init payload. Url of auth extension start |
| 56 * page. | 81 * page. |
| 57 */ | 82 */ |
| 58 onBeforeShow: function(data) { | 83 onBeforeShow: function(data) { |
| 59 console.log('Opening extension: ' + data.startUrl + | 84 console.log('Opening extension: ' + data.startUrl + |
| 60 ', opt_email=' + data.email); | 85 ', opt_email=' + data.email); |
| 61 var frame = $('signin-frame'); | 86 var frame = $('signin-frame'); |
| 62 frame.addEventListener('load', function(e) { | 87 frame.addEventListener('load', function(e) { |
| 63 console.log('Frame loaded: ' + data.startUrl); | 88 console.log('Frame loaded: ' + data.startUrl); |
| 64 }); | 89 }); |
| 65 frame.contentWindow.location.href = data.startUrl; | 90 frame.contentWindow.location.href = data.startUrl; |
| 66 this.extension_url_ = data.startUrl; | 91 this.extension_url_ = data.startUrl; |
| 67 // TODO(xiyuan): Pre-populate Gaia with data.email (if any). | 92 // TODO(xiyuan): Pre-populate Gaia with data.email (if any). |
| 68 | 93 |
| 69 $('createAccount').hidden = !data.createAccount; | 94 $('createAccount').hidden = !data.createAccount; |
| 70 $('guestSignin').hidden = !data.guestSignin; | 95 $('guestSignin').hidden = !data.guestSignin; |
| 96 |
| 97 this.gaiaLoading = true; |
| 71 }, | 98 }, |
| 72 | 99 |
| 73 /** | 100 /** |
| 74 * Checks if message comes from the loaded authentication extension. | 101 * Checks if message comes from the loaded authentication extension. |
| 75 * @param e {object} Payload of the received HTML5 message. | 102 * @param e {object} Payload of the received HTML5 message. |
| 76 * @type {bool} | 103 * @type {bool} |
| 77 */ | 104 */ |
| 78 isAuthExtMessage_: function(e) { | 105 isAuthExtMessage_: function(e) { |
| 79 return this.extension_url_ != null && | 106 return this.extension_url_ != null && |
| 80 this.extension_url_.indexOf(e.origin) == 0 && | 107 this.extension_url_.indexOf(e.origin) == 0 && |
| 81 e.source == $('signin-frame').contentWindow; | 108 e.source == $('signin-frame').contentWindow; |
| 82 }, | 109 }, |
| 83 | 110 |
| 84 /** | 111 /** |
| 85 * Event handler that is invoked when HTML5 message is received. | 112 * Event handler that is invoked when HTML5 message is received. |
| 86 * @param e {object} Payload of the received HTML5 message. | 113 * @param e {object} Payload of the received HTML5 message. |
| 87 */ | 114 */ |
| 88 onMessage_: function(e) { | 115 onMessage_: function(e) { |
| 89 var msg = e.data; | 116 var msg = e.data; |
| 90 if (msg.method == 'completeLogin' && this.isAuthExtMessage_(e)) { | 117 if (msg.method == 'completeLogin' && this.isAuthExtMessage_(e)) { |
| 91 chrome.send('completeLogin', [msg.email, msg.password] ); | 118 chrome.send('completeLogin', [msg.email, msg.password] ); |
| 119 } else if (msg.method == 'loginUILoaded' && this.isAuthExtMessage_(e)) { |
| 120 this.gaiaLoading = false; |
| 92 } | 121 } |
| 93 }, | 122 }, |
| 94 | 123 |
| 95 /** | 124 /** |
| 96 * Clears input fields and switches to input mode. | 125 * Clears input fields and switches to input mode. |
| 97 * @param {boolean} takeFocus True to take focus. | 126 * @param {boolean} takeFocus True to take focus. |
| 98 */ | 127 */ |
| 99 reset: function(takeFocus) { | 128 reset: function(takeFocus) { |
| 100 // Reload and show the sign-in UI. | 129 // Reload and show the sign-in UI. |
| 101 Oobe.showSigninUI(); | 130 Oobe.showSigninUI(); |
| 102 } | 131 } |
| 103 }; | 132 }; |
| 104 | 133 |
| 105 return { | 134 return { |
| 106 GaiaSigninScreen: GaiaSigninScreen | 135 GaiaSigninScreen: GaiaSigninScreen |
| 107 }; | 136 }; |
| 108 }); | 137 }); |
| OLD | NEW |