OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/history_ui.h" | 5 #include "chrome/browser/ui/webui/history_ui.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" | 11 #include "base/command_line.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
24 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
25 #include "chrome/browser/history/history_notifications.h" | 25 #include "chrome/browser/history/history_notifications.h" |
| 26 #include "chrome/browser/history/history_service.h" |
26 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
27 #include "chrome/browser/history/web_history_service.h" | 28 #include "chrome/browser/history/web_history_service.h" |
28 #include "chrome/browser/history/web_history_service_factory.h" | 29 #include "chrome/browser/history/web_history_service_factory.h" |
29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/signin/signin_manager_factory.h" | 31 #include "chrome/browser/signin/signin_manager_factory.h" |
31 #include "chrome/browser/sync/profile_sync_service.h" | 32 #include "chrome/browser/sync/profile_sync_service.h" |
32 #include "chrome/browser/sync/profile_sync_service_factory.h" | 33 #include "chrome/browser/sync/profile_sync_service_factory.h" |
33 #include "chrome/browser/ui/browser_finder.h" | 34 #include "chrome/browser/ui/browser_finder.h" |
34 #include "chrome/browser/ui/chrome_pages.h" | 35 #include "chrome/browser/ui/chrome_pages.h" |
35 #include "chrome/browser/ui/webui/favicon_source.h" | 36 #include "chrome/browser/ui/webui/favicon_source.h" |
36 #include "chrome/browser/ui/webui/metrics_handler.h" | 37 #include "chrome/browser/ui/webui/metrics_handler.h" |
37 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
40 #include "chrome/grit/generated_resources.h" | 41 #include "chrome/grit/generated_resources.h" |
41 #include "components/bookmarks/browser/bookmark_model.h" | 42 #include "components/bookmarks/browser/bookmark_model.h" |
42 #include "components/bookmarks/browser/bookmark_utils.h" | 43 #include "components/bookmarks/browser/bookmark_utils.h" |
43 #include "components/history/core/browser/history_types.h" | 44 #include "components/history/core/browser/history_types.h" |
44 #include "components/search/search.h" | 45 #include "components/search/search.h" |
45 #include "components/signin/core/browser/signin_manager.h" | 46 #include "components/signin/core/browser/signin_manager.h" |
46 #include "components/sync_driver/device_info.h" | 47 #include "components/sync_driver/device_info.h" |
47 #include "content/public/browser/notification_details.h" | |
48 #include "content/public/browser/notification_source.h" | |
49 #include "content/public/browser/url_data_source.h" | 48 #include "content/public/browser/url_data_source.h" |
50 #include "content/public/browser/web_ui.h" | 49 #include "content/public/browser/web_ui.h" |
51 #include "content/public/browser/web_ui_data_source.h" | 50 #include "content/public/browser/web_ui_data_source.h" |
52 #include "grit/browser_resources.h" | 51 #include "grit/browser_resources.h" |
53 #include "grit/theme_resources.h" | 52 #include "grit/theme_resources.h" |
54 #include "net/base/escape.h" | 53 #include "net/base/escape.h" |
55 #include "net/base/net_util.h" | 54 #include "net/base/net_util.h" |
56 #include "sync/protocol/history_delete_directive_specifics.pb.h" | 55 #include "sync/protocol/history_delete_directive_specifics.pb.h" |
57 #include "ui/base/l10n/l10n_util.h" | 56 #include "ui/base/l10n/l10n_util.h" |
58 #include "ui/base/l10n/time_format.h" | 57 #include "ui/base/l10n/time_format.h" |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 406 } |
408 | 407 |
409 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( | 408 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( |
410 const BrowsingHistoryHandler::HistoryEntry& entry1, | 409 const BrowsingHistoryHandler::HistoryEntry& entry1, |
411 const BrowsingHistoryHandler::HistoryEntry& entry2) { | 410 const BrowsingHistoryHandler::HistoryEntry& entry2) { |
412 return entry1.time > entry2.time; | 411 return entry1.time > entry2.time; |
413 } | 412 } |
414 | 413 |
415 BrowsingHistoryHandler::BrowsingHistoryHandler() | 414 BrowsingHistoryHandler::BrowsingHistoryHandler() |
416 : has_pending_delete_request_(false), | 415 : has_pending_delete_request_(false), |
| 416 history_service_observer_(this), |
417 weak_factory_(this) { | 417 weak_factory_(this) { |
418 } | 418 } |
419 | 419 |
420 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 420 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
421 query_task_tracker_.TryCancelAll(); | 421 query_task_tracker_.TryCancelAll(); |
422 web_history_request_.reset(); | 422 web_history_request_.reset(); |
423 } | 423 } |
424 | 424 |
425 void BrowsingHistoryHandler::RegisterMessages() { | 425 void BrowsingHistoryHandler::RegisterMessages() { |
426 // Create our favicon data source. | 426 // Create our favicon data source. |
427 Profile* profile = Profile::FromWebUI(web_ui()); | 427 Profile* profile = Profile::FromWebUI(web_ui()); |
428 content::URLDataSource::Add( | 428 content::URLDataSource::Add( |
429 profile, new FaviconSource(profile, FaviconSource::ANY)); | 429 profile, new FaviconSource(profile, FaviconSource::ANY)); |
430 | 430 |
431 // Get notifications when history is cleared. | 431 // Get notifications when history is cleared. |
432 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 432 HistoryService* hs = |
433 content::Source<Profile>(profile->GetOriginalProfile())); | 433 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
| 434 if (hs) |
| 435 history_service_observer_.Add(hs); |
434 | 436 |
435 web_ui()->RegisterMessageCallback("queryHistory", | 437 web_ui()->RegisterMessageCallback("queryHistory", |
436 base::Bind(&BrowsingHistoryHandler::HandleQueryHistory, | 438 base::Bind(&BrowsingHistoryHandler::HandleQueryHistory, |
437 base::Unretained(this))); | 439 base::Unretained(this))); |
438 web_ui()->RegisterMessageCallback("removeVisits", | 440 web_ui()->RegisterMessageCallback("removeVisits", |
439 base::Bind(&BrowsingHistoryHandler::HandleRemoveVisits, | 441 base::Bind(&BrowsingHistoryHandler::HandleRemoveVisits, |
440 base::Unretained(this))); | 442 base::Unretained(this))); |
441 web_ui()->RegisterMessageCallback("clearBrowsingData", | 443 web_ui()->RegisterMessageCallback("clearBrowsingData", |
442 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData, | 444 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData, |
443 base::Unretained(this))); | 445 base::Unretained(this))); |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 options->begin_time = base::Time::FromLocalExploded(exploded); | 978 options->begin_time = base::Time::FromLocalExploded(exploded); |
977 } | 979 } |
978 } | 980 } |
979 | 981 |
980 // Helper function for Observe that determines if there are any differences | 982 // Helper function for Observe that determines if there are any differences |
981 // between the URLs noticed for deletion and the ones we are expecting. | 983 // between the URLs noticed for deletion and the ones we are expecting. |
982 static bool DeletionsDiffer(const history::URLRows& deleted_rows, | 984 static bool DeletionsDiffer(const history::URLRows& deleted_rows, |
983 const std::set<GURL>& urls_to_be_deleted) { | 985 const std::set<GURL>& urls_to_be_deleted) { |
984 if (deleted_rows.size() != urls_to_be_deleted.size()) | 986 if (deleted_rows.size() != urls_to_be_deleted.size()) |
985 return true; | 987 return true; |
986 for (history::URLRows::const_iterator i = deleted_rows.begin(); | 988 for (const auto& i : deleted_rows) { |
987 i != deleted_rows.end(); ++i) { | 989 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) |
988 if (urls_to_be_deleted.find(i->url()) == urls_to_be_deleted.end()) | |
989 return true; | 990 return true; |
990 } | 991 } |
991 return false; | 992 return false; |
992 } | 993 } |
993 | 994 |
994 void BrowsingHistoryHandler::Observe( | |
995 int type, | |
996 const content::NotificationSource& source, | |
997 const content::NotificationDetails& details) { | |
998 if (type != chrome::NOTIFICATION_HISTORY_URLS_DELETED) { | |
999 NOTREACHED(); | |
1000 return; | |
1001 } | |
1002 history::URLsDeletedDetails* deletedDetails = | |
1003 content::Details<history::URLsDeletedDetails>(details).ptr(); | |
1004 if (deletedDetails->all_history || | |
1005 DeletionsDiffer(deletedDetails->rows, urls_to_be_deleted_)) | |
1006 web_ui()->CallJavascriptFunction("historyDeleted"); | |
1007 } | |
1008 | |
1009 std::string BrowsingHistoryHandler::GetAcceptLanguages() const { | 995 std::string BrowsingHistoryHandler::GetAcceptLanguages() const { |
1010 Profile* profile = Profile::FromWebUI(web_ui()); | 996 Profile* profile = Profile::FromWebUI(web_ui()); |
1011 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 997 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
1012 } | 998 } |
1013 | 999 |
| 1000 void BrowsingHistoryHandler::OnURLsDeleted(HistoryService* history_service, |
| 1001 bool all_history, |
| 1002 bool expired, |
| 1003 const history::URLRows& deleted_rows, |
| 1004 const std::set<GURL>& favicon_urls) { |
| 1005 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
| 1006 web_ui()->CallJavascriptFunction("historyDeleted"); |
| 1007 } |
| 1008 |
1014 //////////////////////////////////////////////////////////////////////////////// | 1009 //////////////////////////////////////////////////////////////////////////////// |
1015 // | 1010 // |
1016 // HistoryUI | 1011 // HistoryUI |
1017 // | 1012 // |
1018 //////////////////////////////////////////////////////////////////////////////// | 1013 //////////////////////////////////////////////////////////////////////////////// |
1019 | 1014 |
1020 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 1015 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
1021 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 1016 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
1022 web_ui->AddMessageHandler(new MetricsHandler()); | 1017 web_ui->AddMessageHandler(new MetricsHandler()); |
1023 | 1018 |
1024 // On mobile we deal with foreign sessions differently. | 1019 // On mobile we deal with foreign sessions differently. |
1025 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 1020 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
1026 if (chrome::IsInstantExtendedAPIEnabled()) { | 1021 if (chrome::IsInstantExtendedAPIEnabled()) { |
1027 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 1022 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
1028 web_ui->AddMessageHandler(new NTPLoginHandler()); | 1023 web_ui->AddMessageHandler(new NTPLoginHandler()); |
1029 } | 1024 } |
1030 #endif | 1025 #endif |
1031 | 1026 |
1032 // Set up the chrome://history-frame/ source. | 1027 // Set up the chrome://history-frame/ source. |
1033 Profile* profile = Profile::FromWebUI(web_ui); | 1028 Profile* profile = Profile::FromWebUI(web_ui); |
1034 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); | 1029 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); |
1035 } | 1030 } |
1036 | 1031 |
1037 // static | 1032 // static |
1038 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 1033 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
1039 ui::ScaleFactor scale_factor) { | 1034 ui::ScaleFactor scale_factor) { |
1040 return ResourceBundle::GetSharedInstance(). | 1035 return ResourceBundle::GetSharedInstance(). |
1041 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 1036 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
1042 } | 1037 } |
OLD | NEW |