OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 User pod row implementation. | 6 * @fileoverview User pod row implementation. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('login', function() { | 9 cr.define('login', function() { |
10 /** | 10 /** |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 /** | 969 /** |
970 * Gets the custom icon. This icon is normally hidden, but can be shown | 970 * Gets the custom icon. This icon is normally hidden, but can be shown |
971 * using the chrome.screenlockPrivate API. | 971 * using the chrome.screenlockPrivate API. |
972 * @type {!HTMLDivElement} | 972 * @type {!HTMLDivElement} |
973 */ | 973 */ |
974 get customIconElement() { | 974 get customIconElement() { |
975 return this.querySelector('.custom-icon-container'); | 975 return this.querySelector('.custom-icon-container'); |
976 }, | 976 }, |
977 | 977 |
978 /** | 978 /** |
| 979 * Get the elements used for statistics display. |
| 980 * @type {Object.<string, !HTMLDivElement>} |
| 981 */ |
| 982 get statsMapElements() { |
| 983 return { |
| 984 'BrowsingHistory': |
| 985 this.querySelector('.action-box-remove-user-warning-history'), |
| 986 'Passwords': |
| 987 this.querySelector('.action-box-remove-user-warning-passwords'), |
| 988 'Bookmarks': |
| 989 this.querySelector('.action-box-remove-user-warning-bookmarks'), |
| 990 'Settings': |
| 991 this.querySelector('.action-box-remove-user-warning-settings') |
| 992 } |
| 993 }, |
| 994 |
| 995 /** |
979 * Updates the user pod element. | 996 * Updates the user pod element. |
980 */ | 997 */ |
981 update: function() { | 998 update: function() { |
982 this.imageElement.src = 'chrome://userimage/' + this.user.username + | 999 this.imageElement.src = 'chrome://userimage/' + this.user.username + |
983 '?id=' + UserPod.userImageSalt_[this.user.username]; | 1000 '?id=' + UserPod.userImageSalt_[this.user.username]; |
984 | 1001 |
985 this.nameElement.textContent = this.user_.displayName; | 1002 this.nameElement.textContent = this.user_.displayName; |
986 this.reauthNameHintElement.textContent = this.user_.displayName; | 1003 this.reauthNameHintElement.textContent = this.user_.displayName; |
987 this.classList.toggle('signed-in', this.user_.signedIn); | 1004 this.classList.toggle('signed-in', this.user_.signedIn); |
988 | 1005 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 | 1414 |
1398 // Move up the menu if it overlaps shelf. | 1415 // Move up the menu if it overlaps shelf. |
1399 var maxHeight = cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping( | 1416 var maxHeight = cr.ui.LoginUITools.getMaxHeightBeforeShelfOverlapping( |
1400 this.actionBoxMenu, true); | 1417 this.actionBoxMenu, true); |
1401 var actualHeight = parseInt( | 1418 var actualHeight = parseInt( |
1402 window.getComputedStyle(this.actionBoxMenu).height); | 1419 window.getComputedStyle(this.actionBoxMenu).height); |
1403 if (maxHeight < actualHeight) { | 1420 if (maxHeight < actualHeight) { |
1404 this.actionBoxMenu.classList.add('menu-moved-up'); | 1421 this.actionBoxMenu.classList.add('menu-moved-up'); |
1405 this.actionBoxAreaElement.classList.add('menu-moved-up'); | 1422 this.actionBoxAreaElement.classList.add('menu-moved-up'); |
1406 } | 1423 } |
1407 chrome.send('logRemoveUserWarningShown'); | |
1408 }, | 1424 }, |
1409 | 1425 |
1410 /** | 1426 /** |
1411 * Shows remove user warning. Used for legacy supervised users on CrOS, and | 1427 * Shows remove user warning. Used for legacy supervised users on CrOS, and |
1412 * for all users on desktop. | 1428 * for all users on desktop. |
1413 */ | 1429 */ |
1414 showRemoveWarning_: function() { | 1430 showRemoveWarning_: function() { |
1415 this.actionBoxMenuRemoveElement.hidden = true; | 1431 this.actionBoxMenuRemoveElement.hidden = true; |
1416 this.actionBoxRemoveUserWarningElement.hidden = false; | 1432 this.actionBoxRemoveUserWarningElement.hidden = false; |
1417 this.actionBoxRemoveUserWarningButtonElement.focus(); | 1433 this.actionBoxRemoveUserWarningButtonElement.focus(); |
1418 | 1434 |
1419 // Show extra statistics information for desktop users | 1435 // Show extra statistics information for desktop users |
1420 var message; | 1436 var message; |
1421 if (this.user.isDesktopUser) { | 1437 if (this.user.isLegacySupervisedUser) { |
1422 this.classList.remove('has-errors'); | 1438 this.moveActionMenuUpIfNeeded_(); |
1423 var isSyncedUser = this.user.emailAddress !== ""; | 1439 } else { |
1424 if (!this.user.isProfileLoaded) { | 1440 this.RemoveWarningDialogSetMessage_(true, false); |
1425 message = loadTimeData.getString( | |
1426 isSyncedUser ? 'removeUserWarningTextSyncNoStats' : | |
1427 'removeUserWarningTextNonSyncNoStats'); | |
1428 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, | |
1429 message); | |
1430 } else { | |
1431 message = loadTimeData.getString( | |
1432 isSyncedUser ? 'removeUserWarningTextSyncCalculating' : | |
1433 'removeUserWarningTextNonSyncCalculating'); | |
1434 substitute = loadTimeData.getString( | |
1435 'removeUserWarningTextCalculating'); | |
1436 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, | |
1437 message, substitute); | |
1438 } | |
1439 | |
1440 // set a global handler for the callback | 1441 // set a global handler for the callback |
1441 window.updateRemoveWarningDialog = | 1442 window.updateRemoveWarningDialog = |
1442 this.updateRemoveWarningDialog_.bind(this); | 1443 this.updateRemoveWarningDialog_.bind(this); |
1443 chrome.send('removeUserWarningLoadStats', [this.user.profilePath]); | 1444 chrome.send('removeUserWarningLoadStats', [this.user.profilePath]); |
1444 } | 1445 } |
1445 | 1446 chrome.send('logRemoveUserWarningShown'); |
1446 this.moveActionMenuUpIfNeeded_(); | |
1447 }, | 1447 }, |
1448 | 1448 |
1449 /** | 1449 /** |
1450 * Refresh the statistics in the remove user warning dialog. | 1450 * Refresh the statistics in the remove user warning dialog. |
1451 * @param {string} profilePath The filepath of the URL (must be verified). | 1451 * @param {string} profilePath The filepath of the URL (must be verified). |
1452 * @param {Object} profileStats Statistics associated with profileURL. | 1452 * @param {Object} profileStats Statistics associated with profileURL. |
1453 */ | 1453 */ |
1454 updateRemoveWarningDialog_: function(profilePath, profileStats) { | 1454 updateRemoveWarningDialog_: function(profilePath, profileStats) { |
1455 if (profilePath !== this.user.profilePath) | 1455 if (profilePath !== this.user.profilePath) |
1456 return; | 1456 return; |
1457 // Converting profileStats into id attribute by an object. | 1457 |
1458 var stats_id_map = { | 1458 var stats_elements = this.statsMapElements; |
1459 'BrowsingHistory': 'action-box-remove-user-warning-history', | 1459 // Update individual statistics |
1460 'Passwords': 'action-box-remove-user-warning-passwords', | 1460 var hasErrors = false; |
1461 'Bookmarks': 'action-box-remove-user-warning-bookmarks', | 1461 for (var key in profileStats) { |
1462 'Settings': 'action-box-remove-user-warning-settings', | 1462 if (stats_elements.hasOwnProperty(key)) { |
| 1463 if (profileStats[key].success) { |
| 1464 this.user.statistics[key] = profileStats[key]; |
| 1465 } else if (!this.user.statistics[key].success) { |
| 1466 hasErrors = true; |
| 1467 stats_elements[key].textContent = ''; |
| 1468 } |
| 1469 } |
1463 } | 1470 } |
1464 // Load individual statistics | 1471 |
| 1472 this.RemoveWarningDialogSetMessage_(false, hasErrors); |
| 1473 }, |
| 1474 |
| 1475 /** |
| 1476 * Set the new message in the dialog. |
| 1477 * @param {boolean} Whether this is the first output, that requires setting |
| 1478 * a in-progress message. |
| 1479 * @param {boolean} Whether any actual query to the statistics have failed. |
| 1480 * Should be true only if there is an error and the corresponding statistic |
| 1481 * is also unavailable in ProfileInfoCache. |
| 1482 */ |
| 1483 RemoveWarningDialogSetMessage_: function(isInitial, hasErrors) { |
| 1484 var stats_elements = this.statsMapElements; |
| 1485 var total_count = 0; |
1465 var num_stats_loaded = 0; | 1486 var num_stats_loaded = 0; |
1466 var total_count = 0; | 1487 for (var key in stats_elements) { |
1467 var failed = false; | 1488 if (this.user.statistics[key].success) { |
1468 for (var key in profileStats) { | 1489 var count = this.user.statistics[key].count; |
1469 if (stats_id_map.hasOwnProperty(key)) { | 1490 stats_elements[key].textContent = count; |
1470 if (profileStats[key].success) { | 1491 total_count += count; |
1471 var count = profileStats[key].count; | |
1472 this.querySelector("." + stats_id_map[key]).textContent = count; | |
1473 total_count += count; | |
1474 } else { | |
1475 failed = true; | |
1476 this.querySelector("." + stats_id_map[key]).textContent = ''; | |
1477 } | |
1478 num_stats_loaded++; | 1492 num_stats_loaded++; |
1479 } | 1493 } |
1480 } | 1494 } |
1481 | 1495 |
1482 // this.classList is used for selecting the appropriate dialog. | 1496 // this.classList is used for selecting the appropriate dialog. |
1483 this.classList.toggle('has-errors', failed); | 1497 if (total_count) |
1484 if (total_count > 0) { | |
1485 this.classList.remove('has-no-stats'); | 1498 this.classList.remove('has-no-stats'); |
1486 } | |
1487 | 1499 |
| 1500 var is_synced_user = this.user.emailAddress !== ""; |
1488 // Write total number if all statistics are loaded. | 1501 // Write total number if all statistics are loaded. |
1489 if (num_stats_loaded === Object.keys(stats_id_map).length) { | 1502 if (num_stats_loaded === Object.keys(stats_elements).length) { |
1490 if (total_count === 0) { | 1503 if (!total_count) { |
1491 this.classList.add('has-no-stats'); | 1504 this.classList.add('has-no-stats'); |
1492 var isSyncedUser = this.user.emailAddress !== ""; | |
1493 var message = loadTimeData.getString( | 1505 var message = loadTimeData.getString( |
1494 isSyncedUser ? 'removeUserWarningTextSyncNoStats' : | 1506 is_synced_user ? 'removeUserWarningTextSyncNoStats' : |
1495 'removeUserWarningTextNonSyncNoStats'); | 1507 'removeUserWarningTextNonSyncNoStats'); |
1496 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, | 1508 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
1497 message); | 1509 message); |
1498 } else { | 1510 } else { |
1499 window.updateRemoveWarningDialogSetMessage = | 1511 window.updateRemoveWarningDialogSetMessage = |
1500 this.updateRemoveWarningDialogSetMessage_.bind(this); | 1512 this.updateRemoveWarningDialogSetMessage_.bind(this); |
1501 chrome.send('getRemoveWarningDialogMessage',[{ | 1513 chrome.send('getRemoveWarningDialogMessage',[{ |
1502 profilePath: this.user.profilePath, | 1514 profilePath: this.user.profilePath, |
1503 isSyncedUser: this.user.emailAddress !== "", | 1515 isSyncedUser: is_synced_user, |
1504 hasErrors: failed, | 1516 hasErrors: hasErrors, |
1505 totalCount: total_count | 1517 totalCount: total_count |
1506 }]); | 1518 }]); |
1507 } | 1519 } |
| 1520 } else if (isInitial) { |
| 1521 if (!this.user.isProfileLoaded) { |
| 1522 message = loadTimeData.getString( |
| 1523 is_synced_user ? 'removeUserWarningTextSyncNoStats' : |
| 1524 'removeUserWarningTextNonSyncNoStats'); |
| 1525 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
| 1526 message); |
| 1527 } else { |
| 1528 message = loadTimeData.getString( |
| 1529 is_synced_user ? 'removeUserWarningTextSyncCalculating' : |
| 1530 'removeUserWarningTextNonSyncCalculating'); |
| 1531 substitute = loadTimeData.getString( |
| 1532 'removeUserWarningTextCalculating'); |
| 1533 this.updateRemoveWarningDialogSetMessage_(this.user.profilePath, |
| 1534 message, substitute); |
| 1535 } |
1508 } | 1536 } |
1509 | |
1510 this.moveActionMenuUpIfNeeded_(); | |
1511 }, | 1537 }, |
1512 | 1538 |
1513 /** | 1539 /** |
1514 * Refresh the message in the remove user warning dialog. | 1540 * Refresh the message in the remove user warning dialog. |
1515 * @param {string} profilePath The filepath of the URL (must be verified). | 1541 * @param {string} profilePath The filepath of the URL (must be verified). |
1516 * @param {string} message The message to be written. | 1542 * @param {string} message The message to be written. |
1517 * @param {number|string=} count The number or string to replace $1 in | 1543 * @param {number|string=} count The number or string to replace $1 in |
1518 * |message|. Can be omitted if $1 is not present in |message|. | 1544 * |message|. Can be omitted if $1 is not present in |message|. |
1519 */ | 1545 */ |
1520 updateRemoveWarningDialogSetMessage_: function(profilePath, message, | 1546 updateRemoveWarningDialogSetMessage_: function(profilePath, message, |
1521 count) { | 1547 count) { |
1522 if (profilePath !== this.user.profilePath) | 1548 if (profilePath !== this.user.profilePath) |
1523 return; | 1549 return; |
1524 // Add localized messages where $1 will be replaced with | 1550 // Add localized messages where $1 will be replaced with |
1525 // <span class="total-count"></span>. | 1551 // <span class="total-count"></span>. |
1526 var element = this.querySelector('.action-box-remove-user-warning-text'); | 1552 var element = this.querySelector('.action-box-remove-user-warning-text'); |
1527 while (element.firstChild) | 1553 element.textContent = ''; |
1528 element.removeChild(element.firstChild); | |
1529 | 1554 |
1530 messageParts = message.split('$1'); | 1555 messageParts = message.split('$1'); |
1531 var numParts = messageParts.length; | 1556 var numParts = messageParts.length; |
1532 for (var j = 0; j < numParts; j++) { | 1557 for (var j = 0; j < numParts; j++) { |
1533 element.appendChild(document.createTextNode(messageParts[j])); | 1558 element.appendChild(document.createTextNode(messageParts[j])); |
1534 if (j < numParts - 1) { | 1559 if (j < numParts - 1) { |
1535 var elementToAdd = document.createElement('span'); | 1560 var elementToAdd = document.createElement('span'); |
1536 elementToAdd.classList.add('total-count'); | 1561 elementToAdd.classList.add('total-count'); |
1537 elementToAdd.textContent = count; | 1562 elementToAdd.textContent = count; |
1538 element.appendChild(elementToAdd); | 1563 element.appendChild(elementToAdd); |
1539 } | 1564 } |
1540 } | 1565 } |
| 1566 this.moveActionMenuUpIfNeeded_(); |
1541 }, | 1567 }, |
1542 | 1568 |
1543 /** | 1569 /** |
1544 * Handles a click event on remove user confirmation button. | 1570 * Handles a click event on remove user confirmation button. |
1545 * @param {Event} e Click event. | 1571 * @param {Event} e Click event. |
1546 */ | 1572 */ |
1547 handleRemoveUserConfirmationClick_: function(e) { | 1573 handleRemoveUserConfirmationClick_: function(e) { |
1548 if (this.isActionBoxMenuActive) { | 1574 if (this.isActionBoxMenuActive) { |
1549 this.isActionBoxMenuActive = false; | 1575 this.isActionBoxMenuActive = false; |
1550 this.removeUser(this.user); | 1576 this.removeUser(this.user); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2070 | 2096 |
2071 var isLockedUser = this.user.needsSignin; | 2097 var isLockedUser = this.user.needsSignin; |
2072 var isLegacySupervisedUser = this.user.legacySupervisedUser; | 2098 var isLegacySupervisedUser = this.user.legacySupervisedUser; |
2073 var isChildUser = this.user.childUser; | 2099 var isChildUser = this.user.childUser; |
2074 var isSyncedUser = this.user.emailAddress !== ""; | 2100 var isSyncedUser = this.user.emailAddress !== ""; |
2075 var isProfileLoaded = this.user.isProfileLoaded; | 2101 var isProfileLoaded = this.user.isProfileLoaded; |
2076 this.classList.toggle('locked', isLockedUser); | 2102 this.classList.toggle('locked', isLockedUser); |
2077 this.classList.toggle('legacy-supervised', isLegacySupervisedUser); | 2103 this.classList.toggle('legacy-supervised', isLegacySupervisedUser); |
2078 this.classList.toggle('child', isChildUser); | 2104 this.classList.toggle('child', isChildUser); |
2079 this.classList.toggle('synced', isSyncedUser); | 2105 this.classList.toggle('synced', isSyncedUser); |
2080 this.classList.toggle('has-no-stats', !isProfileLoaded); | 2106 this.classList.toggle('has-no-stats', |
| 2107 !isProfileLoaded && !this.user.statistics.length); |
2081 | 2108 |
2082 if (this.isAuthTypeUserClick) | 2109 if (this.isAuthTypeUserClick) |
2083 this.passwordLabelElement.textContent = this.authValue; | 2110 this.passwordLabelElement.textContent = this.authValue; |
2084 | 2111 |
2085 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF( | 2112 this.passwordElement.setAttribute('aria-label', loadTimeData.getStringF( |
2086 'passwordFieldAccessibleName', this.user_.emailAddress)); | 2113 'passwordFieldAccessibleName', this.user_.emailAddress)); |
2087 | 2114 |
2088 UserPod.prototype.updateActionBoxArea.call(this); | 2115 UserPod.prototype.updateActionBoxArea.call(this); |
2089 }, | 2116 }, |
2090 | 2117 |
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3293 if (pod && pod.multiProfilesPolicyApplied) { | 3320 if (pod && pod.multiProfilesPolicyApplied) { |
3294 pod.userTypeBubbleElement.classList.remove('bubble-shown'); | 3321 pod.userTypeBubbleElement.classList.remove('bubble-shown'); |
3295 } | 3322 } |
3296 } | 3323 } |
3297 }; | 3324 }; |
3298 | 3325 |
3299 return { | 3326 return { |
3300 PodRow: PodRow | 3327 PodRow: PodRow |
3301 }; | 3328 }; |
3302 }); | 3329 }); |
OLD | NEW |