Chromium Code Reviews| 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..570b96640b8e175203f9385ca37a2a4cc44c55d5 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,71 @@ GURL AutocompleteMatch::GURLToStrippedGURL( |
| return stripped_destination_url; |
| } |
| +// static |
| +base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplay( |
| + const GURL& url, |
| + bool trim_scheme, |
| + size_t* offset_for_adjustment) { |
| + std::vector<size_t> offsets; |
| + if (offset_for_adjustment) |
| + offsets.push_back(*offset_for_adjustment); |
| + base::string16 result = |
| + FormatUrlForSuggestionDisplayWithOffsets(url, trim_scheme, &offsets); |
| + if (offset_for_adjustment) |
| + *offset_for_adjustment = offsets[0]; |
| + return result; |
| +} |
| + |
| +// static |
| +base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithOffsets( |
| + const GURL& url, |
| + bool trim_scheme, |
| + std::vector<size_t>* offsets_for_adjustment) { |
| + base::OffsetAdjuster::Adjustments adjustments; |
| + const base::string16& format_url_return_value = |
| + FormatUrlForSuggestionDisplayWithAdjustments(url, trim_scheme, |
| + &adjustments); |
| + base::OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment); |
| + if (offsets_for_adjustment) { |
| + std::for_each( |
| + offsets_for_adjustment->begin(), offsets_for_adjustment->end(), |
| + base::LimitOffset<std::string>(format_url_return_value.length())); |
| + } |
| + return format_url_return_value; |
| +} |
| + |
| +// static |
| +base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithAdjustments( |
| + const GURL& url, |
| + bool trim_scheme, |
| + base::OffsetAdjuster::Adjustments* adjustments) { |
|
tommycli
2017/06/21 18:53:44
These three methods duplicate a lot of offset adju
Peter Kasting
2017/06/21 23:17:27
I'm a little leery of adding a new flag type and t
tommycli
2017/06/22 19:18:43
Okay cool -- In that case, it seems like the best
tommycli
2017/06/22 19:22:51
FWIW, Justin actually liked that these convenience
|
| + 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 experiment is enabled. Note this intentionally has |
| + // no effect on view-source URLs. |
| + if (trim_scheme && base::FeatureList::IsEnabled( |
| + omnibox::kUIExperimentHideSuggestionUrlScheme)) { |
| + // TODO(tommycli): If this becomes enabled by default, investigate |
| + // folding this logic into url_formatter::FormatUrlWithAdjustments. |
| + const std::string kHTTPS = |
| + std::string(url::kHttpsScheme) + url::kStandardSchemeSeparator; |
| + if (base::StartsWith(result, base::ASCIIToUTF16(kHTTPS), |
| + base::CompareCase::SENSITIVE)) { |
|
Peter Kasting
2017/06/21 23:17:27
Can we just check if url.SchemeIs(url::kHttpsSchem
tommycli
2017/06/22 19:18:43
Done.
|
| + const size_t kHTTPSSize = kHTTPS.size(); |
| + result = result.substr(kHTTPSSize); |
| + adjustments->insert(adjustments->begin(), |
| + base::OffsetAdjuster::Adjustment(0, kHTTPSSize, 0)); |
| + } |
| + } |
| + |
| + return result; |
| +} |
| + |
| void AutocompleteMatch::ComputeStrippedDestinationURL( |
| const AutocompleteInput& input, |
| TemplateURLService* template_url_service) { |