| 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 /** | |
| 20 * Show the authorization consent UI and register a one-shot event handler to | |
| 21 * continue the authorization process. | |
| 22 * | |
| 23 * @param {function():void} authContinue Callback to invoke when the user | |
| 24 * clicks "Continue". | |
| 25 */ | |
| 26 function promptForConsent(authContinue) { | |
| 27 /** @type {HTMLElement} */ | |
| 28 var dialog = document.getElementById('auth-dialog'); | |
| 29 /** @type {HTMLElement} */ | |
| 30 var button = document.getElementById('auth-button'); | |
| 31 var consentGranted = function(event) { | |
| 32 dialog.hidden = true; | |
| 33 button.removeEventListener('click', consentGranted, false); | |
| 34 authContinue(); | |
| 35 remoting.windowShape.updateClientWindowShape(); | |
| 36 }; | |
| 37 dialog.hidden = false; | |
| 38 | |
| 39 /** @type {HTMLElement} */ | |
| 40 var dialog_border = document.getElementById('auth-dialog-border'); | |
| 41 remoting.authDialog = new remoting.AuthDialog(dialog_border); | |
| 42 remoting.windowShape.addCallback(remoting.authDialog); | |
| 43 | |
| 44 button.addEventListener('click', consentGranted, false); | |
| 45 } | |
| 46 | |
| 47 /** @param {remoting.Error} error */ | 19 /** @param {remoting.Error} error */ |
| 48 function onGetIdentityInfoError(error) { | 20 function onGetIdentityInfoError(error) { |
| 49 // No need to show the error message for NOT_AUTHENTICATED | 21 // No need to show the error message for NOT_AUTHENTICATED |
| 50 // because we will show "auth-dialog". | 22 // because we will show "auth-dialog". |
| 51 if (error != remoting.Error.NOT_AUTHENTICATED) { | 23 if (error != remoting.Error.NOT_AUTHENTICATED) { |
| 52 remoting.showErrorMessage(error); | 24 remoting.showErrorMessage(error); |
| 53 } | 25 } |
| 54 } | 26 } |
| 55 | 27 |
| 56 if (base.isAppsV2()) { | 28 if (base.isAppsV2()) { |
| 57 remoting.identity = new remoting.Identity(promptForConsent); | 29 remoting.identity = new remoting.Identity(); |
| 58 } else { | 30 } else { |
| 59 // TODO(garykac) Remove this and replace with identity. | 31 // TODO(garykac) Remove this and replace with identity. |
| 60 remoting.oauth2 = new remoting.OAuth2(); | 32 remoting.oauth2 = new remoting.OAuth2(); |
| 61 if (!remoting.oauth2.isAuthenticated()) { | 33 remoting.identity = remoting.oauth2; |
| 62 document.getElementById('auth-dialog').hidden = false; | 34 if (!remoting.identity.isAuthenticated()) { |
| 35 remoting.AuthDialog.show().then(function() { |
| 36 remoting.identity.handleAuthFailureAndRelaunch(); |
| 37 }); |
| 63 } | 38 } |
| 64 remoting.identity = remoting.oauth2; | |
| 65 } | 39 } |
| 66 | 40 |
| 67 remoting.identity.getUserInfo(onUserInfoAvailable, | 41 remoting.identity.getUserInfo(onUserInfoAvailable, |
| 68 onGetIdentityInfoError); | 42 onGetIdentityInfoError); |
| 69 } | 43 }; |
| OLD | NEW |