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