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

Side by Side Diff: chrome/browser/resources/history/history.js

Issue 15969014: History: Update managed user history page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RTL fix Created 7 years, 6 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 | Annotate | Revision Log
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 <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
11 // Amount of time between pageviews that we consider a 'break' in browsing, 11 // Amount of time between pageviews that we consider a 'break' in browsing,
12 // measured in milliseconds. 12 // measured in milliseconds.
13 /** @const */ var BROWSING_GAP_TIME = 15 * 60 * 1000; 13 /** @const */ var BROWSING_GAP_TIME = 15 * 60 * 1000;
14 14
15 // TODO(glen): Get rid of these global references, replace with a controller 15 // TODO(glen): Get rid of these global references, replace with a controller
16 // or just make the classes own more of the page. 16 // or just make the classes own more of the page.
17 var historyModel; 17 var historyModel;
18 var historyView; 18 var historyView;
19 var pageState; 19 var pageState;
20 var selectionAnchor = -1; 20 var selectionAnchor = -1;
21 var activeVisit = null; 21 var activeVisit = null;
22 22
23 /** @const */ var Command = cr.ui.Command; 23 /** @const */ var Command = cr.ui.Command;
24 /** @const */ var Menu = cr.ui.Menu; 24 /** @const */ var Menu = cr.ui.Menu;
25 /** @const */ var MenuButton = cr.ui.MenuButton; 25 /** @const */ var MenuButton = cr.ui.MenuButton;
26 26
27 /** 27 /**
28 * Enum that shows whether a manual exception is set in managed mode for a 28 * Enum that shows the filtering behavior for a host or URL to a managed user.
29 * host or URL. 29 * Must behave like the FilteringBehavior enum from managed_mode_url_filter.h.
30 * Must behave like the ManualBehavior enum from managed_user_service.h.
31 * @enum {number} 30 * @enum {number}
32 */ 31 */
33 ManagedModeManualBehavior = { 32 ManagedModeFilteringBehavior = {
34 NONE: 0, 33 ALLOW: 0,
35 ALLOW: 1, 34 WARN: 1,
36 BLOCK: 2 35 BLOCK: 2
37 }; 36 };
38 37
39 MenuButton.createDropDownArrows(); 38 MenuButton.createDropDownArrows();
40 39
41 /** 40 /**
42 * Returns true if the mobile (non-desktop) version is being shown. 41 * Returns true if the mobile (non-desktop) version is being shown.
43 * @return {boolean} true if the mobile version is being shown. 42 * @return {boolean} true if the mobile version is being shown.
44 */ 43 */
45 function isMobileVersion() { 44 function isMobileVersion() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // two items easily. 78 // two items easily.
80 79
81 this.date = new Date(result.time); 80 this.date = new Date(result.time);
82 81
83 // See comment in BrowsingHistoryHandler::QueryComplete - we won't always 82 // See comment in BrowsingHistoryHandler::QueryComplete - we won't always
84 // get all of these. 83 // get all of these.
85 this.dateRelativeDay = result.dateRelativeDay || ''; 84 this.dateRelativeDay = result.dateRelativeDay || '';
86 this.dateTimeOfDay = result.dateTimeOfDay || ''; 85 this.dateTimeOfDay = result.dateTimeOfDay || '';
87 this.dateShort = result.dateShort || ''; 86 this.dateShort = result.dateShort || '';
88 87
89 // These values represent indicators shown to users in managed mode. 88 // Shows the filtering behavior for that host (only used for managed users).
90 // |*manualBehavior| shows whether the user has manually added an exception 89 this.hostFilteringBehavior = result.hostFilteringBehavior ||
Bernhard Bauer 2013/06/10 12:33:27 This relies on ALLOW having a falsy value, right?
Sergiu 2013/06/10 13:18:41 Done.
91 // for that URL or host while |*inContentPack| shows whether that URL or host 90 ManagedModeFilteringBehavior.ALLOW;
92 // is in a content pack or not.
93 this.urlManualBehavior = result.urlManualBehavior ||
94 ManagedModeManualBehavior.NONE;
95 this.hostManualBehavior = result.hostManualBehavior ||
96 ManagedModeManualBehavior.NONE;
97 this.urlInContentPack = result.urlInContentPack || false;
98 this.hostInContentPack = result.hostInContentPack || false;
99 this.blockedVisit = result.blockedVisit || false; 91 this.blockedVisit = result.blockedVisit || false;
100 92
101 // Whether this is the continuation of a previous day. 93 // Whether this is the continuation of a previous day.
102 this.continued = continued; 94 this.continued = continued;
103 95
104 this.allTimestamps = result.allTimestamps; 96 this.allTimestamps = result.allTimestamps;
105 } 97 }
106 98
107 // Visit, public: ------------------------------------------------------------- 99 // Visit, public: -------------------------------------------------------------
108 100
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 var self = this; 140 var self = this;
149 var setActiveVisit = function(e) { 141 var setActiveVisit = function(e) {
150 activeVisit = self; 142 activeVisit = self;
151 var menu = $('action-menu'); 143 var menu = $('action-menu');
152 menu.dataset.devicename = self.deviceName; 144 menu.dataset.devicename = self.deviceName;
153 menu.dataset.devicetype = self.deviceType; 145 menu.dataset.devicetype = self.deviceType;
154 }; 146 };
155 domain.textContent = this.getDomainFromURL_(this.url_); 147 domain.textContent = this.getDomainFromURL_(this.url_);
156 148
157 entryBox.appendChild(time); 149 entryBox.appendChild(time);
158 var titleAndDomainWrapper = entryBox.appendChild( 150 var visitEntryWrapper = entryBox.appendChild(document.createElement('div'));
159 createElementWithClassName('div', 'title-and-domain')); 151 if (addTitleFavicon || this.blockedVisit)
152 visitEntryWrapper.classList.add('visit-entry');
160 if (this.blockedVisit) { 153 if (this.blockedVisit) {
161 titleAndDomainWrapper.classList.add('blocked-indicator'); 154 visitEntryWrapper.classList.add('blocked-indicator');
162 titleAndDomainWrapper.appendChild(this.getVisitAttemptDOM_()); 155 visitEntryWrapper.appendChild(this.getVisitAttemptDOM_());
163 } else { 156 } else {
164 titleAndDomainWrapper.appendChild(this.getTitleDOM_()); 157 visitEntryWrapper.appendChild(this.getTitleDOM_());
165 if (addTitleFavicon) 158 if (addTitleFavicon)
166 this.addFaviconToElement_(titleAndDomainWrapper); 159 this.addFaviconToElement_(visitEntryWrapper);
160 visitEntryWrapper.appendChild(domain);
167 } 161 }
168 titleAndDomainWrapper.appendChild(domain);
169 162
170 if (isMobileVersion()) { 163 if (isMobileVersion()) {
171 var removeButton = createElementWithClassName('button', 'remove-entry'); 164 var removeButton = createElementWithClassName('button', 'remove-entry');
172 removeButton.classList.add('custom-appearance'); 165 removeButton.classList.add('custom-appearance');
173 removeButton.addEventListener('click', function(e) { 166 removeButton.addEventListener('click', function(e) {
174 self.removeFromHistory(); 167 self.removeFromHistory();
175 e.stopPropagation(); 168 e.stopPropagation();
176 e.preventDefault(); 169 e.preventDefault();
177 }); 170 });
178 entryBox.appendChild(removeButton); 171 entryBox.appendChild(removeButton);
(...skipping 22 matching lines...) Expand all
201 this.classList.add('contains-focus'); 194 this.classList.add('contains-focus');
202 }, true); 195 }, true);
203 entryBox.addEventListener('blur', function() { 196 entryBox.addEventListener('blur', function() {
204 this.classList.remove('contains-focus'); 197 this.classList.remove('contains-focus');
205 }, true); 198 }, true);
206 199
207 var entryBoxContainer = 200 var entryBoxContainer =
208 createElementWithClassName('div', 'entry-box-container'); 201 createElementWithClassName('div', 'entry-box-container');
209 node.appendChild(entryBoxContainer); 202 node.appendChild(entryBoxContainer);
210 entryBoxContainer.appendChild(entryBox); 203 entryBoxContainer.appendChild(entryBox);
211 if (!isSearchResult && this.model_.isManagedProfile &&
212 this.model_.getGroupByDomain()) {
213 entryBoxContainer.appendChild(
214 getManagedStatusDOM(this.urlManualBehavior, this.urlInContentPack));
215 }
216 204
217 if (isSearchResult) { 205 if (isSearchResult) {
218 time.appendChild(document.createTextNode(this.dateShort)); 206 time.appendChild(document.createTextNode(this.dateShort));
219 var snippet = createElementWithClassName('div', 'snippet'); 207 var snippet = createElementWithClassName('div', 'snippet');
220 this.addHighlightedText_(snippet, 208 this.addHighlightedText_(snippet,
221 this.snippet_, 209 this.snippet_,
222 this.model_.getSearchText()); 210 this.model_.getSearchText());
223 node.appendChild(snippet); 211 node.appendChild(snippet);
224 } else if (useMonthDate) { 212 } else if (useMonthDate) {
225 // Show the day instead of the time. 213 // Show the day instead of the time.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 }; 308 };
321 309
322 /** 310 /**
323 * Returns the DOM element containing the text for a blocked visit attempt. 311 * Returns the DOM element containing the text for a blocked visit attempt.
324 * @return {Element} DOM representation of the visit attempt. 312 * @return {Element} DOM representation of the visit attempt.
325 * @private 313 * @private
326 */ 314 */
327 Visit.prototype.getVisitAttemptDOM_ = function() { 315 Visit.prototype.getVisitAttemptDOM_ = function() {
328 var node = createElementWithClassName('div', 'title'); 316 var node = createElementWithClassName('div', 'title');
329 node.innerHTML = loadTimeData.getStringF('blockedVisitText', 317 node.innerHTML = loadTimeData.getStringF('blockedVisitText',
330 this.url_, this.id_); 318 this.url_,
319 this.id_,
320 this.getDomainFromURL_(this.url_));
331 return node; 321 return node;
332 }; 322 };
333 323
334 /** 324 /**
335 * Set the favicon for an element. 325 * Set the favicon for an element.
336 * @param {Element} el The DOM element to which to add the icon. 326 * @param {Element} el The DOM element to which to add the icon.
337 * @private 327 * @private
338 */ 328 */
339 Visit.prototype.addFaviconToElement_ = function(el) { 329 Visit.prototype.addFaviconToElement_ = function(el) {
340 var url = isMobileVersion() ? 330 var url = isMobileVersion() ?
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 */ 568 */
579 HistoryModel.prototype.clearModel_ = function() { 569 HistoryModel.prototype.clearModel_ = function() {
580 this.inFlight_ = false; // Whether a query is inflight. 570 this.inFlight_ = false; // Whether a query is inflight.
581 this.searchText_ = ''; 571 this.searchText_ = '';
582 // Whether this user is a managed user. 572 // Whether this user is a managed user.
583 this.isManagedProfile = loadTimeData.getBoolean('isManagedProfile'); 573 this.isManagedProfile = loadTimeData.getBoolean('isManagedProfile');
584 this.deletingHistoryAllowed = loadTimeData.getBoolean('allowDeletingHistory'); 574 this.deletingHistoryAllowed = loadTimeData.getBoolean('allowDeletingHistory');
585 575
586 // Only create checkboxes for editing entries if they can be used either to 576 // Only create checkboxes for editing entries if they can be used either to
587 // delete an entry or to block/allow it. 577 // delete an entry or to block/allow it.
588 this.editingEntriesAllowed = this.deletingHistoryAllowed || 578 this.editingEntriesAllowed = this.deletingHistoryAllowed;
589 this.isManagedProfile;
590 579
591 // Flag to show that the results are grouped by domain or not. 580 // Flag to show that the results are grouped by domain or not.
592 this.groupByDomain_ = false; 581 this.groupByDomain_ = false;
593 // Group domains by default for managed users.
594 if (this.isManagedProfile)
595 this.groupByDomain_ = true;
596 582
597 this.visits_ = []; // Date-sorted list of visits (most recent first). 583 this.visits_ = []; // Date-sorted list of visits (most recent first).
598 this.nextVisitId_ = 0; 584 this.nextVisitId_ = 0;
599 selectionAnchor = -1; 585 selectionAnchor = -1;
600 586
601 // The page that the view wants to see - we only fetch slightly past this 587 // The page that the view wants to see - we only fetch slightly past this
602 // point. If the view requests a page that we don't have data for, we try 588 // point. If the view requests a page that we don't have data for, we try
603 // to fetch it and call back when we're done. 589 // to fetch it and call back when we're done.
604 this.requestedPage_ = 0; 590 this.requestedPage_ = 0;
605 591
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 $('newest-button').addEventListener('click', function() { 717 $('newest-button').addEventListener('click', function() {
732 self.setPage(0); 718 self.setPage(0);
733 }); 719 });
734 $('newer-button').addEventListener('click', function() { 720 $('newer-button').addEventListener('click', function() {
735 self.setPage(self.pageIndex_ - 1); 721 self.setPage(self.pageIndex_ - 1);
736 }); 722 });
737 $('older-button').addEventListener('click', function() { 723 $('older-button').addEventListener('click', function() {
738 self.setPage(self.pageIndex_ + 1); 724 self.setPage(self.pageIndex_ + 1);
739 }); 725 });
740 726
727 var handleRangeChange = function(e) {
728 // Update the results and save the last state.
729 self.setRangeInDays(parseInt(e.target.value, 10));
730 };
731
741 // Add handlers for the range options. 732 // Add handlers for the range options.
742 $('timeframe-filter').addEventListener('change', function(e) { 733 $('timeframe-filter-all').addEventListener('change', handleRangeChange);
743 self.setRangeInDays(parseInt(e.target.value, 10)); 734 $('timeframe-filter-week').addEventListener('change', handleRangeChange);
744 }); 735 $('timeframe-filter-month').addEventListener('change', handleRangeChange);
745
746 $('group-by-domain').addEventListener('click', function(e) {
747 self.setGroupByDomain($('group-by-domain').checked);
748 });
749 736
750 $('range-previous').addEventListener('click', function(e) { 737 $('range-previous').addEventListener('click', function(e) {
751 if (self.getRangeInDays() == HistoryModel.Range.ALL_TIME) 738 if (self.getRangeInDays() == HistoryModel.Range.ALL_TIME)
752 self.setPage(self.pageIndex_ + 1); 739 self.setPage(self.pageIndex_ + 1);
753 else 740 else
754 self.setOffset(self.getOffset() + 1); 741 self.setOffset(self.getOffset() + 1);
755 }); 742 });
756 $('range-next').addEventListener('click', function(e) { 743 $('range-next').addEventListener('click', function(e) {
757 if (self.getRangeInDays() == HistoryModel.Range.ALL_TIME) 744 if (self.getRangeInDays() == HistoryModel.Range.ALL_TIME)
758 self.setPage(self.pageIndex_ - 1); 745 self.setPage(self.pageIndex_ - 1);
759 else 746 else
760 self.setOffset(self.getOffset() - 1); 747 self.setOffset(self.getOffset() - 1);
761 }); 748 });
762 $('range-today').addEventListener('click', function(e) { 749 $('range-today').addEventListener('click', function(e) {
763 if (self.getRangeInDays() == HistoryModel.Range.ALL_TIME) 750 if (self.getRangeInDays() == HistoryModel.Range.ALL_TIME)
764 self.setPage(0); 751 self.setPage(0);
765 else 752 else
766 self.setOffset(0); 753 self.setOffset(0);
767 }); 754 });
768 } 755 }
769 756
770 // HistoryView, public: ------------------------------------------------------- 757 // HistoryView, public: -------------------------------------------------------
771 /** 758 /**
772 * Do a search on a specific term. 759 * Do a search on a specific term.
773 * @param {string} term The string to search for. 760 * @param {string} term The string to search for.
774 */ 761 */
775 HistoryView.prototype.setSearch = function(term) { 762 HistoryView.prototype.setSearch = function(term) {
776 window.scrollTo(0, 0); 763 window.scrollTo(0, 0);
777 this.setPageState(term, 0, this.model_.getGroupByDomain(), 764 this.setPageState(term, 0, this.getRangeInDays(), this.getOffset());
778 this.getRangeInDays(), this.getOffset());
779 }; 765 };
780 766
781 /** 767 /**
782 * Enable or disable results as being grouped by domain.
783 * @param {boolean} groupedByDomain Whether to group by domain or not.
784 */
785 HistoryView.prototype.setGroupByDomain = function(groupedByDomain) {
786 // Group by domain is not currently supported for search results, so reset
787 // the search term if there was one.
788 this.setPageState('', this.pageIndex_, groupedByDomain, this.getRangeInDays(),
789 this.getOffset());
790 };
791
792 /**
793 * Reload the current view. 768 * Reload the current view.
794 */ 769 */
795 HistoryView.prototype.reload = function() { 770 HistoryView.prototype.reload = function() {
796 this.model_.reload(); 771 this.model_.reload();
797 this.updateSelectionEditButtons(); 772 this.updateSelectionEditButtons();
798 this.updateRangeButtons_(); 773 this.updateRangeButtons_();
799 }; 774 };
800 775
801 /** 776 /**
802 * Sets all the parameters for the history page and then reloads the view to 777 * Sets all the parameters for the history page and then reloads the view to
803 * update the results. 778 * update the results.
804 * @param {string} searchText The search string to set. 779 * @param {string} searchText The search string to set.
805 * @param {number} page The page to be viewed. 780 * @param {number} page The page to be viewed.
806 * @param {boolean} groupByDomain Whether the results are grouped or not.
807 * @param {HistoryModel.Range} range The range to view or search over. 781 * @param {HistoryModel.Range} range The range to view or search over.
808 * @param {number} offset Set the begining of the query to the specific offset. 782 * @param {number} offset Set the begining of the query to the specific offset.
809 */ 783 */
810 HistoryView.prototype.setPageState = function(searchText, page, groupByDomain, 784 HistoryView.prototype.setPageState = function(searchText, page, range, offset) {
811 range, offset) {
812 this.clear_(); 785 this.clear_();
813 this.model_.searchText_ = searchText; 786 this.model_.searchText_ = searchText;
814 this.pageIndex_ = page; 787 this.pageIndex_ = page;
815 this.model_.requestedPage_ = page; 788 this.model_.requestedPage_ = page;
816 this.model_.groupByDomain_ = groupByDomain;
817 this.model_.rangeInDays_ = range; 789 this.model_.rangeInDays_ = range;
790 this.model_.groupByDomain_ = false;
791 if (range != HistoryModel.Range.ALL_TIME)
792 this.model_.groupByDomain_ = true;
818 this.model_.offset_ = offset; 793 this.model_.offset_ = offset;
819 this.reload(); 794 this.reload();
820 pageState.setUIState(this.model_.getSearchText(), 795 pageState.setUIState(this.model_.getSearchText(),
821 this.pageIndex_, 796 this.pageIndex_,
822 this.model_.getGroupByDomain(),
823 this.getRangeInDays(), 797 this.getRangeInDays(),
824 this.getOffset()); 798 this.getOffset());
825 }; 799 };
826 800
827 /** 801 /**
828 * Switch to a specified page. 802 * Switch to a specified page.
829 * @param {number} page The page we wish to view. 803 * @param {number} page The page we wish to view.
830 */ 804 */
831 HistoryView.prototype.setPage = function(page) { 805 HistoryView.prototype.setPage = function(page) {
832 // TODO(sergiu): Move this function to setPageState as well and see why one 806 // TODO(sergiu): Move this function to setPageState as well and see why one
833 // of the tests fails when using setPageState. 807 // of the tests fails when using setPageState.
834 this.clear_(); 808 this.clear_();
835 this.pageIndex_ = parseInt(page, 10); 809 this.pageIndex_ = parseInt(page, 10);
836 window.scrollTo(0, 0); 810 window.scrollTo(0, 0);
837 this.model_.requestPage(page); 811 this.model_.requestPage(page);
838 pageState.setUIState(this.model_.getSearchText(), 812 pageState.setUIState(this.model_.getSearchText(),
839 this.pageIndex_, 813 this.pageIndex_,
840 this.model_.getGroupByDomain(),
841 this.getRangeInDays(), 814 this.getRangeInDays(),
842 this.getOffset()); 815 this.getOffset());
843 }; 816 };
844 817
845 /** 818 /**
846 * @return {number} The page number being viewed. 819 * @return {number} The page number being viewed.
847 */ 820 */
848 HistoryView.prototype.getPage = function() { 821 HistoryView.prototype.getPage = function() {
849 return this.pageIndex_; 822 return this.pageIndex_;
850 }; 823 };
851 824
852 /** 825 /**
853 * Set the current range for grouped results. 826 * Set the current range for grouped results.
854 * @param {string} range The number of days to which the range should be set. 827 * @param {string} range The number of days to which the range should be set.
855 */ 828 */
856 HistoryView.prototype.setRangeInDays = function(range) { 829 HistoryView.prototype.setRangeInDays = function(range) {
857 // Set the range, offset and reset the page. 830 // Set the range, offset and reset the page.
858 this.setPageState(this.model_.getSearchText(), 0, 831 this.setPageState(this.model_.getSearchText(), 0, range, 0);
859 this.model_.getGroupByDomain(), range, 0);
860 }; 832 };
861 833
862 /** 834 /**
863 * Get the current range in days. 835 * Get the current range in days.
864 * @return {number} Current range in days from the model. 836 * @return {number} Current range in days from the model.
865 */ 837 */
866 HistoryView.prototype.getRangeInDays = function() { 838 HistoryView.prototype.getRangeInDays = function() {
867 return this.model_.rangeInDays; 839 return this.model_.rangeInDays;
868 }; 840 };
869 841
870 /** 842 /**
871 * Set the current offset for grouped results. 843 * Set the current offset for grouped results.
872 * @param {number} offset Offset to set. 844 * @param {number} offset Offset to set.
873 */ 845 */
874 HistoryView.prototype.setOffset = function(offset) { 846 HistoryView.prototype.setOffset = function(offset) {
875 // If there is another query already in flight wait for that to complete. 847 // If there is another query already in flight wait for that to complete.
876 if (this.model_.inFlight_) 848 if (this.model_.inFlight_)
877 return; 849 return;
878 this.setPageState(this.model_.getSearchText(), 850 this.setPageState(this.model_.getSearchText(),
879 this.pageIndex_, 851 this.pageIndex_,
880 this.model_.getGroupByDomain(),
881 this.getRangeInDays(), 852 this.getRangeInDays(),
882 offset); 853 offset);
883 }; 854 };
884 855
885 /** 856 /**
886 * Get the current offset. 857 * Get the current offset.
887 * @return {number} Current offset from the model. 858 * @return {number} Current offset from the model.
888 */ 859 */
889 HistoryView.prototype.getOffset = function() { 860 HistoryView.prototype.getOffset = function() {
890 return this.model_.offset; 861 return this.model_.offset;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1002
1032 numberOfVisits.textContent = loadTimeData.getStringF('numberVisits', 1003 numberOfVisits.textContent = loadTimeData.getStringF('numberVisits',
1033 domainVisits.length); 1004 domainVisits.length);
1034 siteDomain.appendChild(numberOfVisits); 1005 siteDomain.appendChild(numberOfVisits);
1035 1006
1036 domainVisits[0].addFaviconToElement_(siteDomain); 1007 domainVisits[0].addFaviconToElement_(siteDomain);
1037 1008
1038 siteDomainWrapper.addEventListener('click', toggleHandler); 1009 siteDomainWrapper.addEventListener('click', toggleHandler);
1039 1010
1040 if (this.model_.isManagedProfile) { 1011 if (this.model_.isManagedProfile) {
1041 // Visit attempts don't make sense for domains so set the last parameter to 1012 siteDomainWrapper.appendChild(
1042 // false. 1013 getManagedStatusDOM(domainVisits[0].hostFilteringBehavior));
1043 siteDomainWrapper.appendChild(getManagedStatusDOM(
1044 domainVisits[0].hostManualBehavior, domainVisits[0].hostInContentPack));
1045 } 1014 }
1046 1015
1047 siteResults.appendChild(siteDomainWrapper); 1016 siteResults.appendChild(siteDomainWrapper);
1048 var resultsList = siteResults.appendChild( 1017 var resultsList = siteResults.appendChild(
1049 createElementWithClassName('ol', 'site-results')); 1018 createElementWithClassName('ol', 'site-results'));
1050 1019
1051 // Collapse until it gets toggled. 1020 // Collapse until it gets toggled.
1052 resultsList.style.height = 0; 1021 resultsList.style.height = 0;
1053 1022
1054 // Add the results for each of the domain. 1023 // Add the results for each of the domain.
1055 var isMonthGroupedResult = this.getRangeInDays() == HistoryModel.Range.MONTH; 1024 var isMonthGroupedResult = this.getRangeInDays() == HistoryModel.Range.MONTH;
1056 for (var j = 0, visit; visit = domainVisits[j]; j++) { 1025 for (var j = 0, visit; visit = domainVisits[j]; j++) {
1057 resultsList.appendChild(visit.getResultDOM({ 1026 resultsList.appendChild(visit.getResultDOM({
1058 useMonthDate: isMonthGroupedResult 1027 useMonthDate: isMonthGroupedResult
1059 })); 1028 }));
1060 this.setVisitRendered_(visit); 1029 this.setVisitRendered_(visit);
1061 } 1030 }
1062 }; 1031 };
1063 1032
1064 /** 1033 /**
1065 * Enables or disables the time range buttons. 1034 * Enables or disables the time range buttons.
1066 * @private 1035 * @private
1067 */ 1036 */
1068 HistoryView.prototype.updateRangeButtons_ = function() { 1037 HistoryView.prototype.updateRangeButtons_ = function() {
1069 // Update the range button to the current value.
1070 $('timeframe-filter').value = this.getRangeInDays();
1071
1072 // The enabled state for the previous, today and next buttons. 1038 // The enabled state for the previous, today and next buttons.
1073 var previousState = false; 1039 var previousState = false;
1074 var todayState = false; 1040 var todayState = false;
1075 var nextState = false; 1041 var nextState = false;
1076 var usePage = (this.getRangeInDays() == HistoryModel.Range.ALL_TIME); 1042 var usePage = (this.getRangeInDays() == HistoryModel.Range.ALL_TIME);
1077 1043
1078 // Use pagination for most recent visits, offset otherwise. 1044 // Use pagination for most recent visits, offset otherwise.
1079 // TODO(sergiu): Maybe send just one variable in the future. 1045 // TODO(sergiu): Maybe send just one variable in the future.
1080 if (usePage) { 1046 if (usePage) {
1081 if (this.getPage() != 0) { 1047 if (this.getPage() != 0) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 * @param {Array} visits Visits returned by the query. 1095 * @param {Array} visits Visits returned by the query.
1130 * @param {Element} parentElement Element to which to add the results to. 1096 * @param {Element} parentElement Element to which to add the results to.
1131 * @private 1097 * @private
1132 */ 1098 */
1133 HistoryView.prototype.addMonthResults_ = function(visits, parentElement) { 1099 HistoryView.prototype.addMonthResults_ = function(visits, parentElement) {
1134 if (visits.length == 0) 1100 if (visits.length == 0)
1135 return; 1101 return;
1136 1102
1137 var monthResults = parentElement.appendChild( 1103 var monthResults = parentElement.appendChild(
1138 createElementWithClassName('ol', 'month-results')); 1104 createElementWithClassName('ol', 'month-results'));
1105 // Don't add checkboxes if entries can not be edited.
1106 if (!this.model_.editingEntriesAllowed)
1107 monthResults.classList.add('no-checkboxes');
1108
1139 this.groupVisitsByDomain_(visits, monthResults); 1109 this.groupVisitsByDomain_(visits, monthResults);
1140 }; 1110 };
1141 1111
1142 /** 1112 /**
1143 * Adds the results for a certain day. This includes a title with the day of 1113 * Adds the results for a certain day. This includes a title with the day of
1144 * the results and the results themselves, grouped or not. 1114 * the results and the results themselves, grouped or not.
1145 * @param {Array} visits Visits returned by the query. 1115 * @param {Array} visits Visits returned by the query.
1146 * @param {Element} parentElement Element to which to add the results to. 1116 * @param {Element} parentElement Element to which to add the results to.
1147 * @private 1117 * @private
1148 */ 1118 */
1149 HistoryView.prototype.addDayResults_ = function(visits, parentElement) { 1119 HistoryView.prototype.addDayResults_ = function(visits, parentElement) {
1150 if (visits.length == 0) 1120 if (visits.length == 0)
1151 return; 1121 return;
1152 1122
1153 var firstVisit = visits[0]; 1123 var firstVisit = visits[0];
1154 var day = parentElement.appendChild(createElementWithClassName('h3', 'day')); 1124 var day = parentElement.appendChild(createElementWithClassName('h3', 'day'));
1155 day.appendChild(document.createTextNode(firstVisit.dateRelativeDay)); 1125 day.appendChild(document.createTextNode(firstVisit.dateRelativeDay));
1156 if (firstVisit.continued) { 1126 if (firstVisit.continued) {
1157 day.appendChild(document.createTextNode(' ' + 1127 day.appendChild(document.createTextNode(' ' +
1158 loadTimeData.getString('cont'))); 1128 loadTimeData.getString('cont')));
1159 } 1129 }
1160 var dayResults = parentElement.appendChild( 1130 var dayResults = parentElement.appendChild(
1161 createElementWithClassName('ol', 'day-results')); 1131 createElementWithClassName('ol', 'day-results'));
1162 1132
1133 // Don't add checkboxes if entries can not be edited.
1134 if (!this.model_.editingEntriesAllowed)
1135 dayResults.classList.add('no-checkboxes');
1136
1163 if (this.model_.getGroupByDomain()) { 1137 if (this.model_.getGroupByDomain()) {
1164 this.groupVisitsByDomain_(visits, dayResults); 1138 this.groupVisitsByDomain_(visits, dayResults);
1165 } else { 1139 } else {
1166 var lastTime; 1140 var lastTime;
1167 1141
1168 for (var i = 0, visit; visit = visits[i]; i++) { 1142 for (var i = 0, visit; visit = visits[i]; i++) {
1169 // If enough time has passed between visits, indicate a gap in browsing. 1143 // If enough time has passed between visits, indicate a gap in browsing.
1170 var thisTime = visit.date.getTime(); 1144 var thisTime = visit.date.getTime();
1171 if (lastTime && lastTime - thisTime > BROWSING_GAP_TIME) 1145 if (lastTime && lastTime - thisTime > BROWSING_GAP_TIME)
1172 dayResults.appendChild(createElementWithClassName('li', 'gap')); 1146 dayResults.appendChild(createElementWithClassName('li', 'gap'));
1173 1147
1174 // Insert the visit into the DOM. 1148 // Insert the visit into the DOM.
1175 dayResults.appendChild(visit.getResultDOM({ addTitleFavicon: true })); 1149 dayResults.appendChild(visit.getResultDOM({ addTitleFavicon: true }));
1176 this.setVisitRendered_(visit); 1150 this.setVisitRendered_(visit);
1177 1151
1178 lastTime = thisTime; 1152 lastTime = thisTime;
1179 } 1153 }
1180 } 1154 }
1181 }; 1155 };
1182 1156
1183 /** 1157 /**
1158 * Adds the text that shows the current interval, used for week and month
1159 * results.
1160 * @param {Element} resultsFragment The element to which the interval will be
1161 * added to.
1162 * @private
1163 */
1164 HistoryView.prototype.addTimeframeInterval_ = function(resultsFragment) {
1165 if (this.getRangeInDays() == HistoryModel.Range.ALL_TIME)
1166 return;
1167
1168 // If this is a time range result add some text that shows what is the
1169 // time range for the results the user is viewing.
1170 var timeFrame = resultsFragment.appendChild(
1171 createElementWithClassName('h2', 'timeframe'));
1172 // TODO(sergiu): Figure the best way to show this for the first day of
1173 // the month.
1174 timeFrame.appendChild(document.createTextNode(loadTimeData.getStringF(
1175 'historyInterval',
1176 this.model_.queryStartTime,
1177 this.model_.queryEndTime)));
1178 };
1179
1180 /**
1184 * Update the page with results. 1181 * Update the page with results.
1185 * @param {boolean} doneLoading Whether the current request is complete. 1182 * @param {boolean} doneLoading Whether the current request is complete.
1186 * @private 1183 * @private
1187 */ 1184 */
1188 HistoryView.prototype.displayResults_ = function(doneLoading) { 1185 HistoryView.prototype.displayResults_ = function(doneLoading) {
1189 // Either show a page of results received for the all time results or all the 1186 // Either show a page of results received for the all time results or all the
1190 // received results for the weekly and monthly view. 1187 // received results for the weekly and monthly view.
1191 var results = this.model_.visits_; 1188 var results = this.model_.visits_;
1192 if (this.getRangeInDays() == HistoryModel.Range.ALL_TIME) { 1189 if (this.getRangeInDays() == HistoryModel.Range.ALL_TIME) {
1193 var rangeStart = this.pageIndex_ * RESULTS_PER_PAGE; 1190 var rangeStart = this.pageIndex_ * RESULTS_PER_PAGE;
1194 var rangeEnd = rangeStart + RESULTS_PER_PAGE; 1191 var rangeEnd = rangeStart + RESULTS_PER_PAGE;
1195 results = this.model_.getNumberedRange(rangeStart, rangeEnd); 1192 results = this.model_.getNumberedRange(rangeStart, rangeEnd);
1196 } 1193 }
1197 var searchText = this.model_.getSearchText(); 1194 var searchText = this.model_.getSearchText();
1198 var groupByDomain = this.model_.getGroupByDomain(); 1195 var groupByDomain = this.model_.getGroupByDomain();
1199 1196
1200 if (searchText) { 1197 if (searchText) {
1201 // Add a header for the search results, if there isn't already one. 1198 // Add a header for the search results, if there isn't already one.
1202 if (!this.resultDiv_.querySelector('h3')) { 1199 if (!this.resultDiv_.querySelector('h3')) {
1203 var header = document.createElement('h3'); 1200 var header = document.createElement('h3');
1204 header.textContent = loadTimeData.getStringF('searchResultsFor', 1201 header.textContent = loadTimeData.getStringF('searchResultsFor',
1205 searchText); 1202 searchText);
1206 this.resultDiv_.appendChild(header); 1203 this.resultDiv_.appendChild(header);
1207 } 1204 }
1208 1205
1206 this.addTimeframeInterval_(this.resultDiv_);
1207
1209 var searchResults = createElementWithClassName('ol', 'search-results'); 1208 var searchResults = createElementWithClassName('ol', 'search-results');
1209
1210 // Don't add checkboxes if entries can not be edited.
1211 if (!this.model_.editingEntriesAllowed)
1212 searchResults.classList.add('no-checkboxes');
1213
1210 if (results.length == 0 && doneLoading) { 1214 if (results.length == 0 && doneLoading) {
1211 var noSearchResults = searchResults.appendChild( 1215 var noSearchResults = searchResults.appendChild(
1212 createElementWithClassName('div', 'no-results-message')); 1216 createElementWithClassName('div', 'no-results-message'));
1213 noSearchResults.textContent = loadTimeData.getString('noSearchResults'); 1217 noSearchResults.textContent = loadTimeData.getString('noSearchResults');
1214 } else { 1218 } else {
1215 for (var i = 0, visit; visit = results[i]; i++) { 1219 for (var i = 0, visit; visit = results[i]; i++) {
1216 if (!visit.isRendered) { 1220 if (!visit.isRendered) {
1217 searchResults.appendChild(visit.getResultDOM({ 1221 searchResults.appendChild(visit.getResultDOM({
1218 isSearchResult: true, 1222 isSearchResult: true,
1219 addTitleFavicon: true 1223 addTitleFavicon: true
1220 })); 1224 }));
1221 this.setVisitRendered_(visit); 1225 this.setVisitRendered_(visit);
1222 } 1226 }
1223 } 1227 }
1224 } 1228 }
1225 this.resultDiv_.appendChild(searchResults); 1229 this.resultDiv_.appendChild(searchResults);
1226 } else { 1230 } else {
1227 var resultsFragment = document.createDocumentFragment(); 1231 var resultsFragment = document.createDocumentFragment();
1228 1232
1229 if (this.getRangeInDays() == HistoryModel.Range.WEEK || 1233 this.addTimeframeInterval_(resultsFragment);
1230 this.getRangeInDays() == HistoryModel.Range.MONTH) {
1231 // If this is a time range result add some text that shows what is the
1232 // time range for the results the user is viewing.
1233 var timeFrame = resultsFragment.appendChild(
1234 createElementWithClassName('h2', 'timeframe'));
1235 // TODO(sergiu): Figure the best way to show this for the first day of
1236 // the month.
1237 timeFrame.appendChild(document.createTextNode(loadTimeData.getStringF(
1238 'historyInterval',
1239 this.model_.queryStartTime,
1240 this.model_.queryEndTime)));
1241 }
1242 1234
1243 if (results.length == 0 && doneLoading) { 1235 if (results.length == 0 && doneLoading) {
1244 var noResults = resultsFragment.appendChild( 1236 var noResults = resultsFragment.appendChild(
1245 createElementWithClassName('div', 'no-results-message')); 1237 createElementWithClassName('div', 'no-results-message'));
1246 noResults.textContent = loadTimeData.getString('noResults'); 1238 noResults.textContent = loadTimeData.getString('noResults');
1247 this.resultDiv_.appendChild(resultsFragment); 1239 this.resultDiv_.appendChild(resultsFragment);
1248 this.updateNavBar_(); 1240 this.updateNavBar_();
1249 return; 1241 return;
1250 } 1242 }
1251 1243
(...skipping 23 matching lines...) Expand all
1275 } 1267 }
1276 this.updateNavBar_(); 1268 this.updateNavBar_();
1277 }; 1269 };
1278 1270
1279 /** 1271 /**
1280 * Update the visibility of the page navigation buttons. 1272 * Update the visibility of the page navigation buttons.
1281 * @private 1273 * @private
1282 */ 1274 */
1283 HistoryView.prototype.updateNavBar_ = function() { 1275 HistoryView.prototype.updateNavBar_ = function() {
1284 this.updateRangeButtons_(); 1276 this.updateRangeButtons_();
1285 $('newest-button').hidden = this.pageIndex_ == 0; 1277 if (!loadTimeData.getBoolean('isManagedProfile')) {
1286 $('newer-button').hidden = this.pageIndex_ == 0; 1278 // Managed users have the control bar on top, don't show it on the bottom
1287 $('older-button').hidden = 1279 // as well.
1288 this.model_.rangeInDays_ != HistoryModel.Range.ALL_TIME || 1280 $('newest-button').hidden = this.pageIndex_ == 0;
1289 !this.model_.hasMoreResults(); 1281 $('newer-button').hidden = this.pageIndex_ == 0;
1282 $('older-button').hidden =
1283 this.model_.rangeInDays_ != HistoryModel.Range.ALL_TIME ||
1284 !this.model_.hasMoreResults();
1285 }
1290 }; 1286 };
1291 1287
1292 /** 1288 /**
1293 * Updates the visibility of the 'Clear browsing data' button. 1289 * Updates the visibility of the 'Clear browsing data' button.
1294 * Only used on mobile platforms. 1290 * Only used on mobile platforms.
1295 * @private 1291 * @private
1296 */ 1292 */
1297 HistoryView.prototype.updateClearBrowsingDataButton_ = function() { 1293 HistoryView.prototype.updateClearBrowsingDataButton_ = function() {
1298 // Ideally, we should hide the 'Clear browsing data' button whenever the 1294 // Ideally, we should hide the 'Clear browsing data' button whenever the
1299 // soft keyboard is visible. This is not possible, so instead, hide the 1295 // soft keyboard is visible. This is not possible, so instead, hide the
(...skipping 20 matching lines...) Expand all
1320 this.view = view; 1316 this.view = view;
1321 1317
1322 if (typeof this.checker_ != 'undefined' && this.checker_) { 1318 if (typeof this.checker_ != 'undefined' && this.checker_) {
1323 clearInterval(this.checker_); 1319 clearInterval(this.checker_);
1324 } 1320 }
1325 1321
1326 // TODO(glen): Replace this with a bound method so we don't need 1322 // TODO(glen): Replace this with a bound method so we don't need
1327 // public model and view. 1323 // public model and view.
1328 this.checker_ = window.setInterval(function(stateObj) { 1324 this.checker_ = window.setInterval(function(stateObj) {
1329 var hashData = stateObj.getHashData(); 1325 var hashData = stateObj.getHashData();
1330 var isGroupedByDomain = hashData.grouped == 'true';
1331 var page = parseInt(hashData.page, 10); 1326 var page = parseInt(hashData.page, 10);
1332 var range = parseInt(hashData.range, 10); 1327 var range = parseInt(hashData.range, 10);
1333 var offset = parseInt(hashData.offset, 10); 1328 var offset = parseInt(hashData.offset, 10);
1334 if (hashData.q != stateObj.model.getSearchText() || 1329 if (hashData.q != stateObj.model.getSearchText() ||
1335 page != stateObj.view.getPage() || 1330 page != stateObj.view.getPage() ||
1336 isGroupedByDomain != stateObj.view.model_.getGroupByDomain() ||
1337 range != stateObj.model.rangeInDays || 1331 range != stateObj.model.rangeInDays ||
1338 offset != stateObj.model.offset) { 1332 offset != stateObj.model.offset) {
1339 stateObj.view.setPageState(hashData.q, page, isGroupedByDomain, 1333 stateObj.view.setPageState(hashData.q, page, range, offset);
1340 range, offset);
1341 } 1334 }
1342 }, 50, this); 1335 }, 50, this);
1343 } 1336 }
1344 1337
1345 /** 1338 /**
1346 * Holds the singleton instance. 1339 * Holds the singleton instance.
1347 */ 1340 */
1348 PageState.instance = null; 1341 PageState.instance = null;
1349 1342
1350 /** 1343 /**
(...skipping 21 matching lines...) Expand all
1372 1365
1373 return result; 1366 return result;
1374 }; 1367 };
1375 1368
1376 /** 1369 /**
1377 * Set the hash to a specified state, this will create an entry in the 1370 * Set the hash to a specified state, this will create an entry in the
1378 * session history so the back button cycles through hash states, which 1371 * session history so the back button cycles through hash states, which
1379 * are then picked up by our listener. 1372 * are then picked up by our listener.
1380 * @param {string} term The current search string. 1373 * @param {string} term The current search string.
1381 * @param {number} page The page currently being viewed. 1374 * @param {number} page The page currently being viewed.
1382 * @param {boolean} grouped Whether the results are grouped or not.
1383 * @param {HistoryModel.Range} range The range to view or search over. 1375 * @param {HistoryModel.Range} range The range to view or search over.
1384 * @param {number} offset Set the begining of the query to the specific offset. 1376 * @param {number} offset Set the begining of the query to the specific offset.
1385 */ 1377 */
1386 PageState.prototype.setUIState = function(term, page, grouped, range, offset) { 1378 PageState.prototype.setUIState = function(term, page, range, offset) {
1387 // Make sure the form looks pretty. 1379 // Make sure the form looks pretty.
1388 $('search-field').value = term; 1380 $('search-field').value = term;
1389 $('group-by-domain').checked = grouped;
1390 var hash = this.getHashData(); 1381 var hash = this.getHashData();
1391 if (hash.q != term || hash.page != page || hash.grouped != grouped || 1382 if (hash.q != term || hash.page != page || hash.range != range ||
1392 hash.range != range || hash.offset != offset) { 1383 hash.offset != offset) {
1393 window.location.hash = PageState.getHashString( 1384 window.location.hash = PageState.getHashString(term, page, range, offset);
1394 term, page, grouped, range, offset);
1395 } 1385 }
1396 }; 1386 };
1397 1387
1398 /** 1388 /**
1399 * Static method to get the hash string for a specified state 1389 * Static method to get the hash string for a specified state
1400 * @param {string} term The current search string. 1390 * @param {string} term The current search string.
1401 * @param {number} page The page currently being viewed. 1391 * @param {number} page The page currently being viewed.
1402 * @param {boolean} grouped Whether the results are grouped or not.
1403 * @param {HistoryModel.Range} range The range to view or search over. 1392 * @param {HistoryModel.Range} range The range to view or search over.
1404 * @param {number} offset Set the begining of the query to the specific offset. 1393 * @param {number} offset Set the begining of the query to the specific offset.
1405 * @return {string} The string to be used in a hash. 1394 * @return {string} The string to be used in a hash.
1406 */ 1395 */
1407 PageState.getHashString = function(term, page, grouped, range, offset) { 1396 PageState.getHashString = function(term, page, range, offset) {
1408 // Omit elements that are empty. 1397 // Omit elements that are empty.
1409 var newHash = []; 1398 var newHash = [];
1410 1399
1411 if (term) 1400 if (term)
1412 newHash.push('q=' + encodeURIComponent(term)); 1401 newHash.push('q=' + encodeURIComponent(term));
1413 1402
1414 if (page) 1403 if (page)
1415 newHash.push('page=' + page); 1404 newHash.push('page=' + page);
1416 1405
1417 if (grouped)
1418 newHash.push('grouped=' + grouped);
1419
1420 if (range) 1406 if (range)
1421 newHash.push('range=' + range); 1407 newHash.push('range=' + range);
1422 1408
1423 if (offset) 1409 if (offset)
1424 newHash.push('offset=' + offset); 1410 newHash.push('offset=' + offset);
1425 1411
1426 return newHash.join('&'); 1412 return newHash.join('&');
1427 }; 1413 };
1428 1414
1429 /////////////////////////////////////////////////////////////////////////////// 1415 ///////////////////////////////////////////////////////////////////////////////
1430 // Document Functions: 1416 // Document Functions:
1431 /** 1417 /**
1432 * Window onload handler, sets up the page. 1418 * Window onload handler, sets up the page.
1433 */ 1419 */
1434 function load() { 1420 function load() {
1435 uber.onContentFrameLoaded(); 1421 uber.onContentFrameLoaded();
1436 1422
1437 var searchField = $('search-field'); 1423 var searchField = $('search-field');
1438 1424
1439 historyModel = new HistoryModel(); 1425 historyModel = new HistoryModel();
1440 historyView = new HistoryView(historyModel); 1426 historyView = new HistoryView(historyModel);
1441 pageState = new PageState(historyModel, historyView); 1427 pageState = new PageState(historyModel, historyView);
1442 1428
1443 // Create default view. 1429 // Create default view.
1444 var hashData = pageState.getHashData(); 1430 var hashData = pageState.getHashData();
1445 var grouped = (hashData.grouped == 'true') || historyModel.getGroupByDomain(); 1431 var grouped = (hashData.grouped == 'true') || historyModel.getGroupByDomain();
1446 var page = parseInt(hashData.page, 10) || historyView.getPage(); 1432 var page = parseInt(hashData.page, 10) || historyView.getPage();
1447 var range = parseInt(hashData.range, 10) || historyView.getRangeInDays(); 1433 var range = parseInt(hashData.range, 10) || historyView.getRangeInDays();
1448 var offset = parseInt(hashData.offset, 10) || historyView.getOffset(); 1434 var offset = parseInt(hashData.offset, 10) || historyView.getOffset();
1449 historyView.setPageState(hashData.q, page, grouped, range, offset); 1435 historyView.setPageState(hashData.q, page, range, offset);
1450 1436
1451 if ($('overlay')) 1437 if ($('overlay'))
1452 cr.ui.overlay.setupOverlay($('overlay')); 1438 cr.ui.overlay.setupOverlay($('overlay'));
1453 1439
1454 var doSearch = function(e) { 1440 var doSearch = function(e) {
1455 // Disable the group by domain control when a search is active.
1456 $('group-by-domain').disabled = (searchField.value != '');
1457 historyView.setSearch(searchField.value); 1441 historyView.setSearch(searchField.value);
1458 1442
1459 if (isMobileVersion()) 1443 if (isMobileVersion())
1460 searchField.blur(); // Dismiss the keyboard. 1444 searchField.blur(); // Dismiss the keyboard.
1461 }; 1445 };
1462 1446
1463 var mayRemoveVisits = loadTimeData.getBoolean('allowDeletingHistory'); 1447 var mayRemoveVisits = loadTimeData.getBoolean('allowDeletingHistory');
1464 $('remove-visit').disabled = !mayRemoveVisits; 1448 $('remove-visit').disabled = !mayRemoveVisits;
1465 1449
1466 if (mayRemoveVisits) { 1450 if (mayRemoveVisits) {
1467 $('remove-visit').addEventListener('activate', function(e) { 1451 $('remove-visit').addEventListener('activate', function(e) {
1468 activeVisit.removeFromHistory(); 1452 activeVisit.removeFromHistory();
1469 activeVisit = null; 1453 activeVisit = null;
1470 }); 1454 });
1471 } 1455 }
1472 1456
1473 searchField.addEventListener('search', doSearch); 1457 searchField.addEventListener('search', doSearch);
1474 $('search-button').addEventListener('click', doSearch); 1458 $('search-button').addEventListener('click', doSearch);
1475 1459
1476 $('more-from-site').addEventListener('activate', function(e) { 1460 $('more-from-site').addEventListener('activate', function(e) {
1477 activeVisit.showMoreFromSite_(); 1461 activeVisit.showMoreFromSite_();
1478 activeVisit = null; 1462 activeVisit = null;
1479 }); 1463 });
1480 1464
1481 // Only show the controls if the command line switch is activated. 1465 // Only show the controls if the command line switch is activated.
1482 if (loadTimeData.getBoolean('groupByDomain') || 1466 if (loadTimeData.getBoolean('groupByDomain') ||
1483 loadTimeData.getBoolean('isManagedProfile')) { 1467 loadTimeData.getBoolean('isManagedProfile')) {
1468 // Hide the top container which has the "Clear browsing data" and "Remove
1469 // selected entries" buttons since they're unavailable in managed mode
1470 $('top-container').hidden = true;
1471 $('page').classList.add('big-topbar-page');
1484 $('filter-controls').hidden = false; 1472 $('filter-controls').hidden = false;
1485 } 1473 }
1486 1474
1487 var title = loadTimeData.getString('title'); 1475 var title = loadTimeData.getString('title');
1488 uber.invokeMethodOnParent('setTitle', {title: title}); 1476 uber.invokeMethodOnParent('setTitle', {title: title});
1489 1477
1490 // Adjust the position of the notification bar when the window size changes. 1478 // Adjust the position of the notification bar when the window size changes.
1491 window.addEventListener('resize', 1479 window.addEventListener('resize',
1492 historyView.positionNotificationBar.bind(historyView)); 1480 historyView.positionNotificationBar.bind(historyView));
1493 1481
(...skipping 19 matching lines...) Expand all
1513 } else { 1501 } else {
1514 window.addEventListener('message', function(e) { 1502 window.addEventListener('message', function(e) {
1515 if (e.data.method == 'frameSelected') 1503 if (e.data.method == 'frameSelected')
1516 searchField.focus(); 1504 searchField.focus();
1517 }); 1505 });
1518 searchField.focus(); 1506 searchField.focus();
1519 } 1507 }
1520 } 1508 }
1521 1509
1522 /** 1510 /**
1523 * Updates the whitelist status labels of a host/URL entry to the current 1511 * Updates the managed filter status labels of a host/URL entry to the current
1524 * value. 1512 * value.
1525 * @param {Element} statusElement The div which contains the status labels. 1513 * @param {Element} statusElement The div which contains the status labels.
1526 * @param {Object} newStatus A dictionary with two entries: 1514 * @param {ManagedModeFilteringBehavior} newStatus The filter status of the
1527 * - |inContentPack|: whether the current domain/URL is allowed by a 1515 * current domain/URL.
1528 * content pack.
1529 * - |manualBehavior|: The manual status of the current domain/URL.
1530 */ 1516 */
1531 function updateHostStatus(statusElement, newStatus) { 1517 function updateHostStatus(statusElement, newStatus) {
1532 var inContentPackDiv = statusElement.querySelector('.in-content-pack'); 1518 var filteringBehaviorDiv =
1533 inContentPackDiv.className = 'in-content-pack'; 1519 statusElement.querySelector('.filtering-behavior');
1534 1520 // Reset to the base class first, then add modifier classes if needed.
1535 if (newStatus['inContentPack']) { 1521 filteringBehaviorDiv.className = 'filtering-behavior';
1536 if (newStatus['manualBehavior'] != ManagedModeManualBehavior.NONE) 1522 if (newStatus == ManagedModeFilteringBehavior.BLOCK) {
1537 inContentPackDiv.classList.add('in-content-pack-passive'); 1523 filteringBehaviorDiv.textContent =
1538 else 1524 loadTimeData.getString('filterBlocked');
1539 inContentPackDiv.classList.add('in-content-pack-active'); 1525 filteringBehaviorDiv.classList.add('filter-blocked');
1540 } 1526 } else {
1541 1527 filteringBehaviorDiv.textContent = '';
1542 if ('manualBehavior' in newStatus) {
1543 var manualBehaviorDiv = statusElement.querySelector('.manual-behavior');
1544 // Reset to the base class first, then add modifier classes if needed.
1545 manualBehaviorDiv.className = 'manual-behavior';
1546 switch (newStatus['manualBehavior']) {
1547 case ManagedModeManualBehavior.NONE:
1548 manualBehaviorDiv.textContent = '';
1549 break;
1550 case ManagedModeManualBehavior.ALLOW:
1551 manualBehaviorDiv.textContent = loadTimeData.getString('filterAllowed');
1552 manualBehaviorDiv.classList.add('filter-allowed');
1553 break;
1554 case ManagedModeManualBehavior.BLOCK:
1555 manualBehaviorDiv.textContent = loadTimeData.getString('filterBlocked');
1556 manualBehaviorDiv.classList.add('filter-blocked');
1557 break;
1558 }
1559 } 1528 }
1560 } 1529 }
1561 1530
1562 /** 1531 /**
1563 * Click handler for the 'Clear browsing data' dialog. 1532 * Click handler for the 'Clear browsing data' dialog.
1564 * @param {Event} e The click event. 1533 * @param {Event} e The click event.
1565 */ 1534 */
1566 function openClearBrowsingData(e) { 1535 function openClearBrowsingData(e) {
1567 chrome.send('clearBrowsingData'); 1536 chrome.send('clearBrowsingData');
1568 } 1537 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 innerArrow.classList.add('expand'); 1757 innerArrow.classList.add('expand');
1789 } else { 1758 } else {
1790 innerResultList.style.height = 0; 1759 innerResultList.style.height = 0;
1791 innerArrow.classList.remove('expand'); 1760 innerArrow.classList.remove('expand');
1792 innerArrow.classList.add('collapse'); 1761 innerArrow.classList.add('collapse');
1793 } 1762 }
1794 } 1763 }
1795 1764
1796 /** 1765 /**
1797 * Builds the DOM elements to show the managed status of a domain/URL. 1766 * Builds the DOM elements to show the managed status of a domain/URL.
1798 * @param {ManagedModeManualBehavior} manualBehavior The manual behavior for 1767 * @param {ManagedModeFilteringBehavior} filteringBehavior The filter behavior
1799 * this item. 1768 * for this item.
1800 * @param {boolean} inContentPack Whether this element is in a content pack or
1801 * not.
1802 * @return {Element} Returns the DOM elements which show the status. 1769 * @return {Element} Returns the DOM elements which show the status.
1803 */ 1770 */
1804 function getManagedStatusDOM(manualBehavior, inContentPack) { 1771 function getManagedStatusDOM(filteringBehavior) {
1805 var filterStatusDiv = createElementWithClassName('div', 'filter-status'); 1772 var filterStatusDiv = createElementWithClassName('div', 'filter-status');
1806 var inContentPackDiv = createElementWithClassName('div', 'in-content-pack'); 1773 var filteringBehaviorDiv =
1807 inContentPackDiv.textContent = loadTimeData.getString('inContentPack'); 1774 createElementWithClassName('div', 'filtering-behavior');
1808 var manualBehaviorDiv = createElementWithClassName('div', 'manual-behavior'); 1775 filterStatusDiv.appendChild(filteringBehaviorDiv);
1809 filterStatusDiv.appendChild(inContentPackDiv);
1810 filterStatusDiv.appendChild(manualBehaviorDiv);
1811 1776
1812 updateHostStatus(filterStatusDiv, { 1777 updateHostStatus(filterStatusDiv, filteringBehavior);
1813 'inContentPack' : inContentPack,
1814 'manualBehavior' : manualBehavior
1815 });
1816 return filterStatusDiv; 1778 return filterStatusDiv;
1817 } 1779 }
1818 1780
1819 1781
1820 /////////////////////////////////////////////////////////////////////////////// 1782 ///////////////////////////////////////////////////////////////////////////////
1821 // Chrome callbacks: 1783 // Chrome callbacks:
1822 1784
1823 /** 1785 /**
1824 * Our history system calls this function with results from searches. 1786 * Our history system calls this function with results from searches.
1825 * @param {Object} info An object containing information about the query. 1787 * @param {Object} info An object containing information about the query.
(...skipping 28 matching lines...) Expand all
1854 historyView.reload(); 1816 historyView.reload();
1855 } 1817 }
1856 1818
1857 // Add handlers to HTML elements. 1819 // Add handlers to HTML elements.
1858 document.addEventListener('DOMContentLoaded', load); 1820 document.addEventListener('DOMContentLoaded', load);
1859 1821
1860 // This event lets us enable and disable menu items before the menu is shown. 1822 // This event lets us enable and disable menu items before the menu is shown.
1861 document.addEventListener('canExecute', function(e) { 1823 document.addEventListener('canExecute', function(e) {
1862 e.canExecute = true; 1824 e.canExecute = true;
1863 }); 1825 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698