| 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 * Shows a dialog to ask for the user's permission to accept remote assistance | |
| 16 * from a Hangout participant. | |
| 17 * | |
| 18 * @constructor | |
| 19 * @private | |
| 20 */ | |
| 21 remoting.HangoutConsentDialog = function() { | |
| 22 /** | |
| 23 * @type {base.Deferred} | |
| 24 * @private | |
| 25 */ | |
| 26 this.onConsentResponseDeferred_ = null; | |
| 27 | |
| 28 /** @private */ | |
| 29 this.requestToken_ = base.generateXsrfToken(); | |
| 30 | |
| 31 base.Ipc.getInstance().register('remoting.HangoutConsentDialog.confirm', | |
| 32 this.onConfirmResponse_.bind(this)); | |
| 33 }; | |
| 34 | |
| 35 /** | |
| 36 * @param {boolean} confirm Whether the user authorized the it2me connection | |
| 37 * @param {string} responseToken | |
| 38 * @private | |
| 39 */ | |
| 40 remoting.HangoutConsentDialog.prototype.onConfirmResponse_ = function( | |
| 41 confirm, responseToken) { | |
| 42 if (responseToken !== this.requestToken_) { | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 if (confirm) { | |
| 47 this.onConsentResponseDeferred_.resolve(); | |
| 48 } else { | |
| 49 this.onConsentResponseDeferred_.reject( | |
| 50 new Error(remoting.Error.CANCELLED)); | |
| 51 } | |
| 52 this.onConsentResponseDeferred_ = null; | |
| 53 }; | |
| 54 | |
| 55 /** | |
| 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. | |
| 62 */ | |
| 63 remoting.HangoutConsentDialog.prototype.show = function(authorized, | |
| 64 opt_parentBounds) { | |
| 65 if (!this.onConsentResponseDeferred_) { | |
| 66 var DIALOG_WIDTH = 750; | |
| 67 var DIALOG_HEIGHT = 480; | |
| 68 | |
| 69 var createOptions = { | |
| 70 frame: 'none', | |
| 71 resizable: false, | |
| 72 outerBounds: { width: DIALOG_WIDTH, height: DIALOG_HEIGHT } | |
| 73 }; | |
| 74 | |
| 75 var params = { | |
| 76 token: this.requestToken_, | |
| 77 authorized: Boolean(authorized) | |
| 78 }; | |
| 79 | |
| 80 var url = base.urlJoin('dialog_hangout_consent.html', params); | |
| 81 | |
| 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); | |
| 89 } | |
| 90 | |
| 91 this.onConsentResponseDeferred_ = new base.Deferred(); | |
| 92 chrome.app.window.create(url, createOptions); | |
| 93 } | |
| 94 return this.onConsentResponseDeferred_.promise(); | |
| 95 }; | |
| 96 | |
| 97 /** @return {remoting.HangoutConsentDialog} */ | |
| 98 remoting.HangoutConsentDialog.getInstance = function() { | |
| 99 if (!instance_) { | |
| 100 instance_ = new remoting.HangoutConsentDialog(); | |
| 101 } | |
| 102 return instance_; | |
| 103 }; | |
| 104 | |
| 105 }()); | |
| OLD | NEW |