| Index: chrome/browser/history/chrome_scored_history_match_client.cc
|
| diff --git a/chrome/browser/history/chrome_scored_history_match_client.cc b/chrome/browser/history/chrome_scored_history_match_client.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..52366efc99c1a34bb2a3dac9ad76f7f335b852ea
|
| --- /dev/null
|
| +++ b/chrome/browser/history/chrome_scored_history_match_client.cc
|
| @@ -0,0 +1,100 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/history/chrome_scored_history_match_client.h"
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "components/bookmarks/browser/bookmark_model.h"
|
| +#include "components/bookmarks/browser/bookmark_utils.h"
|
| +#include "components/omnibox/omnibox_field_trial.h"
|
| +#include "components/omnibox/url_prefix.h"
|
| +
|
| +ChromeScoredHistoryMatchClient::ChromeScoredHistoryMatchClient(
|
| + bookmarks::BookmarkModel* bookmark_model)
|
| + : bookmark_model_(bookmark_model) {
|
| +}
|
| +
|
| +ChromeScoredHistoryMatchClient::~ChromeScoredHistoryMatchClient() {
|
| +}
|
| +
|
| +bool ChromeScoredHistoryMatchClient::IsBoomarked(const GURL& url) const {
|
| + return bookmark_model_ && bookmark_model_->IsBookmarked(url);
|
| +}
|
| +
|
| +int ChromeScoredHistoryMatchClient::BookmarkValue() const {
|
| + return OmniboxFieldTrial::HQPBookmarkValue();
|
| +}
|
| +
|
| +bool ChromeScoredHistoryMatchClient::AllowTldMatches() const {
|
| + return OmniboxFieldTrial::HQPAllowMatchInTLDValue();
|
| +}
|
| +
|
| +bool ChromeScoredHistoryMatchClient::AllowSchemeMatches() const {
|
| + return OmniboxFieldTrial::HQPAllowMatchInSchemeValue();
|
| +}
|
| +
|
| +bool ChromeScoredHistoryMatchClient::CanInlineAutocompleteMatch(
|
| + const GURL& url,
|
| + const base::string16& term,
|
| + bool* innermost_match) const {
|
| + // We can inline autocomplete a match if:
|
| + // 1) there is only one search term
|
| + // 2) AND the match begins immediately after one of the prefixes in
|
| + // URLPrefix such as http://www and https:// (note that one of these
|
| + // is the empty prefix, for cases where the user has typed the scheme)
|
| + // 3) AND the search string does not end in whitespace (making it look to
|
| + // the IMUI as though there is a single search term when actually there
|
| + // is a second, empty term).
|
| + // |best_inlineable_prefix| stores the inlineable prefix computed in
|
| + // clause (2) or null if no such prefix exists. (The URL is not inlineable.)
|
| + // Note that using the best prefix here means that when multiple
|
| + // prefixes match, we'll choose to inline following the longest one.
|
| + // For a URL like "http://www.washingtonmutual.com", this means
|
| + // typing "w" will inline "ashington..." instead of "ww.washington...".
|
| + base::string16 url_spec = base::UTF8ToUTF16(url.spec());
|
| + const URLPrefix* best_inlineable_prefix =
|
| + URLPrefix::BestURLPrefix(url_spec, term);
|
| + if (best_inlineable_prefix && innermost_match) {
|
| + // Initialize innermost_match.
|
| + // The idea here is that matches that occur in the scheme or
|
| + // "www." are worse than matches which don't. For the URLs
|
| + // "http://www.google.com" and "http://wellsfargo.com", we want
|
| + // the omnibox input "w" to cause the latter URL to rank higher
|
| + // than the former. Note that this is not the same as checking
|
| + // whether one match's inlinable prefix has more components than
|
| + // the other match's, since in this example, both matches would
|
| + // have an inlinable prefix of "http://", which is one component.
|
| + //
|
| + // Instead, we look for the overall best (i.e., most components)
|
| + // prefix of the current URL, and then check whether the inlinable
|
| + // prefix has that many components. If it does, this is an
|
| + // "innermost" match, and should be boosted. In the example
|
| + // above, the best prefixes for the two URLs have two and one
|
| + // components respectively, while the inlinable prefixes each
|
| + // have one component; this means the first match is not innermost
|
| + // and the second match is innermost, resulting in us boosting the
|
| + // second match.
|
| + //
|
| + // Now, the code that implements this.
|
| + // The deepest prefix for this URL regardless of where the match is.
|
| + const URLPrefix* best_prefix =
|
| + URLPrefix::BestURLPrefix(url_spec, base::string16());
|
| + DCHECK(best_prefix);
|
| + // If the URL is inlineable, we must have a match. Note the prefix that
|
| + // makes it inlineable may be empty.
|
| + *innermost_match = (best_inlineable_prefix->num_components ==
|
| + best_prefix->num_components);
|
| + }
|
| + return best_inlineable_prefix != nullptr;
|
| +}
|
| +
|
| +base::string16 ChromeScoredHistoryMatchClient::CleanUpUrlAndTitleForMatching(
|
| + const GURL& url,
|
| + const std::string& languages,
|
| + base::OffsetAdjuster::Adjustments* adjustments,
|
| + base::string16* title) const {
|
| + if (title)
|
| + *title = bookmarks::CleanUpTitleForMatching(*title);
|
| + return bookmarks::CleanUpUrlForMatching(url, languages, adjustments);
|
| +}
|
|
|