OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Class representing the host-list portion of the home screen UI. | 7 * Class representing the host-list portion of the home screen UI. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 30 matching lines...) Expand all Loading... |
41 this.errorMsg_ = errorMsg; | 41 this.errorMsg_ = errorMsg; |
42 /** @private {Element} */ | 42 /** @private {Element} */ |
43 this.errorButton_ = errorButton; | 43 this.errorButton_ = errorButton; |
44 /** @private {HTMLElement} */ | 44 /** @private {HTMLElement} */ |
45 this.loadingIndicator_ = loadingIndicator; | 45 this.loadingIndicator_ = loadingIndicator; |
46 /** @private {Array<remoting.HostTableEntry>} */ | 46 /** @private {Array<remoting.HostTableEntry>} */ |
47 this.hostTableEntries_ = []; | 47 this.hostTableEntries_ = []; |
48 /** @private {Array<remoting.Host>} */ | 48 /** @private {Array<remoting.Host>} */ |
49 this.hosts_ = []; | 49 this.hosts_ = []; |
50 /** @private {!remoting.Error} */ | 50 /** @private {!remoting.Error} */ |
51 this.lastError_ = remoting.Error.NONE; | 51 this.lastError_ = remoting.Error.none(); |
52 /** @private {remoting.LocalHostSection} */ | 52 /** @private {remoting.LocalHostSection} */ |
53 this.localHostSection_ = new remoting.LocalHostSection( | 53 this.localHostSection_ = new remoting.LocalHostSection( |
54 /** @type {HTMLElement} */ (document.querySelector('.daemon-control')), | 54 /** @type {HTMLElement} */ (document.querySelector('.daemon-control')), |
55 new remoting.LocalHostSection.Controller( | 55 new remoting.LocalHostSection.Controller( |
56 this, new remoting.HostSetupDialog(remoting.hostController))); | 56 this, new remoting.HostSetupDialog(remoting.hostController))); |
57 | 57 |
58 /** @private {number} */ | 58 /** @private {number} */ |
59 this.webappMajorVersion_ = parseInt(chrome.runtime.getManifest().version, 10); | 59 this.webappMajorVersion_ = parseInt(chrome.runtime.getManifest().version, 10); |
60 | 60 |
61 this.errorButton_.addEventListener('click', | 61 this.errorButton_.addEventListener('click', |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 * Handle the results of the host list request. A success response will | 150 * Handle the results of the host list request. A success response will |
151 * include a JSON-encoded list of host descriptions, which we display if we're | 151 * include a JSON-encoded list of host descriptions, which we display if we're |
152 * able to successfully parse it. | 152 * able to successfully parse it. |
153 * | 153 * |
154 * @param {function(boolean):void} onDone The callback passed to |refresh|. | 154 * @param {function(boolean):void} onDone The callback passed to |refresh|. |
155 * @param {Array<remoting.Host>} hosts The list of hosts for the user. | 155 * @param {Array<remoting.Host>} hosts The list of hosts for the user. |
156 * @return {void} Nothing. | 156 * @return {void} Nothing. |
157 * @private | 157 * @private |
158 */ | 158 */ |
159 remoting.HostList.prototype.onHostListResponse_ = function(onDone, hosts) { | 159 remoting.HostList.prototype.onHostListResponse_ = function(onDone, hosts) { |
160 this.lastError_ = remoting.Error.NONE; | 160 this.lastError_ = remoting.Error.none(); |
161 this.hosts_ = hosts; | 161 this.hosts_ = hosts; |
162 this.sortHosts_(); | 162 this.sortHosts_(); |
163 this.save_(); | 163 this.save_(); |
164 this.loadingIndicator_.classList.remove('loading'); | 164 this.loadingIndicator_.classList.remove('loading'); |
165 onDone(true); | 165 onDone(true); |
166 }; | 166 }; |
167 | 167 |
168 /** | 168 /** |
169 * Sort the internal list of hosts. | 169 * Sort the internal list of hosts. |
170 * | 170 * |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 */ | 204 */ |
205 remoting.HostList.prototype.display = function() { | 205 remoting.HostList.prototype.display = function() { |
206 this.table_.innerText = ''; | 206 this.table_.innerText = ''; |
207 this.errorMsg_.innerText = ''; | 207 this.errorMsg_.innerText = ''; |
208 this.hostTableEntries_ = []; | 208 this.hostTableEntries_ = []; |
209 | 209 |
210 var noHostsRegistered = (this.hosts_.length == 0); | 210 var noHostsRegistered = (this.hosts_.length == 0); |
211 this.table_.hidden = noHostsRegistered; | 211 this.table_.hidden = noHostsRegistered; |
212 this.noHosts_.hidden = !noHostsRegistered; | 212 this.noHosts_.hidden = !noHostsRegistered; |
213 | 213 |
214 if (this.lastError_.isError()) { | 214 if (!this.lastError_.isNone()) { |
215 l10n.localizeElementFromTag(this.errorMsg_, this.lastError_.tag); | 215 l10n.localizeElementFromTag(this.errorMsg_, this.lastError_.getTag()); |
216 if (this.lastError_.tag == remoting.Error.Tag.AUTHENTICATION_FAILED) { | 216 if (this.lastError_.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { |
217 l10n.localizeElementFromTag(this.errorButton_, | 217 l10n.localizeElementFromTag(this.errorButton_, |
218 /*i18n-content*/'SIGN_IN_BUTTON'); | 218 /*i18n-content*/'SIGN_IN_BUTTON'); |
219 } else { | 219 } else { |
220 l10n.localizeElementFromTag(this.errorButton_, | 220 l10n.localizeElementFromTag(this.errorButton_, |
221 /*i18n-content*/'RETRY'); | 221 /*i18n-content*/'RETRY'); |
222 } | 222 } |
223 } else { | 223 } else { |
224 for (var i = 0; i < this.hosts_.length; ++i) { | 224 for (var i = 0; i < this.hosts_.length; ++i) { |
225 /** @type {remoting.Host} */ | 225 /** @type {remoting.Host} */ |
226 var host = this.hosts_[i]; | 226 var host = this.hosts_[i]; |
227 // Validate the entry to make sure it has all the fields we expect and is | 227 // Validate the entry to make sure it has all the fields we expect and is |
228 // not the local host (which is displayed separately). NB: if the host has | 228 // not the local host (which is displayed separately). NB: if the host has |
229 // never sent a heartbeat, then there will be no jabberId. | 229 // never sent a heartbeat, then there will be no jabberId. |
230 if (host.hostName && host.hostId && host.status && host.publicKey && | 230 if (host.hostName && host.hostId && host.status && host.publicKey && |
231 (host.hostId != this.localHostSection_.getHostId())) { | 231 (host.hostId != this.localHostSection_.getHostId())) { |
232 var hostTableEntry = new remoting.HostTableEntry( | 232 var hostTableEntry = new remoting.HostTableEntry( |
233 this.webappMajorVersion_, | 233 this.webappMajorVersion_, |
234 remoting.connectMe2Me, | 234 remoting.connectMe2Me, |
235 this.renameHost.bind(this), | 235 this.renameHost.bind(this), |
236 this.deleteHost_.bind(this)); | 236 this.deleteHost_.bind(this)); |
237 hostTableEntry.setHost(host); | 237 hostTableEntry.setHost(host); |
238 this.hostTableEntries_[i] = hostTableEntry; | 238 this.hostTableEntries_[i] = hostTableEntry; |
239 this.table_.appendChild(hostTableEntry.element()); | 239 this.table_.appendChild(hostTableEntry.element()); |
240 } | 240 } |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 this.errorMsg_.parentNode.hidden = !this.lastError_.isError(); | 244 this.errorMsg_.parentNode.hidden = this.lastError_.isNone(); |
245 if (noHostsRegistered) { | 245 if (noHostsRegistered) { |
246 this.showHostListEmptyMessage_(this.localHostSection_.canChangeState()); | 246 this.showHostListEmptyMessage_(this.localHostSection_.canChangeState()); |
247 } | 247 } |
248 }; | 248 }; |
249 | 249 |
250 /** | 250 /** |
251 * Displays a message to the user when the host list is empty. | 251 * Displays a message to the user when the host list is empty. |
252 * | 252 * |
253 * @param {boolean} hostingSupported | 253 * @param {boolean} hostingSupported |
254 * @return {void} | 254 * @return {void} |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 348 |
349 /** | 349 /** |
350 * Set the state of the local host and localHostId if any. | 350 * Set the state of the local host and localHostId if any. |
351 * | 351 * |
352 * @param {remoting.HostController.State} state State of the local host. | 352 * @param {remoting.HostController.State} state State of the local host. |
353 * @param {string?} hostId ID of the local host, or null. | 353 * @param {string?} hostId ID of the local host, or null. |
354 * @return {void} Nothing. | 354 * @return {void} Nothing. |
355 */ | 355 */ |
356 remoting.HostList.prototype.setLocalHostStateAndId = function(state, hostId) { | 356 remoting.HostList.prototype.setLocalHostStateAndId = function(state, hostId) { |
357 var host = hostId ? this.getHostForId(hostId) : null; | 357 var host = hostId ? this.getHostForId(hostId) : null; |
358 this.localHostSection_.setModel(host, state, this.lastError_.isError()); | 358 this.localHostSection_.setModel(host, state, !this.lastError_.isNone()); |
359 }; | 359 }; |
360 | 360 |
361 /** | 361 /** |
362 * Called by the HostControlled after the local host has been started. | 362 * Called by the HostControlled after the local host has been started. |
363 * | 363 * |
364 * @param {string} hostName Host name. | 364 * @param {string} hostName Host name. |
365 * @param {string} hostId ID of the local host. | 365 * @param {string} hostId ID of the local host. |
366 * @param {string} publicKey Public key. | 366 * @param {string} publicKey Public key. |
367 * @return {void} Nothing. | 367 * @return {void} Nothing. |
368 */ | 368 */ |
(...skipping 10 matching lines...) Expand all Loading... |
379 // Provide a version number to avoid warning about this dummy host being | 379 // Provide a version number to avoid warning about this dummy host being |
380 // out-of-date. | 380 // out-of-date. |
381 localHost.hostVersion = String(this.webappMajorVersion_) + ".x" | 381 localHost.hostVersion = String(this.webappMajorVersion_) + ".x" |
382 localHost.hostId = hostId; | 382 localHost.hostId = hostId; |
383 localHost.publicKey = publicKey; | 383 localHost.publicKey = publicKey; |
384 localHost.status = 'ONLINE'; | 384 localHost.status = 'ONLINE'; |
385 this.hosts_.push(localHost); | 385 this.hosts_.push(localHost); |
386 this.save_(); | 386 this.save_(); |
387 this.localHostSection_.setModel(localHost, | 387 this.localHostSection_.setModel(localHost, |
388 remoting.HostController.State.STARTED, | 388 remoting.HostController.State.STARTED, |
389 this.lastError_.isError()); | 389 !this.lastError_.isNone()); |
390 }; | 390 }; |
391 | 391 |
392 /** | 392 /** |
393 * Called when the user clicks the button next to the error message. The action | 393 * Called when the user clicks the button next to the error message. The action |
394 * depends on the error. | 394 * depends on the error. |
395 * | 395 * |
396 * @private | 396 * @private |
397 */ | 397 */ |
398 remoting.HostList.prototype.onErrorClick_ = function() { | 398 remoting.HostList.prototype.onErrorClick_ = function() { |
399 if (this.lastError_.tag == remoting.Error.Tag.AUTHENTICATION_FAILED) { | 399 if (this.lastError_.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED)) { |
400 remoting.handleAuthFailureAndRelaunch(); | 400 remoting.handleAuthFailureAndRelaunch(); |
401 } else { | 401 } else { |
402 this.refresh(remoting.updateLocalHostState); | 402 this.refresh(remoting.updateLocalHostState); |
403 } | 403 } |
404 }; | 404 }; |
405 | 405 |
406 /** | 406 /** |
407 * Save the host list to local storage. | 407 * Save the host list to local storage. |
408 */ | 408 */ |
409 remoting.HostList.prototype.save_ = function() { | 409 remoting.HostList.prototype.save_ = function() { |
410 var items = {}; | 410 var items = {}; |
411 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); | 411 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); |
412 chrome.storage.local.set(items); | 412 chrome.storage.local.set(items); |
413 if (this.hosts_.length !== 0) { | 413 if (this.hosts_.length !== 0) { |
414 remoting.AppsV2Migration.saveUserInfo(); | 414 remoting.AppsV2Migration.saveUserInfo(); |
415 } | 415 } |
416 }; | 416 }; |
417 | 417 |
418 /** | 418 /** |
419 * Key name under which Me2Me hosts are cached. | 419 * Key name under which Me2Me hosts are cached. |
420 */ | 420 */ |
421 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; | 421 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; |
422 | 422 |
423 /** @type {remoting.HostList} */ | 423 /** @type {remoting.HostList} */ |
424 remoting.hostList = null; | 424 remoting.hostList = null; |
OLD | NEW |