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