1 // Copyright 2013 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.
6 * @fileoverview Inline login UI.
9 <include src
="../gaia_auth_host/gaia_auth_host.js">
11 cr
.define('inline.login', function() {
15 * The auth extension host instance.
21 * Whether the auth ready event has been fired, for testing purpose.
26 * Handler of auth host 'ready' event.
28 function onAuthReady() {
29 $('contents').classList
.toggle('loading', false);
30 authReadyFired
= true;
34 * Handler of auth host 'completed' event.
35 * @param {!Object} credentials Credentials of the completed authentication.
37 function onAuthCompleted(credentials
) {
38 chrome
.send('completeLogin', [credentials
]);
39 $('contents').classList
.toggle('loading', true);
45 function initialize() {
46 authExtHost
= new cr
.login
.GaiaAuthHost('signin-frame');
47 authExtHost
.addEventListener('ready', onAuthReady
);
49 chrome
.send('initialize');
53 * Loads auth extension.
54 * @param {Object} data Parameters for auth extension.
56 function loadAuthExtension(data
) {
57 authExtHost
.load(data
.authMode
, data
, onAuthCompleted
);
58 $('contents').classList
.toggle('loading',
59 data
.authMode
!= cr
.login
.GaiaAuthHost
.AuthMode
.DESKTOP
||
60 data
.constrained
== '1');
64 * Closes the inline login dialog.
66 function closeDialog() {
67 chrome
.send('dialogClose', ['']);
71 * Invoked when failed to get oauth2 refresh token.
73 function handleOAuth2TokenFailure() {
74 // TODO(xiyuan): Show an error UI.
76 $('contents').classList
.toggle('loading', true);
80 * Returns the auth host instance, for testing purpose.
82 function getAuthExtHost() {
87 * Returns whether the auth UI is ready, for testing purpose.
89 function isAuthReady() {
90 return authReadyFired
;
94 getAuthExtHost
: getAuthExtHost
,
95 isAuthReady
: isAuthReady
,
96 initialize
: initialize
,
97 loadAuthExtension
: loadAuthExtension
,
98 closeDialog
: closeDialog
,
99 handleOAuth2TokenFailure
: handleOAuth2TokenFailure
103 document
.addEventListener('DOMContentLoaded', inline
.login
.initialize
);