Chromium Code Reviews| Index: chrome/browser/autocomplete/url_prefix.cc |
| diff --git a/chrome/browser/autocomplete/url_prefix.cc b/chrome/browser/autocomplete/url_prefix.cc |
| index b304c7c56a5e5fd026a4085ba4e8adbe027ec392..1d680db593014dba849110d29223211b5f76837c 100644 |
| --- a/chrome/browser/autocomplete/url_prefix.cc |
| +++ b/chrome/browser/autocomplete/url_prefix.cc |
| @@ -7,6 +7,27 @@ |
| #include "base/basictypes.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/autocomplete/autocomplete_input.h" |
| + |
| +namespace { |
| + |
| +// Like URLPrefix::BestURLPrefix() except also handles the prefix of |
| +// "www.". |
| +const URLPrefix* BestURLPrefixWithWWWCase( |
|
Mark P
2014/04/09 22:03:17
This code was moved here from shortcuts_provider.c
|
| + const base::string16& text, |
| + const base::string16& prefix_suffix) { |
| + CR_DEFINE_STATIC_LOCAL(URLPrefix, www_prefix, |
| + (base::ASCIIToUTF16("www."), 1)); |
| + const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(text, prefix_suffix); |
| + if ((best_prefix == NULL) || |
| + (best_prefix->num_components < www_prefix.num_components)) { |
| + if (URLPrefix::PrefixMatch(www_prefix, text, prefix_suffix)) |
| + best_prefix = &www_prefix; |
| + } |
| + return best_prefix; |
| +} |
| + |
| +} // namespace |
| URLPrefix::URLPrefix(const base::string16& prefix, size_t num_components) |
| : prefix(prefix), |
| @@ -54,3 +75,36 @@ bool URLPrefix::PrefixMatch(const URLPrefix& prefix, |
| const base::string16& prefix_suffix) { |
| return StartsWith(text, prefix.prefix + prefix_suffix, false); |
| } |
| + |
| +// static |
| +void URLPrefix::ComputeMatchStartAndInlineAutocompleteOffset( |
|
Mark P
2014/04/09 22:03:17
This code was moved here from shortcuts provider w
|
| + const AutocompleteInput& input, |
| + const AutocompleteInput& fixed_up_input, |
| + const bool allow_www_prefix_without_scheme, |
| + const base::string16& text, |
| + size_t* match_start, |
| + size_t* inline_autocomplete_offset) { |
| + const URLPrefix* best_prefix = allow_www_prefix_without_scheme ? |
| + BestURLPrefixWithWWWCase(text, input.text()) : |
| + BestURLPrefix(text, input.text()); |
| + const base::string16* matching_string = &input.text(); |
| + // If we failed to find a best_prefix initially, try again using a fixed-up |
| + // version of the user input. This is especially useful to get about: URLs |
| + // to inline against chrome:// shortcuts. (about: URLs are fixed up to the |
| + // chrome:// scheme.) |
| + if ((best_prefix == NULL) && !fixed_up_input.text().empty() && |
| + (fixed_up_input.text() != input.text())) { |
| + best_prefix = allow_www_prefix_without_scheme ? |
| + BestURLPrefixWithWWWCase(text, fixed_up_input.text()) : |
| + BestURLPrefix(text, fixed_up_input.text()); |
| + matching_string = &fixed_up_input.text(); |
| + } |
| + if (best_prefix != NULL) { |
| + *match_start = best_prefix->prefix.length(); |
| + *inline_autocomplete_offset = |
| + best_prefix->prefix.length() + matching_string->length(); |
| + } else { |
| + *match_start = base::string16::npos; |
| + *inline_autocomplete_offset = base::string16::npos; |
| + } |
| +} |