[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / resources / inline_login / inline_login.js
blob684216a9b2bddf53808367e17231a6a941d0b08d
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 cr.define('inline.login', function() {
10 'use strict';
12 /**
13 * The auth extension host instance.
14 * @type {cr.login.GaiaAuthHost}
16 var authExtHost;
18 /**
19 * Whether the auth ready event has been fired, for testing purpose.
21 var authReadyFired;
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);
51 /**
52 * Initialize the UI.
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');
64 /**
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');
77 /**
78 * Closes the inline login dialog.
80 function closeDialog() {
81 chrome.send('dialogClose', ['']);
84 /**
85 * Invoked when failed to get oauth2 refresh token.
87 function handleOAuth2TokenFailure() {
88 // TODO(xiyuan): Show an error UI.
89 authExtHost.reload();
90 $('contents').classList.toggle('loading', true);
93 /**
94 * Returns the auth host instance, for testing purpose.
96 function getAuthExtHost() {
97 return authExtHost;
101 * Returns whether the auth UI is ready, for testing purpose.
103 function isAuthReady() {
104 return authReadyFired;
107 return {
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);