Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / remoting / webapp / crd / js / crd_auth_dialog.js
blob8d45bde5a93493db7f0881bc0fe4fe49dc2146f9
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.
5 /** @suppress {duplicate} */
6 var remoting = remoting || {};
8 (function() {
10 'use strict';
12 var instance_ = null;
14 /**
15  * @constructor
16  * @implements {remoting.Identity.ConsentDialog}
17  * @param {HTMLElement} rootElement The dialog DOM element.
18  * @private
19  */
20 remoting.AuthDialog = function(rootElement) {
21   /** @private {HTMLElement} */
22   this.rootElement_ = rootElement;
24   /** @private {HTMLElement} */
25   this.borderElement_ = rootElement.querySelector('#auth-dialog-border');
27   /** @private {HTMLElement} */
28   this.authButton_ = rootElement.querySelector('#auth-button');
30   /** @private {base.Deferred} */
31   this.onAuthButtonDeferred_ = null;
33   this.authButton_.addEventListener('click', this.onClick_.bind(this), false);
36 /** @private */
37 remoting.AuthDialog.prototype.onClick_ = function() {
38   this.rootElement_.hidden = true;
39   this.onAuthButtonDeferred_.resolve(null);
40   this.onAuthButtonDeferred_ = null;
43 /**
44  * @return {Promise} A Promise object that resolves when the user clicks on the
45  *   auth button.
46  */
47 remoting.AuthDialog.prototype.show = function() {
48   if (this.isVisible()) {
49     return Promise.reject('Auth dialog is already showing.');
50   }
51   this.rootElement_.hidden = false;
52   console.assert(this.onAuthButtonDeferred_ === null,
53                  'Duplicate show() invocation.');
54   this.onAuthButtonDeferred_ = new base.Deferred();
55   return this.onAuthButtonDeferred_.promise();
58 /**
59  * @return {boolean} whether the auth dialog is visible or not.
60  */
61 remoting.AuthDialog.prototype.isVisible = function() {
62   return !this.rootElement_.hidden;
65 /**
66  * @return {remoting.AuthDialog}
67  */
68 remoting.AuthDialog.getInstance = function() {
69   if (!instance_) {
70     var rootElement = document.getElementById('auth-dialog');
71     instance_ = new remoting.AuthDialog(rootElement);
72   }
73   return instance_;
76 })();