| 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" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "chrome/browser/ui/webui/metrics_handler.h" | 35 #include "chrome/browser/ui/webui/metrics_handler.h" |
| 36 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 39 #include "chrome/grit/generated_resources.h" | 39 #include "chrome/grit/generated_resources.h" |
| 40 #include "components/bookmarks/browser/bookmark_model.h" | 40 #include "components/bookmarks/browser/bookmark_model.h" |
| 41 #include "components/bookmarks/browser/bookmark_utils.h" | 41 #include "components/bookmarks/browser/bookmark_utils.h" |
| 42 #include "components/history/core/browser/history_types.h" | 42 #include "components/history/core/browser/history_types.h" |
| 43 #include "components/search/search.h" | 43 #include "components/search/search.h" |
| 44 #include "components/sync_driver/device_info.h" | 44 #include "components/sync_driver/device_info.h" |
| 45 #include "content/public/browser/notification_details.h" | |
| 46 #include "content/public/browser/notification_source.h" | |
| 47 #include "content/public/browser/url_data_source.h" | 45 #include "content/public/browser/url_data_source.h" |
| 48 #include "content/public/browser/web_ui.h" | 46 #include "content/public/browser/web_ui.h" |
| 49 #include "content/public/browser/web_ui_data_source.h" | 47 #include "content/public/browser/web_ui_data_source.h" |
| 50 #include "grit/browser_resources.h" | 48 #include "grit/browser_resources.h" |
| 51 #include "grit/theme_resources.h" | 49 #include "grit/theme_resources.h" |
| 52 #include "net/base/escape.h" | 50 #include "net/base/escape.h" |
| 53 #include "net/base/net_util.h" | 51 #include "net/base/net_util.h" |
| 54 #include "sync/protocol/history_delete_directive_specifics.pb.h" | 52 #include "sync/protocol/history_delete_directive_specifics.pb.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 53 #include "ui/base/l10n/l10n_util.h" |
| 56 #include "ui/base/l10n/time_format.h" | 54 #include "ui/base/l10n/time_format.h" |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 } | 396 } |
| 399 | 397 |
| 400 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( | 398 bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending( |
| 401 const BrowsingHistoryHandler::HistoryEntry& entry1, | 399 const BrowsingHistoryHandler::HistoryEntry& entry1, |
| 402 const BrowsingHistoryHandler::HistoryEntry& entry2) { | 400 const BrowsingHistoryHandler::HistoryEntry& entry2) { |
| 403 return entry1.time > entry2.time; | 401 return entry1.time > entry2.time; |
| 404 } | 402 } |
| 405 | 403 |
| 406 BrowsingHistoryHandler::BrowsingHistoryHandler() | 404 BrowsingHistoryHandler::BrowsingHistoryHandler() |
| 407 : has_pending_delete_request_(false), | 405 : has_pending_delete_request_(false), |
| 406 history_service_observer_(this), |
| 408 weak_factory_(this) { | 407 weak_factory_(this) { |
| 409 } | 408 } |
| 410 | 409 |
| 411 BrowsingHistoryHandler::~BrowsingHistoryHandler() { | 410 BrowsingHistoryHandler::~BrowsingHistoryHandler() { |
| 412 query_task_tracker_.TryCancelAll(); | 411 query_task_tracker_.TryCancelAll(); |
| 413 web_history_request_.reset(); | 412 web_history_request_.reset(); |
| 414 } | 413 } |
| 415 | 414 |
| 416 void BrowsingHistoryHandler::RegisterMessages() { | 415 void BrowsingHistoryHandler::RegisterMessages() { |
| 417 // Create our favicon data source. | 416 // Create our favicon data source. |
| 418 Profile* profile = Profile::FromWebUI(web_ui()); | 417 Profile* profile = Profile::FromWebUI(web_ui()); |
| 419 content::URLDataSource::Add( | 418 content::URLDataSource::Add( |
| 420 profile, new FaviconSource(profile, FaviconSource::ANY)); | 419 profile, new FaviconSource(profile, FaviconSource::ANY)); |
| 421 | 420 |
| 422 // Get notifications when history is cleared. | 421 // Get notifications when history is cleared. |
| 423 registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 422 HistoryService* hs = |
| 424 content::Source<Profile>(profile->GetOriginalProfile())); | 423 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
| 424 if (hs) |
| 425 history_service_observer_.Add(hs); |
| 425 | 426 |
| 426 web_ui()->RegisterMessageCallback("queryHistory", | 427 web_ui()->RegisterMessageCallback("queryHistory", |
| 427 base::Bind(&BrowsingHistoryHandler::HandleQueryHistory, | 428 base::Bind(&BrowsingHistoryHandler::HandleQueryHistory, |
| 428 base::Unretained(this))); | 429 base::Unretained(this))); |
| 429 web_ui()->RegisterMessageCallback("removeVisits", | 430 web_ui()->RegisterMessageCallback("removeVisits", |
| 430 base::Bind(&BrowsingHistoryHandler::HandleRemoveVisits, | 431 base::Bind(&BrowsingHistoryHandler::HandleRemoveVisits, |
| 431 base::Unretained(this))); | 432 base::Unretained(this))); |
| 432 web_ui()->RegisterMessageCallback("clearBrowsingData", | 433 web_ui()->RegisterMessageCallback("clearBrowsingData", |
| 433 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData, | 434 base::Bind(&BrowsingHistoryHandler::HandleClearBrowsingData, |
| 434 base::Unretained(this))); | 435 base::Unretained(this))); |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 if (deleted_rows.size() != urls_to_be_deleted.size()) | 976 if (deleted_rows.size() != urls_to_be_deleted.size()) |
| 976 return true; | 977 return true; |
| 977 for (history::URLRows::const_iterator i = deleted_rows.begin(); | 978 for (history::URLRows::const_iterator i = deleted_rows.begin(); |
| 978 i != deleted_rows.end(); ++i) { | 979 i != deleted_rows.end(); ++i) { |
| 979 if (urls_to_be_deleted.find(i->url()) == urls_to_be_deleted.end()) | 980 if (urls_to_be_deleted.find(i->url()) == urls_to_be_deleted.end()) |
| 980 return true; | 981 return true; |
| 981 } | 982 } |
| 982 return false; | 983 return false; |
| 983 } | 984 } |
| 984 | 985 |
| 985 void BrowsingHistoryHandler::Observe( | |
| 986 int type, | |
| 987 const content::NotificationSource& source, | |
| 988 const content::NotificationDetails& details) { | |
| 989 if (type != chrome::NOTIFICATION_HISTORY_URLS_DELETED) { | |
| 990 NOTREACHED(); | |
| 991 return; | |
| 992 } | |
| 993 history::URLsDeletedDetails* deletedDetails = | |
| 994 content::Details<history::URLsDeletedDetails>(details).ptr(); | |
| 995 if (deletedDetails->all_history || | |
| 996 DeletionsDiffer(deletedDetails->rows, urls_to_be_deleted_)) | |
| 997 web_ui()->CallJavascriptFunction("historyDeleted"); | |
| 998 } | |
| 999 | |
| 1000 std::string BrowsingHistoryHandler::GetAcceptLanguages() const { | 986 std::string BrowsingHistoryHandler::GetAcceptLanguages() const { |
| 1001 Profile* profile = Profile::FromWebUI(web_ui()); | 987 Profile* profile = Profile::FromWebUI(web_ui()); |
| 1002 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 988 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 1003 } | 989 } |
| 1004 | 990 |
| 991 void BrowsingHistoryHandler::OnURLsDeleted( |
| 992 HistoryService* history_service, |
| 993 const history::URLsDeletedDetails& deleted_details) { |
| 994 if (deleted_details.all_history || |
| 995 DeletionsDiffer(deleted_details.rows, urls_to_be_deleted_)) |
| 996 web_ui()->CallJavascriptFunction("historyDeleted"); |
| 997 } |
| 998 |
| 1005 //////////////////////////////////////////////////////////////////////////////// | 999 //////////////////////////////////////////////////////////////////////////////// |
| 1006 // | 1000 // |
| 1007 // HistoryUI | 1001 // HistoryUI |
| 1008 // | 1002 // |
| 1009 //////////////////////////////////////////////////////////////////////////////// | 1003 //////////////////////////////////////////////////////////////////////////////// |
| 1010 | 1004 |
| 1011 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 1005 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 1012 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 1006 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
| 1013 web_ui->AddMessageHandler(new MetricsHandler()); | 1007 web_ui->AddMessageHandler(new MetricsHandler()); |
| 1014 | 1008 |
| 1015 // On mobile we deal with foreign sessions differently. | 1009 // On mobile we deal with foreign sessions differently. |
| 1016 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 1010 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 1017 if (chrome::IsInstantExtendedAPIEnabled()) { | 1011 if (chrome::IsInstantExtendedAPIEnabled()) { |
| 1018 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 1012 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
| 1019 web_ui->AddMessageHandler(new NTPLoginHandler()); | 1013 web_ui->AddMessageHandler(new NTPLoginHandler()); |
| 1020 } | 1014 } |
| 1021 #endif | 1015 #endif |
| 1022 | 1016 |
| 1023 // Set up the chrome://history-frame/ source. | 1017 // Set up the chrome://history-frame/ source. |
| 1024 Profile* profile = Profile::FromWebUI(web_ui); | 1018 Profile* profile = Profile::FromWebUI(web_ui); |
| 1025 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); | 1019 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile)); |
| 1026 } | 1020 } |
| 1027 | 1021 |
| 1028 // static | 1022 // static |
| 1029 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 1023 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
| 1030 ui::ScaleFactor scale_factor) { | 1024 ui::ScaleFactor scale_factor) { |
| 1031 return ResourceBundle::GetSharedInstance(). | 1025 return ResourceBundle::GetSharedInstance(). |
| 1032 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 1026 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
| 1033 } | 1027 } |
| OLD | NEW |