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 #include "chrome/browser/autocomplete/url_prefix.h" | 5 #include "chrome/browser/autocomplete/url_prefix.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/autocomplete/autocomplete_input.h" | |
11 | 10 |
12 namespace { | 11 namespace { |
13 | 12 |
14 // Like URLPrefix::BestURLPrefix() except also handles the prefix of | 13 // Like URLPrefix::BestURLPrefix() except also handles the prefix of |
15 // "www.". | 14 // "www.". |
16 const URLPrefix* BestURLPrefixWithWWWCase( | 15 const URLPrefix* BestURLPrefixWithWWWCase( |
17 const base::string16& text, | 16 const base::string16& text, |
18 const base::string16& prefix_suffix) { | 17 const base::string16& prefix_suffix) { |
19 CR_DEFINE_STATIC_LOCAL(URLPrefix, www_prefix, | 18 CR_DEFINE_STATIC_LOCAL(URLPrefix, www_prefix, |
20 (base::ASCIIToUTF16("www."), 1)); | 19 (base::ASCIIToUTF16("www."), 1)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 70 |
72 // static | 71 // static |
73 bool URLPrefix::PrefixMatch(const URLPrefix& prefix, | 72 bool URLPrefix::PrefixMatch(const URLPrefix& prefix, |
74 const base::string16& text, | 73 const base::string16& text, |
75 const base::string16& prefix_suffix) { | 74 const base::string16& prefix_suffix) { |
76 return StartsWith(text, prefix.prefix + prefix_suffix, false); | 75 return StartsWith(text, prefix.prefix + prefix_suffix, false); |
77 } | 76 } |
78 | 77 |
79 // static | 78 // static |
80 size_t URLPrefix::GetInlineAutocompleteOffset( | 79 size_t URLPrefix::GetInlineAutocompleteOffset( |
81 const AutocompleteInput& input, | 80 const base::string16& input, |
82 const AutocompleteInput& fixed_up_input, | 81 const base::string16& fixed_up_input, |
83 const bool allow_www_prefix_without_scheme, | 82 const bool allow_www_prefix_without_scheme, |
84 const base::string16& text) { | 83 const base::string16& text) { |
85 const URLPrefix* best_prefix = allow_www_prefix_without_scheme ? | 84 const URLPrefix* best_prefix = allow_www_prefix_without_scheme ? |
86 BestURLPrefixWithWWWCase(text, input.text()) : | 85 BestURLPrefixWithWWWCase(text, input) : BestURLPrefix(text, input); |
87 BestURLPrefix(text, input.text()); | 86 const base::string16* matching_string = &input; |
88 const base::string16* matching_string = &input.text(); | |
89 // If we failed to find a best_prefix initially, try again using a fixed-up | 87 // If we failed to find a best_prefix initially, try again using a fixed-up |
90 // version of the user input. This is especially useful to get about: URLs | 88 // version of the user input. This is especially useful to get about: URLs |
91 // to inline against chrome:// shortcuts. (about: URLs are fixed up to the | 89 // to inline against chrome:// shortcuts. (about: URLs are fixed up to the |
92 // chrome:// scheme.) | 90 // chrome:// scheme.) |
93 if ((best_prefix == NULL) && !fixed_up_input.text().empty() && | 91 if (!best_prefix && !fixed_up_input.empty() && (fixed_up_input != input)) { |
94 (fixed_up_input.text() != input.text())) { | |
95 best_prefix = allow_www_prefix_without_scheme ? | 92 best_prefix = allow_www_prefix_without_scheme ? |
96 BestURLPrefixWithWWWCase(text, fixed_up_input.text()) : | 93 BestURLPrefixWithWWWCase(text, fixed_up_input) : |
97 BestURLPrefix(text, fixed_up_input.text()); | 94 BestURLPrefix(text, fixed_up_input); |
98 matching_string = &fixed_up_input.text(); | 95 matching_string = &fixed_up_input; |
99 } | 96 } |
100 return (best_prefix != NULL) ? | 97 return (best_prefix != NULL) ? |
101 (best_prefix->prefix.length() + matching_string->length()) : | 98 (best_prefix->prefix.length() + matching_string->length()) : |
102 base::string16::npos; | 99 base::string16::npos; |
103 } | 100 } |
OLD | NEW |