Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / resources / inline_login / inline_login.js
blob82ed0922e3901cb5189d3e1094a7eaac535ac2a8
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.
5 /**
6 * @fileoverview Inline login UI.
7 */
9 <include src="../gaia_auth_host/gaia_auth_host.js">
11 cr.define('inline.login', function() {
12 'use strict';
14 /**
15 * The auth extension host instance.
16 * @type {Object}
18 var authExtHost;
20 /**
21 * Whether the auth ready event has been fired, for testing purpose.
23 var authReadyFired;
25 /**
26 * Handler of auth host 'ready' event.
28 function onAuthReady() {
29 $('contents').classList.toggle('loading', false);
30 authReadyFired = true;
33 /**
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);
42 /**
43 * Initialize the UI.
45 function initialize() {
46 authExtHost = new cr.login.GaiaAuthHost('signin-frame');
47 authExtHost.addEventListener('ready', onAuthReady);
49 chrome.send('initialize');
52 /**
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');
63 /**
64 * Closes the inline login dialog.
66 function closeDialog() {
67 chrome.send('dialogClose', ['']);
70 /**
71 * Invoked when failed to get oauth2 refresh token.
73 function handleOAuth2TokenFailure() {
74 // TODO(xiyuan): Show an error UI.
75 authExtHost.reload();
76 $('contents').classList.toggle('loading', true);
79 /**
80 * Returns the auth host instance, for testing purpose.
82 function getAuthExtHost() {
83 return authExtHost;
86 /**
87 * Returns whether the auth UI is ready, for testing purpose.
89 function isAuthReady() {
90 return authReadyFired;
93 return {
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);