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.
7 /** @suppress {duplicate} */
8 var remoting = remoting || {};
11 * HostInstallDialog prompts the user to install host components.
15 remoting.HostInstallDialog = function() {
16 this.continueInstallButton_ = document.getElementById(
17 'host-install-continue');
18 this.cancelInstallButton_ = document.getElementById(
19 'host-install-dismiss');
20 this.retryInstallButton_ = document.getElementById(
21 'host-install-retry');
23 this.onOkClickedHandler_ = this.onOkClicked_.bind(this);
24 this.onCancelClickedHandler_ = this.onCancelClicked_.bind(this);
25 this.onRetryClickedHandler_ = this.onRetryClicked_.bind(this);
27 this.continueInstallButton_.disabled = false;
28 this.cancelInstallButton_.disabled = false;
30 /** @private {function():void} */
31 this.onDoneHandler_ = function() {};
33 /** @private {function(!remoting.Error):void} */
34 this.onErrorHandler_ = function(error) {};
36 /** @private {remoting.HostInstaller} */
37 this.hostInstaller_ = new remoting.HostInstaller();
41 * Starts downloading host components and shows installation prompt.
43 * @param {function():void} onDone Callback called when user clicks Ok,
44 * presumably after installing the host. The handler must verify that the host
45 * has been installed and call tryAgain() otherwise.
46 * @param {function(!remoting.Error):void} onError Callback called when user
47 * clicks Cancel button or there is some other unexpected error.
50 remoting.HostInstallDialog.prototype.show = function(onDone, onError) {
51 this.continueInstallButton_.addEventListener(
52 'click', this.onOkClickedHandler_, false);
53 this.cancelInstallButton_.addEventListener(
54 'click', this.onCancelClickedHandler_, false);
55 remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT);
57 this.onDoneHandler_ = onDone;
59 this.onErrorHandler_ = onError;
61 /** @type {remoting.HostInstaller} */
62 var hostInstaller = new remoting.HostInstaller();
64 /** @type {remoting.HostInstallDialog} */
67 this.hostInstaller_.downloadAndWaitForInstall().then(function() {
68 that.continueInstallButton_.click();
69 that.hostInstaller_.cancel();
71 that.onErrorHandler_(new remoting.Error(remoting.Error.Tag.CANCELLED));
72 that.hostInstaller_.cancel();
77 * In manual host installation, onDone handler must call this method if it
78 * detects that the host components are still unavailable. The same onDone
79 * and onError callbacks will be used when user clicks Ok or Cancel.
81 remoting.HostInstallDialog.prototype.tryAgain = function() {
82 this.retryInstallButton_.addEventListener(
83 'click', this.onRetryClickedHandler_.bind(this), false);
84 remoting.setMode(remoting.AppMode.HOST_INSTALL_PENDING);
85 this.continueInstallButton_.disabled = false;
86 this.cancelInstallButton_.disabled = false;
89 remoting.HostInstallDialog.prototype.onOkClicked_ = function() {
90 this.continueInstallButton_.removeEventListener(
91 'click', this.onOkClickedHandler_, false);
92 this.cancelInstallButton_.removeEventListener(
93 'click', this.onCancelClickedHandler_, false);
94 this.continueInstallButton_.disabled = true;
95 this.cancelInstallButton_.disabled = true;
97 this.onDoneHandler_();
100 remoting.HostInstallDialog.prototype.onCancelClicked_ = function() {
101 this.continueInstallButton_.removeEventListener(
102 'click', this.onOkClickedHandler_, false);
103 this.cancelInstallButton_.removeEventListener(
104 'click', this.onCancelClickedHandler_, false);
105 this.hostInstaller_.cancel();
106 this.onErrorHandler_(new remoting.Error(remoting.Error.Tag.CANCELLED));
109 remoting.HostInstallDialog.prototype.onRetryClicked_ = function() {
110 this.retryInstallButton_.removeEventListener(
111 'click', this.onRetryClickedHandler_.bind(this), false);
112 this.continueInstallButton_.addEventListener(
113 'click', this.onOkClickedHandler_, false);
114 this.cancelInstallButton_.addEventListener(
115 'click', this.onCancelClickedHandler_, false);
116 remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT);