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

Side by Side Diff: chrome/browser/autofill/autocomplete_history_manager.cc

Issue 11000016: Move forms/ out of webkit/. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 8 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/autofill/autocomplete_history_manager.h" 5 #include "chrome/browser/autofill/autocomplete_history_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/api/prefs/pref_service_base.h" 12 #include "chrome/browser/api/prefs/pref_service_base.h"
13 #include "chrome/browser/autofill/autofill_external_delegate.h" 13 #include "chrome/browser/autofill/autofill_external_delegate.h"
14 #include "chrome/browser/autofill/credit_card.h" 14 #include "chrome/browser/autofill/credit_card.h"
15 #include "chrome/common/autofill_messages.h" 15 #include "chrome/common/autofill_messages.h"
16 #include "chrome/common/form_data.h"
16 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 #include "webkit/forms/form_data.h"
21 21
22 using base::StringPiece16; 22 using base::StringPiece16;
23 using content::BrowserContext; 23 using content::BrowserContext;
24 using content::WebContents; 24 using content::WebContents;
25 using webkit::forms::FormData;
26 using webkit::forms::FormField;
27 25
28 DEFINE_WEB_CONTENTS_USER_DATA_KEY(AutocompleteHistoryManager) 26 DEFINE_WEB_CONTENTS_USER_DATA_KEY(AutocompleteHistoryManager)
29 27
30 namespace { 28 namespace {
31 29
32 // Limit on the number of suggestions to appear in the pop-up menu under an 30 // Limit on the number of suggestions to appear in the pop-up menu under an
33 // text input element in a form. 31 // text input element in a form.
34 const int kMaxAutocompleteMenuItems = 6; 32 const int kMaxAutocompleteMenuItems = 6;
35 33
36 // The separator characters for SSNs. 34 // The separator characters for SSNs.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 if (!base::StringToInt(StringPiece16(number_string.begin() + 5, 89 if (!base::StringToInt(StringPiece16(number_string.begin() + 5,
92 number_string.begin() + 9), 90 number_string.begin() + 9),
93 &serial) 91 &serial)
94 || serial == 0) { 92 || serial == 0) {
95 return false; 93 return false;
96 } 94 }
97 95
98 return true; 96 return true;
99 } 97 }
100 98
101 bool IsTextField(const FormField& field) { 99 bool IsTextField(const FormFieldData& field) {
102 return 100 return
103 field.form_control_type == ASCIIToUTF16("text") || 101 field.form_control_type == ASCIIToUTF16("text") ||
104 field.form_control_type == ASCIIToUTF16("search") || 102 field.form_control_type == ASCIIToUTF16("search") ||
105 field.form_control_type == ASCIIToUTF16("tel") || 103 field.form_control_type == ASCIIToUTF16("tel") ||
106 field.form_control_type == ASCIIToUTF16("url") || 104 field.form_control_type == ASCIIToUTF16("url") ||
107 field.form_control_type == ASCIIToUTF16("email") || 105 field.form_control_type == ASCIIToUTF16("email") ||
108 field.form_control_type == ASCIIToUTF16("text"); 106 field.form_control_type == ASCIIToUTF16("text");
109 } 107 }
110 108
111 } // namespace 109 } // namespace
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // Don't save data that was submitted through JavaScript. 200 // Don't save data that was submitted through JavaScript.
203 if (!form.user_submitted) 201 if (!form.user_submitted)
204 return; 202 return;
205 203
206 // We put the following restriction on stored FormFields: 204 // We put the following restriction on stored FormFields:
207 // - non-empty name 205 // - non-empty name
208 // - non-empty value 206 // - non-empty value
209 // - text field 207 // - text field
210 // - value is not a credit card number 208 // - value is not a credit card number
211 // - value is not a SSN 209 // - value is not a SSN
212 std::vector<FormField> values; 210 std::vector<FormFieldData> values;
213 for (std::vector<FormField>::const_iterator iter = 211 for (std::vector<FormFieldData>::const_iterator iter =
214 form.fields.begin(); 212 form.fields.begin();
215 iter != form.fields.end(); ++iter) { 213 iter != form.fields.end(); ++iter) {
216 if (!iter->value.empty() && 214 if (!iter->value.empty() &&
217 !iter->name.empty() && 215 !iter->name.empty() &&
218 IsTextField(*iter) && 216 IsTextField(*iter) &&
219 !CreditCard::IsValidCreditCardNumber(iter->value) && 217 !CreditCard::IsValidCreditCardNumber(iter->value) &&
220 !IsSSN(iter->value)) { 218 !IsSSN(iter->value)) {
221 values.push_back(*iter); 219 values.push_back(*iter);
222 } 220 }
223 } 221 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 autofill_icons_, 297 autofill_icons_,
300 autofill_unique_ids_)); 298 autofill_unique_ids_));
301 } 299 }
302 300
303 query_id_ = 0; 301 query_id_ = 0;
304 autofill_values_.clear(); 302 autofill_values_.clear();
305 autofill_labels_.clear(); 303 autofill_labels_.clear();
306 autofill_icons_.clear(); 304 autofill_icons_.clear();
307 autofill_unique_ids_.clear(); 305 autofill_unique_ids_.clear();
308 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698