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.WindowShape.ClientUI}
17 * @implements {remoting.Identity.ConsentDialog}
18 * @param {HTMLElement} rootElement The dialog DOM element.
21 remoting
.AuthDialog = function(rootElement
) {
26 this.rootElement_
= rootElement
;
32 this.borderElement_
= rootElement
.querySelector('#auth-dialog-border');
38 this.authButton_
= rootElement
.querySelector('#auth-button');
41 * @type {base.Deferred}
44 this.onAuthButtonDeferred_
= null;
46 this.authButton_
.addEventListener('click', this.onClick_
.bind(this), false);
47 remoting
.windowShape
.addCallback(this);
51 * @param {Array<{left: number, top: number, width: number, height: number}>}
52 * rects List of rectangles.
54 remoting
.AuthDialog
.prototype.addToRegion = function(rects
) {
56 /** @type {ClientRect} */(this.borderElement_
.getBoundingClientRect());
57 rects
.push({left
: rect
.left
,
60 height
: rect
.height
});
64 remoting
.AuthDialog
.prototype.onClick_ = function() {
65 this.rootElement_
.hidden
= true;
66 this.onAuthButtonDeferred_
.resolve(null);
67 this.onAuthButtonDeferred_
= null;
68 remoting
.windowShape
.updateClientWindowShape();
72 * @return {Promise} A Promise object that resolves when the user clicks on the
75 remoting
.AuthDialog
.prototype.show = function() {
76 if (this.isVisible()) {
77 return Promise
.reject('Auth dialog is already showing.');
79 this.rootElement_
.hidden
= false;
80 base
.debug
.assert(this.onAuthButtonDeferred_
=== null);
81 remoting
.windowShape
.updateClientWindowShape();
82 this.onAuthButtonDeferred_
= new base
.Deferred();
83 return this.onAuthButtonDeferred_
.promise();
87 * @return {boolean} whether the auth dialog is visible or not.
89 remoting
.AuthDialog
.prototype.isVisible = function() {
90 return !this.rootElement_
.hidden
;
94 * @return {remoting.AuthDialog}
96 remoting
.AuthDialog
.getInstance = function() {
98 var rootElement
= document
.getElementById('auth-dialog');
99 instance_
= new remoting
.AuthDialog(rootElement
);