OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/browsing_history_handler.h" | 5 #include "chrome/browser/ui/webui/browsing_history_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 53 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
54 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" | 54 #include "chrome/browser/supervised_user/supervised_user_url_filter.h" |
55 #endif | 55 #endif |
56 | 56 |
57 #if defined(OS_ANDROID) | 57 #if defined(OS_ANDROID) |
58 #include "chrome/browser/android/preferences/preferences_launcher.h" | 58 #include "chrome/browser/android/preferences/preferences_launcher.h" |
59 #else | 59 #else |
60 #include "chrome/common/chrome_features.h" | 60 #include "chrome/common/chrome_features.h" |
61 #endif | 61 #endif |
62 | 62 |
63 // Number of chars to truncate titles when making them "short". | |
64 static const size_t kShortTitleLength = 300; | |
65 | |
66 using bookmarks::BookmarkModel; | 63 using bookmarks::BookmarkModel; |
67 | 64 |
68 namespace { | 65 namespace { |
69 | 66 |
70 // Identifiers for the type of device from which a history entry originated. | 67 // Identifiers for the type of device from which a history entry originated. |
71 static const char kDeviceTypeLaptop[] = "laptop"; | 68 static const char kDeviceTypeLaptop[] = "laptop"; |
72 static const char kDeviceTypePhone[] = "phone"; | 69 static const char kDeviceTypePhone[] = "phone"; |
73 static const char kDeviceTypeTablet[] = "tablet"; | 70 static const char kDeviceTypeTablet[] = "tablet"; |
74 | 71 |
75 // Returns a localized version of |visit_time| including a relative | 72 // Returns a localized version of |visit_time| including a relative |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 123 } |
127 return; | 124 return; |
128 } | 125 } |
129 | 126 |
130 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE); | 127 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE); |
131 *type = kDeviceTypeLaptop; | 128 *type = kDeviceTypeLaptop; |
132 } | 129 } |
133 | 130 |
134 // Formats |entry|'s URL and title and adds them to |result|. | 131 // Formats |entry|'s URL and title and adds them to |result|. |
135 void SetHistoryEntryUrlAndTitle(BrowsingHistoryService::HistoryEntry* entry, | 132 void SetHistoryEntryUrlAndTitle(BrowsingHistoryService::HistoryEntry* entry, |
136 base::DictionaryValue* result, | 133 base::DictionaryValue* result) { |
137 bool limit_title_length) { | |
138 result->SetString("url", entry->url.spec()); | 134 result->SetString("url", entry->url.spec()); |
139 | 135 |
140 bool using_url_as_the_title = false; | 136 bool using_url_as_the_title = false; |
141 base::string16 title_to_set(entry->title); | 137 base::string16 title_to_set(entry->title); |
142 if (entry->title.empty()) { | 138 if (entry->title.empty()) { |
143 using_url_as_the_title = true; | 139 using_url_as_the_title = true; |
144 title_to_set = base::UTF8ToUTF16(entry->url.spec()); | 140 title_to_set = base::UTF8ToUTF16(entry->url.spec()); |
145 } | 141 } |
146 | 142 |
147 // Since the title can contain BiDi text, we need to mark the text as either | 143 // Since the title can contain BiDi text, we need to mark the text as either |
148 // RTL or LTR, depending on the characters in the string. If we use the URL | 144 // RTL or LTR, depending on the characters in the string. If we use the URL |
149 // as the title, we mark the title as LTR since URLs are always treated as | 145 // as the title, we mark the title as LTR since URLs are always treated as |
150 // left to right strings. | 146 // left to right strings. |
151 if (base::i18n::IsRTL()) { | 147 if (base::i18n::IsRTL()) { |
152 if (using_url_as_the_title) | 148 if (using_url_as_the_title) |
153 base::i18n::WrapStringWithLTRFormatting(&title_to_set); | 149 base::i18n::WrapStringWithLTRFormatting(&title_to_set); |
154 else | 150 else |
155 base::i18n::AdjustStringForLocaleDirection(&title_to_set); | 151 base::i18n::AdjustStringForLocaleDirection(&title_to_set); |
156 } | 152 } |
157 | 153 |
158 result->SetString("title", | 154 #if !defined(OS_ANDROID) |
159 limit_title_length ? title_to_set.substr(0, kShortTitleLength) | 155 // Number of chars to truncate titles when making them "short". |
160 : title_to_set); | 156 static const size_t kShortTitleLength = 300; |
| 157 if (title_to_set.size() > kShortTitleLength) |
| 158 title_to_set.resize(kShortTitleLength); |
| 159 #endif |
| 160 |
| 161 result->SetString("title", title_to_set); |
161 } | 162 } |
162 | 163 |
163 // Converts |entry| to a DictionaryValue to be owned by the caller. | 164 // Converts |entry| to a DictionaryValue to be owned by the caller. |
164 std::unique_ptr<base::DictionaryValue> HistoryEntryToValue( | 165 std::unique_ptr<base::DictionaryValue> HistoryEntryToValue( |
165 BrowsingHistoryService::HistoryEntry* entry, | 166 BrowsingHistoryService::HistoryEntry* entry, |
166 BookmarkModel* bookmark_model, | 167 BookmarkModel* bookmark_model, |
167 SupervisedUserService* supervised_user_service, | 168 SupervisedUserService* supervised_user_service, |
168 const browser_sync::ProfileSyncService* sync_service, | 169 const browser_sync::ProfileSyncService* sync_service) { |
169 bool limit_title_length) { | |
170 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 170 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
171 SetHistoryEntryUrlAndTitle(entry, result.get(), limit_title_length); | 171 SetHistoryEntryUrlAndTitle(entry, result.get()); |
172 | 172 |
173 base::string16 domain = url_formatter::IDNToUnicode(entry->url.host()); | 173 base::string16 domain = url_formatter::IDNToUnicode(entry->url.host()); |
174 // When the domain is empty, use the scheme instead. This allows for a | 174 // When the domain is empty, use the scheme instead. This allows for a |
175 // sensible treatment of e.g. file: URLs when group by domain is on. | 175 // sensible treatment of e.g. file: URLs when group by domain is on. |
176 if (domain.empty()) | 176 if (domain.empty()) |
177 domain = base::UTF8ToUTF16(entry->url.scheme() + ":"); | 177 domain = base::UTF8ToUTF16(entry->url.scheme() + ":"); |
178 | 178 |
179 // The items which are to be written into result are also described in | 179 // The items which are to be written into result are also described in |
180 // chrome/browser/resources/history/history.js in @typedef for | 180 // chrome/browser/resources/history/history.js in @typedef for |
181 // HistoryEntry. Please update it whenever you add or remove | 181 // HistoryEntry. Please update it whenever you add or remove |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 BookmarkModelFactory::GetForBrowserContext(profile); | 481 BookmarkModelFactory::GetForBrowserContext(profile); |
482 SupervisedUserService* supervised_user_service = NULL; | 482 SupervisedUserService* supervised_user_service = NULL; |
483 #if defined(ENABLE_SUPERVISED_USERS) | 483 #if defined(ENABLE_SUPERVISED_USERS) |
484 if (profile->IsSupervised()) | 484 if (profile->IsSupervised()) |
485 supervised_user_service = | 485 supervised_user_service = |
486 SupervisedUserServiceFactory::GetForProfile(profile); | 486 SupervisedUserServiceFactory::GetForProfile(profile); |
487 #endif | 487 #endif |
488 browser_sync::ProfileSyncService* sync_service = | 488 browser_sync::ProfileSyncService* sync_service = |
489 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 489 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
490 | 490 |
491 bool is_md = false; | |
492 #if !defined(OS_ANDROID) | |
493 is_md = base::FeatureList::IsEnabled(::features::kMaterialDesignHistory); | |
494 #endif | |
495 | |
496 // Convert the result vector into a ListValue. | 491 // Convert the result vector into a ListValue. |
497 base::ListValue results_value; | 492 base::ListValue results_value; |
498 for (std::vector<BrowsingHistoryService::HistoryEntry>::iterator it = | 493 for (std::vector<BrowsingHistoryService::HistoryEntry>::iterator it = |
499 results->begin(); it != results->end(); ++it) { | 494 results->begin(); it != results->end(); ++it) { |
500 std::unique_ptr<base::Value> value(HistoryEntryToValue(&(*it), | 495 std::unique_ptr<base::Value> value(HistoryEntryToValue( |
501 bookmark_model, supervised_user_service, sync_service, is_md)); | 496 &(*it), bookmark_model, supervised_user_service, sync_service)); |
502 results_value.Append(std::move(value)); | 497 results_value.Append(std::move(value)); |
503 } | 498 } |
504 | 499 |
505 base::DictionaryValue results_info; | 500 base::DictionaryValue results_info; |
506 // The items which are to be written into results_info_value_ are also | 501 // The items which are to be written into results_info_value_ are also |
507 // described in chrome/browser/resources/history/history.js in @typedef for | 502 // described in chrome/browser/resources/history/history.js in @typedef for |
508 // HistoryQuery. Please update it whenever you add or remove any keys in | 503 // HistoryQuery. Please update it whenever you add or remove any keys in |
509 // results_info_value_. | 504 // results_info_value_. |
510 results_info.SetString("term", query_results_info->search_text); | 505 results_info.SetString("term", query_results_info->search_text); |
511 results_info.SetBoolean("finished", query_results_info->reached_beginning); | 506 results_info.SetBoolean("finished", query_results_info->reached_beginning); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 web_ui()->CallJavascriptFunctionUnsafe("historyDeleted"); | 546 web_ui()->CallJavascriptFunctionUnsafe("historyDeleted"); |
552 } | 547 } |
553 | 548 |
554 void BrowsingHistoryHandler::HasOtherFormsOfBrowsingHistory( | 549 void BrowsingHistoryHandler::HasOtherFormsOfBrowsingHistory( |
555 bool has_other_forms, | 550 bool has_other_forms, |
556 bool has_synced_results) { | 551 bool has_synced_results) { |
557 web_ui()->CallJavascriptFunctionUnsafe("showNotification", | 552 web_ui()->CallJavascriptFunctionUnsafe("showNotification", |
558 base::Value(has_synced_results), | 553 base::Value(has_synced_results), |
559 base::Value(has_other_forms)); | 554 base::Value(has_other_forms)); |
560 } | 555 } |
OLD | NEW |