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 || {};
15 * Shows a dialog to ask for the user's permission to accept remote assistance
16 * from a Hangout participant.
21 remoting.HangoutConsentDialog = function() {
23 * @type {base.Deferred}
26 this.onConsentResponseDeferred_ = null;
29 this.requestToken_ = base.generateXsrfToken();
31 base.Ipc.getInstance().register('remoting.HangoutConsentDialog.confirm',
32 this.onConfirmResponse_.bind(this));
36 * @param {boolean} confirm Whether the user authorized the it2me connection
37 * @param {string} responseToken
40 remoting.HangoutConsentDialog.prototype.onConfirmResponse_ = function(
41 confirm, responseToken) {
42 if (responseToken !== this.requestToken_) {
47 this.onConsentResponseDeferred_.resolve();
49 this.onConsentResponseDeferred_.reject(
50 new Error(remoting.Error.CANCELLED));
52 this.onConsentResponseDeferred_ = null;
56 * @param {boolean} authorized If true, the consent dialog will hide the
57 * authorization section.
58 * @param {Bounds=} opt_parentBounds If present, the consent dialog will be
59 * centered within |opt_parentBounds|.
60 * @return {Promise} A Promise that will resolve when permission is granted or
61 * reject if the user cancels.
63 remoting.HangoutConsentDialog.prototype.show = function(authorized,
65 if (!this.onConsentResponseDeferred_) {
66 var DIALOG_WIDTH = 750;
67 var DIALOG_HEIGHT = 480;
72 outerBounds: { width: DIALOG_WIDTH, height: DIALOG_HEIGHT }
76 token: this.requestToken_,
77 authorized: Boolean(authorized)
80 var url = base.urlJoin('dialog_hangout_consent.html', params);
82 if (opt_parentBounds) {
83 // Center the dialog on the parent bounds.
84 var rect = opt_parentBounds;
85 createOptions.outerBounds.top =
86 Math.round(rect.top + rect.height / 2 - DIALOG_HEIGHT / 2);
87 createOptions.outerBounds.left =
88 Math.round(rect.left + rect.width / 2 - DIALOG_WIDTH / 2);
91 this.onConsentResponseDeferred_ = new base.Deferred();
92 chrome.app.window.create(url, createOptions);
94 return this.onConsentResponseDeferred_.promise();
97 /** @return {remoting.HangoutConsentDialog} */
98 remoting.HangoutConsentDialog.getInstance = function() {
100 instance_ = new remoting.HangoutConsentDialog();