| 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 remoting.initIdentity = function() { | 10 /** |
| 11 * Get the user's email address and full name. |
| 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. |
| 16 */ |
| 17 remoting.initIdentity = function(onUserInfoAvailable) { |
| 11 | 18 |
| 12 /** | 19 /** |
| 13 * Show the authorization consent UI and register a one-shot event handler to | 20 * Show the authorization consent UI and register a one-shot event handler to |
| 14 * continue the authorization process. | 21 * continue the authorization process. |
| 15 * | 22 * |
| 16 * @param {function():void} authContinue Callback to invoke when the user | 23 * @param {function():void} authContinue Callback to invoke when the user |
| 17 * clicks "Continue". | 24 * clicks "Continue". |
| 18 */ | 25 */ |
| 19 function promptForConsent(authContinue) { | 26 function promptForConsent(authContinue) { |
| 20 /** @type {HTMLElement} */ | 27 /** @type {HTMLElement} */ |
| 21 var dialog = document.getElementById('auth-dialog'); | 28 var dialog = document.getElementById('auth-dialog'); |
| 22 /** @type {HTMLElement} */ | 29 /** @type {HTMLElement} */ |
| 23 var button = document.getElementById('auth-button'); | 30 var button = document.getElementById('auth-button'); |
| 24 var consentGranted = function(event) { | 31 var consentGranted = function(event) { |
| 25 dialog.hidden = true; | 32 dialog.hidden = true; |
| 26 button.removeEventListener('click', consentGranted, false); | 33 button.removeEventListener('click', consentGranted, false); |
| 27 authContinue(); | 34 authContinue(); |
| 28 remoting.windowShape.updateClientWindowShape(); | 35 remoting.windowShape.updateClientWindowShape(); |
| 29 }; | 36 }; |
| 30 dialog.hidden = false; | 37 dialog.hidden = false; |
| 31 | 38 |
| 32 /** @type {HTMLElement} */ | 39 /** @type {HTMLElement} */ |
| 33 var dialog_border = document.getElementById('auth-dialog-border'); | 40 var dialog_border = document.getElementById('auth-dialog-border'); |
| 34 remoting.authDialog = new remoting.AuthDialog(dialog_border); | 41 remoting.authDialog = new remoting.AuthDialog(dialog_border); |
| 35 remoting.windowShape.addCallback(remoting.authDialog); | 42 remoting.windowShape.addCallback(remoting.authDialog); |
| 36 | 43 |
| 37 button.addEventListener('click', consentGranted, false); | 44 button.addEventListener('click', consentGranted, false); |
| 38 } | 45 } |
| 39 | 46 |
| 47 /** @param {remoting.Error} error */ |
| 48 function onGetIdentityInfoError(error) { |
| 49 // No need to show the error message for NOT_AUTHENTICATED |
| 50 // because we will show "auth-dialog". |
| 51 if (error != remoting.Error.NOT_AUTHENTICATED) { |
| 52 remoting.showErrorMessage(error); |
| 53 } |
| 54 } |
| 55 |
| 40 if (base.isAppsV2()) { | 56 if (base.isAppsV2()) { |
| 41 remoting.identity = new remoting.Identity(promptForConsent); | 57 remoting.identity = new remoting.Identity(promptForConsent); |
| 42 } else { | 58 } else { |
| 43 // TODO(garykac) Remove this and replace with identity. | 59 // TODO(garykac) Remove this and replace with identity. |
| 44 remoting.oauth2 = new remoting.OAuth2(); | 60 remoting.oauth2 = new remoting.OAuth2(); |
| 45 if (!remoting.oauth2.isAuthenticated()) { | 61 if (!remoting.oauth2.isAuthenticated()) { |
| 46 document.getElementById('auth-dialog').hidden = false; | 62 document.getElementById('auth-dialog').hidden = false; |
| 47 } | 63 } |
| 48 remoting.identity = remoting.oauth2; | 64 remoting.identity = remoting.oauth2; |
| 49 } | 65 } |
| 66 |
| 67 remoting.identity.getUserInfo(onUserInfoAvailable, |
| 68 onGetIdentityInfoError); |
| 50 } | 69 } |
| 51 | |
| 52 /** @param {remoting.Error} error */ | |
| 53 remoting.onGetIdentityInfoError = function(error) { | |
| 54 // No need to show the error message for NOT_AUTHENTICATED | |
| 55 // because we will show "auth-dialog". | |
| 56 if (error != remoting.Error.NOT_AUTHENTICATED) { | |
| 57 remoting.showErrorMessage(error); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * @param {function(string):void} onEmailAvailable Callback invoked when the | |
| 63 * email address is available. | |
| 64 * @return {void} Nothing. | |
| 65 */ | |
| 66 remoting.initIdentityEmail = function(onEmailAvailable) { | |
| 67 remoting.identity.getEmail(onEmailAvailable, | |
| 68 remoting.onGetIdentityInfoError); | |
| 69 } | |
| 70 | |
| 71 /** | |
| 72 * Get the user's email address and full name. | |
| 73 * | |
| 74 * @param {function(string,string):void} onUserInfoAvailable Callback invoked | |
| 75 * when the user's email address and full name are available. | |
| 76 * @return {void} Nothing. | |
| 77 */ | |
| 78 remoting.initIdentityUserInfo = function(onUserInfoAvailable) { | |
| 79 remoting.identity.getUserInfo(onUserInfoAvailable, | |
| 80 remoting.onGetIdentityInfoError); | |
| 81 } | |
| OLD | NEW |