| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 * @type {Array<remoting.HostTableEntry>} | 60 * @type {Array<remoting.HostTableEntry>} |
| 61 * @private | 61 * @private |
| 62 */ | 62 */ |
| 63 this.hostTableEntries_ = []; | 63 this.hostTableEntries_ = []; |
| 64 /** | 64 /** |
| 65 * @type {Array<remoting.Host>} | 65 * @type {Array<remoting.Host>} |
| 66 * @private | 66 * @private |
| 67 */ | 67 */ |
| 68 this.hosts_ = []; | 68 this.hosts_ = []; |
| 69 /** | 69 /** |
| 70 * @type {string} | 70 * @type {!remoting.Error} |
| 71 * @private | 71 * @private |
| 72 */ | 72 */ |
| 73 this.lastError_ = ''; | 73 this.lastError_ = remoting.Error.NONE; |
| 74 /** | 74 /** |
| 75 * @type {remoting.Host?} | 75 * @type {remoting.Host?} |
| 76 * @private | 76 * @private |
| 77 */ | 77 */ |
| 78 this.localHost_ = null; | 78 this.localHost_ = null; |
| 79 /** | 79 /** |
| 80 * @type {remoting.HostController.State} | 80 * @type {remoting.HostController.State} |
| 81 * @private | 81 * @private |
| 82 */ | 82 */ |
| 83 this.localHostState_ = remoting.HostController.State.UNKNOWN; | 83 this.localHostState_ = remoting.HostController.State.UNKNOWN; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 * Query the Remoting Directory for the user's list of hosts. | 160 * Query the Remoting Directory for the user's list of hosts. |
| 161 * | 161 * |
| 162 * @param {function(boolean):void} onDone Callback invoked with true on success | 162 * @param {function(boolean):void} onDone Callback invoked with true on success |
| 163 * or false on failure. | 163 * or false on failure. |
| 164 * @return {void} Nothing. | 164 * @return {void} Nothing. |
| 165 */ | 165 */ |
| 166 remoting.HostList.prototype.refresh = function(onDone) { | 166 remoting.HostList.prototype.refresh = function(onDone) { |
| 167 this.loadingIndicator_.classList.add('loading'); | 167 this.loadingIndicator_.classList.add('loading'); |
| 168 /** @type {remoting.HostList} */ | 168 /** @type {remoting.HostList} */ |
| 169 var that = this; | 169 var that = this; |
| 170 /** @param {remoting.Error} error */ | 170 /** @param {!remoting.Error} error */ |
| 171 var onError = function(error) { | 171 var onError = function(error) { |
| 172 that.lastError_ = error; | 172 that.lastError_ = error; |
| 173 onDone(false); | 173 onDone(false); |
| 174 }; | 174 }; |
| 175 remoting.hostListApi.get(this.onHostListResponse_.bind(this, onDone), | 175 remoting.hostListApi.get(this.onHostListResponse_.bind(this, onDone), |
| 176 onError); | 176 onError); |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 /** | 179 /** |
| 180 * Handle the results of the host list request. A success response will | 180 * Handle the results of the host list request. A success response will |
| 181 * include a JSON-encoded list of host descriptions, which we display if we're | 181 * include a JSON-encoded list of host descriptions, which we display if we're |
| 182 * able to successfully parse it. | 182 * able to successfully parse it. |
| 183 * | 183 * |
| 184 * @param {function(boolean):void} onDone The callback passed to |refresh|. | 184 * @param {function(boolean):void} onDone The callback passed to |refresh|. |
| 185 * @param {Array<remoting.Host>} hosts The list of hosts for the user. | 185 * @param {Array<remoting.Host>} hosts The list of hosts for the user. |
| 186 * @return {void} Nothing. | 186 * @return {void} Nothing. |
| 187 * @private | 187 * @private |
| 188 */ | 188 */ |
| 189 remoting.HostList.prototype.onHostListResponse_ = function(onDone, hosts) { | 189 remoting.HostList.prototype.onHostListResponse_ = function(onDone, hosts) { |
| 190 this.lastError_ = ''; | 190 this.lastError_ = remoting.Error.NONE; |
| 191 this.hosts_ = hosts; | 191 this.hosts_ = hosts; |
| 192 this.sortHosts_(); | 192 this.sortHosts_(); |
| 193 this.save_(); | 193 this.save_(); |
| 194 this.loadingIndicator_.classList.remove('loading'); | 194 this.loadingIndicator_.classList.remove('loading'); |
| 195 onDone(this.lastError_ == ''); | 195 onDone(true); |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * Sort the internal list of hosts. | 199 * Sort the internal list of hosts. |
| 200 * | 200 * |
| 201 * @suppress {reportUnknownTypes} | 201 * @suppress {reportUnknownTypes} |
| 202 * @return {void} Nothing. | 202 * @return {void} Nothing. |
| 203 */ | 203 */ |
| 204 remoting.HostList.prototype.sortHosts_ = function() { | 204 remoting.HostList.prototype.sortHosts_ = function() { |
| 205 /** | 205 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 235 remoting.HostList.prototype.display = function() { | 235 remoting.HostList.prototype.display = function() { |
| 236 this.table_.innerText = ''; | 236 this.table_.innerText = ''; |
| 237 this.errorMsg_.innerText = ''; | 237 this.errorMsg_.innerText = ''; |
| 238 this.hostTableEntries_ = []; | 238 this.hostTableEntries_ = []; |
| 239 | 239 |
| 240 var noHostsRegistered = (this.hosts_.length == 0); | 240 var noHostsRegistered = (this.hosts_.length == 0); |
| 241 this.table_.hidden = noHostsRegistered; | 241 this.table_.hidden = noHostsRegistered; |
| 242 this.noHosts_.hidden = !noHostsRegistered; | 242 this.noHosts_.hidden = !noHostsRegistered; |
| 243 | 243 |
| 244 if (this.lastError_ != '') { | 244 if (this.lastError_ != '') { |
| 245 l10n.localizeElementFromTag(this.errorMsg_, this.lastError_); | 245 l10n.localizeElementFromTag(this.errorMsg_, this.lastError_.tag); |
| 246 if (this.lastError_ == remoting.Error.AUTHENTICATION_FAILED) { | 246 if (this.lastError_.tag == remoting.Error.Tag.AUTHENTICATION_FAILED) { |
| 247 l10n.localizeElementFromTag(this.errorButton_, | 247 l10n.localizeElementFromTag(this.errorButton_, |
| 248 /*i18n-content*/'SIGN_IN_BUTTON'); | 248 /*i18n-content*/'SIGN_IN_BUTTON'); |
| 249 } else { | 249 } else { |
| 250 l10n.localizeElementFromTag(this.errorButton_, | 250 l10n.localizeElementFromTag(this.errorButton_, |
| 251 /*i18n-content*/'RETRY'); | 251 /*i18n-content*/'RETRY'); |
| 252 } | 252 } |
| 253 } else { | 253 } else { |
| 254 for (var i = 0; i < this.hosts_.length; ++i) { | 254 for (var i = 0; i < this.hosts_.length; ++i) { |
| 255 /** @type {remoting.Host} */ | 255 /** @type {remoting.Host} */ |
| 256 var host = this.hosts_[i]; | 256 var host = this.hosts_[i]; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 this.setLocalHost_(localHost); | 474 this.setLocalHost_(localHost); |
| 475 }; | 475 }; |
| 476 | 476 |
| 477 /** | 477 /** |
| 478 * Called when the user clicks the button next to the error message. The action | 478 * Called when the user clicks the button next to the error message. The action |
| 479 * depends on the error. | 479 * depends on the error. |
| 480 * | 480 * |
| 481 * @private | 481 * @private |
| 482 */ | 482 */ |
| 483 remoting.HostList.prototype.onErrorClick_ = function() { | 483 remoting.HostList.prototype.onErrorClick_ = function() { |
| 484 if (this.lastError_ == remoting.Error.AUTHENTICATION_FAILED) { | 484 if (this.lastError_.tag == remoting.Error.Tag.AUTHENTICATION_FAILED) { |
| 485 remoting.handleAuthFailureAndRelaunch(); | 485 remoting.handleAuthFailureAndRelaunch(); |
| 486 } else { | 486 } else { |
| 487 this.refresh(remoting.updateLocalHostState); | 487 this.refresh(remoting.updateLocalHostState); |
| 488 } | 488 } |
| 489 }; | 489 }; |
| 490 | 490 |
| 491 /** | 491 /** |
| 492 * Save the host list to local storage. | 492 * Save the host list to local storage. |
| 493 */ | 493 */ |
| 494 remoting.HostList.prototype.save_ = function() { | 494 remoting.HostList.prototype.save_ = function() { |
| 495 var items = {}; | 495 var items = {}; |
| 496 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); | 496 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); |
| 497 chrome.storage.local.set(items); | 497 chrome.storage.local.set(items); |
| 498 if (this.hosts_.length !== 0) { | 498 if (this.hosts_.length !== 0) { |
| 499 remoting.AppsV2Migration.saveUserInfo(); | 499 remoting.AppsV2Migration.saveUserInfo(); |
| 500 } | 500 } |
| 501 }; | 501 }; |
| 502 | 502 |
| 503 /** | 503 /** |
| 504 * Key name under which Me2Me hosts are cached. | 504 * Key name under which Me2Me hosts are cached. |
| 505 */ | 505 */ |
| 506 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; | 506 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; |
| 507 | 507 |
| 508 /** @type {remoting.HostList} */ | 508 /** @type {remoting.HostList} */ |
| 509 remoting.hostList = null; | 509 remoting.hostList = null; |
| OLD | NEW |