Chromium Code Reviews| 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 * Initialize the identity and authentication components. |
| 12 * | 12 * |
| 13 * @param {function(string,string):void} onUserInfoAvailable Callback invoked | |
| 14 * when the user's email address and full name are available. | |
| 15 * @return {void} Nothing. | 13 * @return {void} Nothing. |
| 16 */ | 14 */ |
| 17 remoting.initIdentity = function(onUserInfoAvailable) { | 15 remoting.initIdentity = function() { |
| 18 | |
| 19 /** @param {remoting.Error} error */ | |
| 20 function onGetIdentityInfoError(error) { | |
| 21 // No need to show the error message for NOT_AUTHENTICATED | |
| 22 // because we will show "auth-dialog". | |
| 23 if (error != remoting.Error.NOT_AUTHENTICATED) { | |
| 24 remoting.showErrorMessage(error); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 if (base.isAppsV2()) { | 16 if (base.isAppsV2()) { |
| 17 // TODO(jamiewalch): Add a getAuthDialog method to Application.Delegate | |
| 18 // to allow this behaviour to be customized. | |
|
Jamie
2015/03/05 01:35:55
For example, AppStreaming should not use an in-DOM
| |
| 29 remoting.identity = | 19 remoting.identity = |
| 30 new remoting.Identity(remoting.AuthDialog.getInstance()); | 20 new remoting.Identity(remoting.AuthDialog.getInstance()); |
| 31 } else { | 21 } else { |
| 32 // TODO(garykac) Remove this and replace with identity. | 22 // TODO(garykac) Remove this and replace with identity. |
| 33 remoting.oauth2 = new remoting.OAuth2(); | 23 remoting.oauth2 = new remoting.OAuth2(); |
| 34 var oauth2 = /** @type {*} */ (remoting.oauth2); | 24 var oauth2 = /** @type {*} */ (remoting.oauth2); |
| 35 remoting.identity = /** @type {remoting.Identity} */ (oauth2); | 25 remoting.identity = /** @type {remoting.Identity} */ (oauth2); |
| 36 if (!remoting.identity.isAuthenticated()) { | 26 if (!remoting.identity.isAuthenticated()) { |
| 37 remoting.AuthDialog.getInstance().show().then(function() { | 27 remoting.AuthDialog.getInstance().show().then(function() { |
| 38 remoting.oauth2.doAuthRedirect(function(){ | 28 remoting.oauth2.doAuthRedirect(function(){ |
| 39 window.location.reload(); | 29 window.location.reload(); |
| 40 }); | 30 }); |
| 41 }); | 31 }); |
| 42 } | 32 } |
| 43 } | 33 } |
| 44 | |
| 45 remoting.identity.getUserInfo().then( | |
| 46 /** @param {{email:string, name:string}} userInfo */ | |
| 47 function(userInfo) { | |
| 48 onUserInfoAvailable(userInfo.email, userInfo.name); | |
| 49 }).catch(function(error) { | |
| 50 onGetIdentityInfoError( | |
| 51 /** @type {remoting.Error} */ (error)); | |
| 52 }); | |
| 53 }; | 34 }; |
| 54 | 35 |
| 55 /** | 36 /** |
| 56 * Removes the cached token and restarts the app. | 37 * Removes the cached token and restarts the app. |
| 57 * | 38 * |
| 58 * @return {void} Nothing. | 39 * @return {void} Nothing. |
| 59 */ | 40 */ |
| 60 remoting.handleAuthFailureAndRelaunch = function() { | 41 remoting.handleAuthFailureAndRelaunch = function() { |
| 61 remoting.identity.removeCachedAuthToken().then(function(){ | 42 remoting.identity.removeCachedAuthToken().then(function(){ |
| 62 if (base.isAppsV2()) { | 43 if (base.isAppsV2()) { |
| 63 base.Ipc.invoke('remoting.ActivationHandler.restart', | 44 base.Ipc.invoke('remoting.ActivationHandler.restart', |
| 64 chrome.app.window.current().id); | 45 chrome.app.window.current().id); |
| 65 } else { | 46 } else { |
| 66 window.location.reload(); | 47 window.location.reload(); |
| 67 } | 48 } |
| 68 }); | 49 }); |
| 69 }; | 50 }; |
| OLD | NEW |