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

Side by Side Diff: components/autofill/core/browser/autocomplete_history_manager.cc

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses Vaclav's inputs. Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/autocomplete_history_manager.h" 5 #include "components/autofill/core/browser/autocomplete_history_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "components/autofill/core/browser/autofill_client.h" 14 #include "components/autofill/core/browser/autofill_client.h"
14 #include "components/autofill/core/browser/autofill_driver.h" 15 #include "components/autofill/core/browser/autofill_driver.h"
15 #include "components/autofill/core/browser/autofill_external_delegate.h" 16 #include "components/autofill/core/browser/autofill_external_delegate.h"
16 #include "components/autofill/core/browser/validation.h" 17 #include "components/autofill/core/browser/validation.h"
17 #include "components/autofill/core/common/autofill_pref_names.h" 18 #include "components/autofill/core/common/autofill_pref_names.h"
19 #include "components/autofill/core/common/autofill_util.h"
18 #include "components/autofill/core/common/form_data.h" 20 #include "components/autofill/core/common/form_data.h"
19 21
20 namespace autofill { 22 namespace autofill {
21 namespace { 23 namespace {
22 24
23 // Limit on the number of suggestions to appear in the pop-up menu under an 25 // Limit on the number of suggestions to appear in the pop-up menu under an
24 // text input element in a form. 26 // text input element in a form.
25 const int kMaxAutocompleteMenuItems = 6; 27 const int kMaxAutocompleteMenuItems = 6;
26 28
27 bool IsTextField(const FormFieldData& field) { 29 bool IsTextField(const FormFieldData& field) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // See http://crbug.com/68783. 76 // See http://crbug.com/68783.
75 if (!result) { 77 if (!result) {
76 SendSuggestions(NULL); 78 SendSuggestions(NULL);
77 return; 79 return;
78 } 80 }
79 81
80 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); 82 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType());
81 const WDResult<std::vector<base::string16> >* autofill_result = 83 const WDResult<std::vector<base::string16> >* autofill_result =
82 static_cast<const WDResult<std::vector<base::string16> >*>(result); 84 static_cast<const WDResult<std::vector<base::string16> >*>(result);
83 std::vector<base::string16> suggestions = autofill_result->GetValue(); 85 std::vector<base::string16> suggestions = autofill_result->GetValue();
84 SendSuggestions(&suggestions); 86
87 if (!IsFeatureSubstringMatchEnabled() || user_input_.empty()) {
88 SendSuggestions(&suggestions);
89 } else {
90 std::vector<base::string16> prefix_suggestions;
91 std::vector<base::string16> substring_suggestions;
92 for (base::string16 suggestion : suggestions) {
93 // Populate all suggestions with prefix matched followed by substring
94 // matched.
95 if (StartsWith(suggestion, user_input_, false)) {
96 prefix_suggestions.push_back(suggestion);
97 } else if (IsContentsPrefixOfSuggestionToken(suggestion, user_input_,
98 CASE_IGNORE)) {
99 substring_suggestions.push_back(suggestion);
100 }
101 }
102
103 // Now append substring matched suggestions to the prefix matched
104 // suggestion list.
105 for (base::string16 substring_match : substring_suggestions) {
106 prefix_suggestions.push_back(substring_match);
107 }
108
109 SendSuggestions(&prefix_suggestions);
110 }
85 } 111 }
86 112
87 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( 113 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
88 int query_id, 114 int query_id,
89 const base::string16& name, 115 const base::string16& name,
90 const base::string16& prefix, 116 const base::string16& prefix,
91 const std::string& form_control_type, 117 const std::string& form_control_type,
92 const std::vector<Suggestion>& suggestions) { 118 const std::vector<Suggestion>& suggestions) {
93 CancelPendingQuery(); 119 CancelPendingQuery();
94 120
95 query_id_ = query_id; 121 query_id_ = query_id;
96 autofill_suggestions_ = suggestions; 122 autofill_suggestions_ = suggestions;
97 if (!autofill_client_->IsAutocompleteEnabled() || 123 if (!autofill_client_->IsAutocompleteEnabled() ||
98 form_control_type == "textarea") { 124 form_control_type == "textarea") {
99 SendSuggestions(NULL); 125 SendSuggestions(NULL);
100 return; 126 return;
101 } 127 }
102 128
103 if (database_.get()) { 129 if (database_.get()) {
130 user_input_ = prefix;
104 pending_query_handle_ = database_->GetFormValuesForElementName( 131 pending_query_handle_ = database_->GetFormValuesForElementName(
105 name, prefix, kMaxAutocompleteMenuItems, this); 132 name, IsFeatureSubstringMatchEnabled() ? base::string16() : prefix,
133 kMaxAutocompleteMenuItems, this);
106 } 134 }
107 } 135 }
108 136
109 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { 137 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
110 if (!autofill_client_->IsAutocompleteEnabled()) 138 if (!autofill_client_->IsAutocompleteEnabled())
111 return; 139 return;
112 140
113 if (driver_->IsOffTheRecord()) 141 if (driver_->IsOffTheRecord())
114 return; 142 return;
115 143
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 208 }
181 } 209 }
182 210
183 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_); 211 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_);
184 212
185 query_id_ = 0; 213 query_id_ = 0;
186 autofill_suggestions_.clear(); 214 autofill_suggestions_.clear();
187 } 215 }
188 216
189 } // namespace autofill 217 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698