| OLD | NEW |
| 1 // Copyright 2015 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/browsing_history_handler.h" | 5 #include "chrome/browser/ui/webui/browsing_history_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/i18n/time_formatting.h" | 14 #include "base/i18n/time_formatting.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "chrome/browser/banners/app_banner_settings_helper.h" | 22 #include "chrome/browser/banners/app_banner_settings_helper.h" |
| 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 24 #include "chrome/browser/engagement/site_engagement_service.h" | 24 #include "chrome/browser/engagement/site_engagement_service.h" |
| 25 #include "chrome/browser/favicon/fallback_icon_service_factory.h" |
| 26 #include "chrome/browser/favicon/large_icon_service_factory.h" |
| 25 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
| 26 #include "chrome/browser/history/history_utils.h" | 28 #include "chrome/browser/history/history_utils.h" |
| 27 #include "chrome/browser/history/web_history_service_factory.h" | 29 #include "chrome/browser/history/web_history_service_factory.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 31 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 30 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
| 31 #include "chrome/browser/ui/chrome_pages.h" | 33 #include "chrome/browser/ui/chrome_pages.h" |
| 32 #include "chrome/browser/ui/webui/favicon_source.h" | 34 #include "chrome/browser/ui/webui/favicon_source.h" |
| 35 #include "chrome/browser/ui/webui/large_icon_source.h" |
| 33 #include "chrome/common/features.h" | 36 #include "chrome/common/features.h" |
| 34 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 35 #include "components/bookmarks/browser/bookmark_model.h" | 38 #include "components/bookmarks/browser/bookmark_model.h" |
| 36 #include "components/bookmarks/browser/bookmark_utils.h" | 39 #include "components/bookmarks/browser/bookmark_utils.h" |
| 37 #include "components/browser_sync/browser/profile_sync_service.h" | 40 #include "components/browser_sync/browser/profile_sync_service.h" |
| 41 #include "components/favicon/core/fallback_icon_service.h" |
| 42 #include "components/favicon/core/fallback_url_util.h" |
| 43 #include "components/favicon/core/large_icon_service.h" |
| 38 #include "components/history/core/browser/history_service.h" | 44 #include "components/history/core/browser/history_service.h" |
| 39 #include "components/history/core/browser/history_types.h" | 45 #include "components/history/core/browser/history_types.h" |
| 40 #include "components/history/core/browser/web_history_service.h" | 46 #include "components/history/core/browser/web_history_service.h" |
| 41 #include "components/keyed_service/core/service_access_type.h" | 47 #include "components/keyed_service/core/service_access_type.h" |
| 42 #include "components/query_parser/snippet.h" | 48 #include "components/query_parser/snippet.h" |
| 43 #include "components/sync_driver/device_info.h" | 49 #include "components/sync_driver/device_info.h" |
| 44 #include "components/sync_driver/device_info_tracker.h" | 50 #include "components/sync_driver/device_info_tracker.h" |
| 45 #include "components/url_formatter/url_formatter.h" | 51 #include "components/url_formatter/url_formatter.h" |
| 46 #include "content/public/browser/url_data_source.h" | 52 #include "content/public/browser/url_data_source.h" |
| 47 #include "content/public/browser/web_ui.h" | 53 #include "content/public/browser/web_ui.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // When the domain is empty, use the scheme instead. This allows for a | 219 // When the domain is empty, use the scheme instead. This allows for a |
| 214 // sensible treatment of e.g. file: URLs when group by domain is on. | 220 // sensible treatment of e.g. file: URLs when group by domain is on. |
| 215 if (domain.empty()) | 221 if (domain.empty()) |
| 216 domain = base::UTF8ToUTF16(url.scheme() + ":"); | 222 domain = base::UTF8ToUTF16(url.scheme() + ":"); |
| 217 | 223 |
| 218 // The items which are to be written into result are also described in | 224 // The items which are to be written into result are also described in |
| 219 // chrome/browser/resources/history/history.js in @typedef for | 225 // chrome/browser/resources/history/history.js in @typedef for |
| 220 // HistoryEntry. Please update it whenever you add or remove | 226 // HistoryEntry. Please update it whenever you add or remove |
| 221 // any keys in result. | 227 // any keys in result. |
| 222 result->SetString("domain", domain); | 228 result->SetString("domain", domain); |
| 229 |
| 230 result->SetString( |
| 231 "fallbackFaviconText", |
| 232 base::UTF16ToASCII(favicon::GetFallbackIconText(url))); |
| 233 |
| 223 result->SetDouble("time", time.ToJsTime()); | 234 result->SetDouble("time", time.ToJsTime()); |
| 224 | 235 |
| 225 // Pass the timestamps in a list. | 236 // Pass the timestamps in a list. |
| 226 scoped_ptr<base::ListValue> timestamps(new base::ListValue); | 237 scoped_ptr<base::ListValue> timestamps(new base::ListValue); |
| 227 for (std::set<int64_t>::const_iterator it = all_timestamps.begin(); | 238 for (std::set<int64_t>::const_iterator it = all_timestamps.begin(); |
| 228 it != all_timestamps.end(); ++it) { | 239 it != all_timestamps.end(); ++it) { |
| 229 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); | 240 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); |
| 230 } | 241 } |
| 231 result->Set("allTimestamps", timestamps.release()); | 242 result->Set("allTimestamps", timestamps.release()); |
| 232 | 243 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 300 } |
| 290 | 301 |
| 291 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 302 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
| 292 query_task_tracker_.TryCancelAll(); | 303 query_task_tracker_.TryCancelAll(); |
| 293 web_history_request_.reset(); | 304 web_history_request_.reset(); |
| 294 } | 305 } |
| 295 | 306 |
| 296 void BrowsingHistoryHandler::RegisterMessages() { | 307 void BrowsingHistoryHandler::RegisterMessages() { |
| 297 // Create our favicon data source. | 308 // Create our favicon data source. |
| 298 Profile* profile = Profile::FromWebUI(web_ui()); | 309 Profile* profile = Profile::FromWebUI(web_ui()); |
| 310 |
| 311 #if defined(OS_ANDROID) |
| 312 favicon::FallbackIconService* fallback_icon_service = |
| 313 FallbackIconServiceFactory::GetForBrowserContext(profile); |
| 314 favicon::LargeIconService* large_icon_service = |
| 315 LargeIconServiceFactory::GetForBrowserContext(profile); |
| 316 content::URLDataSource::Add( |
| 317 profile, new LargeIconSource(fallback_icon_service, large_icon_service)); |
| 318 #else |
| 299 content::URLDataSource::Add( | 319 content::URLDataSource::Add( |
| 300 profile, new FaviconSource(profile, FaviconSource::ANY)); | 320 profile, new FaviconSource(profile, FaviconSource::ANY)); |
| 321 #endif |
| 301 | 322 |
| 302 // Get notifications when history is cleared. | 323 // Get notifications when history is cleared. |
| 303 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( | 324 history::HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 304 profile, ServiceAccessType::EXPLICIT_ACCESS); | 325 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 305 if (hs) | 326 if (hs) |
| 306 history_service_observer_.Add(hs); | 327 history_service_observer_.Add(hs); |
| 307 | 328 |
| 308 web_ui()->RegisterMessageCallback("queryHistory", | 329 web_ui()->RegisterMessageCallback("queryHistory", |
| 309 base::Bind(&BrowsingHistoryHandler::HandleQueryHistory, | 330 base::Bind(&BrowsingHistoryHandler::HandleQueryHistory, |
| 310 base::Unretained(this))); | 331 base::Unretained(this))); |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 | 900 |
| 880 void BrowsingHistoryHandler::OnURLsDeleted( | 901 void BrowsingHistoryHandler::OnURLsDeleted( |
| 881 history::HistoryService* history_service, | 902 history::HistoryService* history_service, |
| 882 bool all_history, | 903 bool all_history, |
| 883 bool expired, | 904 bool expired, |
| 884 const history::URLRows& deleted_rows, | 905 const history::URLRows& deleted_rows, |
| 885 const std::set<GURL>& favicon_urls) { | 906 const std::set<GURL>& favicon_urls) { |
| 886 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) | 907 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
| 887 web_ui()->CallJavascriptFunction("historyDeleted"); | 908 web_ui()->CallJavascriptFunction("historyDeleted"); |
| 888 } | 909 } |
| OLD | NEW |