| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "chrome/common/url_constants.h" | 44 #include "chrome/common/url_constants.h" |
| 45 #include "content/public/browser/notification_details.h" | 45 #include "content/public/browser/notification_details.h" |
| 46 #include "content/public/browser/notification_source.h" | 46 #include "content/public/browser/notification_source.h" |
| 47 #include "content/public/browser/url_data_source.h" | 47 #include "content/public/browser/url_data_source.h" |
| 48 #include "content/public/browser/web_ui.h" | 48 #include "content/public/browser/web_ui.h" |
| 49 #include "content/public/browser/web_ui_data_source.h" | 49 #include "content/public/browser/web_ui_data_source.h" |
| 50 #include "grit/browser_resources.h" | 50 #include "grit/browser_resources.h" |
| 51 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
| 52 #include "grit/theme_resources.h" | 52 #include "grit/theme_resources.h" |
| 53 #include "net/base/escape.h" | 53 #include "net/base/escape.h" |
| 54 #include "net/base/net_util.h" |
| 54 #include "sync/protocol/history_delete_directive_specifics.pb.h" | 55 #include "sync/protocol/history_delete_directive_specifics.pb.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 56 #include "ui/base/l10n/l10n_util.h" |
| 56 #include "ui/base/resource/resource_bundle.h" | 57 #include "ui/base/resource/resource_bundle.h" |
| 57 | 58 |
| 58 #if defined(ENABLE_MANAGED_USERS) | 59 #if defined(ENABLE_MANAGED_USERS) |
| 59 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" | 60 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" |
| 60 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 61 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 61 #include "chrome/browser/managed_mode/managed_user_service.h" | 62 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 62 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 63 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 63 #endif | 64 #endif |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 //////////////////////////////////////////////////////////////////////////////// | 270 //////////////////////////////////////////////////////////////////////////////// |
| 270 // | 271 // |
| 271 // BrowsingHistoryHandler | 272 // BrowsingHistoryHandler |
| 272 // | 273 // |
| 273 //////////////////////////////////////////////////////////////////////////////// | 274 //////////////////////////////////////////////////////////////////////////////// |
| 274 | 275 |
| 275 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( | 276 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( |
| 276 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type, | 277 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type, |
| 277 const GURL& url, const string16& title, base::Time time, | 278 const GURL& url, const string16& title, base::Time time, |
| 278 const std::string& client_id, bool is_search_result, | 279 const std::string& client_id, bool is_search_result, |
| 279 const string16& snippet, bool blocked_visit) { | 280 const string16& snippet, bool blocked_visit, |
| 281 const std::string& accept_languages) { |
| 280 this->entry_type = entry_type; | 282 this->entry_type = entry_type; |
| 281 this->url = url; | 283 this->url = url; |
| 282 this->title = title; | 284 this->title = title; |
| 283 this->time = time; | 285 this->time = time; |
| 284 this->client_id = client_id; | 286 this->client_id = client_id; |
| 285 all_timestamps.insert(time.ToInternalValue()); | 287 all_timestamps.insert(time.ToInternalValue()); |
| 286 this->is_search_result = is_search_result; | 288 this->is_search_result = is_search_result; |
| 287 this->snippet = snippet; | 289 this->snippet = snippet; |
| 288 this->blocked_visit = blocked_visit; | 290 this->blocked_visit = blocked_visit; |
| 291 this->accept_languages = accept_languages; |
| 289 } | 292 } |
| 290 | 293 |
| 291 BrowsingHistoryHandler::HistoryEntry::HistoryEntry() | 294 BrowsingHistoryHandler::HistoryEntry::HistoryEntry() |
| 292 : entry_type(EMPTY_ENTRY), is_search_result(false), blocked_visit(false) { | 295 : entry_type(EMPTY_ENTRY), is_search_result(false), blocked_visit(false) { |
| 293 } | 296 } |
| 294 | 297 |
| 295 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() { | 298 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() { |
| 296 } | 299 } |
| 297 | 300 |
| 298 void BrowsingHistoryHandler::HistoryEntry::SetUrlAndTitle( | 301 void BrowsingHistoryHandler::HistoryEntry::SetUrlAndTitle( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 318 } | 321 } |
| 319 result->SetString("title", title_to_set); | 322 result->SetString("title", title_to_set); |
| 320 } | 323 } |
| 321 | 324 |
| 322 scoped_ptr<DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( | 325 scoped_ptr<DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( |
| 323 BookmarkModel* bookmark_model, | 326 BookmarkModel* bookmark_model, |
| 324 ManagedUserService* managed_user_service, | 327 ManagedUserService* managed_user_service, |
| 325 const ProfileSyncService* sync_service) const { | 328 const ProfileSyncService* sync_service) const { |
| 326 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 329 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
| 327 SetUrlAndTitle(result.get()); | 330 SetUrlAndTitle(result.get()); |
| 331 result->SetString("domain", |
| 332 net::IDNToUnicode(url.host(), accept_languages)); |
| 328 result->SetDouble("time", time.ToJsTime()); | 333 result->SetDouble("time", time.ToJsTime()); |
| 329 | 334 |
| 330 // Pass the timestamps in a list. | 335 // Pass the timestamps in a list. |
| 331 scoped_ptr<ListValue> timestamps(new ListValue); | 336 scoped_ptr<ListValue> timestamps(new ListValue); |
| 332 for (std::set<int64>::const_iterator it = all_timestamps.begin(); | 337 for (std::set<int64>::const_iterator it = all_timestamps.begin(); |
| 333 it != all_timestamps.end(); ++it) { | 338 it != all_timestamps.end(); ++it) { |
| 334 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); | 339 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); |
| 335 } | 340 } |
| 336 result->Set("allTimestamps", timestamps.release()); | 341 result->Set("allTimestamps", timestamps.release()); |
| 337 | 342 |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 web_history_query_results_.clear(); | 739 web_history_query_results_.clear(); |
| 735 } | 740 } |
| 736 | 741 |
| 737 void BrowsingHistoryHandler::QueryComplete( | 742 void BrowsingHistoryHandler::QueryComplete( |
| 738 const string16& search_text, | 743 const string16& search_text, |
| 739 const history::QueryOptions& options, | 744 const history::QueryOptions& options, |
| 740 HistoryService::Handle request_handle, | 745 HistoryService::Handle request_handle, |
| 741 history::QueryResults* results) { | 746 history::QueryResults* results) { |
| 742 DCHECK_EQ(0U, query_results_.size()); | 747 DCHECK_EQ(0U, query_results_.size()); |
| 743 query_results_.reserve(results->size()); | 748 query_results_.reserve(results->size()); |
| 749 const std::string accept_languages = GetAcceptLanguages(); |
| 744 | 750 |
| 745 for (size_t i = 0; i < results->size(); ++i) { | 751 for (size_t i = 0; i < results->size(); ++i) { |
| 746 history::URLResult const &page = (*results)[i]; | 752 history::URLResult const &page = (*results)[i]; |
| 747 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready. | 753 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready. |
| 748 query_results_.push_back( | 754 query_results_.push_back( |
| 749 HistoryEntry( | 755 HistoryEntry( |
| 750 HistoryEntry::LOCAL_ENTRY, | 756 HistoryEntry::LOCAL_ENTRY, |
| 751 page.url(), | 757 page.url(), |
| 752 page.title(), | 758 page.title(), |
| 753 page.visit_time(), | 759 page.visit_time(), |
| 754 std::string(), | 760 std::string(), |
| 755 !search_text.empty(), | 761 !search_text.empty(), |
| 756 page.snippet().text(), | 762 page.snippet().text(), |
| 757 page.blocked_visit())); | 763 page.blocked_visit(), |
| 764 accept_languages)); |
| 758 } | 765 } |
| 759 | 766 |
| 760 results_info_value_.SetString("term", search_text); | 767 results_info_value_.SetString("term", search_text); |
| 761 results_info_value_.SetBoolean("finished", results->reached_beginning()); | 768 results_info_value_.SetBoolean("finished", results->reached_beginning()); |
| 762 | 769 |
| 763 // Add the specific dates that were searched to display them. | 770 // Add the specific dates that were searched to display them. |
| 764 // TODO(sergiu): Put today if the start is in the future. | 771 // TODO(sergiu): Put today if the start is in the future. |
| 765 results_info_value_.SetString("queryStartTime", | 772 results_info_value_.SetString("queryStartTime", |
| 766 getRelativeDateLocalized(options.begin_time)); | 773 getRelativeDateLocalized(options.begin_time)); |
| 767 if (!options.end_time.is_null()) { | 774 if (!options.end_time.is_null()) { |
| 768 results_info_value_.SetString("queryEndTime", | 775 results_info_value_.SetString("queryEndTime", |
| 769 getRelativeDateLocalized(options.end_time - | 776 getRelativeDateLocalized(options.end_time - |
| 770 base::TimeDelta::FromDays(1))); | 777 base::TimeDelta::FromDays(1))); |
| 771 } else { | 778 } else { |
| 772 results_info_value_.SetString("queryEndTime", | 779 results_info_value_.SetString("queryEndTime", |
| 773 getRelativeDateLocalized(base::Time::Now())); | 780 getRelativeDateLocalized(base::Time::Now())); |
| 774 } | 781 } |
| 775 if (!web_history_timer_.IsRunning()) | 782 if (!web_history_timer_.IsRunning()) |
| 776 ReturnResultsToFrontEnd(); | 783 ReturnResultsToFrontEnd(); |
| 777 } | 784 } |
| 778 | 785 |
| 779 void BrowsingHistoryHandler::WebHistoryQueryComplete( | 786 void BrowsingHistoryHandler::WebHistoryQueryComplete( |
| 780 const string16& search_text, | 787 const string16& search_text, |
| 781 const history::QueryOptions& options, | 788 const history::QueryOptions& options, |
| 782 base::TimeTicks start_time, | 789 base::TimeTicks start_time, |
| 783 history::WebHistoryService::Request* request, | 790 history::WebHistoryService::Request* request, |
| 784 const DictionaryValue* results_value) { | 791 const DictionaryValue* results_value) { |
| 785 base::TimeDelta delta = base::TimeTicks::Now() - start_time; | 792 base::TimeDelta delta = base::TimeTicks::Now() - start_time; |
| 786 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); | 793 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); |
| 794 const std::string accept_languages = GetAcceptLanguages(); |
| 787 | 795 |
| 788 // If the response came in too late, do nothing. | 796 // If the response came in too late, do nothing. |
| 789 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? | 797 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? |
| 790 if (!web_history_timer_.IsRunning()) | 798 if (!web_history_timer_.IsRunning()) |
| 791 return; | 799 return; |
| 792 web_history_timer_.Stop(); | 800 web_history_timer_.Stop(); |
| 793 | 801 |
| 794 UMA_HISTOGRAM_ENUMERATION( | 802 UMA_HISTOGRAM_ENUMERATION( |
| 795 "WebHistory.QueryCompletion", | 803 "WebHistory.QueryCompletion", |
| 796 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, | 804 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 | 852 |
| 845 web_history_query_results_.push_back( | 853 web_history_query_results_.push_back( |
| 846 HistoryEntry( | 854 HistoryEntry( |
| 847 HistoryEntry::REMOTE_ENTRY, | 855 HistoryEntry::REMOTE_ENTRY, |
| 848 GURL(url), | 856 GURL(url), |
| 849 title, | 857 title, |
| 850 time, | 858 time, |
| 851 client_id, | 859 client_id, |
| 852 !search_text.empty(), | 860 !search_text.empty(), |
| 853 string16(), | 861 string16(), |
| 854 /* blocked_visit */ false)); | 862 /* blocked_visit */ false, |
| 863 accept_languages)); |
| 855 } | 864 } |
| 856 } | 865 } |
| 857 } else if (results_value) { | 866 } else if (results_value) { |
| 858 NOTREACHED() << "Failed to parse JSON response."; | 867 NOTREACHED() << "Failed to parse JSON response."; |
| 859 } | 868 } |
| 860 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); | 869 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); |
| 861 if (!history_request_consumer_.HasPendingRequests()) | 870 if (!history_request_consumer_.HasPendingRequests()) |
| 862 ReturnResultsToFrontEnd(); | 871 ReturnResultsToFrontEnd(); |
| 863 } | 872 } |
| 864 | 873 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 NOTREACHED(); | 956 NOTREACHED(); |
| 948 return; | 957 return; |
| 949 } | 958 } |
| 950 history::URLsDeletedDetails* deletedDetails = | 959 history::URLsDeletedDetails* deletedDetails = |
| 951 content::Details<history::URLsDeletedDetails>(details).ptr(); | 960 content::Details<history::URLsDeletedDetails>(details).ptr(); |
| 952 if (deletedDetails->all_history || | 961 if (deletedDetails->all_history || |
| 953 DeletionsDiffer(deletedDetails->rows, urls_to_be_deleted_)) | 962 DeletionsDiffer(deletedDetails->rows, urls_to_be_deleted_)) |
| 954 web_ui()->CallJavascriptFunction("historyDeleted"); | 963 web_ui()->CallJavascriptFunction("historyDeleted"); |
| 955 } | 964 } |
| 956 | 965 |
| 966 std::string BrowsingHistoryHandler::GetAcceptLanguages() const { |
| 967 Profile* profile = Profile::FromWebUI(web_ui()); |
| 968 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 969 } |
| 970 |
| 957 //////////////////////////////////////////////////////////////////////////////// | 971 //////////////////////////////////////////////////////////////////////////////// |
| 958 // | 972 // |
| 959 // HistoryUI | 973 // HistoryUI |
| 960 // | 974 // |
| 961 //////////////////////////////////////////////////////////////////////////////// | 975 //////////////////////////////////////////////////////////////////////////////// |
| 962 | 976 |
| 963 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 977 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 964 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 978 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
| 965 web_ui->AddMessageHandler(new MetricsHandler()); | 979 web_ui->AddMessageHandler(new MetricsHandler()); |
| 966 | 980 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 982 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 996 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
| 983 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 997 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
| 984 } | 998 } |
| 985 | 999 |
| 986 // static | 1000 // static |
| 987 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 1001 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
| 988 ui::ScaleFactor scale_factor) { | 1002 ui::ScaleFactor scale_factor) { |
| 989 return ResourceBundle::GetSharedInstance(). | 1003 return ResourceBundle::GetSharedInstance(). |
| 990 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 1004 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
| 991 } | 1005 } |
| OLD | NEW |