1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Inline login UI.
*/
<include src="../gaia_auth_host/gaia_auth_host.js"></include>
cr.define('inline.login', function() {
'use strict';
/**
* The auth extension host instance.
* @type {Object}
*/
var authExtHost;
/**
* Handler of auth host 'ready' event.
*/
function onAuthReady() {
$('contents').classList.toggle('loading', false);
}
/**
* Handler of auth host 'completed' event.
* @param {!Object} credentials Credentials of the completed authentication.
*/
function onAuthCompleted(credentials) {
chrome.send('completeLogin', [credentials]);
$('contents').classList.toggle('loading', true);
}
/**
* Initialize the UI.
*/
function initialize() {
authExtHost = new cr.login.GaiaAuthHost('signin-frame');
authExtHost.addEventListener('ready', onAuthReady);
chrome.send('initialize');
}
/**
* Loads auth extension.
* @param {Object} data Parameters for auth extension.
*/
function loadAuthExtension(data) {
authExtHost.load(data.authMode, data, onAuthCompleted);
// Do not show loading spinner to give user a faster response
// with inline flows.
$('contents').classList.toggle('loading',
data.authMode != cr.login.GaiaAuthHost.AuthMode.INLINE);
}
/**
* Closes the inline login dialog.
*/
function closeDialog() {
chrome.send('DialogClose', ['']);
}
/**
* Invoked when failed to get oauth2 refresh token.
*/
function handleOAuth2TokenFailure() {
// TODO(xiyuan): Show an error UI.
authExtHost.reload();
$('contents').classList.toggle('loading', true);
}
return {
initialize: initialize,
loadAuthExtension: loadAuthExtension,
closeDialog: closeDialog,
handleOAuth2TokenFailure: handleOAuth2TokenFailure
};
});
document.addEventListener('DOMContentLoaded', inline.login.initialize);
|