OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** | 10 /** |
11 * Get the user's email address and full name. | 11 * Get the user's email address and full name. |
12 * | 12 * |
13 * @param {function(string,string):void} onUserInfoAvailable Callback invoked | 13 * @param {function(string,string):void} onUserInfoAvailable Callback invoked |
14 * when the user's email address and full name are available. | 14 * when the user's email address and full name are available. |
15 * @return {void} Nothing. | 15 * @return {void} Nothing. |
16 */ | 16 */ |
17 remoting.initIdentity = function(onUserInfoAvailable) { | 17 remoting.initIdentity = function(onUserInfoAvailable) { |
18 | 18 |
19 /** @param {remoting.Error} error */ | 19 /** @param {!remoting.Error} error */ |
20 function onGetIdentityInfoError(error) { | 20 function onGetIdentityInfoError(error) { |
21 // No need to show the error message for NOT_AUTHENTICATED | 21 // No need to show the error message for NOT_AUTHENTICATED |
22 // because we will show "auth-dialog". | 22 // because we will show "auth-dialog". |
23 if (error != remoting.Error.NOT_AUTHENTICATED) { | 23 if (error.tag != remoting.Error.Tag.NOT_AUTHENTICATED) { |
24 remoting.showErrorMessage(error); | 24 remoting.showErrorMessage(error); |
25 } | 25 } |
26 } | 26 } |
27 | 27 |
28 if (base.isAppsV2()) { | 28 if (base.isAppsV2()) { |
29 remoting.identity = | 29 remoting.identity = |
30 new remoting.Identity(remoting.AuthDialog.getInstance()); | 30 new remoting.Identity(remoting.AuthDialog.getInstance()); |
31 } else { | 31 } else { |
32 // TODO(garykac) Remove this and replace with identity. | 32 // TODO(garykac) Remove this and replace with identity. |
33 remoting.oauth2 = new remoting.OAuth2(); | 33 remoting.oauth2 = new remoting.OAuth2(); |
34 var oauth2 = /** @type {*} */ (remoting.oauth2); | 34 var oauth2 = /** @type {*} */ (remoting.oauth2); |
35 remoting.identity = /** @type {remoting.Identity} */ (oauth2); | 35 remoting.identity = /** @type {remoting.Identity} */ (oauth2); |
36 if (!remoting.identity.isAuthenticated()) { | 36 if (!remoting.identity.isAuthenticated()) { |
37 remoting.AuthDialog.getInstance().show().then(function() { | 37 remoting.AuthDialog.getInstance().show().then(function() { |
38 remoting.oauth2.doAuthRedirect(function(){ | 38 remoting.oauth2.doAuthRedirect(function(){ |
39 window.location.reload(); | 39 window.location.reload(); |
40 }); | 40 }); |
41 }); | 41 }); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 remoting.identity.getUserInfo().then(function(userInfo) { | 45 remoting.identity.getUserInfo().then(function(userInfo) { |
46 onUserInfoAvailable(userInfo.email, userInfo.name); | 46 onUserInfoAvailable(userInfo.email, userInfo.name); |
47 }).catch(function(error) { | 47 }).catch(function(error) { |
48 onGetIdentityInfoError( | 48 onGetIdentityInfoError( |
49 /** @type {remoting.Error} */ (error)); | 49 /** @type {!remoting.Error} */ (error)); |
50 }); | 50 }); |
51 }; | 51 }; |
52 | 52 |
53 /** | 53 /** |
54 * Removes the cached token and restarts the app. | 54 * Removes the cached token and restarts the app. |
55 * | 55 * |
56 * @return {void} Nothing. | 56 * @return {void} Nothing. |
57 */ | 57 */ |
58 remoting.handleAuthFailureAndRelaunch = function() { | 58 remoting.handleAuthFailureAndRelaunch = function() { |
59 remoting.identity.removeCachedAuthToken().then(function(){ | 59 remoting.identity.removeCachedAuthToken().then(function(){ |
60 if (base.isAppsV2()) { | 60 if (base.isAppsV2()) { |
61 base.Ipc.invoke('remoting.ActivationHandler.restart', | 61 base.Ipc.invoke('remoting.ActivationHandler.restart', |
62 chrome.app.window.current().id); | 62 chrome.app.window.current().id); |
63 } else { | 63 } else { |
64 window.location.reload(); | 64 window.location.reload(); |
65 } | 65 } |
66 }); | 66 }); |
67 }; | 67 }; |
OLD | NEW |