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

Side by Side Diff: chrome/browser/ui/webui/browsing_history_handler.cc

Issue 1462813003: Split BrowsingHistoryHandler out of history_ui.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/ui/webui/history_ui.h" 5 #include "chrome/browser/ui/webui/browsing_history_handler.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h"
12 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
13 #include "base/i18n/time_formatting.h" 12 #include "base/i18n/time_formatting.h"
14 #include "base/memory/singleton.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
17 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
18 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
19 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
21 #include "base/time/time.h" 18 #include "base/time/time.h"
22 #include "base/values.h" 19 #include "base/values.h"
23 #include "chrome/browser/banners/app_banner_settings_helper.h" 20 #include "chrome/browser/banners/app_banner_settings_helper.h"
24 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
25 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/engagement/site_engagement_service.h" 22 #include "chrome/browser/engagement/site_engagement_service.h"
27 #include "chrome/browser/history/history_service_factory.h" 23 #include "chrome/browser/history/history_service_factory.h"
28 #include "chrome/browser/history/history_utils.h" 24 #include "chrome/browser/history/history_utils.h"
29 #include "chrome/browser/history/web_history_service_factory.h" 25 #include "chrome/browser/history/web_history_service_factory.h"
30 #include "chrome/browser/prefs/incognito_mode_prefs.h"
31 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/signin/signin_manager_factory.h"
33 #include "chrome/browser/sync/profile_sync_service_factory.h" 27 #include "chrome/browser/sync/profile_sync_service_factory.h"
34 #include "chrome/browser/ui/browser_finder.h" 28 #include "chrome/browser/ui/browser_finder.h"
35 #include "chrome/browser/ui/chrome_pages.h" 29 #include "chrome/browser/ui/chrome_pages.h"
36 #include "chrome/browser/ui/webui/favicon_source.h" 30 #include "chrome/browser/ui/webui/favicon_source.h"
37 #include "chrome/browser/ui/webui/metrics_handler.h"
38 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
40 #include "chrome/common/url_constants.h"
41 #include "chrome/grit/generated_resources.h" 32 #include "chrome/grit/generated_resources.h"
42 #include "components/bookmarks/browser/bookmark_model.h" 33 #include "components/bookmarks/browser/bookmark_model.h"
43 #include "components/bookmarks/browser/bookmark_utils.h" 34 #include "components/bookmarks/browser/bookmark_utils.h"
44 #include "components/browser_sync/browser/profile_sync_service.h" 35 #include "components/browser_sync/browser/profile_sync_service.h"
45 #include "components/history/core/browser/history_service.h" 36 #include "components/history/core/browser/history_service.h"
46 #include "components/history/core/browser/history_types.h" 37 #include "components/history/core/browser/history_types.h"
47 #include "components/history/core/browser/web_history_service.h" 38 #include "components/history/core/browser/web_history_service.h"
48 #include "components/search/search.h" 39 #include "components/keyed_service/core/service_access_type.h"
49 #include "components/signin/core/browser/signin_manager.h" 40 #include "components/query_parser/snippet.h"
50 #include "components/sync_driver/device_info.h" 41 #include "components/sync_driver/device_info.h"
42 #include "components/sync_driver/device_info_tracker.h"
51 #include "components/url_formatter/url_formatter.h" 43 #include "components/url_formatter/url_formatter.h"
52 #include "content/public/browser/url_data_source.h" 44 #include "content/public/browser/url_data_source.h"
53 #include "content/public/browser/web_ui.h" 45 #include "content/public/browser/web_ui.h"
54 #include "content/public/browser/web_ui_data_source.h"
55 #include "grit/browser_resources.h"
56 #include "grit/theme_resources.h"
57 #include "net/base/escape.h"
58 #include "sync/protocol/history_delete_directive_specifics.pb.h" 46 #include "sync/protocol/history_delete_directive_specifics.pb.h"
47 #include "sync/protocol/sync_enums.pb.h"
59 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
60 #include "ui/base/l10n/time_format.h" 49 #include "ui/base/l10n/time_format.h"
61 #include "ui/base/resource/resource_bundle.h"
62 #include "ui/base/webui/web_ui_util.h"
63 50
64 #if defined(ENABLE_EXTENSIONS) 51 #if defined(ENABLE_EXTENSIONS)
65 #include "chrome/browser/extensions/activity_log/activity_log.h" 52 #include "chrome/browser/extensions/activity_log/activity_log.h"
66 #endif 53 #endif
67 54
68 #if defined(ENABLE_SUPERVISED_USERS) 55 #if defined(ENABLE_SUPERVISED_USERS)
69 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h" 56 #include "chrome/browser/supervised_user/supervised_user_navigation_observer.h"
70 #include "chrome/browser/supervised_user/supervised_user_service.h" 57 #include "chrome/browser/supervised_user/supervised_user_service.h"
71 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 58 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
72 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" 59 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
73 #endif 60 #endif
74 61
75 #if defined(OS_ANDROID) 62 #if defined(OS_ANDROID)
76 #include "chrome/browser/android/chrome_application.h" 63 #include "chrome/browser/android/chrome_application.h"
77 #endif 64 #endif
78 65
79 #if !defined(OS_ANDROID) && !defined(OS_IOS)
80 #include "chrome/browser/ui/webui/foreign_session_handler.h"
81 #include "chrome/browser/ui/webui/history_login_handler.h"
82 #endif
83
84 using bookmarks::BookmarkModel;
85
86 static const char kStringsJsFile[] = "strings.js";
87 static const char kHistoryJsFile[] = "history.js";
88 static const char kOtherDevicesJsFile[] = "other_devices.js";
89
90 // The amount of time to wait for a response from the WebHistoryService. 66 // The amount of time to wait for a response from the WebHistoryService.
91 static const int kWebHistoryTimeoutSeconds = 3; 67 static const int kWebHistoryTimeoutSeconds = 3;
92 68
69 using bookmarks::BookmarkModel;
70
93 namespace { 71 namespace {
94 72
95 // Buckets for UMA histograms. 73 // Buckets for UMA histograms.
96 enum WebHistoryQueryBuckets { 74 enum WebHistoryQueryBuckets {
97 WEB_HISTORY_QUERY_FAILED = 0, 75 WEB_HISTORY_QUERY_FAILED = 0,
98 WEB_HISTORY_QUERY_SUCCEEDED, 76 WEB_HISTORY_QUERY_SUCCEEDED,
99 WEB_HISTORY_QUERY_TIMED_OUT, 77 WEB_HISTORY_QUERY_TIMED_OUT,
100 NUM_WEB_HISTORY_QUERY_BUCKETS 78 NUM_WEB_HISTORY_QUERY_BUCKETS
101 }; 79 };
102 80
103 #if defined(OS_MACOSX)
104 const char kIncognitoModeShortcut[] = "("
105 "\xE2\x87\xA7" // Shift symbol (U+21E7 'UPWARDS WHITE ARROW').
106 "\xE2\x8C\x98" // Command symbol (U+2318 'PLACE OF INTEREST SIGN').
107 "N)";
108 #elif defined(OS_WIN)
109 const char kIncognitoModeShortcut[] = "(Ctrl+Shift+N)";
110 #else
111 const char kIncognitoModeShortcut[] = "(Shift+Ctrl+N)";
112 #endif
113
114 // Identifiers for the type of device from which a history entry originated. 81 // Identifiers for the type of device from which a history entry originated.
115 static const char kDeviceTypeLaptop[] = "laptop"; 82 static const char kDeviceTypeLaptop[] = "laptop";
116 static const char kDeviceTypePhone[] = "phone"; 83 static const char kDeviceTypePhone[] = "phone";
117 static const char kDeviceTypeTablet[] = "tablet"; 84 static const char kDeviceTypeTablet[] = "tablet";
118 85
119 content::WebUIDataSource* CreateHistoryUIHTMLSource(Profile* profile) {
120 PrefService* prefs = profile->GetPrefs();
121
122 // Check if the profile is authenticated. Guest profiles or incognito
123 // windows may not have a sign in manager, and are considered not
124 // authenticated.
125 SigninManagerBase* signin_manager =
126 SigninManagerFactory::GetForProfile(profile);
127 bool is_authenticated = signin_manager != nullptr &&
128 signin_manager->IsAuthenticated();
129
130 content::WebUIDataSource* source =
131 content::WebUIDataSource::Create(chrome::kChromeUIHistoryFrameHost);
132 source->AddBoolean("isUserSignedIn", is_authenticated);
133 source->AddLocalizedString("collapseSessionMenuItemText",
134 IDS_HISTORY_OTHER_SESSIONS_COLLAPSE_SESSION);
135 source->AddLocalizedString("expandSessionMenuItemText",
136 IDS_HISTORY_OTHER_SESSIONS_EXPAND_SESSION);
137 source->AddLocalizedString("restoreSessionMenuItemText",
138 IDS_HISTORY_OTHER_SESSIONS_OPEN_ALL);
139 source->AddLocalizedString("xMore", IDS_HISTORY_OTHER_DEVICES_X_MORE);
140 source->AddLocalizedString("loading", IDS_HISTORY_LOADING);
141 source->AddLocalizedString("title", IDS_HISTORY_TITLE);
142 source->AddLocalizedString("newest", IDS_HISTORY_NEWEST);
143 source->AddLocalizedString("newer", IDS_HISTORY_NEWER);
144 source->AddLocalizedString("older", IDS_HISTORY_OLDER);
145 source->AddLocalizedString("searchResultsFor", IDS_HISTORY_SEARCHRESULTSFOR);
146 source->AddLocalizedString("searchResult", IDS_HISTORY_SEARCH_RESULT);
147 source->AddLocalizedString("searchResults", IDS_HISTORY_SEARCH_RESULTS);
148 source->AddLocalizedString("foundSearchResults",
149 IDS_HISTORY_FOUND_SEARCH_RESULTS);
150 source->AddLocalizedString("history", IDS_HISTORY_BROWSERESULTS);
151 source->AddLocalizedString("cont", IDS_HISTORY_CONTINUED);
152 source->AddLocalizedString("searchButton", IDS_HISTORY_SEARCH_BUTTON);
153 source->AddLocalizedString("noSearchResults", IDS_HISTORY_NO_SEARCH_RESULTS);
154 source->AddLocalizedString("noResults", IDS_HISTORY_NO_RESULTS);
155 source->AddLocalizedString("historyInterval", IDS_HISTORY_INTERVAL);
156 source->AddLocalizedString("removeSelected",
157 IDS_HISTORY_REMOVE_SELECTED_ITEMS);
158 source->AddLocalizedString("clearAllHistory",
159 IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG);
160
161 auto availability = IncognitoModePrefs::GetAvailability(profile->GetPrefs());
162 base::string16 delete_warning = availability == IncognitoModePrefs::ENABLED ?
163 l10n_util::GetStringFUTF16(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING,
164 base::UTF8ToUTF16(kIncognitoModeShortcut)) :
165 l10n_util::GetStringUTF16(
166 IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING_NO_INCOGNITO);
167 source->AddString("deleteWarning", delete_warning);
168
169 source->AddLocalizedString("removeBookmark", IDS_HISTORY_REMOVE_BOOKMARK);
170 source->AddLocalizedString("actionMenuDescription",
171 IDS_HISTORY_ACTION_MENU_DESCRIPTION);
172 source->AddLocalizedString("removeFromHistory", IDS_HISTORY_REMOVE_PAGE);
173 source->AddLocalizedString("moreFromSite", IDS_HISTORY_MORE_FROM_SITE);
174 source->AddLocalizedString("groupByDomainLabel", IDS_GROUP_BY_DOMAIN_LABEL);
175 source->AddLocalizedString("rangeLabel", IDS_HISTORY_RANGE_LABEL);
176 source->AddLocalizedString("rangeAllTime", IDS_HISTORY_RANGE_ALL_TIME);
177 source->AddLocalizedString("rangeWeek", IDS_HISTORY_RANGE_WEEK);
178 source->AddLocalizedString("rangeMonth", IDS_HISTORY_RANGE_MONTH);
179 source->AddLocalizedString("rangeToday", IDS_HISTORY_RANGE_TODAY);
180 source->AddLocalizedString("rangeNext", IDS_HISTORY_RANGE_NEXT);
181 source->AddLocalizedString("rangePrevious", IDS_HISTORY_RANGE_PREVIOUS);
182 source->AddLocalizedString("numberVisits", IDS_HISTORY_NUMBER_VISITS);
183 source->AddLocalizedString("filterAllowed", IDS_HISTORY_FILTER_ALLOWED);
184 source->AddLocalizedString("filterBlocked", IDS_HISTORY_FILTER_BLOCKED);
185 source->AddLocalizedString("inContentPack", IDS_HISTORY_IN_CONTENT_PACK);
186 source->AddLocalizedString("allowItems", IDS_HISTORY_FILTER_ALLOW_ITEMS);
187 source->AddLocalizedString("blockItems", IDS_HISTORY_FILTER_BLOCK_ITEMS);
188 source->AddLocalizedString("blockedVisitText",
189 IDS_HISTORY_BLOCKED_VISIT_TEXT);
190 source->AddLocalizedString("hasSyncedResults",
191 IDS_HISTORY_HAS_SYNCED_RESULTS);
192 source->AddLocalizedString("noSyncedResults", IDS_HISTORY_NO_SYNCED_RESULTS);
193 source->AddLocalizedString("cancel", IDS_CANCEL);
194 source->AddLocalizedString("deleteConfirm",
195 IDS_HISTORY_DELETE_PRIOR_VISITS_CONFIRM_BUTTON);
196 source->AddLocalizedString("bookmarked", IDS_HISTORY_ENTRY_BOOKMARKED);
197 source->AddLocalizedString("entrySummary", IDS_HISTORY_ENTRY_SUMMARY);
198 source->AddBoolean("isFullHistorySyncEnabled",
199 WebHistoryServiceFactory::GetForProfile(profile) != NULL);
200 bool group_by_domain = base::CommandLine::ForCurrentProcess()->HasSwitch(
201 switches::kHistoryEnableGroupByDomain);
202 // Supervised users get the "group by domain" version, but not on mobile,
203 // because that version isn't adjusted for small screens yet. crbug.com/452859
204 #if !defined(OS_ANDROID) && !defined(OS_IOS)
205 group_by_domain = group_by_domain || profile->IsSupervised();
206 #endif
207 source->AddBoolean("groupByDomain", group_by_domain);
208 bool allow_deleting_history =
209 prefs->GetBoolean(prefs::kAllowDeletingBrowserHistory);
210 source->AddBoolean("allowDeletingHistory", allow_deleting_history);
211 source->AddBoolean("isInstantExtendedApiEnabled",
212 search::IsInstantExtendedAPIEnabled());
213 source->AddBoolean("isSupervisedProfile", profile->IsSupervised());
214 source->AddBoolean("hideDeleteVisitUI",
215 profile->IsSupervised() && !allow_deleting_history);
216
217 source->SetJsonPath(kStringsJsFile);
218 source->AddResourcePath(kHistoryJsFile, IDR_HISTORY_JS);
219 source->AddResourcePath(kOtherDevicesJsFile, IDR_OTHER_DEVICES_JS);
220 source->SetDefaultResource(IDR_HISTORY_HTML);
221 source->DisableDenyXFrameOptions();
222
223 return source;
224 }
225
226 // Returns a localized version of |visit_time| including a relative 86 // Returns a localized version of |visit_time| including a relative
227 // indicator (e.g. today, yesterday). 87 // indicator (e.g. today, yesterday).
228 base::string16 getRelativeDateLocalized(const base::Time& visit_time) { 88 base::string16 GetRelativeDateLocalized(const base::Time& visit_time) {
229 base::Time midnight = base::Time::Now().LocalMidnight(); 89 base::Time midnight = base::Time::Now().LocalMidnight();
230 base::string16 date_str = ui::TimeFormat::RelativeDate(visit_time, &midnight); 90 base::string16 date_str = ui::TimeFormat::RelativeDate(visit_time, &midnight);
231 if (date_str.empty()) { 91 if (date_str.empty()) {
232 date_str = base::TimeFormatFriendlyDate(visit_time); 92 date_str = base::TimeFormatFriendlyDate(visit_time);
233 } else { 93 } else {
234 date_str = l10n_util::GetStringFUTF16( 94 date_str = l10n_util::GetStringFUTF16(
235 IDS_HISTORY_DATE_WITH_RELATIVE_TIME, 95 IDS_HISTORY_DATE_WITH_RELATIVE_TIME,
236 date_str, 96 date_str,
237 base::TimeFormatFriendlyDate(visit_time)); 97 base::TimeFormatFriendlyDate(visit_time));
238 } 98 }
239 return date_str; 99 return date_str;
240 } 100 }
241 101
242
243 // Sets the correct year when substracting months from a date. 102 // Sets the correct year when substracting months from a date.
244 void normalizeMonths(base::Time::Exploded* exploded) { 103 void NormalizeMonths(base::Time::Exploded* exploded) {
245 // Decrease a year at a time until we have a proper date. 104 // Decrease a year at a time until we have a proper date.
246 while (exploded->month < 1) { 105 while (exploded->month < 1) {
247 exploded->month += 12; 106 exploded->month += 12;
248 exploded->year--; 107 exploded->year--;
249 } 108 }
250 } 109 }
251 110
252 // Returns true if |entry| represents a local visit that had no corresponding 111 // Returns true if |entry| represents a local visit that had no corresponding
253 // visit on the server. 112 // visit on the server.
254 bool IsLocalOnlyResult(const BrowsingHistoryHandler::HistoryEntry& entry) { 113 bool IsLocalOnlyResult(const BrowsingHistoryHandler::HistoryEntry& entry) {
(...skipping 28 matching lines...) Expand all
283 } 142 }
284 return; 143 return;
285 } 144 }
286 145
287 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE); 146 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE);
288 *type = kDeviceTypeLaptop; 147 *type = kDeviceTypeLaptop;
289 } 148 }
290 149
291 } // namespace 150 } // namespace
292 151
293 ////////////////////////////////////////////////////////////////////////////////
294 //
295 // BrowsingHistoryHandler
296 //
297 ////////////////////////////////////////////////////////////////////////////////
298
299 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( 152 BrowsingHistoryHandler::HistoryEntry::HistoryEntry(
300 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type, 153 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type,
301 const GURL& url, const base::string16& title, base::Time time, 154 const GURL& url, const base::string16& title, base::Time time,
302 const std::string& client_id, bool is_search_result, 155 const std::string& client_id, bool is_search_result,
303 const base::string16& snippet, bool blocked_visit, 156 const base::string16& snippet, bool blocked_visit,
304 const std::string& accept_languages) { 157 const std::string& accept_languages) {
305 this->entry_type = entry_type; 158 this->entry_type = entry_type;
306 this->url = url; 159 this->url = url;
307 this->title = title; 160 this->title = title;
308 this->time = time; 161 this->time = time;
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 // The items which are to be written into results_info_value_ are also 683 // The items which are to be written into results_info_value_ are also
831 // described in chrome/browser/resources/history/history.js in @typedef for 684 // described in chrome/browser/resources/history/history.js in @typedef for
832 // HistoryQuery. Please update it whenever you add or remove any keys in 685 // HistoryQuery. Please update it whenever you add or remove any keys in
833 // results_info_value_. 686 // results_info_value_.
834 results_info_value_.SetString("term", search_text); 687 results_info_value_.SetString("term", search_text);
835 results_info_value_.SetBoolean("finished", results->reached_beginning()); 688 results_info_value_.SetBoolean("finished", results->reached_beginning());
836 689
837 // Add the specific dates that were searched to display them. 690 // Add the specific dates that were searched to display them.
838 // TODO(sergiu): Put today if the start is in the future. 691 // TODO(sergiu): Put today if the start is in the future.
839 results_info_value_.SetString("queryStartTime", 692 results_info_value_.SetString("queryStartTime",
840 getRelativeDateLocalized(options.begin_time)); 693 GetRelativeDateLocalized(options.begin_time));
841 if (!options.end_time.is_null()) { 694 if (!options.end_time.is_null()) {
842 results_info_value_.SetString("queryEndTime", 695 results_info_value_.SetString("queryEndTime",
843 getRelativeDateLocalized(options.end_time - 696 GetRelativeDateLocalized(options.end_time -
844 base::TimeDelta::FromDays(1))); 697 base::TimeDelta::FromDays(1)));
845 } else { 698 } else {
846 results_info_value_.SetString("queryEndTime", 699 results_info_value_.SetString("queryEndTime",
847 getRelativeDateLocalized(base::Time::Now())); 700 GetRelativeDateLocalized(base::Time::Now()));
848 } 701 }
849 if (!web_history_timer_.IsRunning()) 702 if (!web_history_timer_.IsRunning())
850 ReturnResultsToFrontEnd(); 703 ReturnResultsToFrontEnd();
851 } 704 }
852 705
853 void BrowsingHistoryHandler::WebHistoryQueryComplete( 706 void BrowsingHistoryHandler::WebHistoryQueryComplete(
854 const base::string16& search_text, 707 const base::string16& search_text,
855 const history::QueryOptions& options, 708 const history::QueryOptions& options,
856 base::TimeTicks start_time, 709 base::TimeTicks start_time,
857 history::WebHistoryService::Request* request, 710 history::WebHistoryService::Request* request,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // show results from the future, should the user's clock have 839 // show results from the future, should the user's clock have
987 // been set incorrectly). 840 // been set incorrectly).
988 options->end_time = base::Time(); 841 options->end_time = base::Time();
989 } else { 842 } else {
990 // Go back |offset| months in the past. The end time is not inclusive, so 843 // Go back |offset| months in the past. The end time is not inclusive, so
991 // use the first day of the |offset| - 1 and |offset| months (e.g. for 844 // use the first day of the |offset| - 1 and |offset| months (e.g. for
992 // the last month, |offset| = 1, use the first days of the last month and 845 // the last month, |offset| = 1, use the first days of the last month and
993 // the current month. 846 // the current month.
994 exploded.month -= offset - 1; 847 exploded.month -= offset - 1;
995 // Set the correct year. 848 // Set the correct year.
996 normalizeMonths(&exploded); 849 NormalizeMonths(&exploded);
997 options->end_time = base::Time::FromLocalExploded(exploded); 850 options->end_time = base::Time::FromLocalExploded(exploded);
998 851
999 exploded.month -= 1; 852 exploded.month -= 1;
1000 // Set the correct year 853 // Set the correct year
1001 normalizeMonths(&exploded); 854 NormalizeMonths(&exploded);
1002 options->begin_time = base::Time::FromLocalExploded(exploded); 855 options->begin_time = base::Time::FromLocalExploded(exploded);
1003 } 856 }
1004 } 857 }
1005 858
1006 // Helper function for Observe that determines if there are any differences 859 // Helper function for Observe that determines if there are any differences
1007 // between the URLs noticed for deletion and the ones we are expecting. 860 // between the URLs noticed for deletion and the ones we are expecting.
1008 static bool DeletionsDiffer(const history::URLRows& deleted_rows, 861 static bool DeletionsDiffer(const history::URLRows& deleted_rows,
1009 const std::set<GURL>& urls_to_be_deleted) { 862 const std::set<GURL>& urls_to_be_deleted) {
1010 if (deleted_rows.size() != urls_to_be_deleted.size()) 863 if (deleted_rows.size() != urls_to_be_deleted.size())
1011 return true; 864 return true;
(...skipping 11 matching lines...) Expand all
1023 876
1024 void BrowsingHistoryHandler::OnURLsDeleted( 877 void BrowsingHistoryHandler::OnURLsDeleted(
1025 history::HistoryService* history_service, 878 history::HistoryService* history_service,
1026 bool all_history, 879 bool all_history,
1027 bool expired, 880 bool expired,
1028 const history::URLRows& deleted_rows, 881 const history::URLRows& deleted_rows,
1029 const std::set<GURL>& favicon_urls) { 882 const std::set<GURL>& favicon_urls) {
1030 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) 883 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_))
1031 web_ui()->CallJavascriptFunction("historyDeleted"); 884 web_ui()->CallJavascriptFunction("historyDeleted");
1032 } 885 }
1033
1034 ////////////////////////////////////////////////////////////////////////////////
1035 //
1036 // HistoryUI
1037 //
1038 ////////////////////////////////////////////////////////////////////////////////
1039
1040 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
1041 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
1042 web_ui->AddMessageHandler(new MetricsHandler());
1043
1044 // On mobile we deal with foreign sessions differently.
1045 #if !defined(OS_ANDROID) && !defined(OS_IOS)
1046 if (search::IsInstantExtendedAPIEnabled()) {
1047 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
1048 web_ui->AddMessageHandler(new HistoryLoginHandler());
1049 }
1050 #endif
1051
1052 // Set up the chrome://history-frame/ source.
1053 Profile* profile = Profile::FromWebUI(web_ui);
1054 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile));
1055 }
1056
1057 HistoryUI::~HistoryUI() {}
1058
1059 // static
1060 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes(
1061 ui::ScaleFactor scale_factor) {
1062 return ResourceBundle::GetSharedInstance().
1063 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor);
1064 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/browsing_history_handler.h ('k') | chrome/browser/ui/webui/browsing_history_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698