| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Inline login UI. | 6 * @fileoverview Inline login UI. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 <include src="../gaia_auth_host/gaia_auth_host.js"> | |
| 10 | |
| 11 cr.define('inline.login', function() { | 9 cr.define('inline.login', function() { |
| 12 'use strict'; | 10 'use strict'; |
| 13 | 11 |
| 14 /** | 12 /** |
| 15 * The auth extension host instance. | 13 * The auth extension host instance. |
| 16 * @type {Object} | 14 * @type {cr.login.GaiaAuthHost} |
| 17 */ | 15 */ |
| 18 var authExtHost; | 16 var authExtHost; |
| 19 | 17 |
| 20 /** | 18 /** |
| 21 * Whether the auth ready event has been fired, for testing purpose. | 19 * Whether the auth ready event has been fired, for testing purpose. |
| 22 */ | 20 */ |
| 23 var authReadyFired; | 21 var authReadyFired; |
| 24 | 22 |
| 25 /** | 23 /** |
| 24 * A listener class for authentication events from GaiaAuthHost. |
| 25 * @constructor |
| 26 * @implements {cr.login.GaiaAuthHost.Listener} |
| 27 */ |
| 28 function GaiaAuthHostListener() {} |
| 29 |
| 30 /** @override */ |
| 31 GaiaAuthHostListener.prototype.onSuccess = function(credentials) { |
| 32 onAuthCompleted(credentials); |
| 33 }; |
| 34 |
| 35 /** @override */ |
| 36 GaiaAuthHostListener.prototype.onReady = function(e) { |
| 37 onAuthReady(); |
| 38 }; |
| 39 |
| 40 /** @override */ |
| 41 GaiaAuthHostListener.prototype.onResize = function(url) { |
| 42 chrome.send('switchToFullTab', url); |
| 43 }; |
| 44 |
| 45 /** @override */ |
| 46 GaiaAuthHostListener.prototype.onNewWindow = function(e) { |
| 47 window.open(e.targetUrl, '_blank'); |
| 48 e.window.discard(); |
| 49 }; |
| 50 |
| 51 /** |
| 26 * Handler of auth host 'ready' event. | 52 * Handler of auth host 'ready' event. |
| 27 */ | 53 */ |
| 28 function onAuthReady() { | 54 function onAuthReady() { |
| 29 $('contents').classList.toggle('loading', false); | 55 $('contents').classList.toggle('loading', false); |
| 30 authReadyFired = true; | 56 authReadyFired = true; |
| 31 } | 57 } |
| 32 | 58 |
| 33 /** | 59 /** |
| 34 * Handler of auth host 'completed' event. | 60 * Handler of auth host 'completed' event. |
| 35 * @param {!Object} credentials Credentials of the completed authentication. | 61 * @param {!Object} credentials Credentials of the completed authentication. |
| 36 */ | 62 */ |
| 37 function onAuthCompleted(credentials) { | 63 function onAuthCompleted(credentials) { |
| 38 chrome.send('completeLogin', [credentials]); | 64 chrome.send('completeLogin', [credentials]); |
| 39 $('contents').classList.toggle('loading', true); | 65 $('contents').classList.toggle('loading', true); |
| 40 } | 66 } |
| 41 | 67 |
| 42 /** | 68 /** |
| 43 * Initialize the UI. | 69 * Initialize the UI. |
| 44 */ | 70 */ |
| 45 function initialize() { | 71 function initialize() { |
| 46 authExtHost = new cr.login.GaiaAuthHost('signin-frame'); | 72 authExtHost = new cr.login.GaiaAuthHost( |
| 73 'signin-frame', new GaiaAuthHostListener()); |
| 47 authExtHost.addEventListener('ready', onAuthReady); | 74 authExtHost.addEventListener('ready', onAuthReady); |
| 48 | 75 |
| 49 chrome.send('initialize'); | 76 chrome.send('initialize'); |
| 50 } | 77 } |
| 51 | 78 |
| 52 /** | 79 /** |
| 53 * Loads auth extension. | 80 * Loads auth extension. |
| 54 * @param {Object} data Parameters for auth extension. | 81 * @param {Object} data Parameters for auth extension. |
| 55 */ | 82 */ |
| 56 function loadAuthExtension(data) { | 83 function loadAuthExtension(data) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 getAuthExtHost: getAuthExtHost, | 121 getAuthExtHost: getAuthExtHost, |
| 95 isAuthReady: isAuthReady, | 122 isAuthReady: isAuthReady, |
| 96 initialize: initialize, | 123 initialize: initialize, |
| 97 loadAuthExtension: loadAuthExtension, | 124 loadAuthExtension: loadAuthExtension, |
| 98 closeDialog: closeDialog, | 125 closeDialog: closeDialog, |
| 99 handleOAuth2TokenFailure: handleOAuth2TokenFailure | 126 handleOAuth2TokenFailure: handleOAuth2TokenFailure |
| 100 }; | 127 }; |
| 101 }); | 128 }); |
| 102 | 129 |
| 103 document.addEventListener('DOMContentLoaded', inline.login.initialize); | 130 document.addEventListener('DOMContentLoaded', inline.login.initialize); |
| OLD | NEW |