| 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 <include src="../uber/uber_utils.js"> | 5 <include src="../uber/uber_utils.js"> |
| 6 | 6 |
| 7 /////////////////////////////////////////////////////////////////////////////// | 7 /////////////////////////////////////////////////////////////////////////////// |
| 8 // Globals: | 8 // Globals: |
| 9 /** @const */ var RESULTS_PER_PAGE = 150; | 9 /** @const */ var RESULTS_PER_PAGE = 150; |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 var isSearchResult = propertyBag.isSearchResult || false; | 119 var isSearchResult = propertyBag.isSearchResult || false; |
| 120 var addTitleFavicon = propertyBag.addTitleFavicon || false; | 120 var addTitleFavicon = propertyBag.addTitleFavicon || false; |
| 121 var useMonthDate = propertyBag.useMonthDate || false; | 121 var useMonthDate = propertyBag.useMonthDate || false; |
| 122 var node = createElementWithClassName('li', 'entry'); | 122 var node = createElementWithClassName('li', 'entry'); |
| 123 var time = createElementWithClassName('div', 'time'); | 123 var time = createElementWithClassName('div', 'time'); |
| 124 var entryBox = createElementWithClassName('label', 'entry-box'); | 124 var entryBox = createElementWithClassName('label', 'entry-box'); |
| 125 var domain = createElementWithClassName('div', 'domain'); | 125 var domain = createElementWithClassName('div', 'domain'); |
| 126 | 126 |
| 127 this.id_ = this.model_.nextVisitId_++; | 127 this.id_ = this.model_.nextVisitId_++; |
| 128 | 128 |
| 129 // Checkbox is always created, but only visible on hover & when checked. | 129 // Only create the checkbox if it can be used either to delete an entry or to |
| 130 var checkbox = document.createElement('input'); | 130 // block/allow it. |
| 131 checkbox.type = 'checkbox'; | 131 if (this.model_.createEditingCheckboxes) { |
| 132 checkbox.id = 'checkbox-' + this.id_; | 132 var checkbox = document.createElement('input'); |
| 133 checkbox.time = this.date.getTime(); | 133 checkbox.type = 'checkbox'; |
| 134 checkbox.addEventListener('click', checkboxClicked); | 134 checkbox.id = 'checkbox-' + this.id_; |
| 135 time.appendChild(checkbox); | 135 checkbox.time = this.date.getTime(); |
| 136 checkbox.addEventListener('click', checkboxClicked); |
| 137 time.appendChild(checkbox); |
| 138 |
| 139 // Clicking anywhere in the entryBox will check/uncheck the checkbox. |
| 140 entryBox.setAttribute('for', checkbox.id); |
| 141 entryBox.addEventListener('mousedown', entryBoxMousedown); |
| 142 } |
| 136 | 143 |
| 137 // Keep track of the drop down that triggered the menu, so we know | 144 // Keep track of the drop down that triggered the menu, so we know |
| 138 // which element to apply the command to. | 145 // which element to apply the command to. |
| 139 // TODO(dubroy): Ideally we'd use 'activate', but MenuButton swallows it. | 146 // TODO(dubroy): Ideally we'd use 'activate', but MenuButton swallows it. |
| 140 var self = this; | 147 var self = this; |
| 141 var setActiveVisit = function(e) { | 148 var setActiveVisit = function(e) { |
| 142 activeVisit = self; | 149 activeVisit = self; |
| 143 var menu = $('action-menu'); | 150 var menu = $('action-menu'); |
| 144 menu.dataset.devicename = self.deviceName; | 151 menu.dataset.devicename = self.deviceName; |
| 145 menu.dataset.devicetype = self.deviceType; | 152 menu.dataset.devicetype = self.deviceType; |
| 146 }; | 153 }; |
| 147 domain.textContent = this.getDomainFromURL_(this.url_); | 154 domain.textContent = this.getDomainFromURL_(this.url_); |
| 148 | 155 |
| 149 // Clicking anywhere in the entryBox will check/uncheck the checkbox. | |
| 150 entryBox.setAttribute('for', checkbox.id); | |
| 151 entryBox.addEventListener('mousedown', entryBoxMousedown); | |
| 152 | |
| 153 entryBox.appendChild(time); | 156 entryBox.appendChild(time); |
| 154 var titleAndDomainWrapper = entryBox.appendChild( | 157 var titleAndDomainWrapper = entryBox.appendChild( |
| 155 createElementWithClassName('div', 'title-and-domain')); | 158 createElementWithClassName('div', 'title-and-domain')); |
| 156 titleAndDomainWrapper.appendChild(this.getTitleDOM_()); | 159 titleAndDomainWrapper.appendChild(this.getTitleDOM_()); |
| 157 titleAndDomainWrapper.appendChild(domain); | 160 titleAndDomainWrapper.appendChild(domain); |
| 158 if (addTitleFavicon) | 161 if (addTitleFavicon) |
| 159 this.addFaviconToElement_(titleAndDomainWrapper); | 162 this.addFaviconToElement_(titleAndDomainWrapper); |
| 160 | 163 |
| 161 if (isMobileVersion()) { | 164 if (isMobileVersion()) { |
| 162 var removeButton = createElementWithClassName('button', 'remove-entry'); | 165 var removeButton = createElementWithClassName('button', 'remove-entry'); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 556 |
| 554 /** | 557 /** |
| 555 * Clear the history model. | 558 * Clear the history model. |
| 556 * @private | 559 * @private |
| 557 */ | 560 */ |
| 558 HistoryModel.prototype.clearModel_ = function() { | 561 HistoryModel.prototype.clearModel_ = function() { |
| 559 this.inFlight_ = false; // Whether a query is inflight. | 562 this.inFlight_ = false; // Whether a query is inflight. |
| 560 this.searchText_ = ''; | 563 this.searchText_ = ''; |
| 561 // Whether this user is a managed user. | 564 // Whether this user is a managed user. |
| 562 this.isManagedProfile = loadTimeData.getBoolean('isManagedProfile'); | 565 this.isManagedProfile = loadTimeData.getBoolean('isManagedProfile'); |
| 566 this.deletingHistoryAllowed = loadTimeData.getBoolean('allowDeletingHistory'); |
| 567 |
| 568 // Only create checkboxes for editing entries if they can be used either to |
| 569 // delete an entry or to block/allow it. |
| 570 this.createEditingCheckboxes = this.deletingHistoryAllowed || |
| 571 this.isManagedProfile; |
| 563 | 572 |
| 564 // Flag to show that the results are grouped by domain or not. | 573 // Flag to show that the results are grouped by domain or not. |
| 565 this.groupByDomain_ = false; | 574 this.groupByDomain_ = false; |
| 566 // Group domains by default for managed users. | 575 // Group domains by default for managed users. |
| 567 if (this.isManagedProfile) | 576 if (this.isManagedProfile) |
| 568 this.groupByDomain_ = true; | 577 this.groupByDomain_ = true; |
| 569 | 578 |
| 570 this.visits_ = []; // Date-sorted list of visits (most recent first). | 579 this.visits_ = []; // Date-sorted list of visits (most recent first). |
| 571 this.nextVisitId_ = 0; | 580 this.nextVisitId_ = 0; |
| 572 selectionAnchor = -1; | 581 selectionAnchor = -1; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 document.body.classList.remove('has-results'); | 896 document.body.classList.remove('has-results'); |
| 888 | 897 |
| 889 this.updateNavBar_(); | 898 this.updateNavBar_(); |
| 890 }; | 899 }; |
| 891 | 900 |
| 892 /** | 901 /** |
| 893 * Enables or disables the buttons that control editing entries depending on | 902 * Enables or disables the buttons that control editing entries depending on |
| 894 * whether there are any checked boxes. | 903 * whether there are any checked boxes. |
| 895 */ | 904 */ |
| 896 HistoryView.prototype.updateSelectionEditButtons = function() { | 905 HistoryView.prototype.updateSelectionEditButtons = function() { |
| 897 var anyChecked = document.querySelector('.entry input:checked') != null; | 906 if (loadTimeData.getBoolean('allowDeletingHistory')) { |
| 898 $('remove-selected').disabled = !anyChecked; | 907 var anyChecked = document.querySelector('.entry input:checked') != null; |
| 908 $('remove-selected').disabled = !anyChecked; |
| 909 } else { |
| 910 $('remove-selected').disabled = true; |
| 911 } |
| 899 $('allow-selected').disabled = !anyChecked; | 912 $('allow-selected').disabled = !anyChecked; |
| 900 $('block-selected').disabled = !anyChecked; | 913 $('block-selected').disabled = !anyChecked; |
| 901 }; | 914 }; |
| 902 | 915 |
| 903 /** | 916 /** |
| 904 * Callback triggered by the backend after the manual allow or block changes | 917 * Callback triggered by the backend after the manual allow or block changes |
| 905 * have been commited. Once the changes are commited the backend builds an | 918 * have been commited. Once the changes are commited the backend builds an |
| 906 * updated set of data which contains the new managed mode status and passes | 919 * updated set of data which contains the new managed mode status and passes |
| 907 * it through this function to the client. The function takes that data and | 920 * it through this function to the client. The function takes that data and |
| 908 * updates the individiual host/URL elements with their new managed mode status. | 921 * updates the individiual host/URL elements with their new managed mode status. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 * @param {Element} results DOM object to which to add the elements. | 1023 * @param {Element} results DOM object to which to add the elements. |
| 1011 * @param {string} domain Current domain name. | 1024 * @param {string} domain Current domain name. |
| 1012 * @param {Array} domainVisits Array of visits for this domain. | 1025 * @param {Array} domainVisits Array of visits for this domain. |
| 1013 * @private | 1026 * @private |
| 1014 */ | 1027 */ |
| 1015 HistoryView.prototype.getGroupedVisitsDOM_ = function( | 1028 HistoryView.prototype.getGroupedVisitsDOM_ = function( |
| 1016 results, domain, domainVisits) { | 1029 results, domain, domainVisits) { |
| 1017 // Add a new domain entry. | 1030 // Add a new domain entry. |
| 1018 var siteResults = results.appendChild( | 1031 var siteResults = results.appendChild( |
| 1019 createElementWithClassName('li', 'site-entry')); | 1032 createElementWithClassName('li', 'site-entry')); |
| 1020 var siteDomainCheckbox = | 1033 |
| 1021 createElementWithClassName('input', 'domain-checkbox'); | |
| 1022 siteDomainCheckbox.type = 'checkbox'; | |
| 1023 siteDomainCheckbox.addEventListener('click', domainCheckboxClicked); | |
| 1024 siteDomainCheckbox.domain_ = domain; | |
| 1025 // Make a wrapper that will contain the arrow, the favicon and the domain. | 1034 // Make a wrapper that will contain the arrow, the favicon and the domain. |
| 1026 var siteDomainWrapper = siteResults.appendChild( | 1035 var siteDomainWrapper = siteResults.appendChild( |
| 1027 createElementWithClassName('div', 'site-domain-wrapper')); | 1036 createElementWithClassName('div', 'site-domain-wrapper')); |
| 1028 siteDomainWrapper.appendChild(siteDomainCheckbox); | 1037 |
| 1038 if (this.model_.createEditingCheckboxes) { |
| 1039 var siteDomainCheckbox = |
| 1040 createElementWithClassName('input', 'domain-checkbox'); |
| 1041 |
| 1042 siteDomainCheckbox.type = 'checkbox'; |
| 1043 siteDomainCheckbox.addEventListener('click', domainCheckboxClicked); |
| 1044 siteDomainCheckbox.domain_ = domain; |
| 1045 |
| 1046 siteDomainWrapper.appendChild(siteDomainCheckbox); |
| 1047 } |
| 1048 |
| 1029 var siteArrow = siteDomainWrapper.appendChild( | 1049 var siteArrow = siteDomainWrapper.appendChild( |
| 1030 createElementWithClassName('div', 'site-domain-arrow collapse')); | 1050 createElementWithClassName('div', 'site-domain-arrow collapse')); |
| 1031 var siteDomain = siteDomainWrapper.appendChild( | 1051 var siteDomain = siteDomainWrapper.appendChild( |
| 1032 createElementWithClassName('div', 'site-domain')); | 1052 createElementWithClassName('div', 'site-domain')); |
| 1033 var siteDomainLink = siteDomain.appendChild( | 1053 var siteDomainLink = siteDomain.appendChild( |
| 1034 createElementWithClassName('button', 'link-button')); | 1054 createElementWithClassName('button', 'link-button')); |
| 1035 siteDomainLink.addEventListener('click', function(e) { e.preventDefault(); }); | 1055 siteDomainLink.addEventListener('click', function(e) { e.preventDefault(); }); |
| 1036 siteDomainLink.textContent = domain; | 1056 siteDomainLink.textContent = domain; |
| 1037 var numberOfVisits = createElementWithClassName('span', 'number-visits'); | 1057 var numberOfVisits = createElementWithClassName('span', 'number-visits'); |
| 1038 var domainElement = document.createElement('span'); | 1058 var domainElement = document.createElement('span'); |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 | 1463 |
| 1444 var doSearch = function(e) { | 1464 var doSearch = function(e) { |
| 1445 // Disable the group by domain control when a search is active. | 1465 // Disable the group by domain control when a search is active. |
| 1446 $('group-by-domain').disabled = (searchField.value != ''); | 1466 $('group-by-domain').disabled = (searchField.value != ''); |
| 1447 historyView.setSearch(searchField.value); | 1467 historyView.setSearch(searchField.value); |
| 1448 | 1468 |
| 1449 if (isMobileVersion()) | 1469 if (isMobileVersion()) |
| 1450 searchField.blur(); // Dismiss the keyboard. | 1470 searchField.blur(); // Dismiss the keyboard. |
| 1451 }; | 1471 }; |
| 1452 | 1472 |
| 1473 var mayRemoveVisits = loadTimeData.getBoolean('allowDeletingHistory'); |
| 1474 $('remove-visit').disabled = !mayRemoveVisits; |
| 1475 |
| 1476 if (mayRemoveVisits) { |
| 1477 $('remove-visit').addEventListener('activate', function(e) { |
| 1478 activeVisit.removeFromHistory_(); |
| 1479 activeVisit = null; |
| 1480 }); |
| 1481 } |
| 1482 |
| 1453 searchField.addEventListener('search', doSearch); | 1483 searchField.addEventListener('search', doSearch); |
| 1454 $('search-button').addEventListener('click', doSearch); | 1484 $('search-button').addEventListener('click', doSearch); |
| 1455 | 1485 |
| 1456 $('remove-visit').addEventListener('activate', function(e) { | |
| 1457 activeVisit.removeFromHistory(); | |
| 1458 activeVisit = null; | |
| 1459 }); | |
| 1460 $('more-from-site').addEventListener('activate', function(e) { | 1486 $('more-from-site').addEventListener('activate', function(e) { |
| 1461 activeVisit.showMoreFromSite_(); | 1487 activeVisit.showMoreFromSite_(); |
| 1462 activeVisit = null; | 1488 activeVisit = null; |
| 1463 }); | 1489 }); |
| 1464 | 1490 |
| 1465 // Only show the controls if the command line switch is activated. | 1491 // Only show the controls if the command line switch is activated. |
| 1466 if (loadTimeData.getBoolean('groupByDomain') || | 1492 if (loadTimeData.getBoolean('groupByDomain') || |
| 1467 loadTimeData.getBoolean('isManagedProfile')) { | 1493 loadTimeData.getBoolean('isManagedProfile')) { |
| 1468 $('filter-controls').hidden = false; | 1494 $('filter-controls').hidden = false; |
| 1469 } | 1495 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 */ | 1607 */ |
| 1582 function openClearBrowsingData(e) { | 1608 function openClearBrowsingData(e) { |
| 1583 chrome.send('clearBrowsingData'); | 1609 chrome.send('clearBrowsingData'); |
| 1584 } | 1610 } |
| 1585 | 1611 |
| 1586 /** | 1612 /** |
| 1587 * Click handler for the 'Remove selected items' button. | 1613 * Click handler for the 'Remove selected items' button. |
| 1588 * Confirms the deletion with the user, and then deletes the selected visits. | 1614 * Confirms the deletion with the user, and then deletes the selected visits. |
| 1589 */ | 1615 */ |
| 1590 function removeItems() { | 1616 function removeItems() { |
| 1617 if (!loadTimeData.getBoolean('allowDeletingHistory')) |
| 1618 return; |
| 1619 |
| 1591 var checked = $('results-display').querySelectorAll( | 1620 var checked = $('results-display').querySelectorAll( |
| 1592 '.entry-box input[type=checkbox]:checked:not([disabled])'); | 1621 '.entry-box input[type=checkbox]:checked:not([disabled])'); |
| 1593 var disabledItems = []; | 1622 var disabledItems = []; |
| 1594 var toBeRemoved = []; | 1623 var toBeRemoved = []; |
| 1595 | 1624 |
| 1596 for (var i = 0; i < checked.length; i++) { | 1625 for (var i = 0; i < checked.length; i++) { |
| 1597 var checkbox = checked[i]; | 1626 var checkbox = checked[i]; |
| 1598 var entry = findAncestorByClass(checkbox, 'entry'); | 1627 var entry = findAncestorByClass(checkbox, 'entry'); |
| 1599 toBeRemoved.push(entry.visit); | 1628 toBeRemoved.push(entry.visit); |
| 1600 | 1629 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 } | 1871 } |
| 1843 } | 1872 } |
| 1844 | 1873 |
| 1845 // Add handlers to HTML elements. | 1874 // Add handlers to HTML elements. |
| 1846 document.addEventListener('DOMContentLoaded', load); | 1875 document.addEventListener('DOMContentLoaded', load); |
| 1847 | 1876 |
| 1848 // This event lets us enable and disable menu items before the menu is shown. | 1877 // This event lets us enable and disable menu items before the menu is shown. |
| 1849 document.addEventListener('canExecute', function(e) { | 1878 document.addEventListener('canExecute', function(e) { |
| 1850 e.canExecute = true; | 1879 e.canExecute = true; |
| 1851 }); | 1880 }); |
| OLD | NEW |