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 'use strict'; 6 7 /** @suppress {duplicate} */ 8 var remoting = remoting || {}; 9 10 /** 11 * HostInstallDialog prompts the user to install host components. 12 * 13 * @constructor 14 */ 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'); 22 23 this.onOkClickedHandler_ = this.onOkClicked_.bind(this); 24 this.onCancelClickedHandler_ = this.onCancelClicked_.bind(this); 25 this.onRetryClickedHandler_ = this.onRetryClicked_.bind(this); 26 27 this.continueInstallButton_.disabled = false; 28 this.cancelInstallButton_.disabled = false; 29 30 /** @private*/ 31 this.onDoneHandler_ = function() {} 32 33 /** @param {remoting.Error} error @private */ 34 this.onErrorHandler_ = function(error) {} 35 }; 36 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' 47 }; 48 49 /** 50 * Starts downloading host components and shows installation prompt. 51 * 52 * @param {function():void} onDone Callback called when user clicks Ok, 53 * presumably after installing the host. The handler must verify that the host 54 * 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. 57 * @return {void} 58 */ 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); 65 66 var hostPackageUrl = 67 remoting.HostInstallDialog.hostDownloadUrls[navigator.platform]; 68 if (hostPackageUrl === undefined) { 69 this.onErrorHandler_(remoting.Error.CANCELLED); 70 return; 71 } 72 73 // Start downloading the package. 74 if (remoting.isAppsV2) { 75 // TODO(jamiewalch): Use chrome.downloads when it is available to 76 // apps v2 (http://crbug.com/174046) 77 window.open(hostPackageUrl); 78 } else { 79 window.location = hostPackageUrl; 80 } 81 82 /** @type {function():void} */ 83 this.onDoneHandler_ = onDone; 84 85 /** @type {function(remoting.Error):void} */ 86 this.onErrorHandler_ = onError; 87 } 88 89 /** 90 * In manual host installation, onDone handler must call this method if it 91 * detects that the host components are still unavailable. The same onDone 92 * and onError callbacks will be used when user clicks Ok or Cancel. 93 */ 94 remoting.HostInstallDialog.prototype.tryAgain = function() { 95 this.retryInstallButton_.addEventListener( 96 'click', this.onRetryClickedHandler_.bind(this), false); 97 remoting.setMode(remoting.AppMode.HOST_INSTALL_PENDING); 98 this.continueInstallButton_.disabled = false; 99 this.cancelInstallButton_.disabled = false; 100 }; 101 102 remoting.HostInstallDialog.prototype.onOkClicked_ = function() { 103 this.continueInstallButton_.removeEventListener( 104 'click', this.onOkClickedHandler_, false); 105 this.cancelInstallButton_.removeEventListener( 106 'click', this.onCancelClickedHandler_, false); 107 this.continueInstallButton_.disabled = true; 108 this.cancelInstallButton_.disabled = true; 109 110 this.onDoneHandler_(); 111 } 112 113 remoting.HostInstallDialog.prototype.onCancelClicked_ = function() { 114 this.continueInstallButton_.removeEventListener( 115 'click', this.onOkClickedHandler_, false); 116 this.cancelInstallButton_.removeEventListener( 117 'click', this.onCancelClickedHandler_, false); 118 this.onErrorHandler_(remoting.Error.CANCELLED); 119 } 120 121 remoting.HostInstallDialog.prototype.onRetryClicked_ = function() { 122 this.retryInstallButton_.removeEventListener( 123 'click', this.onRetryClickedHandler_.bind(this), false); 124 this.continueInstallButton_.addEventListener( 125 'click', this.onOkClickedHandler_, false); 126 this.cancelInstallButton_.addEventListener( 127 'click', this.onCancelClickedHandler_, false); 128 remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT); 129 }; 130