| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE); | 130 *name = l10n_util::GetStringUTF8(IDS_HISTORY_UNKNOWN_DEVICE); |
| 131 *type = kDeviceTypeLaptop; | 131 *type = kDeviceTypeLaptop; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Formats |entry|'s URL and title and adds them to |result|. | 134 // Formats |entry|'s URL and title and adds them to |result|. |
| 135 void SetHistoryEntryUrlAndTitle(BrowsingHistoryService::HistoryEntry* entry, | 135 void SetHistoryEntryUrlAndTitle(BrowsingHistoryService::HistoryEntry* entry, |
| 136 base::DictionaryValue* result, | 136 base::DictionaryValue* result) { |
| 137 bool limit_title_length) { | |
| 138 result->SetString("url", entry->url.spec()); | 137 result->SetString("url", entry->url.spec()); |
| 139 | 138 |
| 140 bool using_url_as_the_title = false; | 139 bool using_url_as_the_title = false; |
| 141 base::string16 title_to_set(entry->title); | 140 base::string16 title_to_set(entry->title); |
| 142 if (entry->title.empty()) { | 141 if (entry->title.empty()) { |
| 143 using_url_as_the_title = true; | 142 using_url_as_the_title = true; |
| 144 title_to_set = base::UTF8ToUTF16(entry->url.spec()); | 143 title_to_set = base::UTF8ToUTF16(entry->url.spec()); |
| 145 } | 144 } |
| 146 | 145 |
| 147 // Since the title can contain BiDi text, we need to mark the text as either | 146 // 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 | 147 // 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 | 148 // as the title, we mark the title as LTR since URLs are always treated as |
| 150 // left to right strings. | 149 // left to right strings. |
| 151 if (base::i18n::IsRTL()) { | 150 if (base::i18n::IsRTL()) { |
| 152 if (using_url_as_the_title) | 151 if (using_url_as_the_title) |
| 153 base::i18n::WrapStringWithLTRFormatting(&title_to_set); | 152 base::i18n::WrapStringWithLTRFormatting(&title_to_set); |
| 154 else | 153 else |
| 155 base::i18n::AdjustStringForLocaleDirection(&title_to_set); | 154 base::i18n::AdjustStringForLocaleDirection(&title_to_set); |
| 156 } | 155 } |
| 157 | 156 |
| 158 result->SetString("title", | 157 #if !defined(OS_ANDROID) |
| 159 limit_title_length ? title_to_set.substr(0, kShortTitleLength) | 158 if (title_to_set.size() > kShortTitleLength) |
| 160 : title_to_set); | 159 title_to_set.resize(kShortTitleLength); |
| 160 #endif |
| 161 |
| 162 result->SetString("title", title_to_set); |
| 161 } | 163 } |
| 162 | 164 |
| 163 // Converts |entry| to a DictionaryValue to be owned by the caller. | 165 // Converts |entry| to a DictionaryValue to be owned by the caller. |
| 164 std::unique_ptr<base::DictionaryValue> HistoryEntryToValue( | 166 std::unique_ptr<base::DictionaryValue> HistoryEntryToValue( |
| 165 BrowsingHistoryService::HistoryEntry* entry, | 167 BrowsingHistoryService::HistoryEntry* entry, |
| 166 BookmarkModel* bookmark_model, | 168 BookmarkModel* bookmark_model, |
| 167 SupervisedUserService* supervised_user_service, | 169 SupervisedUserService* supervised_user_service, |
| 168 const browser_sync::ProfileSyncService* sync_service, | 170 const browser_sync::ProfileSyncService* sync_service) { |
| 169 bool limit_title_length) { | |
| 170 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 171 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 171 SetHistoryEntryUrlAndTitle(entry, result.get(), limit_title_length); | 172 SetHistoryEntryUrlAndTitle(entry, result.get()); |
| 172 | 173 |
| 173 base::string16 domain = url_formatter::IDNToUnicode(entry->url.host()); | 174 base::string16 domain = url_formatter::IDNToUnicode(entry->url.host()); |
| 174 // When the domain is empty, use the scheme instead. This allows for a | 175 // 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. | 176 // sensible treatment of e.g. file: URLs when group by domain is on. |
| 176 if (domain.empty()) | 177 if (domain.empty()) |
| 177 domain = base::UTF8ToUTF16(entry->url.scheme() + ":"); | 178 domain = base::UTF8ToUTF16(entry->url.scheme() + ":"); |
| 178 | 179 |
| 179 // The items which are to be written into result are also described in | 180 // The items which are to be written into result are also described in |
| 180 // chrome/browser/resources/history/history.js in @typedef for | 181 // chrome/browser/resources/history/history.js in @typedef for |
| 181 // HistoryEntry. Please update it whenever you add or remove | 182 // 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); | 482 BookmarkModelFactory::GetForBrowserContext(profile); |
| 482 SupervisedUserService* supervised_user_service = NULL; | 483 SupervisedUserService* supervised_user_service = NULL; |
| 483 #if defined(ENABLE_SUPERVISED_USERS) | 484 #if defined(ENABLE_SUPERVISED_USERS) |
| 484 if (profile->IsSupervised()) | 485 if (profile->IsSupervised()) |
| 485 supervised_user_service = | 486 supervised_user_service = |
| 486 SupervisedUserServiceFactory::GetForProfile(profile); | 487 SupervisedUserServiceFactory::GetForProfile(profile); |
| 487 #endif | 488 #endif |
| 488 browser_sync::ProfileSyncService* sync_service = | 489 browser_sync::ProfileSyncService* sync_service = |
| 489 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 490 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 490 | 491 |
| 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. | 492 // Convert the result vector into a ListValue. |
| 497 base::ListValue results_value; | 493 base::ListValue results_value; |
| 498 for (std::vector<BrowsingHistoryService::HistoryEntry>::iterator it = | 494 for (std::vector<BrowsingHistoryService::HistoryEntry>::iterator it = |
| 499 results->begin(); it != results->end(); ++it) { | 495 results->begin(); it != results->end(); ++it) { |
| 500 std::unique_ptr<base::Value> value(HistoryEntryToValue(&(*it), | 496 std::unique_ptr<base::Value> value(HistoryEntryToValue( |
| 501 bookmark_model, supervised_user_service, sync_service, is_md)); | 497 &(*it), bookmark_model, supervised_user_service, sync_service)); |
| 502 results_value.Append(std::move(value)); | 498 results_value.Append(std::move(value)); |
| 503 } | 499 } |
| 504 | 500 |
| 505 base::DictionaryValue results_info; | 501 base::DictionaryValue results_info; |
| 506 // The items which are to be written into results_info_value_ are also | 502 // 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 | 503 // described in chrome/browser/resources/history/history.js in @typedef for |
| 508 // HistoryQuery. Please update it whenever you add or remove any keys in | 504 // HistoryQuery. Please update it whenever you add or remove any keys in |
| 509 // results_info_value_. | 505 // results_info_value_. |
| 510 results_info.SetString("term", query_results_info->search_text); | 506 results_info.SetString("term", query_results_info->search_text); |
| 511 results_info.SetBoolean("finished", query_results_info->reached_beginning); | 507 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"); | 547 web_ui()->CallJavascriptFunctionUnsafe("historyDeleted"); |
| 552 } | 548 } |
| 553 | 549 |
| 554 void BrowsingHistoryHandler::HasOtherFormsOfBrowsingHistory( | 550 void BrowsingHistoryHandler::HasOtherFormsOfBrowsingHistory( |
| 555 bool has_other_forms, | 551 bool has_other_forms, |
| 556 bool has_synced_results) { | 552 bool has_synced_results) { |
| 557 web_ui()->CallJavascriptFunctionUnsafe("showNotification", | 553 web_ui()->CallJavascriptFunctionUnsafe("showNotification", |
| 558 base::Value(has_synced_results), | 554 base::Value(has_synced_results), |
| 559 base::Value(has_other_forms)); | 555 base::Value(has_other_forms)); |
| 560 } | 556 } |
| OLD | NEW |