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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 var canChangeLocalHostState = | 269 var canChangeLocalHostState = |
270 (state != remoting.HostController.State.NOT_IMPLEMENTED) && | 270 (state != remoting.HostController.State.NOT_IMPLEMENTED) && |
271 (state != remoting.HostController.State.UNKNOWN) && | 271 (state != remoting.HostController.State.UNKNOWN) && |
272 (state != remoting.HostController.State.NOT_INSTALLED || | 272 (state != remoting.HostController.State.NOT_INSTALLED || |
273 remoting.isMe2MeInstallable()) && | 273 remoting.isMe2MeInstallable()) && |
274 (enabled || this.lastError_ == ''); | 274 (enabled || this.lastError_ == ''); |
275 | 275 |
276 remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); | 276 remoting.updateModalUi(enabled ? 'enabled' : 'disabled', 'data-daemon-state'); |
277 var element = document.getElementById('daemon-control'); | 277 var element = document.getElementById('daemon-control'); |
278 element.hidden = !canChangeLocalHostState; | 278 element.hidden = !canChangeLocalHostState; |
279 element = document.getElementById('host-list-empty-hosting-supported'); | 279 |
280 element.hidden = !canChangeLocalHostState; | 280 if (noHostsRegistered) { |
281 element = document.getElementById('host-list-empty-hosting-unsupported'); | 281 this.showEmptyText_(canChangeLocalHostState); |
282 element.hidden = canChangeLocalHostState; | 282 } |
283 }; | 283 }; |
284 | 284 |
285 /** | 285 /** |
286 * Displays a message to the user when the host list is empty. | |
287 * | |
288 * @param {boolean} hostingSupported | |
289 * @return {void} | |
290 * @private | |
291 */ | |
292 remoting.HostList.prototype.showEmptyText_ = function(hostingSupported) { | |
293 this.showHostMigrationTips_().then( | |
294 /** | |
295 * @param {boolean} migrationTipsShown | |
296 * @this {remoting.HostList} | |
297 */ | |
298 function(migrationTipsShown) { | |
299 if (migrationTipsShown) { | |
300 return; | |
Jamie
2015/01/14 03:55:29
This doesn't seem right. migrationTipShown==true s
kelvinp
2015/01/15 01:10:14
I have change the structure of the code now. Let
| |
301 } | |
302 | |
303 var localize = l10n.getTranslationOrError; | |
Jamie
2015/01/14 03:55:29
Please don't assign these shortened aliases if you
kelvinp
2015/01/15 01:10:13
Done.
| |
304 var buttonLabel = localize('HOME_DAEMON_START_BUTTON'); | |
Jamie
2015/01/14 03:55:29
Please annotate these strings with /**i18n-content
kelvinp
2015/01/15 01:10:14
Done.
| |
305 this.noHosts_.innerText = | |
306 (hostingSupported) ? | |
307 localize('HOST_LIST_EMPTY_HOSTING_SUPPORTED', [buttonLabel]) : | |
308 localize('HOST_LIST_EMPTY_HOSTING_NOT_SUPPORTED', [buttonLabel]); | |
309 | |
310 }.bind(this)); | |
311 }; | |
312 | |
313 /** | |
314 * Checks whether the user has hosts registered to a different account and | |
315 * informs the user to sign-in with that account if necessary. | |
316 * | |
317 * @return {Promise} A Promise object that would resolve to true if the | |
318 * migration tips is shown to the user. | |
319 * @private | |
320 */ | |
321 remoting.HostList.prototype.showHostMigrationTips_ = function() { | |
322 if (!base.isAppsV2()) { | |
323 return Promise.resolve(false); | |
Jamie
2015/01/14 03:55:29
I don't have a strong opinion either way, but sinc
kelvinp
2015/01/15 01:10:14
I have renamed the function to WasSignedWithDiffer
| |
324 } | |
325 | |
326 var getCachedInfo = new Promise( | |
327 /** @param {function(*) : void} resolve */ | |
328 function(resolve) { | |
329 chrome.storage.local.get( | |
330 ['remoting-email','remoting-fullname',remoting.HostList.HOSTS_KEY], | |
331 /** @param {*} results */ | |
332 function(results) { resolve(results); } | |
333 ); | |
334 } | |
335 ); | |
336 | |
337 var getCurrentEmail = new Promise( | |
338 /** | |
339 * @param {function(*) : void} resolve | |
340 * @param {function(*) : void} reject | |
341 */ | |
342 function(resolve, reject) { | |
343 /** | |
344 * @param {string} email | |
345 * @param {string} name | |
346 */ | |
347 remoting.identity.getUserInfo(function(email, name) { | |
348 resolve(email); | |
349 }, reject); | |
350 } | |
351 ); | |
352 | |
353 var noHosts = this.noHosts_; | |
354 | |
355 return Promise.all([getCachedInfo, getCurrentEmail]).then( | |
356 /** @param {Object.<string>} results */ | |
357 function(results){ | |
358 var cached = /** @type {Object} */ results[0]; | |
359 var currentEmail = /** @type {string} */ results[1]; | |
360 var cachedHosts = /** @type {Array} */ | |
361 base.jsonParseSafe(cached[remoting.HostList.HOSTS_KEY]); | |
362 var cachedEmail = getStringAttr(cached, 'remoting-email'); | |
363 var cachedName = getStringAttr(cached, 'remoting-fullname'); | |
364 | |
365 /** | |
366 * @param {string} email | |
367 * @param {string} fullName | |
368 * @return {string} | |
369 */ | |
370 function buildMigrationTips(email, fullName) { | |
371 var localize = l10n.getTranslationOrError; | |
372 var params = [ | |
373 fullName, | |
374 email, | |
375 '<a href="https://support.google.com/chrome/answer/2364824?hl=en" ' + | |
376 'target="_blank">', | |
377 '</a>']; | |
378 return localize('HOST_LIST_EMPTY_V2_MIGRATION', params); | |
379 } | |
380 | |
381 if (cachedEmail && cachedEmail !== currentEmail && | |
382 cachedHosts && cachedHosts.length !== 0) { | |
383 noHosts.innerHTML = buildMigrationTips(cachedEmail, cachedName); | |
Jamie
2015/01/14 03:55:29
I don't think this is the right way to do structur
kelvinp
2015/01/15 01:10:13
Done.
| |
384 return true; | |
385 } | |
386 return false; | |
387 }); | |
388 }; | |
389 | |
390 /** | |
286 * Remove a host from the list, and deregister it. | 391 * Remove a host from the list, and deregister it. |
287 * @param {remoting.HostTableEntry} hostTableEntry The host to be removed. | 392 * @param {remoting.HostTableEntry} hostTableEntry The host to be removed. |
288 * @return {void} Nothing. | 393 * @return {void} Nothing. |
289 * @private | 394 * @private |
290 */ | 395 */ |
291 remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { | 396 remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { |
292 this.table_.removeChild(hostTableEntry.tableRow); | 397 this.table_.removeChild(hostTableEntry.tableRow); |
293 var index = this.hostTableEntries_.indexOf(hostTableEntry); | 398 var index = this.hostTableEntries_.indexOf(hostTableEntry); |
294 if (index != -1) { | 399 if (index != -1) { |
295 this.hostTableEntries_.splice(index, 1); | 400 this.hostTableEntries_.splice(index, 1); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 }); | 544 }); |
440 } else { | 545 } else { |
441 this.refresh(remoting.updateLocalHostState); | 546 this.refresh(remoting.updateLocalHostState); |
442 } | 547 } |
443 }; | 548 }; |
444 | 549 |
445 /** | 550 /** |
446 * Save the host list to local storage. | 551 * Save the host list to local storage. |
447 */ | 552 */ |
448 remoting.HostList.prototype.save_ = function() { | 553 remoting.HostList.prototype.save_ = function() { |
554 if (this.hosts_.length === 0) { | |
555 return; | |
556 } | |
557 | |
449 var items = {}; | 558 var items = {}; |
450 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); | 559 items[remoting.HostList.HOSTS_KEY] = JSON.stringify(this.hosts_); |
560 if (base.isAppsV2()) { | |
561 chrome.storage.local.remove('remoting-email'); | |
562 } | |
451 chrome.storage.local.set(items); | 563 chrome.storage.local.set(items); |
452 }; | 564 }; |
453 | 565 |
454 /** | 566 /** |
455 * Key name under which Me2Me hosts are cached. | 567 * Key name under which Me2Me hosts are cached. |
456 */ | 568 */ |
457 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; | 569 remoting.HostList.HOSTS_KEY = 'me2me-cached-hosts'; |
458 | 570 |
459 /** @type {remoting.HostList} */ | 571 /** @type {remoting.HostList} */ |
460 remoting.hostList = null; | 572 remoting.hostList = null; |
OLD | NEW |