-
Notifications
You must be signed in to change notification settings - Fork 8
/
auth_dialog.js
104 lines (89 loc) · 2.56 KB
/
auth_dialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// 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.
/** @suppress {duplicate} */
var remoting = remoting || {};
(function() {
'use strict';
var instance_ = null;
/**
* @constructor
* @implements {remoting.WindowShape.ClientUI}
* @implements {remoting.Identity.ConsentDialog}
* @param {HTMLElement} rootElement The dialog DOM element.
* @private
*/
remoting.AuthDialog = function(rootElement) {
/**
* @type {HTMLElement}
* @private
*/
this.rootElement_ = rootElement;
/**
* @type {HTMLElement}
* @private
*/
this.borderElement_ = rootElement.querySelector('#auth-dialog-border');
/**
* @type {HTMLElement}
* @private
*/
this.authButton_ = rootElement.querySelector('#auth-button');
/**
* @type {base.Deferred}
* @private
*/
this.onAuthButtonDeferred_ = null;
this.authButton_.addEventListener('click', this.onClick_.bind(this), false);
remoting.windowShape.addCallback(this);
};
/**
* @param {Array<{left: number, top: number, width: number, height: number}>}
* rects List of rectangles.
*/
remoting.AuthDialog.prototype.addToRegion = function(rects) {
var rect =
/** @type {ClientRect} */(this.borderElement_.getBoundingClientRect());
rects.push({left: rect.left,
top: rect.top,
width: rect.width,
height: rect.height});
};
/** @private */
remoting.AuthDialog.prototype.onClick_ = function() {
this.rootElement_.hidden = true;
this.onAuthButtonDeferred_.resolve();
this.onAuthButtonDeferred_ = null;
remoting.windowShape.updateClientWindowShape();
};
/**
* @return {Promise} A Promise object that resolves when the user clicks on the
* auth button.
*/
remoting.AuthDialog.prototype.show = function() {
if (this.isVisible()) {
return Promise.reject('Auth dialog is already showing.');
}
this.rootElement_.hidden = false;
base.debug.assert(this.onAuthButtonDeferred_ === null);
remoting.windowShape.updateClientWindowShape();
this.onAuthButtonDeferred_ = new base.Deferred();
return this.onAuthButtonDeferred_.promise();
};
/**
* @return {boolean} whether the auth dialog is visible or not.
*/
remoting.AuthDialog.prototype.isVisible = function() {
return !this.rootElement_.hidden;
};
/**
* @return {remoting.AuthDialog}
*/
remoting.AuthDialog.getInstance = function() {
if (!instance_) {
var rootElement = document.getElementById('auth-dialog');
instance_ = new remoting.AuthDialog(rootElement);
}
return instance_;
};
})();