OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 'use strict'; |
| 6 |
| 7 /** @suppress {duplicate} */ |
| 8 var remoting = remoting || {}; |
| 9 |
| 10 remoting.initIdentity = function() { |
| 11 |
| 12 /** |
| 13 * Show the authorization consent UI and register a one-shot event handler to |
| 14 * continue the authorization process. |
| 15 * |
| 16 * @param {function():void} authContinue Callback to invoke when the user |
| 17 * clicks "Continue". |
| 18 */ |
| 19 function promptForConsent(authContinue) { |
| 20 /** @type {HTMLElement} */ |
| 21 var dialog = document.getElementById('auth-dialog'); |
| 22 /** @type {HTMLElement} */ |
| 23 var button = document.getElementById('auth-button'); |
| 24 var consentGranted = function(event) { |
| 25 dialog.hidden = true; |
| 26 button.removeEventListener('click', consentGranted, false); |
| 27 authContinue(); |
| 28 remoting.windowShape.updateClientWindowShape(); |
| 29 }; |
| 30 dialog.hidden = false; |
| 31 |
| 32 /** @type {HTMLElement} */ |
| 33 var dialog_border = document.getElementById('auth-dialog-border'); |
| 34 remoting.authDialog = new remoting.AuthDialog(dialog_border); |
| 35 remoting.windowShape.addCallback(remoting.authDialog); |
| 36 |
| 37 button.addEventListener('click', consentGranted, false); |
| 38 } |
| 39 |
| 40 if (base.isAppsV2()) { |
| 41 remoting.identity = new remoting.Identity(promptForConsent); |
| 42 } else { |
| 43 // TODO(garykac) Remove this and replace with identity. |
| 44 remoting.oauth2 = new remoting.OAuth2(); |
| 45 if (!remoting.oauth2.isAuthenticated()) { |
| 46 document.getElementById('auth-dialog').hidden = false; |
| 47 } |
| 48 remoting.identity = remoting.oauth2; |
| 49 } |
| 50 } |
| 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 |