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

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

Issue 71683003: Have AutofillManagerDelegate supply the AutofillWebDataService to core code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 7 years, 1 month 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/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "components/autofill/core/browser/autofill_driver.h" 12 #include "components/autofill/core/browser/autofill_driver.h"
13 #include "components/autofill/core/browser/autofill_external_delegate.h" 13 #include "components/autofill/core/browser/autofill_external_delegate.h"
14 #include "components/autofill/core/browser/autofill_manager_delegate.h" 14 #include "components/autofill/core/browser/autofill_manager_delegate.h"
15 #include "components/autofill/core/browser/validation.h" 15 #include "components/autofill/core/browser/validation.h"
16 #include "components/autofill/core/common/autofill_messages.h" 16 #include "components/autofill/core/common/autofill_messages.h"
17 #include "components/autofill/core/common/autofill_pref_names.h" 17 #include "components/autofill/core/common/autofill_pref_names.h"
18 #include "components/autofill/core/common/form_data.h" 18 #include "components/autofill/core/common/form_data.h"
19 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/web_contents.h"
21
22 using content::BrowserContext;
23 using content::WebContents;
24 19
25 namespace autofill { 20 namespace autofill {
26 namespace { 21 namespace {
27 22
28 // Limit on the number of suggestions to appear in the pop-up menu under an 23 // Limit on the number of suggestions to appear in the pop-up menu under an
29 // text input element in a form. 24 // text input element in a form.
30 const int kMaxAutocompleteMenuItems = 6; 25 const int kMaxAutocompleteMenuItems = 6;
31 26
32 bool IsTextField(const FormFieldData& field) { 27 bool IsTextField(const FormFieldData& field) {
33 return 28 return
34 field.form_control_type == "text" || 29 field.form_control_type == "text" ||
35 field.form_control_type == "search" || 30 field.form_control_type == "search" ||
36 field.form_control_type == "tel" || 31 field.form_control_type == "tel" ||
37 field.form_control_type == "url" || 32 field.form_control_type == "url" ||
38 field.form_control_type == "email"; 33 field.form_control_type == "email";
39 } 34 }
40 35
41 } // namespace 36 } // namespace
42 37
43 AutocompleteHistoryManager::AutocompleteHistoryManager( 38 AutocompleteHistoryManager::AutocompleteHistoryManager(
44 AutofillDriver* driver, 39 AutofillDriver* driver,
45 AutofillManagerDelegate* manager_delegate) 40 AutofillManagerDelegate* manager_delegate)
46 : browser_context_(driver->GetWebContents()->GetBrowserContext()), 41 : driver_(driver),
47 driver_(driver), 42 database_(manager_delegate->GetDatabase()),
48 autofill_data_(
49 AutofillWebDataService::FromBrowserContext(browser_context_)),
50 pending_query_handle_(0), 43 pending_query_handle_(0),
51 query_id_(0), 44 query_id_(0),
52 external_delegate_(NULL), 45 external_delegate_(NULL),
53 manager_delegate_(manager_delegate), 46 manager_delegate_(manager_delegate),
54 send_ipc_(true) { 47 send_ipc_(true) {
55 DCHECK(manager_delegate_); 48 DCHECK(manager_delegate_);
56 } 49 }
57 50
58 AutocompleteHistoryManager::~AutocompleteHistoryManager() { 51 AutocompleteHistoryManager::~AutocompleteHistoryManager() {
59 CancelPendingQuery(); 52 CancelPendingQuery();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 query_id_ = query_id; 92 query_id_ = query_id;
100 autofill_values_ = autofill_values; 93 autofill_values_ = autofill_values;
101 autofill_labels_ = autofill_labels; 94 autofill_labels_ = autofill_labels;
102 autofill_icons_ = autofill_icons; 95 autofill_icons_ = autofill_icons;
103 autofill_unique_ids_ = autofill_unique_ids; 96 autofill_unique_ids_ = autofill_unique_ids;
104 if (!manager_delegate_->IsAutocompleteEnabled()) { 97 if (!manager_delegate_->IsAutocompleteEnabled()) {
105 SendSuggestions(NULL); 98 SendSuggestions(NULL);
106 return; 99 return;
107 } 100 }
108 101
109 if (autofill_data_.get()) { 102 if (database_.get()) {
110 pending_query_handle_ = autofill_data_->GetFormValuesForElementName( 103 pending_query_handle_ = database_->GetFormValuesForElementName(
111 name, prefix, kMaxAutocompleteMenuItems, this); 104 name, prefix, kMaxAutocompleteMenuItems, this);
112 } 105 }
113 } 106 }
114 107
115 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { 108 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
116 if (!manager_delegate_->IsAutocompleteEnabled()) 109 if (!manager_delegate_->IsAutocompleteEnabled())
117 return; 110 return;
118 111
119 if (driver_->IsOffTheRecord()) 112 if (driver_->IsOffTheRecord())
120 return; 113 return;
(...skipping 14 matching lines...) Expand all
135 iter != form.fields.end(); ++iter) { 128 iter != form.fields.end(); ++iter) {
136 if (!iter->value.empty() && 129 if (!iter->value.empty() &&
137 !iter->name.empty() && 130 !iter->name.empty() &&
138 IsTextField(*iter) && 131 IsTextField(*iter) &&
139 !autofill::IsValidCreditCardNumber(iter->value) && 132 !autofill::IsValidCreditCardNumber(iter->value) &&
140 !autofill::IsSSN(iter->value)) { 133 !autofill::IsSSN(iter->value)) {
141 values.push_back(*iter); 134 values.push_back(*iter);
142 } 135 }
143 } 136 }
144 137
145 if (!values.empty() && autofill_data_.get()) 138 if (!values.empty() && database_.get())
146 autofill_data_->AddFormFields(values); 139 database_->AddFormFields(values);
147 } 140 }
148 141
149 void AutocompleteHistoryManager::OnRemoveAutocompleteEntry( 142 void AutocompleteHistoryManager::OnRemoveAutocompleteEntry(
150 const base::string16& name, const base::string16& value) { 143 const base::string16& name, const base::string16& value) {
151 if (autofill_data_.get()) 144 if (database_.get())
152 autofill_data_->RemoveFormValueForElementName(name, value); 145 database_->RemoveFormValueForElementName(name, value);
153 } 146 }
154 147
155 void AutocompleteHistoryManager::SetExternalDelegate( 148 void AutocompleteHistoryManager::SetExternalDelegate(
156 AutofillExternalDelegate* delegate) { 149 AutofillExternalDelegate* delegate) {
157 external_delegate_ = delegate; 150 external_delegate_ = delegate;
158 } 151 }
159 152
160 void AutocompleteHistoryManager::CancelPendingQuery() { 153 void AutocompleteHistoryManager::CancelPendingQuery() {
161 if (pending_query_handle_) { 154 if (pending_query_handle_) {
162 if (autofill_data_.get()) 155 if (database_.get())
163 autofill_data_->CancelRequest(pending_query_handle_); 156 database_->CancelRequest(pending_query_handle_);
164 pending_query_handle_ = 0; 157 pending_query_handle_ = 0;
165 } 158 }
166 } 159 }
167 160
168 void AutocompleteHistoryManager::SendSuggestions( 161 void AutocompleteHistoryManager::SendSuggestions(
169 const std::vector<base::string16>* suggestions) { 162 const std::vector<base::string16>* suggestions) {
170 if (suggestions) { 163 if (suggestions) {
171 // Combine Autofill and Autocomplete values into values and labels. 164 // Combine Autofill and Autocomplete values into values and labels.
172 for (size_t i = 0; i < suggestions->size(); ++i) { 165 for (size_t i = 0; i < suggestions->size(); ++i) {
173 bool unique = true; 166 bool unique = true;
(...skipping 21 matching lines...) Expand all
195 autofill_unique_ids_); 188 autofill_unique_ids_);
196 189
197 query_id_ = 0; 190 query_id_ = 0;
198 autofill_values_.clear(); 191 autofill_values_.clear();
199 autofill_labels_.clear(); 192 autofill_labels_.clear();
200 autofill_icons_.clear(); 193 autofill_icons_.clear();
201 autofill_unique_ids_.clear(); 194 autofill_unique_ids_.clear();
202 } 195 }
203 196
204 } // namespace autofill 197 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698