| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * | 7 * |
| 8 * HostInstaller allows the caller to download the host binary and monitor the | 8 * HostInstaller allows the caller to download the host binary and monitor the |
| 9 * install progress of the host by pinging the host periodically via native | 9 * install progress of the host by pinging the host periodically via native |
| 10 * messaging. | 10 * messaging. |
| 11 * | 11 * |
| 12 * To download the host and wait for install: | 12 * To download the host and wait for install: |
| 13 * var hostInstaller = new remoting.HostInstaller(); | 13 * var hostInstaller = new remoting.HostInstaller(); |
| 14 * hostInstaller.downloadAndWaitForInstall().then(function() { | 14 * hostInstaller.downloadAndWaitForInstall().then(function() { |
| 15 * // Install has completed. | 15 * // Install has completed. |
| 16 * }, function(){ | 16 * }, function(){ |
| 17 * // Download has failed. | 17 * // Download has failed. |
| 18 * }) | 18 * }) |
| 19 * | 19 * |
| 20 * To stop listening to the install progress: | 20 * To stop listening to the install progress: |
| 21 * hostInstaller.cancel(); | 21 * hostInstaller.cancel(); |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 'use strict'; | 24 'use strict'; |
| 25 | 25 |
| 26 /** @suppress {duplicate} */ | 26 /** @suppress {duplicate} */ |
| 27 var remoting = remoting || {}; | 27 var remoting = remoting || {}; |
| 28 | 28 |
| 29 (function() { |
| 30 |
| 29 /** | 31 /** |
| 30 * @constructor | 32 * @constructor |
| 31 */ | 33 */ |
| 32 remoting.HostInstaller = function() { | 34 remoting.HostInstaller = function() { |
| 33 /** | 35 /** |
| 34 * @type {Promise} | 36 * @type {Promise} |
| 35 * @private | 37 * @private |
| 36 */ | 38 */ |
| 37 this.downloadAndWaitForInstallPromise_ = null; | 39 this.downloadAndWaitForInstallPromise_ = null; |
| 38 | 40 |
| 39 /** | 41 /** |
| 40 * @type {?number} | 42 * @type {?number} |
| 41 * @private | 43 * @private |
| 42 */ | 44 */ |
| 43 this.checkInstallIntervalId_ = null; | 45 this.checkInstallIntervalId_ = null; |
| 44 }; | 46 }; |
| 45 | 47 |
| 46 /** | 48 /** |
| 47 * @return {Promise} The promise will resolve to a boolean value indicating | 49 * @return {Promise} The promise will resolve to a boolean value indicating |
| 48 * whether the host is installed or not. | 50 * whether the host is installed or not. |
| 49 */ | 51 */ |
| 50 remoting.HostInstaller.prototype.isInstalled = function() { | 52 remoting.HostInstaller.isInstalled = function() { |
| 51 // Always do a fresh check as we don't get notified when the host is | 53 // Always do a fresh check as we don't get notified when the host is |
| 52 // uninstalled. | 54 // uninstalled. |
| 53 | 55 |
| 54 /** @param {function(*=):void} resolve */ | 56 /** @param {function(*=):void} resolve */ |
| 55 return new Promise(function(resolve) { | 57 return new Promise(function(resolve) { |
| 56 // TODO(kelvinp): Use different native messaging ports for the Me2me host | 58 // TODO(kelvinp): Use different native messaging ports for the Me2me host |
| 57 // vs It2MeHost. | 59 // vs It2MeHost. |
| 58 /** @type {chrome.runtime.Port} */ | 60 /** @type {chrome.runtime.Port} */ |
| 59 var port = | 61 var port = |
| 60 chrome.runtime.connectNative('com.google.chrome.remote_assistance'); | 62 chrome.runtime.connectNative('com.google.chrome.remote_assistance'); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 71 port.onMessage.removeListener(onMessage); | 73 port.onMessage.removeListener(onMessage); |
| 72 resolve(false); | 74 resolve(false); |
| 73 } | 75 } |
| 74 | 76 |
| 75 port.onDisconnect.addListener(onDisconnected); | 77 port.onDisconnect.addListener(onDisconnected); |
| 76 port.onMessage.addListener(onMessage); | 78 port.onMessage.addListener(onMessage); |
| 77 port.postMessage({type: 'hello'}); | 79 port.postMessage({type: 'hello'}); |
| 78 }); | 80 }); |
| 79 }; | 81 }; |
| 80 | 82 |
| 83 /** @type {Object.<string,string>} */ |
| 84 var HOST_DOWNLOAD_URLS = { |
| 85 'Win32': 'http://dl.google.com/dl/edgedl/chrome-remote-desktop/' + |
| 86 'chromeremotedesktophost.msi', |
| 87 'Win64': 'http://dl.google.com/dl/edgedl/chrome-remote-desktop/' + |
| 88 'chromeremotedesktophost.msi', |
| 89 'MacIntel': 'https://dl.google.com/chrome-remote-desktop/' + |
| 90 'chromeremotedesktop.dmg', |
| 91 'Linux x86_64': 'https://dl.google.com/linux/direct/' + |
| 92 'chrome-remote-desktop_current_amd64.deb', |
| 93 'Linux i386': 'https://dl.google.com/linux/direct/' + |
| 94 'chrome-remote-desktop_current_i386.deb', |
| 95 'Linux i686': 'https://dl.google.com/linux/direct/' + |
| 96 'chrome-remote-desktop_current_i386.deb' |
| 97 }; |
| 98 |
| 99 /** |
| 100 * Returns true if the host is installable on the current platform. |
| 101 * @returns {boolean} |
| 102 */ |
| 103 remoting.HostInstaller.canInstall = function() { |
| 104 return !!HOST_DOWNLOAD_URLS[navigator.platform]; |
| 105 }; |
| 106 |
| 81 /** | 107 /** |
| 82 * @throws {Error} Throws if there is no matching host binary for the current | 108 * @throws {Error} Throws if there is no matching host binary for the current |
| 83 * platform. | 109 * platform. |
| 84 */ | 110 */ |
| 85 remoting.HostInstaller.prototype.download = function() { | 111 remoting.HostInstaller.prototype.download = function() { |
| 86 /** @type {Object.<string,string>} */ | 112 var hostPackageUrl = HOST_DOWNLOAD_URLS[navigator.platform]; |
| 87 var hostDownloadUrls = { | |
| 88 'Win32' : 'http://dl.google.com/dl/edgedl/chrome-remote-desktop/' + | |
| 89 'chromeremotedesktophost.msi', | |
| 90 'Win64' : 'http://dl.google.com/dl/edgedl/chrome-remote-desktop/' + | |
| 91 'chromeremotedesktophost.msi', | |
| 92 'MacIntel' : 'https://dl.google.com/chrome-remote-desktop/' + | |
| 93 'chromeremotedesktop.dmg', | |
| 94 'Linux x86_64' : 'https://dl.google.com/linux/direct/' + | |
| 95 'chrome-remote-desktop_current_amd64.deb', | |
| 96 'Linux i386' : 'https://dl.google.com/linux/direct/' + | |
| 97 'chrome-remote-desktop_current_i386.deb' | |
| 98 }; | |
| 99 | |
| 100 var hostPackageUrl = hostDownloadUrls[navigator.platform]; | |
| 101 if (hostPackageUrl === undefined) { | 113 if (hostPackageUrl === undefined) { |
| 102 throw new Error(remoting.Error.CANCELLED); | 114 console.error("Tried to install host on " + navigator.platform); |
| 115 throw new Error(remoting.Error.UNEXPECTED); |
| 103 } | 116 } |
| 104 | 117 |
| 105 // Start downloading the package. | 118 // Start downloading the package. |
| 106 if (base.isAppsV2()) { | 119 if (base.isAppsV2()) { |
| 107 // TODO(jamiewalch): Use chrome.downloads when it is available to | 120 // TODO(jamiewalch): Use chrome.downloads when it is available to |
| 108 // apps v2 (http://crbug.com/174046) | 121 // apps v2 (http://crbug.com/174046) |
| 109 window.open(hostPackageUrl); | 122 window.open(hostPackageUrl); |
| 110 } else { | 123 } else { |
| 111 window.location = hostPackageUrl; | 124 window.location = hostPackageUrl; |
| 112 } | 125 } |
| 113 }; | 126 }; |
| 114 | 127 |
| 115 /** @return {Promise} */ | 128 /** @return {Promise} */ |
| 116 remoting.HostInstaller.prototype.downloadAndWaitForInstall = function() { | 129 remoting.HostInstaller.prototype.downloadAndWaitForInstall = function() { |
| 117 /** @type {remoting.HostInstaller} */ | 130 /** @type {remoting.HostInstaller} */ |
| 118 var that = this; | 131 var that = this; |
| 119 /** | 132 /** |
| 120 * @type {number} | 133 * @type {number} |
| 121 * @const | 134 * @const |
| 122 */ | 135 */ |
| 123 var CHECK_INSTALL_INTERVAL_IN_MILLISECONDS = 1000; | 136 var CHECK_INSTALL_INTERVAL_IN_MILLISECONDS = 1000; |
| 124 | 137 |
| 125 return this.isInstalled().then( | 138 return remoting.HostInstaller.isInstalled().then( |
| 126 /** @param {boolean} installed */ | 139 /** @param {boolean} installed */ |
| 127 function(installed){ | 140 function(installed){ |
| 128 if (installed) { | 141 if (installed) { |
| 129 return Promise.resolve(true); | 142 return Promise.resolve(true); |
| 130 } | 143 } |
| 131 | 144 |
| 132 if (that.downloadAndWaitForInstallPromise_ === null) { | 145 if (that.downloadAndWaitForInstallPromise_ === null) { |
| 133 that.downloadAndWaitForInstallPromise_ = new Promise( | 146 that.downloadAndWaitForInstallPromise_ = new Promise( |
| 134 /** @param {Function} resolve */ | 147 /** @param {Function} resolve */ |
| 135 function(resolve){ | 148 function(resolve){ |
| 136 that.download(); | 149 that.download(); |
| 137 that.checkInstallIntervalId_ = window.setInterval(function() { | 150 that.checkInstallIntervalId_ = window.setInterval(function() { |
| 138 that.isInstalled().then( | 151 remoting.HostInstaller.isInstalled().then( |
| 139 /** @param {boolean} installed */ | 152 /** @param {boolean} installed */ |
| 140 function(installed) { | 153 function(installed) { |
| 141 if (installed) { | 154 if (installed) { |
| 142 that.cancel(); | 155 that.cancel(); |
| 143 resolve(); | 156 resolve(); |
| 144 } | 157 } |
| 145 }); | 158 }); |
| 146 }, CHECK_INSTALL_INTERVAL_IN_MILLISECONDS); | 159 }, CHECK_INSTALL_INTERVAL_IN_MILLISECONDS); |
| 147 }); | 160 }); |
| 148 } | 161 } |
| 149 return that.downloadAndWaitForInstallPromise_; | 162 return that.downloadAndWaitForInstallPromise_; |
| 150 }); | 163 }); |
| 151 }; | 164 }; |
| 152 | 165 |
| 153 /** | 166 /** |
| 154 * Stops waiting for the host to be installed. | 167 * Stops waiting for the host to be installed. |
| 155 * For example | 168 * For example |
| 156 * var promise = hostInstaller.downloadAndWaitForInstall(); | 169 * var promise = hostInstaller.downloadAndWaitForInstall(); |
| 157 * hostInstaller.cancel(); // This will prevent |promise| from fulfilling. | 170 * hostInstaller.cancel(); // This will prevent |promise| from fulfilling. |
| 158 */ | 171 */ |
| 159 remoting.HostInstaller.prototype.cancel = function() { | 172 remoting.HostInstaller.prototype.cancel = function() { |
| 160 if (this.checkInstallIntervalId_ !== null) { | 173 if (this.checkInstallIntervalId_ !== null) { |
| 161 window.clearInterval(this.checkInstallIntervalId_); | 174 window.clearInterval(this.checkInstallIntervalId_); |
| 162 this.checkInstallIntervalId_ = null; | 175 this.checkInstallIntervalId_ = null; |
| 163 } | 176 } |
| 164 this.downloadAndWaitForInstallPromise_ = null; | 177 this.downloadAndWaitForInstallPromise_ = null; |
| 165 }; | 178 }; |
| 179 |
| 180 })(); |
| OLD | NEW |