Index: components/omnibox/browser/autocomplete_match.cc |
diff --git a/components/omnibox/browser/autocomplete_match.cc b/components/omnibox/browser/autocomplete_match.cc |
index 00565376a2b2e7c0cc12e80bdb6da84fd490e55b..054d81d37ab3c6b84d3c13f4d35cb8a1fbec9255 100644 |
--- a/components/omnibox/browser/autocomplete_match.cc |
+++ b/components/omnibox/browser/autocomplete_match.cc |
@@ -7,6 +7,7 @@ |
#include <algorithm> |
#include <utility> |
+#include "base/feature_list.h" |
#include "base/logging.h" |
#include "base/macros.h" |
#include "base/strings/string16.h" |
@@ -15,9 +16,11 @@ |
#include "base/strings/string_split.h" |
#include "base/strings/string_util.h" |
#include "base/strings/stringprintf.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
#include "build/build_config.h" |
#include "components/omnibox/browser/autocomplete_provider.h" |
+#include "components/omnibox/browser/omnibox_field_trial.h" |
#include "components/omnibox/browser/suggestion_answer.h" |
#include "components/search_engines/template_url.h" |
#include "components/search_engines/template_url_service.h" |
@@ -485,6 +488,48 @@ GURL AutocompleteMatch::GURLToStrippedGURL( |
return stripped_destination_url; |
} |
+// static |
+base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplay( |
+ const GURL& url, |
+ bool trim_scheme, |
+ size_t* offset_for_adjustment) { |
+ base::OffsetAdjuster::Adjustments adjustments; |
+ const base::string16& format_url_return_value = |
+ FormatUrlForSuggestionDisplayWithAdjustments(url, trim_scheme, |
+ &adjustments); |
+ if (offset_for_adjustment) |
+ base::OffsetAdjuster::AdjustOffset(adjustments, offset_for_adjustment); |
+ return format_url_return_value; |
+} |
+ |
+// static |
+base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithAdjustments( |
+ const GURL& url, |
+ bool trim_scheme, |
+ base::OffsetAdjuster::Adjustments* adjustments) { |
+ const url_formatter::FormatUrlTypes format_types = |
+ url_formatter::kFormatUrlOmitAll & |
+ ~(trim_scheme ? 0 : url_formatter::kFormatUrlOmitHTTP); |
+ base::string16 result = url_formatter::FormatUrlWithAdjustments( |
+ url, format_types, net::UnescapeRule::SPACES, nullptr, nullptr, |
+ adjustments); |
+ |
+ // Also trim HTTPS if this experiment is enabled. |
Justin Donnelly
2017/06/20 17:31:01
Can you add a note that it's intentional that this
tommycli
2017/06/20 22:51:21
Done.
|
+ if (trim_scheme && base::FeatureList::IsEnabled( |
+ omnibox::kUIExperimentHideSuggestionUrlScheme)) { |
+ constexpr char kHTTPS[] = "https://"; |
Justin Donnelly
2017/06/20 17:31:01
std::string(url::kHttpsScheme) + url::kStandardSch
tommycli
2017/06/20 22:51:21
Done.
|
+ if (base::StartsWith(result, base::ASCIIToUTF16(kHTTPS), |
+ base::CompareCase::SENSITIVE)) { |
+ const size_t kHTTPSSize = arraysize(kHTTPS) - 1; |
+ result = result.substr(kHTTPSSize); |
+ adjustments->insert(adjustments->begin(), |
Justin Donnelly
2017/06/20 17:31:01
Is this right? Inserting at the beginning instead
tommycli
2017/06/20 22:51:21
Acknowledged.
|
+ base::OffsetAdjuster::Adjustment(0, kHTTPSSize, 0)); |
+ } |
+ } |
+ |
+ return result; |
+} |
+ |
void AutocompleteMatch::ComputeStrippedDestinationURL( |
const AutocompleteInput& input, |
TemplateURLService* template_url_service) { |