Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Unified Diff: chrome/browser/autocomplete/bookmark_provider.cc

Issue 229733004: Omnibox: Make Bookmarks Set Inline_Autocompletion (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixup user input Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autocomplete/bookmark_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/bookmark_provider.cc
diff --git a/chrome/browser/autocomplete/bookmark_provider.cc b/chrome/browser/autocomplete/bookmark_provider.cc
index 73d17370919e2185c555b1a12dc9a25a1baf6e71..7a3de804fbdf2ba499047be641905b51bdfd8c34 100644
--- a/chrome/browser/autocomplete/bookmark_provider.cc
+++ b/chrome/browser/autocomplete/bookmark_provider.cc
@@ -9,7 +9,9 @@
#include <vector>
#include "base/prefs/pref_service.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_result.h"
+#include "chrome/browser/autocomplete/url_prefix.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/bookmark_title_match.h"
@@ -39,14 +41,9 @@ void BookmarkProvider::Start(const AutocompleteInput& input,
return;
matches_.clear();
- // Short-circuit any matching when inline autocompletion is disabled and
- // we're looking for BEST_MATCH because none of the BookmarkProvider's
- // matches can score high enough to qualify.
if (input.text().empty() ||
((input.type() != AutocompleteInput::UNKNOWN) &&
- (input.type() != AutocompleteInput::QUERY)) ||
- ((input.matches_requested() == AutocompleteInput::BEST_MATCH) &&
- input.prevent_inline_autocomplete()))
+ (input.type() != AutocompleteInput::QUERY)))
return;
DoAutocomplete(input,
@@ -94,11 +91,16 @@ void BookmarkProvider::DoAutocomplete(const AutocompleteInput& input,
&matches);
if (matches.empty())
return; // There were no matches.
+ AutocompleteInput fixed_up_input;
+ // If the input fails to get fixed up, pretend the fixed up version is the
+ // original.
+ if (!FixupUserInput(&fixed_up_input))
+ fixed_up_input = input;
for (TitleMatches::const_iterator i = matches.begin(); i != matches.end();
++i) {
// Create and score the AutocompleteMatch. If its score is 0 then the
// match is discarded.
- AutocompleteMatch match(TitleMatchToACMatch(*i));
+ AutocompleteMatch match(TitleMatchToACMatch(input, fixed_up_input, *i));
if (match.relevance > 0)
matches_.push_back(match);
}
@@ -153,6 +155,8 @@ class ScoringFunctor {
} // namespace
AutocompleteMatch BookmarkProvider::TitleMatchToACMatch(
+ const AutocompleteInput& input,
+ const AutocompleteInput& fixed_up_input,
const BookmarkTitleMatch& title_match) {
// The AutocompleteMatch we construct is non-deletable because the only
// way to support this would be to delete the underlying bookmark, which is
@@ -161,16 +165,50 @@ AutocompleteMatch BookmarkProvider::TitleMatchToACMatch(
AutocompleteMatchType::BOOKMARK_TITLE);
const base::string16& title(title_match.node->GetTitle());
DCHECK(!title.empty());
+
+ // Determine |inline_autocomplete_offset|.
Peter Kasting 2014/04/09 00:53:32 This whole block looks suspiciously similar to wha
Mark P 2014/04/09 02:44:42 I thought about this as I was transferred code her
Mark P 2014/04/09 20:21:41 I found a bug this code, causing me to change my m
const GURL& url(title_match.node->url());
+ const base::string16& url_utf16 = base::UTF8ToUTF16(url.spec());
+ const URLPrefix* best_prefix = URLPrefix::BestURLPrefix(url_utf16,
+ input.text());
+ base::string16 matching_string = input.text();
+ // If we failed to find a best_prefix initially, try again using a fixed-up
+ // version of the user input. This is especially useful to get about: URLs
+ // to inline against chrome:// URLs. (about: URLs are fixed up to the
+ // chrome:// scheme.)
+ if ((best_prefix == NULL) && !fixed_up_input.text().empty() &&
+ (fixed_up_input.text() != input.text())) {
+ best_prefix = URLPrefix::BestURLPrefix(url_utf16, fixed_up_input.text());
+ matching_string = fixed_up_input.text();
+ }
+ size_t inline_autocomplete_offset =
+ (best_prefix != NULL) ?
+ (best_prefix->prefix.length() + matching_string.length()) :
+ base::string16::npos;
+
match.destination_url = url;
+ const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()) &&
+ ((best_prefix != NULL) || (inline_autocomplete_offset != 0));
Peter Kasting 2014/04/09 00:53:32 I don't think I understand this conditional. Woul
Mark P 2014/04/09 02:44:42 Oops, you're right. It should be best_prefix == N
match.contents = net::FormatUrl(url, languages_,
- net::kFormatUrlOmitAll & net::kFormatUrlOmitHTTP,
- net::UnescapeRule::SPACES, NULL, NULL, NULL);
+ net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP),
+ net::UnescapeRule::SPACES, NULL, NULL, &inline_autocomplete_offset);
match.contents_class.push_back(
ACMatchClassification(0, ACMatchClassification::URL));
match.fill_into_edit =
AutocompleteInput::FormattedStringWithEquivalentMeaning(url,
match.contents);
+ if (inline_autocomplete_offset != base::string16::npos) {
+ // |inline_autocomplete_offset| may be beyond the end of the
+ // |fill_into_edit| if the user has typed an URL with a scheme and the
+ // last character typed is a slash. That slash is removed by the
+ // FormatURLWithOffsets call above.
+ if (inline_autocomplete_offset < match.fill_into_edit.length()) {
+ match.inline_autocompletion =
+ match.fill_into_edit.substr(inline_autocomplete_offset);
+ }
+ match.allowed_to_be_default_match = match.inline_autocompletion.empty() ||
+ !input.prevent_inline_autocomplete();
+ }
match.description = title;
match.description_class =
ClassificationsFromMatch(title_match.match_positions,
« no previous file with comments | « chrome/browser/autocomplete/bookmark_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698