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& 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->languages = 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 13 matching lines...) Expand all Loading... | |
312 // left to right strings. | 315 // left to right strings. |
313 if (base::i18n::IsRTL()) { | 316 if (base::i18n::IsRTL()) { |
314 if (using_url_as_the_title) | 317 if (using_url_as_the_title) |
315 base::i18n::WrapStringWithLTRFormatting(&title_to_set); | 318 base::i18n::WrapStringWithLTRFormatting(&title_to_set); |
316 else | 319 else |
317 base::i18n::AdjustStringForLocaleDirection(&title_to_set); | 320 base::i18n::AdjustStringForLocaleDirection(&title_to_set); |
318 } | 321 } |
319 result->SetString("title", title_to_set); | 322 result->SetString("title", title_to_set); |
320 } | 323 } |
321 | 324 |
325 void BrowsingHistoryHandler::HistoryEntry::SetDisplayableDomain( | |
Patrick Dubroy
2013/08/20 14:26:37
I don't see much value in having this as a separat
| |
326 DictionaryValue* result) const { | |
327 result->SetString("displayableDomain", | |
328 net::IDNToUnicode(url.host(), languages)); | |
329 } | |
330 | |
322 scoped_ptr<DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( | 331 scoped_ptr<DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( |
323 BookmarkModel* bookmark_model, | 332 BookmarkModel* bookmark_model, |
324 ManagedUserService* managed_user_service, | 333 ManagedUserService* managed_user_service, |
325 const ProfileSyncService* sync_service) const { | 334 const ProfileSyncService* sync_service) const { |
326 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 335 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
327 SetUrlAndTitle(result.get()); | 336 SetUrlAndTitle(result.get()); |
337 SetDisplayableDomain(result.get()); | |
328 result->SetDouble("time", time.ToJsTime()); | 338 result->SetDouble("time", time.ToJsTime()); |
329 | 339 |
330 // Pass the timestamps in a list. | 340 // Pass the timestamps in a list. |
331 scoped_ptr<ListValue> timestamps(new ListValue); | 341 scoped_ptr<ListValue> timestamps(new ListValue); |
332 for (std::set<int64>::const_iterator it = all_timestamps.begin(); | 342 for (std::set<int64>::const_iterator it = all_timestamps.begin(); |
333 it != all_timestamps.end(); ++it) { | 343 it != all_timestamps.end(); ++it) { |
334 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); | 344 timestamps->AppendDouble(base::Time::FromInternalValue(*it).ToJsTime()); |
335 } | 345 } |
336 result->Set("allTimestamps", timestamps.release()); | 346 result->Set("allTimestamps", timestamps.release()); |
337 | 347 |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 web_history_query_results_.clear(); | 744 web_history_query_results_.clear(); |
735 } | 745 } |
736 | 746 |
737 void BrowsingHistoryHandler::QueryComplete( | 747 void BrowsingHistoryHandler::QueryComplete( |
738 const string16& search_text, | 748 const string16& search_text, |
739 const history::QueryOptions& options, | 749 const history::QueryOptions& options, |
740 HistoryService::Handle request_handle, | 750 HistoryService::Handle request_handle, |
741 history::QueryResults* results) { | 751 history::QueryResults* results) { |
742 DCHECK_EQ(0U, query_results_.size()); | 752 DCHECK_EQ(0U, query_results_.size()); |
743 query_results_.reserve(results->size()); | 753 query_results_.reserve(results->size()); |
754 const std::string languages = GetLanguages(); | |
744 | 755 |
745 for (size_t i = 0; i < results->size(); ++i) { | 756 for (size_t i = 0; i < results->size(); ++i) { |
746 history::URLResult const &page = (*results)[i]; | 757 history::URLResult const &page = (*results)[i]; |
747 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready. | 758 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready. |
748 query_results_.push_back( | 759 query_results_.push_back( |
749 HistoryEntry( | 760 HistoryEntry( |
750 HistoryEntry::LOCAL_ENTRY, | 761 HistoryEntry::LOCAL_ENTRY, |
751 page.url(), | 762 page.url(), |
752 page.title(), | 763 page.title(), |
753 page.visit_time(), | 764 page.visit_time(), |
754 std::string(), | 765 std::string(), |
755 !search_text.empty(), | 766 !search_text.empty(), |
756 page.snippet().text(), | 767 page.snippet().text(), |
757 page.blocked_visit())); | 768 page.blocked_visit(), |
769 languages)); | |
758 } | 770 } |
759 | 771 |
760 results_info_value_.SetString("term", search_text); | 772 results_info_value_.SetString("term", search_text); |
761 results_info_value_.SetBoolean("finished", results->reached_beginning()); | 773 results_info_value_.SetBoolean("finished", results->reached_beginning()); |
762 | 774 |
763 // Add the specific dates that were searched to display them. | 775 // Add the specific dates that were searched to display them. |
764 // TODO(sergiu): Put today if the start is in the future. | 776 // TODO(sergiu): Put today if the start is in the future. |
765 results_info_value_.SetString("queryStartTime", | 777 results_info_value_.SetString("queryStartTime", |
766 getRelativeDateLocalized(options.begin_time)); | 778 getRelativeDateLocalized(options.begin_time)); |
767 if (!options.end_time.is_null()) { | 779 if (!options.end_time.is_null()) { |
768 results_info_value_.SetString("queryEndTime", | 780 results_info_value_.SetString("queryEndTime", |
769 getRelativeDateLocalized(options.end_time - | 781 getRelativeDateLocalized(options.end_time - |
770 base::TimeDelta::FromDays(1))); | 782 base::TimeDelta::FromDays(1))); |
771 } else { | 783 } else { |
772 results_info_value_.SetString("queryEndTime", | 784 results_info_value_.SetString("queryEndTime", |
773 getRelativeDateLocalized(base::Time::Now())); | 785 getRelativeDateLocalized(base::Time::Now())); |
774 } | 786 } |
775 if (!web_history_timer_.IsRunning()) | 787 if (!web_history_timer_.IsRunning()) |
776 ReturnResultsToFrontEnd(); | 788 ReturnResultsToFrontEnd(); |
777 } | 789 } |
778 | 790 |
779 void BrowsingHistoryHandler::WebHistoryQueryComplete( | 791 void BrowsingHistoryHandler::WebHistoryQueryComplete( |
780 const string16& search_text, | 792 const string16& search_text, |
781 const history::QueryOptions& options, | 793 const history::QueryOptions& options, |
782 base::TimeTicks start_time, | 794 base::TimeTicks start_time, |
783 history::WebHistoryService::Request* request, | 795 history::WebHistoryService::Request* request, |
784 const DictionaryValue* results_value) { | 796 const DictionaryValue* results_value) { |
785 base::TimeDelta delta = base::TimeTicks::Now() - start_time; | 797 base::TimeDelta delta = base::TimeTicks::Now() - start_time; |
786 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); | 798 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); |
799 const std::string languages = GetLanguages(); | |
787 | 800 |
788 // If the response came in too late, do nothing. | 801 // If the response came in too late, do nothing. |
789 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? | 802 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? |
790 if (!web_history_timer_.IsRunning()) | 803 if (!web_history_timer_.IsRunning()) |
791 return; | 804 return; |
792 web_history_timer_.Stop(); | 805 web_history_timer_.Stop(); |
793 | 806 |
794 UMA_HISTOGRAM_ENUMERATION( | 807 UMA_HISTOGRAM_ENUMERATION( |
795 "WebHistory.QueryCompletion", | 808 "WebHistory.QueryCompletion", |
796 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, | 809 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
844 | 857 |
845 web_history_query_results_.push_back( | 858 web_history_query_results_.push_back( |
846 HistoryEntry( | 859 HistoryEntry( |
847 HistoryEntry::REMOTE_ENTRY, | 860 HistoryEntry::REMOTE_ENTRY, |
848 GURL(url), | 861 GURL(url), |
849 title, | 862 title, |
850 time, | 863 time, |
851 client_id, | 864 client_id, |
852 !search_text.empty(), | 865 !search_text.empty(), |
853 string16(), | 866 string16(), |
854 /* blocked_visit */ false)); | 867 /* blocked_visit */ false, |
868 languages)); | |
855 } | 869 } |
856 } | 870 } |
857 } else if (results_value) { | 871 } else if (results_value) { |
858 NOTREACHED() << "Failed to parse JSON response."; | 872 NOTREACHED() << "Failed to parse JSON response."; |
859 } | 873 } |
860 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); | 874 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); |
861 if (!history_request_consumer_.HasPendingRequests()) | 875 if (!history_request_consumer_.HasPendingRequests()) |
862 ReturnResultsToFrontEnd(); | 876 ReturnResultsToFrontEnd(); |
863 } | 877 } |
864 | 878 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 NOTREACHED(); | 961 NOTREACHED(); |
948 return; | 962 return; |
949 } | 963 } |
950 history::URLsDeletedDetails* deletedDetails = | 964 history::URLsDeletedDetails* deletedDetails = |
951 content::Details<history::URLsDeletedDetails>(details).ptr(); | 965 content::Details<history::URLsDeletedDetails>(details).ptr(); |
952 if (deletedDetails->all_history || | 966 if (deletedDetails->all_history || |
953 DeletionsDiffer(deletedDetails->rows, urls_to_be_deleted_)) | 967 DeletionsDiffer(deletedDetails->rows, urls_to_be_deleted_)) |
954 web_ui()->CallJavascriptFunction("historyDeleted"); | 968 web_ui()->CallJavascriptFunction("historyDeleted"); |
955 } | 969 } |
956 | 970 |
971 std::string BrowsingHistoryHandler::GetLanguages() const { | |
972 Profile* profile = Profile::FromWebUI(web_ui()); | |
973 return profile ? profile->GetPrefs()->GetString(prefs::kAcceptLanguages) : | |
Patrick Dubroy
2013/08/20 14:26:37
Nit: looks like this actually fits on one line.
| |
974 ""; | |
975 } | |
976 | |
957 //////////////////////////////////////////////////////////////////////////////// | 977 //////////////////////////////////////////////////////////////////////////////// |
958 // | 978 // |
959 // HistoryUI | 979 // HistoryUI |
960 // | 980 // |
961 //////////////////////////////////////////////////////////////////////////////// | 981 //////////////////////////////////////////////////////////////////////////////// |
962 | 982 |
963 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 983 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
964 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 984 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
965 web_ui->AddMessageHandler(new MetricsHandler()); | 985 web_ui->AddMessageHandler(new MetricsHandler()); |
966 | 986 |
(...skipping 15 matching lines...) Expand all Loading... | |
982 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + | 1002 return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" + |
983 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); | 1003 net::EscapeQueryParamValue(UTF16ToUTF8(text), true)); |
984 } | 1004 } |
985 | 1005 |
986 // static | 1006 // static |
987 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( | 1007 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( |
988 ui::ScaleFactor scale_factor) { | 1008 ui::ScaleFactor scale_factor) { |
989 return ResourceBundle::GetSharedInstance(). | 1009 return ResourceBundle::GetSharedInstance(). |
990 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); | 1010 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); |
991 } | 1011 } |
OLD | NEW |