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 cr.define('inline.login', function() {
13 * The auth extension host instance.
14 * @type {cr.login.GaiaAuthHost}
19 * Whether the auth ready event has been fired, for testing purpose.
23 function onResize(e) {
24 chrome.send('switchToFullTab', [e.detail]);
27 function onAuthReady(e) {
28 $('contents').classList.toggle('loading', false);
29 authReadyFired = true;
32 function onDropLink(e) {
33 // Navigate to the dropped link.
34 window.location.href = e.detail;
37 function onNewWindow(e) {
38 window.open(e.detail.targetUrl, '_blank');
39 e.detail.window.discard();
42 function onAuthCompleted(e) {
43 completeLogin(e.detail);
46 function completeLogin(credentials) {
47 chrome.send('completeLogin', [credentials]);
48 $('contents').classList.toggle('loading', true);
54 function initialize() {
55 authExtHost = new cr.login.GaiaAuthHost('signin-frame');
56 authExtHost.addEventListener('dropLink', onDropLink);
57 authExtHost.addEventListener('ready', onAuthReady);
58 authExtHost.addEventListener('newWindow', onNewWindow);
59 authExtHost.addEventListener('resize', onResize);
60 authExtHost.addEventListener('authCompleted', onAuthCompleted);
61 chrome.send('initialize');
65 * Loads auth extension.
66 * @param {Object} data Parameters for auth extension.
68 function loadAuthExtension(data) {
69 // TODO(rogerta): in when using webview, the |completeLogin| argument
70 // is ignored. See addEventListener() call above.
71 authExtHost.load(data.authMode, data, completeLogin);
72 $('contents').classList.toggle('loading',
73 data.authMode != cr.login.GaiaAuthHost.AuthMode.DESKTOP ||
74 data.constrained == '1');
78 * Closes the inline login dialog.
80 function closeDialog() {
81 chrome.send('dialogClose', ['']);
85 * Invoked when failed to get oauth2 refresh token.
87 function handleOAuth2TokenFailure() {
88 // TODO(xiyuan): Show an error UI.
90 $('contents').classList.toggle('loading', true);
94 * Returns the auth host instance, for testing purpose.
96 function getAuthExtHost() {
101 * Returns whether the auth UI is ready, for testing purpose.
103 function isAuthReady() {
104 return authReadyFired;
108 getAuthExtHost: getAuthExtHost,
109 isAuthReady: isAuthReady,
110 initialize: initialize,
111 loadAuthExtension: loadAuthExtension,
112 closeDialog: closeDialog,
113 handleOAuth2TokenFailure: handleOAuth2TokenFailure
117 document.addEventListener('DOMContentLoaded', inline.login.initialize);