Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / remoting / webapp / host_install_dialog.js
blobab072e830eecafb866a892183a70526a8714be51
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.
5 'use strict';
7 /** @suppress {duplicate} */
8 var remoting = remoting || {};
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');
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*/
31   this.onDoneHandler_ = function() {};
33   /** @param {remoting.Error} error @private */
34   this.onErrorHandler_ = function(error) {};
36   /**
37    * @type {remoting.HostInstaller}
38    * @private
39    */
40   this.hostInstaller_ = new remoting.HostInstaller();
43 /**
44  * Starts downloading host components and shows installation prompt.
45  *
46  * @param {function():void} onDone Callback called when user clicks Ok,
47  * presumably after installing the host. The handler must verify that the host
48  * has been installed and call tryAgain() otherwise.
49  * @param {function(remoting.Error):void} onError Callback called when user
50  *    clicks Cancel button or there is some other unexpected error.
51  * @return {void}
52  */
53 remoting.HostInstallDialog.prototype.show = function(onDone, onError) {
54   this.continueInstallButton_.addEventListener(
55       'click', this.onOkClickedHandler_, false);
56   this.cancelInstallButton_.addEventListener(
57       'click', this.onCancelClickedHandler_, false);
58   remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT);
60   /** @type {function():void} */
61   this.onDoneHandler_ = onDone;
63   /** @type {function(remoting.Error):void} */
64   this.onErrorHandler_ = onError;
66   /** @type {remoting.HostInstaller} */
67   var hostInstaller = new remoting.HostInstaller();
69   /** @type {remoting.HostInstallDialog} */
70   var that = this;
72   this.hostInstaller_.downloadAndWaitForInstall().then(function() {
73     that.continueInstallButton_.click();
74     that.hostInstaller_.cancel();
75   }, function(){
76     that.onErrorHandler_(remoting.Error.CANCELLED);
77     that.hostInstaller_.cancel();
78   });
81 /**
82  * In manual host installation, onDone handler must call this method if it
83  * detects that the host components are still unavailable. The same onDone
84  * and onError callbacks will be used when user clicks Ok or Cancel.
85  */
86 remoting.HostInstallDialog.prototype.tryAgain = function() {
87   this.retryInstallButton_.addEventListener(
88       'click', this.onRetryClickedHandler_.bind(this), false);
89   remoting.setMode(remoting.AppMode.HOST_INSTALL_PENDING);
90   this.continueInstallButton_.disabled = false;
91   this.cancelInstallButton_.disabled = false;
94 remoting.HostInstallDialog.prototype.onOkClicked_ = function() {
95   this.continueInstallButton_.removeEventListener(
96       'click', this.onOkClickedHandler_, false);
97   this.cancelInstallButton_.removeEventListener(
98       'click', this.onCancelClickedHandler_, false);
99   this.continueInstallButton_.disabled = true;
100   this.cancelInstallButton_.disabled = true;
102   this.onDoneHandler_();
105 remoting.HostInstallDialog.prototype.onCancelClicked_ = function() {
106   this.continueInstallButton_.removeEventListener(
107       'click', this.onOkClickedHandler_, false);
108   this.cancelInstallButton_.removeEventListener(
109       'click', this.onCancelClickedHandler_, false);
110   this.hostInstaller_.cancel();
111   this.onErrorHandler_(remoting.Error.CANCELLED);
114 remoting.HostInstallDialog.prototype.onRetryClicked_ = function() {
115   this.retryInstallButton_.removeEventListener(
116       'click', this.onRetryClickedHandler_.bind(this), false);
117   this.continueInstallButton_.addEventListener(
118       'click', this.onOkClickedHandler_, false);
119   this.cancelInstallButton_.addEventListener(
120       'click', this.onCancelClickedHandler_, false);
121   remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT);