OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ios/chrome/browser/ui/webui/history/browsing_history_handler.h" | 5 #include "ios/chrome/browser/ui/webui/history/browsing_history_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/i18n/time_formatting.h" | 14 #include "base/i18n/time_formatting.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "components/bookmarks/browser/bookmark_model.h" | 21 #include "components/bookmarks/browser/bookmark_model.h" |
22 #include "components/bookmarks/browser/bookmark_utils.h" | 22 #include "components/bookmarks/browser/bookmark_utils.h" |
23 #include "components/browser_sync/browser/profile_sync_service.h" | 23 #include "components/browser_sync/browser/profile_sync_service.h" |
24 #include "components/history/core/browser/history_service.h" | 24 #include "components/history/core/browser/history_service.h" |
25 #include "components/history/core/browser/history_types.h" | 25 #include "components/history/core/browser/history_types.h" |
26 #include "components/history/core/browser/top_sites.h" | 26 #include "components/history/core/browser/top_sites.h" |
27 #include "components/history/core/browser/web_history_service.h" | 27 #include "components/history/core/browser/web_history_service.h" |
28 #include "components/keyed_service/core/service_access_type.h" | 28 #include "components/keyed_service/core/service_access_type.h" |
29 #include "components/prefs/pref_service.h" | |
30 #include "components/strings/grit/components_strings.h" | 29 #include "components/strings/grit/components_strings.h" |
31 #include "components/sync_driver/device_info.h" | 30 #include "components/sync_driver/device_info.h" |
32 #include "components/sync_driver/device_info_tracker.h" | 31 #include "components/sync_driver/device_info_tracker.h" |
33 #include "components/url_formatter/url_formatter.h" | 32 #include "components/url_formatter/url_formatter.h" |
34 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 33 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
35 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 34 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
36 #include "ios/chrome/browser/chrome_url_constants.h" | 35 #include "ios/chrome/browser/chrome_url_constants.h" |
37 #include "ios/chrome/browser/favicon/favicon_service_factory.h" | 36 #include "ios/chrome/browser/favicon/favicon_service_factory.h" |
38 #include "ios/chrome/browser/history/history_service_factory.h" | 37 #include "ios/chrome/browser/history/history_service_factory.h" |
39 #include "ios/chrome/browser/history/history_utils.h" | 38 #include "ios/chrome/browser/history/history_utils.h" |
40 #include "ios/chrome/browser/history/top_sites_factory.h" | 39 #include "ios/chrome/browser/history/top_sites_factory.h" |
41 #include "ios/chrome/browser/history/web_history_service_factory.h" | 40 #include "ios/chrome/browser/history/web_history_service_factory.h" |
42 #include "ios/chrome/browser/pref_names.h" | |
43 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 41 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
44 #include "ios/chrome/browser/ui/show_privacy_settings_util.h" | 42 #include "ios/chrome/browser/ui/show_privacy_settings_util.h" |
45 #include "ios/chrome/browser/ui/webui/history/favicon_source.h" | 43 #include "ios/chrome/browser/ui/webui/history/favicon_source.h" |
46 #include "ios/public/provider/web/web_ui_ios.h" | 44 #include "ios/public/provider/web/web_ui_ios.h" |
47 #include "ios/web/public/url_data_source_ios.h" | 45 #include "ios/web/public/url_data_source_ios.h" |
48 #include "sync/protocol/history_delete_directive_specifics.pb.h" | 46 #include "sync/protocol/history_delete_directive_specifics.pb.h" |
49 #include "sync/protocol/sync_enums.pb.h" | 47 #include "sync/protocol/sync_enums.pb.h" |
50 #include "ui/base/l10n/l10n_util.h" | 48 #include "ui/base/l10n/l10n_util.h" |
51 #include "ui/base/l10n/time_format.h" | 49 #include "ui/base/l10n/time_format.h" |
52 | 50 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } // namespace | 134 } // namespace |
137 | 135 |
138 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( | 136 BrowsingHistoryHandler::HistoryEntry::HistoryEntry( |
139 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type, | 137 BrowsingHistoryHandler::HistoryEntry::EntryType entry_type, |
140 const GURL& url, | 138 const GURL& url, |
141 const base::string16& title, | 139 const base::string16& title, |
142 base::Time time, | 140 base::Time time, |
143 const std::string& client_id, | 141 const std::string& client_id, |
144 bool is_search_result, | 142 bool is_search_result, |
145 const base::string16& snippet, | 143 const base::string16& snippet, |
146 bool blocked_visit, | 144 bool blocked_visit) { |
147 const std::string& accept_languages) { | |
148 this->entry_type = entry_type; | 145 this->entry_type = entry_type; |
149 this->url = url; | 146 this->url = url; |
150 this->title = title; | 147 this->title = title; |
151 this->time = time; | 148 this->time = time; |
152 this->client_id = client_id; | 149 this->client_id = client_id; |
153 all_timestamps.insert(time.ToInternalValue()); | 150 all_timestamps.insert(time.ToInternalValue()); |
154 this->is_search_result = is_search_result; | 151 this->is_search_result = is_search_result; |
155 this->snippet = snippet; | 152 this->snippet = snippet; |
156 this->blocked_visit = blocked_visit; | 153 this->blocked_visit = blocked_visit; |
157 this->accept_languages = accept_languages; | |
158 } | 154 } |
159 | 155 |
160 BrowsingHistoryHandler::HistoryEntry::HistoryEntry() | 156 BrowsingHistoryHandler::HistoryEntry::HistoryEntry() |
161 : entry_type(EMPTY_ENTRY), is_search_result(false), blocked_visit(false) {} | 157 : entry_type(EMPTY_ENTRY), is_search_result(false), blocked_visit(false) {} |
162 | 158 |
163 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() {} | 159 BrowsingHistoryHandler::HistoryEntry::~HistoryEntry() {} |
164 | 160 |
165 void BrowsingHistoryHandler::HistoryEntry::SetUrlAndTitle( | 161 void BrowsingHistoryHandler::HistoryEntry::SetUrlAndTitle( |
166 base::DictionaryValue* result) const { | 162 base::DictionaryValue* result) const { |
167 result->SetString("url", url.spec()); | 163 result->SetString("url", url.spec()); |
(...skipping 18 matching lines...) Expand all Loading... |
186 result->SetString("title", title_to_set); | 182 result->SetString("title", title_to_set); |
187 } | 183 } |
188 | 184 |
189 scoped_ptr<base::DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( | 185 scoped_ptr<base::DictionaryValue> BrowsingHistoryHandler::HistoryEntry::ToValue( |
190 BookmarkModel* bookmark_model, | 186 BookmarkModel* bookmark_model, |
191 SupervisedUserService* supervised_user_service, | 187 SupervisedUserService* supervised_user_service, |
192 const ProfileSyncService* sync_service) const { | 188 const ProfileSyncService* sync_service) const { |
193 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 189 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
194 SetUrlAndTitle(result.get()); | 190 SetUrlAndTitle(result.get()); |
195 | 191 |
196 base::string16 domain = | 192 base::string16 domain = url_formatter::IDNToUnicode(url.host()); |
197 url_formatter::IDNToUnicode(url.host(), accept_languages); | |
198 // When the domain is empty, use the scheme instead. This allows for a | 193 // When the domain is empty, use the scheme instead. This allows for a |
199 // sensible treatment of e.g. file: URLs when group by domain is on. | 194 // sensible treatment of e.g. file: URLs when group by domain is on. |
200 if (domain.empty()) | 195 if (domain.empty()) |
201 domain = base::UTF8ToUTF16(url.scheme() + ":"); | 196 domain = base::UTF8ToUTF16(url.scheme() + ":"); |
202 | 197 |
203 // The items which are to be written into result are also described in | 198 // The items which are to be written into result are also described in |
204 // chrome/browser/resources/history/history.js in @typedef for | 199 // chrome/browser/resources/history/history.js in @typedef for |
205 // HistoryEntry. Please update it whenever you add or remove | 200 // HistoryEntry. Please update it whenever you add or remove |
206 // any keys in result. | 201 // any keys in result. |
207 result->SetString("domain", domain); | 202 result->SetString("domain", domain); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 results_info_value_.Clear(); | 599 results_info_value_.Clear(); |
605 query_results_.clear(); | 600 query_results_.clear(); |
606 web_history_query_results_.clear(); | 601 web_history_query_results_.clear(); |
607 } | 602 } |
608 | 603 |
609 void BrowsingHistoryHandler::QueryComplete(const base::string16& search_text, | 604 void BrowsingHistoryHandler::QueryComplete(const base::string16& search_text, |
610 const history::QueryOptions& options, | 605 const history::QueryOptions& options, |
611 history::QueryResults* results) { | 606 history::QueryResults* results) { |
612 DCHECK_EQ(0U, query_results_.size()); | 607 DCHECK_EQ(0U, query_results_.size()); |
613 query_results_.reserve(results->size()); | 608 query_results_.reserve(results->size()); |
614 const std::string accept_languages = GetAcceptLanguages(); | |
615 | 609 |
616 for (size_t i = 0; i < results->size(); ++i) { | 610 for (size_t i = 0; i < results->size(); ++i) { |
617 history::URLResult const& page = (*results)[i]; | 611 history::URLResult const& page = (*results)[i]; |
618 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready. | 612 // TODO(dubroy): Use sane time (crbug.com/146090) here when it's ready. |
619 query_results_.push_back(HistoryEntry( | 613 query_results_.push_back( |
620 HistoryEntry::LOCAL_ENTRY, page.url(), page.title(), page.visit_time(), | 614 HistoryEntry(HistoryEntry::LOCAL_ENTRY, page.url(), page.title(), |
621 std::string(), !search_text.empty(), page.snippet().text(), | 615 page.visit_time(), std::string(), !search_text.empty(), |
622 page.blocked_visit(), accept_languages)); | 616 page.snippet().text(), page.blocked_visit())); |
623 } | 617 } |
624 | 618 |
625 // The items which are to be written into results_info_value_ are also | 619 // The items which are to be written into results_info_value_ are also |
626 // described in chrome/browser/resources/history/history.js in @typedef for | 620 // described in chrome/browser/resources/history/history.js in @typedef for |
627 // HistoryQuery. Please update it whenever you add or remove any keys in | 621 // HistoryQuery. Please update it whenever you add or remove any keys in |
628 // results_info_value_. | 622 // results_info_value_. |
629 results_info_value_.SetString("term", search_text); | 623 results_info_value_.SetString("term", search_text); |
630 results_info_value_.SetBoolean("finished", results->reached_beginning()); | 624 results_info_value_.SetBoolean("finished", results->reached_beginning()); |
631 | 625 |
632 // Add the specific dates that were searched to display them. | 626 // Add the specific dates that were searched to display them. |
(...skipping 13 matching lines...) Expand all Loading... |
646 } | 640 } |
647 | 641 |
648 void BrowsingHistoryHandler::WebHistoryQueryComplete( | 642 void BrowsingHistoryHandler::WebHistoryQueryComplete( |
649 const base::string16& search_text, | 643 const base::string16& search_text, |
650 const history::QueryOptions& options, | 644 const history::QueryOptions& options, |
651 base::TimeTicks start_time, | 645 base::TimeTicks start_time, |
652 history::WebHistoryService::Request* request, | 646 history::WebHistoryService::Request* request, |
653 const base::DictionaryValue* results_value) { | 647 const base::DictionaryValue* results_value) { |
654 base::TimeDelta delta = base::TimeTicks::Now() - start_time; | 648 base::TimeDelta delta = base::TimeTicks::Now() - start_time; |
655 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); | 649 UMA_HISTOGRAM_TIMES("WebHistory.ResponseTime", delta); |
656 const std::string accept_languages = GetAcceptLanguages(); | |
657 | 650 |
658 // If the response came in too late, do nothing. | 651 // If the response came in too late, do nothing. |
659 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? | 652 // TODO(dubroy): Maybe show a banner, and prompt the user to reload? |
660 if (!web_history_timer_.IsRunning()) | 653 if (!web_history_timer_.IsRunning()) |
661 return; | 654 return; |
662 web_history_timer_.Stop(); | 655 web_history_timer_.Stop(); |
663 | 656 |
664 UMA_HISTOGRAM_ENUMERATION( | 657 UMA_HISTOGRAM_ENUMERATION( |
665 "WebHistory.QueryCompletion", | 658 "WebHistory.QueryCompletion", |
666 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, | 659 results_value ? WEB_HISTORY_QUERY_SUCCEEDED : WEB_HISTORY_QUERY_FAILED, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 base::Time time = base::Time::UnixEpoch() + | 706 base::Time time = base::Time::UnixEpoch() + |
714 base::TimeDelta::FromMicroseconds(timestamp_usec); | 707 base::TimeDelta::FromMicroseconds(timestamp_usec); |
715 | 708 |
716 // Get the ID of the client that this visit came from. | 709 // Get the ID of the client that this visit came from. |
717 std::string client_id; | 710 std::string client_id; |
718 id->GetString("client_id", &client_id); | 711 id->GetString("client_id", &client_id); |
719 | 712 |
720 web_history_query_results_.push_back( | 713 web_history_query_results_.push_back( |
721 HistoryEntry(HistoryEntry::REMOTE_ENTRY, gurl, title, time, | 714 HistoryEntry(HistoryEntry::REMOTE_ENTRY, gurl, title, time, |
722 client_id, !search_text.empty(), base::string16(), | 715 client_id, !search_text.empty(), base::string16(), |
723 /* blocked_visit */ false, accept_languages)); | 716 /* blocked_visit */ false)); |
724 } | 717 } |
725 } | 718 } |
726 } | 719 } |
727 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); | 720 results_info_value_.SetBoolean("hasSyncedResults", results_value != NULL); |
728 if (!query_task_tracker_.HasTrackedTasks()) | 721 if (!query_task_tracker_.HasTrackedTasks()) |
729 ReturnResultsToFrontEnd(); | 722 ReturnResultsToFrontEnd(); |
730 } | 723 } |
731 | 724 |
732 void BrowsingHistoryHandler::RemoveComplete() { | 725 void BrowsingHistoryHandler::RemoveComplete() { |
733 urls_to_be_deleted_.clear(); | 726 urls_to_be_deleted_.clear(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 const std::set<GURL>& urls_to_be_deleted) { | 789 const std::set<GURL>& urls_to_be_deleted) { |
797 if (deleted_rows.size() != urls_to_be_deleted.size()) | 790 if (deleted_rows.size() != urls_to_be_deleted.size()) |
798 return true; | 791 return true; |
799 for (const auto& i : deleted_rows) { | 792 for (const auto& i : deleted_rows) { |
800 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) | 793 if (urls_to_be_deleted.find(i.url()) == urls_to_be_deleted.end()) |
801 return true; | 794 return true; |
802 } | 795 } |
803 return false; | 796 return false; |
804 } | 797 } |
805 | 798 |
806 std::string BrowsingHistoryHandler::GetAcceptLanguages() const { | |
807 ios::ChromeBrowserState* browser_state = | |
808 ios::ChromeBrowserState::FromWebUIIOS(web_ui()); | |
809 return browser_state->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
810 } | |
811 | |
812 void BrowsingHistoryHandler::OnURLsDeleted( | 799 void BrowsingHistoryHandler::OnURLsDeleted( |
813 history::HistoryService* history_service, | 800 history::HistoryService* history_service, |
814 bool all_history, | 801 bool all_history, |
815 bool expired, | 802 bool expired, |
816 const history::URLRows& deleted_rows, | 803 const history::URLRows& deleted_rows, |
817 const std::set<GURL>& favicon_urls) { | 804 const std::set<GURL>& favicon_urls) { |
818 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) | 805 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) |
819 web_ui()->CallJavascriptFunction("historyDeleted"); | 806 web_ui()->CallJavascriptFunction("historyDeleted"); |
820 } | 807 } |
OLD | NEW |