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 cr.define('inline.login', function() { | 9 cr.define('inline.login', function() { |
10 'use strict'; | 10 'use strict'; |
11 | 11 |
12 /** | 12 /** |
13 * The auth extension host instance. | 13 * The auth extension host instance. |
14 * @type {cr.login.GaiaAuthHost} | 14 * @type {cr.login.GaiaAuthHost} |
15 */ | 15 */ |
16 var authExtHost; | 16 var authExtHost; |
17 | 17 |
18 /** | 18 /** |
19 * Whether the auth ready event has been fired, for testing purpose. | 19 * Whether the auth ready event has been fired, for testing purpose. |
20 */ | 20 */ |
21 var authReadyFired; | 21 var authReadyFired; |
22 | 22 |
23 /** | 23 function onResize(e) { |
24 * A listener class for authentication events from GaiaAuthHost. | 24 chrome.send('switchToFullTab', [e.detail]); |
25 * @constructor | 25 } |
26 * @implements {cr.login.GaiaAuthHost.Listener} | |
27 */ | |
28 function GaiaAuthHostListener() {} | |
29 | 26 |
30 /** @override */ | 27 function onAuthReady(e) { |
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 /** | |
52 * Handler of auth host 'ready' event. | |
53 */ | |
54 function onAuthReady() { | |
55 $('contents').classList.toggle('loading', false); | 28 $('contents').classList.toggle('loading', false); |
56 authReadyFired = true; | 29 authReadyFired = true; |
57 } | 30 } |
58 | 31 |
59 /** | 32 function onNewWindow(e) { |
60 * Handler of auth host 'completed' event. | 33 window.open(e.detail.targetUrl, '_blank'); |
61 * @param {!Object} credentials Credentials of the completed authentication. | 34 e.window.discard(); |
62 */ | 35 } |
63 function onAuthCompleted(credentials) { | 36 |
| 37 function onAuthCompleted(e) { |
| 38 completeLogin(e.detail); |
| 39 } |
| 40 |
| 41 function completeLogin(credentials) { |
64 chrome.send('completeLogin', [credentials]); | 42 chrome.send('completeLogin', [credentials]); |
65 $('contents').classList.toggle('loading', true); | 43 $('contents').classList.toggle('loading', true); |
66 } | 44 } |
67 | 45 |
68 /** | 46 /** |
69 * Initialize the UI. | 47 * Initialize the UI. |
70 */ | 48 */ |
71 function initialize() { | 49 function initialize() { |
72 authExtHost = new cr.login.GaiaAuthHost( | 50 authExtHost = new cr.login.GaiaAuthHost('signin-frame'); |
73 'signin-frame', new GaiaAuthHostListener()); | |
74 authExtHost.addEventListener('ready', onAuthReady); | 51 authExtHost.addEventListener('ready', onAuthReady); |
75 | 52 authExtHost.addEventListener('newWindow', onNewWindow); |
| 53 authExtHost.addEventListener('resize', onResize); |
| 54 authExtHost.addEventListener('authCompleted', onAuthCompleted); |
76 chrome.send('initialize'); | 55 chrome.send('initialize'); |
77 } | 56 } |
78 | 57 |
79 /** | 58 /** |
80 * Loads auth extension. | 59 * Loads auth extension. |
81 * @param {Object} data Parameters for auth extension. | 60 * @param {Object} data Parameters for auth extension. |
82 */ | 61 */ |
83 function loadAuthExtension(data) { | 62 function loadAuthExtension(data) { |
84 authExtHost.load(data.authMode, data, onAuthCompleted); | 63 // TODO(rogerta): in when using webview, the |completeLogin| argument |
| 64 // is ignored. See addEventListener() call above. |
| 65 authExtHost.load(data.authMode, data, completeLogin); |
85 $('contents').classList.toggle('loading', | 66 $('contents').classList.toggle('loading', |
86 data.authMode != cr.login.GaiaAuthHost.AuthMode.DESKTOP || | 67 data.authMode != cr.login.GaiaAuthHost.AuthMode.DESKTOP || |
87 data.constrained == '1'); | 68 data.constrained == '1'); |
88 } | 69 } |
89 | 70 |
90 /** | 71 /** |
91 * Closes the inline login dialog. | 72 * Closes the inline login dialog. |
92 */ | 73 */ |
93 function closeDialog() { | 74 function closeDialog() { |
94 chrome.send('dialogClose', ['']); | 75 chrome.send('dialogClose', ['']); |
(...skipping 26 matching lines...) Expand all Loading... |
121 getAuthExtHost: getAuthExtHost, | 102 getAuthExtHost: getAuthExtHost, |
122 isAuthReady: isAuthReady, | 103 isAuthReady: isAuthReady, |
123 initialize: initialize, | 104 initialize: initialize, |
124 loadAuthExtension: loadAuthExtension, | 105 loadAuthExtension: loadAuthExtension, |
125 closeDialog: closeDialog, | 106 closeDialog: closeDialog, |
126 handleOAuth2TokenFailure: handleOAuth2TokenFailure | 107 handleOAuth2TokenFailure: handleOAuth2TokenFailure |
127 }; | 108 }; |
128 }); | 109 }); |
129 | 110 |
130 document.addEventListener('DOMContentLoaded', inline.login.initialize); | 111 document.addEventListener('DOMContentLoaded', inline.login.initialize); |
OLD | NEW |