Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: remoting/webapp/crd/js/host_list.js

Issue 955283002: Converted remoting.Error from an enum to a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
40 /** @private {Element} */ 40 /** @private {Element} */
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 {string} */ 50 /** @private {!remoting.Error} */
51 this.lastError_ = ''; 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 * Query the Remoting Directory for the user's list of hosts. 130 * Query the Remoting Directory for the user's list of hosts.
131 * 131 *
132 * @param {function(boolean):void} onDone Callback invoked with true on success 132 * @param {function(boolean):void} onDone Callback invoked with true on success
133 * or false on failure. 133 * or false on failure.
134 * @return {void} Nothing. 134 * @return {void} Nothing.
135 */ 135 */
136 remoting.HostList.prototype.refresh = function(onDone) { 136 remoting.HostList.prototype.refresh = function(onDone) {
137 this.loadingIndicator_.classList.add('loading'); 137 this.loadingIndicator_.classList.add('loading');
138 /** @type {remoting.HostList} */ 138 /** @type {remoting.HostList} */
139 var that = this; 139 var that = this;
140 /** @param {remoting.Error} error */ 140 /** @param {!remoting.Error} error */
141 var onError = function(error) { 141 var onError = function(error) {
142 that.lastError_ = error; 142 that.lastError_ = error;
143 onDone(false); 143 onDone(false);
144 }; 144 };
145 remoting.hostListApi.get(this.onHostListResponse_.bind(this, onDone), 145 remoting.hostListApi.get(this.onHostListResponse_.bind(this, onDone),
146 onError); 146 onError);
147 }; 147 };
148 148
149 /** 149 /**
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_ = ''; 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(this.lastError_ == ''); 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 *
171 * @suppress {reportUnknownTypes} 171 * @suppress {reportUnknownTypes}
172 * @return {void} Nothing. 172 * @return {void} Nothing.
173 */ 173 */
174 remoting.HostList.prototype.sortHosts_ = function() { 174 remoting.HostList.prototype.sortHosts_ = function() {
175 /** 175 /**
(...skipping 29 matching lines...) Expand all
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_ != '') { 214 if (this.lastError_ != '') {
215 l10n.localizeElementFromTag(this.errorMsg_, this.lastError_); 215 l10n.localizeElementFromTag(this.errorMsg_, this.lastError_.tag);
216 if (this.lastError_ == remoting.Error.AUTHENTICATION_FAILED) { 216 if (this.lastError_.tag == 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_ == ''); 244 this.errorMsg_.parentNode.hidden = !this.lastError_.isError();
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 329
330 /** 330 /**
331 * Set the state of the local host and localHostId if any. 331 * Set the state of the local host and localHostId if any.
332 * 332 *
333 * @param {remoting.HostController.State} state State of the local host. 333 * @param {remoting.HostController.State} state State of the local host.
334 * @param {string?} hostId ID of the local host, or null. 334 * @param {string?} hostId ID of the local host, or null.
335 * @return {void} Nothing. 335 * @return {void} Nothing.
336 */ 336 */
337 remoting.HostList.prototype.setLocalHostStateAndId = function(state, hostId) { 337 remoting.HostList.prototype.setLocalHostStateAndId = function(state, hostId) {
338 var host = hostId ? this.getHostForId(hostId) : null; 338 var host = hostId ? this.getHostForId(hostId) : null;
339 this.localHostSection_.setModel(host, state, this.lastError_ !== ''); 339 this.localHostSection_.setModel(host, state, this.lastError_.isError());
340 }; 340 };
341 341
342 /** 342 /**
343 * Called by the HostControlled after the local host has been started. 343 * Called by the HostControlled after the local host has been started.
344 * 344 *
345 * @param {string} hostName Host name. 345 * @param {string} hostName Host name.
346 * @param {string} hostId ID of the local host. 346 * @param {string} hostId ID of the local host.
347 * @param {string} publicKey Public key. 347 * @param {string} publicKey Public key.
348 * @return {void} Nothing. 348 * @return {void} Nothing.
349 */ 349 */
(...skipping 10 matching lines...) Expand all
360 // Provide a version number to avoid warning about this dummy host being 360 // Provide a version number to avoid warning about this dummy host being
361 // out-of-date. 361 // out-of-date.
362 localHost.hostVersion = String(this.webappMajorVersion_) + ".x" 362 localHost.hostVersion = String(this.webappMajorVersion_) + ".x"
363 localHost.hostId = hostId; 363 localHost.hostId = hostId;
364 localHost.publicKey = publicKey; 364 localHost.publicKey = publicKey;
365 localHost.status = 'ONLINE'; 365 localHost.status = 'ONLINE';
366 this.hosts_.push(localHost); 366 this.hosts_.push(localHost);
367 this.save_(); 367 this.save_();
368 this.localHostSection_.setModel(localHost, 368 this.localHostSection_.setModel(localHost,
369 remoting.HostController.State.STARTED, 369 remoting.HostController.State.STARTED,
370 this.lastError_ !== ''); 370 this.lastError_.isError());
371 }; 371 };
372 372
373 /** 373 /**
374 * Called when the user clicks the button next to the error message. The action 374 * Called when the user clicks the button next to the error message. The action
375 * depends on the error. 375 * depends on the error.
376 * 376 *
377 * @private 377 * @private
378 */ 378 */
379 remoting.HostList.prototype.onErrorClick_ = function() { 379 remoting.HostList.prototype.onErrorClick_ = function() {
380 if (this.lastError_ == remoting.Error.AUTHENTICATION_FAILED) { 380 if (this.lastError_.tag == remoting.Error.Tag.AUTHENTICATION_FAILED) {
381 remoting.handleAuthFailureAndRelaunch(); 381 remoting.handleAuthFailureAndRelaunch();
382 } else { 382 } else {
383 this.refresh(remoting.updateLocalHostState); 383 this.refresh(remoting.updateLocalHostState);
384 } 384 }
385 }; 385 };
386 386
387 /** 387 /**
388 * Save the host list to local storage. 388 * Save the host list to local storage.
389 */ 389 */
390 remoting.HostList.prototype.save_ = function() { 390 remoting.HostList.prototype.save_ = function() {
391 var items = {}; 391 var items = {};
392 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); 392 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_);
393 chrome.storage.local.set(items); 393 chrome.storage.local.set(items);
394 if (this.hosts_.length !== 0) { 394 if (this.hosts_.length !== 0) {
395 remoting.AppsV2Migration.saveUserInfo(); 395 remoting.AppsV2Migration.saveUserInfo();
396 } 396 }
397 }; 397 };
398 398
399 /** 399 /**
400 * Key name under which Me2Me hosts are cached. 400 * Key name under which Me2Me hosts are cached.
401 */ 401 */
402 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; 402 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts';
403 403
404 /** @type {remoting.HostList} */ 404 /** @type {remoting.HostList} */
405 remoting.hostList = null; 405 remoting.hostList = null;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698