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

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: Incorporates Evan's review comments. Created 5 years, 7 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() || pending_query_prefix_.empty()) {
88 SendSuggestions(&suggestions);
89 } else {
90 std::vector<base::string16> preferred_suggestions;
91 for (base::string16 suggestion : suggestions) {
92 if (StartsWith(suggestion, pending_query_prefix_, false) ||
93 IsContentsPrefixOfSuggestionToken(suggestion, pending_query_prefix_,
94 false)) {
95 preferred_suggestions.push_back(suggestion);
96 }
97 }
98
99 SendSuggestions(&preferred_suggestions);
100 }
85 } 101 }
86 102
87 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions( 103 void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
88 int query_id, 104 int query_id,
89 const base::string16& name, 105 const base::string16& name,
90 const base::string16& prefix, 106 const base::string16& prefix,
91 const std::string& form_control_type, 107 const std::string& form_control_type,
92 const std::vector<Suggestion>& suggestions) { 108 const std::vector<Suggestion>& suggestions) {
93 CancelPendingQuery(); 109 CancelPendingQuery();
94 110
95 query_id_ = query_id; 111 query_id_ = query_id;
96 autofill_suggestions_ = suggestions; 112 autofill_suggestions_ = suggestions;
97 if (!autofill_client_->IsAutocompleteEnabled() || 113 if (!autofill_client_->IsAutocompleteEnabled() ||
98 form_control_type == "textarea") { 114 form_control_type == "textarea") {
99 SendSuggestions(NULL); 115 SendSuggestions(NULL);
100 return; 116 return;
101 } 117 }
102 118
103 if (database_.get()) { 119 if (database_.get()) {
120 pending_query_prefix_ = prefix;
104 pending_query_handle_ = database_->GetFormValuesForElementName( 121 pending_query_handle_ = database_->GetFormValuesForElementName(
105 name, prefix, kMaxAutocompleteMenuItems, this); 122 name, IsFeatureSubstringMatchEnabled() ? base::string16() : prefix,
123 kMaxAutocompleteMenuItems, this);
106 } 124 }
107 } 125 }
108 126
109 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { 127 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
110 if (!autofill_client_->IsAutocompleteEnabled()) 128 if (!autofill_client_->IsAutocompleteEnabled())
111 return; 129 return;
112 130
113 if (driver_->IsOffTheRecord()) 131 if (driver_->IsOffTheRecord())
114 return; 132 return;
115 133
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 196 }
179 } 197 }
180 198
181 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_); 199 external_delegate_->OnSuggestionsReturned(query_id_, autofill_suggestions_);
182 200
183 query_id_ = 0; 201 query_id_ = 0;
184 autofill_suggestions_.clear(); 202 autofill_suggestions_.clear();
185 } 203 }
186 204
187 } // namespace autofill 205 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698