Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: remoting/webapp/base/js/auth_init.js

Issue 742473002: [Chromoting] Break up the webapp's init function into smaller chunks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Upload Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/base/js/auth_init.js
diff --git a/remoting/webapp/base/js/auth_init.js b/remoting/webapp/base/js/auth_init.js
new file mode 100644
index 0000000000000000000000000000000000000000..abcff1d0e2194ef80aeeb7aaff46e7598bc24541
--- /dev/null
+++ b/remoting/webapp/base/js/auth_init.js
@@ -0,0 +1,79 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+remoting.initIdentity = function() {
+ if (base.isAppsV2()) {
+ remoting.identity = new remoting.Identity(consentRequired_);
+ } else {
+ 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
+ if (!remoting.oauth2.isAuthenticated()) {
+ document.getElementById('auth-dialog').hidden = false;
+ }
+ remoting.identity = remoting.oauth2;
+ }
+}
+
+/** @param {remoting.Error} error */
+remoting.onGetIdentityInfoError = function(error) {
+ // No need to show the error message for NOT_AUTHENTICATED
+ // because we will show "auth-dialog".
+ if (error != remoting.Error.NOT_AUTHENTICATED) {
+ remoting.showErrorMessage(error);
+ }
+}
+
+/**
+ * @param {function(string):void} onEmailAvailable Callback invoked when the
+ * email address is available.
+ * @return {void} Nothing.
+ */
+remoting.initIdentityEmail = function(onEmailAvailable) {
+ remoting.identity.getEmail(onEmailAvailable,
+ remoting.onGetIdentityInfoError);
+}
+
+/**
+ * Get the user's email address and full name.
+ *
+ * @param {function(string,string):void} onUserInfoAvailable Callback invoked
+ * when the user's email address and full name are available.
+ * @return {void} Nothing.
+ */
+remoting.initIdentityUserInfo = function(onUserInfoAvailable) {
+ remoting.identity.getUserInfo(onUserInfoAvailable,
+ remoting.onGetIdentityInfoError);
+}
+
+/**
+ * Show the authorization consent UI and register a one-shot event handler to
+ * continue the authorization process.
+ *
+ * @param {function():void} authContinue Callback to invoke when the user
+ * clicks "Continue".
+ */
+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.
+ /** @type {HTMLElement} */
+ var dialog = document.getElementById('auth-dialog');
+ /** @type {HTMLElement} */
+ var button = document.getElementById('auth-button');
+ var consentGranted = function(event) {
+ dialog.hidden = true;
+ button.removeEventListener('click', consentGranted, false);
+ authContinue();
+ remoting.windowShape.updateClientWindowShape();
+ };
+ dialog.hidden = false;
+
+ /** @type {HTMLElement} */
+ var dialog_border = document.getElementById('auth-dialog-border');
+ remoting.authDialog = new remoting.AuthDialog(dialog_border);
+ remoting.windowShape.addCallback(remoting.authDialog);
+
+ button.addEventListener('click', consentGranted, false);
+}

Powered by Google App Engine
This is Rietveld 408576698