Chromium Code Reviews| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 var canChangeLocalHostState = | 282 var canChangeLocalHostState = |
| 283 (state != remoting.HostController.State.NOT_IMPLEMENTED) && | 283 (state != remoting.HostController.State.NOT_IMPLEMENTED) && |
| 284 (state != remoting.HostController.State.UNKNOWN) && | 284 (state != remoting.HostController.State.UNKNOWN) && |
| 285 (state != remoting.HostController.State.NOT_INSTALLED || | 285 (state != remoting.HostController.State.NOT_INSTALLED || |
| 286 remoting.isMe2MeInstallable()) && | 286 remoting.isMe2MeInstallable()) && |
| 287 (enabled || this.lastError_ == ''); | 287 (enabled || this.lastError_ == ''); |
| 288 | 288 |
| 289 remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); | 289 remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); |
| 290 var element = document.getElementById('daemon-control'); | 290 var element = document.getElementById('daemon-control'); |
| 291 element.hidden = !canChangeLocalHostState; | 291 element.hidden = !canChangeLocalHostState; |
| 292 element = document.getElementById('host-list-empty-hosting-supported'); | 292 |
| 293 element.hidden = !canChangeLocalHostState; | 293 if (noHostsRegistered) { |
| 294 element = document.getElementById('host-list-empty-hosting-unsupported'); | 294 this.showEmptyText_(canChangeLocalHostState); |
| 295 element.hidden = canChangeLocalHostState; | 295 } |
| 296 }; | 296 }; |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * Displays a message to the user when the host list is empty. | |
| 300 * | |
| 301 * @param {boolean} hostingSupported | |
| 302 * @return {void} | |
| 303 * @private | |
| 304 */ | |
| 305 remoting.HostList.prototype.showEmptyText_ = function(hostingSupported) { | |
|
Jamie
2015/01/15 20:51:30
"Empty text" suggests that the text is empty, not
kelvinp
2015/01/20 19:41:00
Done.
| |
| 306 /** | |
| 307 * @param {string} email | |
| 308 * @param {string} fullName | |
| 309 * @return {string} | |
| 310 */ | |
| 311 function buildMigrationTips(email, fullName) { | |
| 312 var params = [ | |
| 313 fullName, | |
| 314 email, | |
| 315 '<a href="https://support.google.com/chrome/answer/2364824?hl=en" ' + | |
| 316 'target="_blank">', | |
| 317 '</a>']; | |
| 318 return l10n.getTranslationOrError( | |
| 319 /*i18n-content*/'HOST_LIST_EMPTY_V2_MIGRATION', params); | |
| 320 } | |
| 321 | |
| 322 var emptyTextDiv = this.noHosts_; | |
|
Jamie
2015/01/15 20:51:30
I'm not sure what the value of this assignment is.
kelvinp
2015/01/20 19:41:00
This variable is necessary for the annonymous func
| |
| 323 | |
| 324 this.isSignedInWithDifferentIdentity_().then( | |
| 325 /** | |
| 326 * @param {{ email: string, fullName: string}} previousIdentity | |
| 327 * @this {remoting.HostList} | |
| 328 */ | |
| 329 function(previousIdentity) { | |
| 330 var buttonLabel = l10n.getTranslationOrError( | |
| 331 /*i18n-content*/'HOME_DAEMON_START_BUTTON'); | |
| 332 | |
| 333 if (Boolean(previousIdentity)) { | |
| 334 emptyTextDiv.innerHTML = buildMigrationTips(previousIdentity.email, | |
| 335 previousIdentity.fullName); | |
| 336 } else if (hostingSupported) { | |
| 337 emptyTextDiv.innerText = l10n.getTranslationOrError( | |
| 338 /*i18n-content*/'HOST_LIST_EMPTY_HOSTING_SUPPORTED', | |
| 339 [buttonLabel]); | |
| 340 } else { | |
| 341 emptyTextDiv.innerText = l10n.getTranslationOrError( | |
| 342 /*i18n-content*/'HOST_LIST_EMPTY_HOSTING_UNSUPPORTED', | |
| 343 [buttonLabel]); | |
| 344 } | |
| 345 } | |
| 346 ); | |
| 347 }; | |
| 348 | |
| 349 /** | |
| 350 * @return {Promise} A Promise object that would resolve to | |
| 351 * { email: string, fullName: string} if the user has signed in with a | |
| 352 * different account that has hosts registered to it. Otherwise, resolves to | |
| 353 * null. | |
| 354 * @private | |
| 355 */ | |
| 356 remoting.HostList.prototype.isSignedInWithDifferentIdentity_ = function() { | |
| 357 if (!base.isAppsV2()) { | |
| 358 return Promise.resolve(null); | |
|
Jamie
2015/01/15 20:51:31
I think my original objection still applies. For t
kelvinp
2015/01/20 19:41:00
Done.
| |
| 359 } | |
| 360 | |
| 361 var getCachedInfo = new Promise( | |
|
Jamie
2015/01/15 20:51:30
s/Info/UserInfo/
You could also consider s/Cached
kelvinp
2015/01/20 19:41:00
Done.
| |
| 362 /** @param {function(*) : void} resolve */ | |
| 363 function(resolve) { | |
| 364 chrome.storage.local.get( | |
| 365 ['remoting-email','remoting-fullname',remoting.HostList.HOSTS_KEY], | |
|
Jamie
2015/01/15 20:51:30
Nit: Spaces between list elements.
Jamie
2015/01/15 20:51:30
These strings are duplicated. You should define th
kelvinp
2015/01/20 19:41:00
Done.
| |
| 366 /** @param {*} results */ | |
| 367 function(results) { resolve(results); } | |
| 368 ); | |
| 369 } | |
| 370 ); | |
| 371 | |
| 372 var getCurrentEmail = new Promise( | |
| 373 /** | |
| 374 * @param {function(*) : void} resolve | |
| 375 * @param {function(*) : void} reject | |
| 376 */ | |
| 377 function(resolve, reject) { | |
| 378 /** | |
| 379 * @param {string} email | |
| 380 * @param {string} name | |
| 381 */ | |
| 382 remoting.identity.getUserInfo(function(email, name) { | |
| 383 resolve(email); | |
| 384 }, reject); | |
| 385 } | |
| 386 ); | |
| 387 | |
| 388 return Promise.all([getCachedInfo, getCurrentEmail]).then( | |
| 389 /** @param {Object} results */ | |
| 390 function(results){ | |
| 391 var cached = /** @type {Object} */ (results[0]); | |
|
Jamie
2015/01/15 20:51:31
s/cached/cachedUserInfo/
| |
| 392 var currentEmail = /** @type {string} */ (results[1]); | |
| 393 var cachedHosts = /** @type {Array} */ | |
| 394 (base.jsonParseSafe(cached[remoting.HostList.HOSTS_KEY])); | |
| 395 var cachedEmail = getStringAttr(cached, 'remoting-email', ''); | |
| 396 var cachedName = getStringAttr(cached, 'remoting-fullname', ''); | |
| 397 | |
| 398 if (cachedEmail && cachedEmail !== currentEmail && | |
| 399 Array.isArray(cachedHosts) && cachedHosts.length !== 0) { | |
| 400 return { | |
| 401 email: cachedEmail, | |
| 402 fullName: cachedName | |
| 403 }; | |
| 404 } | |
| 405 return null; | |
| 406 }); | |
| 407 }; | |
| 408 | |
| 409 /** | |
| 299 * Remove a host from the list, and deregister it. | 410 * Remove a host from the list, and deregister it. |
| 300 * @param {remoting.HostTableEntry} hostTableEntry The host to be removed. | 411 * @param {remoting.HostTableEntry} hostTableEntry The host to be removed. |
| 301 * @return {void} Nothing. | 412 * @return {void} Nothing. |
| 302 * @private | 413 * @private |
| 303 */ | 414 */ |
| 304 remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { | 415 remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { |
| 305 this.table_.removeChild(hostTableEntry.tableRow); | 416 this.table_.removeChild(hostTableEntry.tableRow); |
| 306 var index = this.hostTableEntries_.indexOf(hostTableEntry); | 417 var index = this.hostTableEntries_.indexOf(hostTableEntry); |
| 307 if (index != -1) { | 418 if (index != -1) { |
| 308 this.hostTableEntries_.splice(index, 1); | 419 this.hostTableEntries_.splice(index, 1); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 }); | 563 }); |
| 453 } else { | 564 } else { |
| 454 this.refresh(remoting.updateLocalHostState); | 565 this.refresh(remoting.updateLocalHostState); |
| 455 } | 566 } |
| 456 }; | 567 }; |
| 457 | 568 |
| 458 /** | 569 /** |
| 459 * Save the host list to local storage. | 570 * Save the host list to local storage. |
| 460 */ | 571 */ |
| 461 remoting.HostList.prototype.save_ = function() { | 572 remoting.HostList.prototype.save_ = function() { |
| 573 if (this.hosts_.length === 0) { | |
| 574 return; | |
| 575 } | |
|
Jamie
2015/01/15 20:51:30
I don't think this logic is correct. It will preve
kelvinp
2015/01/20 19:41:00
Done.
| |
| 576 | |
| 462 var items = {}; | 577 var items = {}; |
| 463 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); | 578 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); |
| 579 if (base.isAppsV2()) { | |
| 580 chrome.storage.local.remove('remoting-email'); | |
|
Jamie
2015/01/15 20:51:31
Clearing this here seems a bit ad-hoc. I think you
kelvinp
2015/01/20 19:41:00
Done.
| |
| 581 } | |
| 464 chrome.storage.local.set(items); | 582 chrome.storage.local.set(items); |
| 465 }; | 583 }; |
| 466 | 584 |
| 467 /** | 585 /** |
| 468 * Key name under which Me2Me hosts are cached. | 586 * Key name under which Me2Me hosts are cached. |
| 469 */ | 587 */ |
| 470 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; | 588 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; |
| 471 | 589 |
| 472 /** @type {remoting.HostList} */ | 590 /** @type {remoting.HostList} */ |
| 473 remoting.hostList = null; | 591 remoting.hostList = null; |
| OLD | NEW |