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 || {};
16 * @implements {remoting.Identity.ConsentDialog}
17 * @param {HTMLElement} rootElement The dialog DOM element.
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);
37 remoting.AuthDialog.prototype.onClick_ = function() {
38 this.rootElement_.hidden = true;
39 this.onAuthButtonDeferred_.resolve(null);
40 this.onAuthButtonDeferred_ = null;
44 * @return {Promise} A Promise object that resolves when the user clicks on the
47 remoting.AuthDialog.prototype.show = function() {
48 if (this.isVisible()) {
49 return Promise.reject('Auth dialog is already showing.');
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();
59 * @return {boolean} whether the auth dialog is visible or not.
61 remoting.AuthDialog.prototype.isVisible = function() {
62 return !this.rootElement_.hidden;
66 * @return {remoting.AuthDialog}
68 remoting.AuthDialog.getInstance = function() {
70 var rootElement = document.getElementById('auth-dialog');
71 instance_ = new remoting.AuthDialog(rootElement);