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