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/shortcuts_provider.h" | 5 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "chrome/browser/autocomplete/autocomplete_input.h" | 21 #include "chrome/browser/autocomplete/autocomplete_input.h" |
22 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 22 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
23 #include "chrome/browser/autocomplete/autocomplete_result.h" | 23 #include "chrome/browser/autocomplete/autocomplete_result.h" |
24 #include "chrome/browser/autocomplete/url_prefix.h" | 24 #include "chrome/browser/autocomplete/url_prefix.h" |
25 #include "chrome/browser/history/history_notifications.h" | 25 #include "chrome/browser/history/history_notifications.h" |
26 #include "chrome/browser/history/history_service.h" | 26 #include "chrome/browser/history/history_service.h" |
27 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
28 #include "chrome/browser/history/shortcuts_backend_factory.h" | 28 #include "chrome/browser/history/shortcuts_backend_factory.h" |
29 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 29 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/common/net/url_fixer_upper.h" | |
31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
33 #include "url/url_parse.h" | 34 #include "url/url_parse.h" |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
37 class DestinationURLEqualsURL { | 38 class DestinationURLEqualsURL { |
38 public: | 39 public: |
39 explicit DestinationURLEqualsURL(const GURL& url) : url_(url) {} | 40 explicit DestinationURLEqualsURL(const GURL& url) : url_(url) {} |
40 bool operator()(const AutocompleteMatch& match) const { | 41 bool operator()(const AutocompleteMatch& match) const { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 // the default list didn't have a match or the default list's match | 222 // the default list didn't have a match or the default list's match |
222 // was shorter than it could've been. | 223 // was shorter than it could've been. |
223 if (URLPrefix::PrefixMatch(www_prefix, match.fill_into_edit, term_string)) | 224 if (URLPrefix::PrefixMatch(www_prefix, match.fill_into_edit, term_string)) |
224 best_prefix = &www_prefix; | 225 best_prefix = &www_prefix; |
225 } | 226 } |
226 if (best_prefix != NULL) { | 227 if (best_prefix != NULL) { |
227 match.inline_autocompletion = match.fill_into_edit.substr( | 228 match.inline_autocompletion = match.fill_into_edit.substr( |
228 best_prefix->prefix.length() + term_string.length()); | 229 best_prefix->prefix.length() + term_string.length()); |
229 match.allowed_to_be_default_match = | 230 match.allowed_to_be_default_match = |
230 !prevent_inline_autocomplete || match.inline_autocompletion.empty(); | 231 !prevent_inline_autocomplete || match.inline_autocompletion.empty(); |
232 } else { | |
233 // Special case to allow URL-like inputs that need to be fixed up to | |
234 // inline against URL shortcuts. This is especially userful to get | |
Peter Kasting
2013/12/17 19:56:49
Nit: userful -> useful
Mark P
2013/12/17 20:36:18
Done.
| |
235 // about: URLs to inline against chrome:// shortcuts. (about: URLs | |
236 // are fixed up to the chrome:// scheme.) | |
Peter Kasting
2013/12/17 19:56:49
What about if the fill_into_edit is about:foo and
Mark P
2013/12/17 20:36:18
This will not happen. There's no way to select a
| |
237 GURL url = | |
238 URLFixerUpper::FixupURL(UTF16ToUTF8(term_string), std::string()); | |
239 if (url.is_valid()) { | |
Mark P
2013/12/17 19:29:02
Alternatively, do I want to skip is_valid() and si
Peter Kasting
2013/12/17 19:56:49
I think so. "about:" might get fixed to "chrome:/
Mark P
2013/12/17 20:36:18
Done. I thought I tested this case but apparently
| |
240 base::string16 url_spec_utf16 = ASCIIToUTF16(url.spec()); | |
241 if ((term_string[term_string.length() - 1] != char16('/')) && | |
242 (url_spec_utf16[url_spec_utf16.length() - 1] == char16('/'))) { | |
243 // If the url.spec() added a trailing '/' that wasn't in the input | |
244 // (e.g., at the end of a hostname in a URL such as chrome://version), | |
245 // remove it for the purposes of calculating whether this can be | |
246 // the default match. (Fill_into_edit may be missing the trailing | |
Peter Kasting
2013/12/17 19:56:49
Nit: Fill -> fill
Mark P
2013/12/17 20:36:18
Done.
| |
247 // slash in some cases.) | |
248 url_spec_utf16 = | |
249 url_spec_utf16.substr(0, url_spec_utf16.length() - 1); | |
250 } | |
251 if (StartsWith(match.fill_into_edit, url_spec_utf16, false)) { | |
252 match.inline_autocompletion = match.fill_into_edit.substr( | |
253 url_spec_utf16.length()); | |
254 match.allowed_to_be_default_match = !prevent_inline_autocomplete || | |
255 match.inline_autocompletion.empty(); | |
256 } | |
257 } | |
Mark P
2013/12/17 19:29:02
I think this strategy works but I'm not positive.
Peter Kasting
2013/12/17 19:56:49
Check i18n domain names and escaped versus unescap
Mark P
2013/12/17 20:36:18
Seems to work. I can only manage to get shortcut'
| |
231 } | 258 } |
232 } | 259 } |
233 | 260 |
234 // Try to mark pieces of the contents and description as matches if they | 261 // Try to mark pieces of the contents and description as matches if they |
235 // appear in |term_string|. | 262 // appear in |term_string|. |
236 WordMap terms_map(CreateWordMapForString(term_string)); | 263 WordMap terms_map(CreateWordMapForString(term_string)); |
237 if (!terms_map.empty()) { | 264 if (!terms_map.empty()) { |
238 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, | 265 match.contents_class = ClassifyAllMatchesInString(term_string, terms_map, |
239 match.contents, match.contents_class); | 266 match.contents, match.contents_class); |
240 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, | 267 match.description_class = ClassifyAllMatchesInString(term_string, terms_map, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. | 419 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. |
393 const double kMaxDecaySpeedDivisor = 5.0; | 420 const double kMaxDecaySpeedDivisor = 5.0; |
394 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; | 421 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; |
395 double decay_divisor = std::min(kMaxDecaySpeedDivisor, | 422 double decay_divisor = std::min(kMaxDecaySpeedDivisor, |
396 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / | 423 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / |
397 kNumUsesPerDecaySpeedDivisorIncrement); | 424 kNumUsesPerDecaySpeedDivisorIncrement); |
398 | 425 |
399 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + | 426 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + |
400 0.5); | 427 0.5); |
401 } | 428 } |
OLD | NEW |