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 DIALOG_URL = 'dialog_hangout_consent.html'; | |
13 var DIALOG_WIDTH = 750; | |
14 var DIALOG_HEIGHT = 480; | |
15 var AUTHENTICATED_PARAM = 'authenticated'; | |
16 var AUTHENTICATED_MARGIN = 100; | |
Jamie
2015/02/02 19:07:40
Can these constants be computed (eg, using getBoun
kelvinp
2015/02/03 01:15:33
Good point. In the new iteration, I added a measur
| |
17 | |
18 var instance_ = null; | |
19 | |
20 /** | |
21 * Shows a dialog to ask for the user's permission to accept remote assistance | |
22 * from a Hangout participant. | |
23 * | |
24 * @constructor | |
25 * @private | |
26 */ | |
27 remoting.HangoutConsentDialog = function() { | |
28 /** | |
29 * @type {base.Deferred} | |
30 * @private | |
31 */ | |
32 this.onConsentResponseDeferred_ = null; | |
33 | |
34 base.Ipc.getInstance().register('remoting.HangoutConsentDialog.confirm', | |
35 this.onConfirmResponse_.bind(this)); | |
36 }; | |
37 | |
38 /** | |
39 * @param {boolean} confirm whether the user authorize the it2me connection | |
Jamie
2015/02/02 19:07:40
s/whether/Whether/ (also, capitalize the first wor
kelvinp
2015/02/03 01:15:32
Done.
Jamie
2015/02/03 18:22:44
You've only addressed the first comment in this gr
kelvinp
2015/02/03 19:31:45
Done.
| |
40 * @private | |
41 */ | |
42 remoting.HangoutConsentDialog.prototype.onConfirmResponse_ = function(confirm) { | |
43 if (this.onConsentResponseDeferred_) { | |
Jamie
2015/02/02 19:07:40
Under what circumstances can this be null? Would a
kelvinp
2015/02/03 01:15:32
I am trying guard against invalid IPC's. I think
| |
44 if (confirm) { | |
45 this.onConsentResponseDeferred_.resolve(); | |
46 } else { | |
47 this.onConsentResponseDeferred_.reject( | |
48 new Error(remoting.Error.NOT_AUTHORIZED)); | |
49 } | |
50 this.onConsentResponseDeferred_ = null; | |
51 } | |
52 }; | |
53 | |
54 /** | |
55 * @param {boolean} authenticated if set, the consent dialog will hide the | |
Jamie
2015/02/02 19:07:40
s/set/true/
kelvinp
2015/02/03 01:15:33
Done.
| |
56 * authorization section. | |
Jamie
2015/02/02 19:07:40
Authentication and authorization have very specifi
kelvinp
2015/02/03 01:15:33
Done.
| |
57 * @param {Bounds=} opt_parentBounds if set, the consent dialog will be centered | |
58 * upon |opt_parentBounds|. | |
Jamie
2015/02/02 19:07:40
s/upon/within/
kelvinp
2015/02/03 01:15:33
Done.
| |
59 * @return {Promise} A Promise that will resolve when permission is granted or | |
60 * reject if the user cancels. | |
61 */ | |
62 remoting.HangoutConsentDialog.prototype.show = function(authenticated, | |
63 opt_parentBounds) { | |
64 if (!this.onConsentResponseDeferred_) { | |
Jamie
2015/02/02 19:07:40
I think this needs to be an assert. Returning the
kelvinp
2015/02/03 01:15:32
Adding then() is equivalent to subscribing to the
| |
65 var height = | |
66 (authenticated) ? DIALOG_HEIGHT - AUTHENTICATED_MARGIN : DIALOG_HEIGHT; | |
67 var createOptions = { | |
68 frame: 'none', | |
69 resizable: false, | |
70 outerBounds: {width: DIALOG_WIDTH, height: height} | |
Jamie
2015/02/02 19:07:40
Space after '{' and before '}' (the only time we d
kelvinp
2015/02/03 01:15:33
Done.
| |
71 }; | |
72 | |
73 var url = | |
74 DIALOG_URL + '?' + AUTHENTICATED_PARAM + '=' + String(!!authenticated); | |
Jamie
2015/02/02 19:07:40
I think Boolean(authenticated) would be clearer th
kelvinp
2015/02/03 01:15:33
Done.
| |
75 | |
76 if (opt_parentBounds) { | |
77 // Center the dialog on the parent bounds. | |
78 var rect = opt_parentBounds; | |
79 createOptions.outerBounds.top = | |
80 Math.round(rect.top + rect.height / 2 - DIALOG_HEIGHT / 2); | |
81 createOptions.outerBounds.left = | |
82 Math.round(rect.left + rect.width / 2 - DIALOG_WIDTH / 2); | |
83 } | |
84 | |
85 this.onConsentResponseDeferred_ = new base.Deferred(); | |
86 chrome.app.window.create(url, createOptions); | |
87 } | |
88 return this.onConsentResponseDeferred_.promise(); | |
89 }; | |
90 | |
91 /** @return {remoting.HangoutConsentDialog} */ | |
92 remoting.HangoutConsentDialog.getInstance = function() { | |
93 if (!instance_) { | |
94 instance_ = new remoting.HangoutConsentDialog(); | |
95 } | |
96 return instance_; | |
97 }; | |
98 | |
99 }()); | |
100 | |
OLD | NEW |