| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_OMNIBOX_BROWSER_URL_PREFIX_H_ | 5 #ifndef COMPONENTS_OMNIBOX_BROWSER_URL_PREFIX_H_ |
| 6 #define COMPONENTS_OMNIBOX_BROWSER_URL_PREFIX_H_ | 6 #define COMPONENTS_OMNIBOX_BROWSER_URL_PREFIX_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 | 13 |
| 14 struct URLPrefix; | 14 struct URLPrefix; |
| 15 typedef std::vector<URLPrefix> URLPrefixes; | 15 typedef std::vector<URLPrefix> URLPrefixes; |
| 16 | 16 |
| 17 // A URL prefix; combinations of schemes and (least significant) domain labels | 17 // A URL prefix; combinations of schemes and (least significant) domain labels |
| 18 // that may be inferred from certain URL-like input strings. | 18 // that may be inferred from certain URL-like input strings. |
| 19 struct URLPrefix { | 19 struct URLPrefix { |
| 20 URLPrefix(const base::string16& prefix, size_t num_components); | 20 URLPrefix(const base::string16& prefix, size_t num_components); |
| 21 | 21 |
| 22 // Returns a vector of URL prefixes sorted by descending number of components. | 22 // Returns a vector of URL prefixes sorted by descending number of components. |
| 23 static const URLPrefixes& GetURLPrefixes(); | 23 static const URLPrefixes& GetURLPrefixes(); |
| 24 | 24 |
| 25 // Returns if the argument is a valid URL prefix. | |
| 26 static bool IsURLPrefix(const base::string16& prefix); | |
| 27 | |
| 28 // Returns the URL prefix of |text| with the most components, or NULL. | 25 // Returns the URL prefix of |text| with the most components, or NULL. |
| 29 // |prefix_suffix| (which may be empty) is appended to every attempted prefix, | 26 // |prefix_suffix| (which may be empty) is appended to every attempted prefix, |
| 30 // which is useful for finding the innermost match of user input in a URL. | 27 // which is useful for finding the innermost match of user input in a URL. |
| 31 // Performs case insensitive string comparison. | 28 // Performs case insensitive string comparison. |
| 32 static const URLPrefix* BestURLPrefix(const base::string16& text, | 29 static const URLPrefix* BestURLPrefix(const base::string16& text, |
| 33 const base::string16& prefix_suffix); | 30 const base::string16& prefix_suffix); |
| 34 | 31 |
| 35 // A helper function for BestURLPrefix(). Returns true if |text| starts | |
| 36 // with |prefix| which is then followed by |prefix_suffix|. | |
| 37 // Performs case insensitive string comparison. | |
| 38 static bool PrefixMatch(const URLPrefix& prefix, | |
| 39 const base::string16& text, | |
| 40 const base::string16& prefix_suffix); | |
| 41 | |
| 42 // Sees if |text| is inlineable against either |input| or |fixed_up_input|, | 32 // Sees if |text| is inlineable against either |input| or |fixed_up_input|, |
| 43 // returning the appropriate inline autocomplete offset or | 33 // returning the appropriate inline autocomplete offset or |
| 44 // base::string16::npos if |text| is not inlineable. | 34 // base::string16::npos if |text| is not inlineable. |
| 45 // |allow_www_prefix_without_scheme| says whether to consider an input such | 35 // |allow_www_prefix_without_scheme| says whether to consider an input such |
| 46 // as "foo" to be allowed to match against text "www.foo.com". This is | 36 // as "foo" to be allowed to match against text "www.foo.com". This is |
| 47 // needed because sometimes the string we're matching against here can come | 37 // needed because sometimes the string we're matching against here can come |
| 48 // from a match's fill_into_edit, which can start with "www." without having | 38 // from a match's fill_into_edit, which can start with "www." without having |
| 49 // a protocol at the beginning, and we want to allow these matches to be | 39 // a protocol at the beginning, and we want to allow these matches to be |
| 50 // inlineable. ("www." is not otherwise on the default prefix list.) | 40 // inlineable. ("www." is not otherwise on the default prefix list.) |
| 51 static size_t GetInlineAutocompleteOffset( | 41 static size_t GetInlineAutocompleteOffset( |
| 52 const base::string16& input, | 42 const base::string16& input, |
| 53 const base::string16& fixed_up_input, | 43 const base::string16& fixed_up_input, |
| 54 const bool allow_www_prefix_without_scheme, | 44 const bool allow_www_prefix_without_scheme, |
| 55 const base::string16& text); | 45 const base::string16& text); |
| 56 | 46 |
| 57 base::string16 prefix; | 47 base::string16 prefix; |
| 58 | 48 |
| 59 // The number of URL components (scheme, domain label, etc.) in the prefix. | 49 // The number of URL components (scheme, domain label, etc.) in the prefix. |
| 60 // For example, "http://foo.com" and "www.bar.com" each have one component, | 50 // For example, "http://foo.com" and "www.bar.com" each have one component, |
| 61 // while "ftp://ftp.ftp.com" has two, and "mysite.com" has none. | 51 // while "ftp://ftp.ftp.com" has two, and "mysite.com" has none. |
| 62 size_t num_components; | 52 size_t num_components; |
| 63 }; | 53 }; |
| 64 | 54 |
| 65 #endif // COMPONENTS_OMNIBOX_BROWSER_URL_PREFIX_H_ | 55 #endif // COMPONENTS_OMNIBOX_BROWSER_URL_PREFIX_H_ |
| OLD | NEW |