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;
31 this.onDoneHandler_ = function() {}
33 /** @param {remoting.Error} error @private */
34 this.onErrorHandler_ = function(error) {}
37 /** @type {Object.<string,string>} */
38 remoting.HostInstallDialog.hostDownloadUrls = {
39 'Win32' : 'http://dl.google.com/dl/edgedl/chrome-remote-desktop/' +
40 'chromeremotedesktophost.msi',
41 'MacIntel' : 'https://dl.google.com/chrome-remote-desktop/' +
42 'chromeremotedesktop.dmg',
43 'Linux x86_64' : 'https://dl.google.com/linux/direct/' +
44 'chrome-remote-desktop_current_amd64.deb',
45 'Linux i386' : 'https://dl.google.com/linux/direct/' +
46 'chrome-remote-desktop_current_i386.deb'
50 * Starts downloading host components and shows installation prompt.
52 * @param {function():void} onDone Callback called when user clicks Ok,
53 * presumably after installing the host. The handler must verify that the
54 * host has been installed and call tryAgain() otherwise.
55 * @param {function(remoting.Error):void} onError Callback called when user
56 * clicks Cancel button or there is some other unexpected error.
59 remoting.HostInstallDialog.prototype.show = function(onDone, onError) {
60 this.continueInstallButton_.addEventListener(
61 'click', this.onOkClickedHandler_, false);
62 this.cancelInstallButton_.addEventListener(
63 'click', this.onCancelClickedHandler_, false);
64 remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT);
67 remoting.HostInstallDialog.hostDownloadUrls[navigator.platform];
68 if (hostPackageUrl === undefined) {
69 this.onErrorHandler_(remoting.Error.CANCELLED);
73 // Start downloading the package.
74 window.location = hostPackageUrl;
76 /** @type {function():void} */
77 this.onDoneHandler_ = onDone;
79 /** @type {function(remoting.Error):void} */
80 this.onErrorHandler_ = onError;
84 * onDone handler must call this method if it detects that the host components
85 * are still unavailable. The same onDone and onError callbacks will be used
86 * when user clicks Ok or Cancel.
88 remoting.HostInstallDialog.prototype.tryAgain = function() {
89 this.retryInstallButton_.addEventListener(
90 'click', this.onRetryClickedHandler_.bind(this), false);
91 remoting.setMode(remoting.AppMode.HOST_INSTALL_PENDING);
92 this.continueInstallButton_.disabled = false;
93 this.cancelInstallButton_.disabled = false;
96 remoting.HostInstallDialog.prototype.onOkClicked_ = function() {
97 this.continueInstallButton_.removeEventListener(
98 'click', this.onOkClickedHandler_, false);
99 this.cancelInstallButton_.removeEventListener(
100 'click', this.onCancelClickedHandler_, false);
101 this.continueInstallButton_.disabled = true;
102 this.cancelInstallButton_.disabled = true;
104 this.onDoneHandler_();
107 remoting.HostInstallDialog.prototype.onCancelClicked_ = function() {
108 this.continueInstallButton_.removeEventListener(
109 'click', this.onOkClickedHandler_, false);
110 this.cancelInstallButton_.removeEventListener(
111 'click', this.onCancelClickedHandler_, false);
112 this.onErrorHandler_(remoting.Error.CANCELLED);
115 remoting.HostInstallDialog.prototype.onRetryClicked_ = function() {
116 this.retryInstallButton_.removeEventListener(
117 'click', this.onRetryClickedHandler_.bind(this), false);
118 this.continueInstallButton_.addEventListener(
119 'click', this.onOkClickedHandler_, false);
120 this.cancelInstallButton_.addEventListener(
121 'click', this.onCancelClickedHandler_, false);
122 remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT);