1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var remoting = remoting || {};
(function() {
'use strict';
/**
* @param {HTMLElement} rootElement
* @param {remoting.LocalHostSection.Controller} controller
*
* @constructor
* @implements {base.Disposable}
*/
remoting.LocalHostSection = function(rootElement, controller) {
/** @private */
this.rootElement_ = rootElement;
/** @private */
this.controller_ = controller;
/** @private {remoting.Host} */
this.host_ = null;
/** @private {remoting.HostController.State} */
this.state_ = remoting.HostController.State.UNKNOWN;
var hostContainer = rootElement.querySelector('.host-entry');
/** @private */
this.hostTableEntry_ = new remoting.HostTableEntry(
parseInt(chrome.runtime.getManifest().version, 10),
remoting.connectMe2Me,
this.rename_.bind(this));
hostContainer.appendChild(this.hostTableEntry_.element());
this.hostTableEntry_.element().id = 'local-host-connect-button';
var startButton = rootElement.querySelector('.start-daemon');
var stopButton = rootElement.querySelector('.stop-daemon');
var stopLocalDaemonButton = rootElement.querySelector('.stop-local-daemon');
var changePINButton = rootElement.querySelector('.change-daemon-pin');
/** @private */
this.eventHooks_ = new base.Disposables(
new base.DomEventHook(startButton, 'click',
controller.start.bind(controller), false),
new base.DomEventHook(stopButton, 'click',
controller.stop.bind(controller), false),
new base.DomEventHook(stopLocalDaemonButton, 'click',
controller.stop.bind(controller), false),
new base.DomEventHook(changePINButton, 'click',
controller.changePIN.bind(controller), false));
/** @private */
this.hasError_ = false;
};
remoting.LocalHostSection.prototype.dispose = function() {
base.dispose(this.eventHooks_);
this.eventHooks_ = null;
};
/**
* @param {remoting.Host} host
* @param {remoting.HostController.State} state
* @param {boolean} hasError Whether the host list is in an error state.
*/
remoting.LocalHostSection.prototype.setModel = function(host, state, hasError) {
this.host_ = host;
this.state_ = state;
this.hasError_ = hasError;
this.updateUI_();
};
/**
* @return {?string}
*/
remoting.LocalHostSection.prototype.getHostId = function() {
return this.host_ ? this.host_.hostId : null;
};
/** @return {boolean} */
remoting.LocalHostSection.prototype.isEnabled_ = function() {
return (this.state_ == remoting.HostController.State.STARTING) ||
(this.state_ == remoting.HostController.State.STARTED);
};
/** @return {boolean} */
remoting.LocalHostSection.prototype.canChangeState = function() {
// The local host cannot be stopped or started if the host controller is not
// implemented for this platform.
var state = this.state_;
if (state === remoting.HostController.State.NOT_IMPLEMENTED ||
state === remoting.HostController.State.UNKNOWN) {
return false;
}
// Return false if the host is uninstallable. The NOT_INSTALLED check is
// required to handle the special case for Ubuntu, as we report the host as
// uninstallable on Linux.
if (!this.isMe2MeInstallable_() &&
state === remoting.HostController.State.NOT_INSTALLED) {
return false;
}
// In addition, it cannot be started if there is an error (in many error
// states, the start operation will fail anyway, but even if it succeeds, the
// chance of a related but hard-to-diagnose future error is high).
return this.isEnabled_() || !this.hasError_;
};
/**
* Returns true if the current platform is fully supported. It's only used when
* we detect that host native messaging components are not installed. In that
* case the result of this function determines if the webapp should show the
* controls that allow to install and enable Me2Me host.
*
* @return {boolean}
* @private
*/
remoting.LocalHostSection.prototype.isMe2MeInstallable_ = function() {
// The chromoting host is currently not installable on ChromeOS.
// For Linux, we have a install package for Ubuntu but not other distros.
// Since we cannot tell from javascript alone the Linux distro the client is
// on, we don't show the daemon-control UI for Linux unless the host is
// installed.
return remoting.platformIsWindows() || remoting.platformIsMac();
}
/** @private */
remoting.LocalHostSection.prototype.updateUI_ = function() {
this.hostTableEntry_.setHost(this.host_);
// Disable elements.
var enabled = this.isEnabled_();
var canChangeLocalHostState = this.canChangeState();
var daemonState = '';
if (!enabled) {
daemonState = 'disabled';
} else if (this.host_ !== null) {
daemonState = 'enabled';
} else {
daemonState = 'enabled-other-account';
}
remoting.updateModalUi(daemonState, 'data-daemon-state');
this.rootElement_.hidden = !canChangeLocalHostState;
};
remoting.LocalHostSection.prototype.rename_ = function() {
return this.controller_.rename(this.hostTableEntry_);
};
/**
* @constructor
* @param {remoting.HostList} hostList
* @param {remoting.HostSetupDialog} setupDialog
*/
remoting.LocalHostSection.Controller = function(hostList, setupDialog) {
/** @private */
this.hostList_ = hostList;
this.setupDialog_ = setupDialog;
};
remoting.LocalHostSection.Controller.prototype.start = function() {
this.setupDialog_.showForStart();
};
remoting.LocalHostSection.Controller.prototype.stop = function() {
this.setupDialog_.showForStop();
};
remoting.LocalHostSection.Controller.prototype.changePIN = function() {
this.setupDialog_.showForPin();
};
/** @param {remoting.HostTableEntry} host */
remoting.LocalHostSection.Controller.prototype.rename = function(host) {
this.hostList_.renameHost(host);
};
}());
|