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