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

Side by Side Diff: components/autofill/browser/form_structure.cc

Issue 12721004: Autofill:Autocomplete: Enable autocheckout of input elements of type password. This will support fi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 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 | Annotate | Revision Log
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 "components/autofill/browser/form_structure.h" 5 #include "components/autofill/browser/form_structure.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 226 }
227 227
228 } // namespace 228 } // namespace
229 229
230 FormStructure::FormStructure(const FormData& form, 230 FormStructure::FormStructure(const FormData& form,
231 const std::string& autocheckout_url_prefix) 231 const std::string& autocheckout_url_prefix)
232 : form_name_(form.name), 232 : form_name_(form.name),
233 source_url_(form.origin), 233 source_url_(form.origin),
234 target_url_(form.action), 234 target_url_(form.action),
235 autofill_count_(0), 235 autofill_count_(0),
236 checkable_field_count_(0), 236 active_field_count_(0),
237 upload_required_(USE_UPLOAD_RATES), 237 upload_required_(USE_UPLOAD_RATES),
238 server_experiment_id_("no server response"), 238 server_experiment_id_("no server response"),
239 has_author_specified_types_(false), 239 has_author_specified_types_(false),
240 autocheckout_url_prefix_(autocheckout_url_prefix) { 240 autocheckout_url_prefix_(autocheckout_url_prefix) {
241 // Copy the form fields. 241 // Copy the form fields.
242 std::map<string16, size_t> unique_names; 242 std::map<string16, size_t> unique_names;
243 for (std::vector<FormFieldData>::const_iterator field = 243 for (std::vector<FormFieldData>::const_iterator field =
244 form.fields.begin(); 244 form.fields.begin();
245 field != form.fields.end(); field++) { 245 field != form.fields.end(); field++) {
246 246
247 // Skipping checkable elements when Autocheckout is not enabled, else 247 // Skipping checkable elements when Autocheckout is not enabled, else
248 // these fields will interfere with existing field signatures with Autofill 248 // these fields will interfere with existing field signatures with Autofill
249 // servers. 249 // servers.
Ilya Sherman 2013/03/18 22:33:46 nit: Please update this comment.
Raman Kakilate 2013/03/18 23:01:54 Done.
250 if (!field->is_checkable || IsAutocheckoutEnabled()) { 250 if ((!field->is_checkable && field->form_control_type != "password") ||
251 IsAutocheckoutEnabled()) {
251 // Add all supported form fields (including with empty names) to the 252 // Add all supported form fields (including with empty names) to the
252 // signature. This is a requirement for Autofill servers. 253 // signature. This is a requirement for Autofill servers.
253 form_signature_field_names_.append("&"); 254 form_signature_field_names_.append("&");
254 form_signature_field_names_.append(UTF16ToUTF8(field->name)); 255 form_signature_field_names_.append(UTF16ToUTF8(field->name));
256
257 ++active_field_count_;
255 } 258 }
256 259
257 // Generate a unique name for this field by appending a counter to the name. 260 // Generate a unique name for this field by appending a counter to the name.
258 // Make sure to prepend the counter with a non-numeric digit so that we are 261 // Make sure to prepend the counter with a non-numeric digit so that we are
259 // guaranteed to avoid collisions. 262 // guaranteed to avoid collisions.
260 if (!unique_names.count(field->name)) 263 if (!unique_names.count(field->name))
261 unique_names[field->name] = 1; 264 unique_names[field->name] = 1;
262 else 265 else
263 ++unique_names[field->name]; 266 ++unique_names[field->name];
264 string16 unique_name = field->name + ASCIIToUTF16("_") + 267 string16 unique_name = field->name + ASCIIToUTF16("_") +
265 base::IntToString16(unique_names[field->name]); 268 base::IntToString16(unique_names[field->name]);
266 fields_.push_back(new AutofillField(*field, unique_name)); 269 fields_.push_back(new AutofillField(*field, unique_name));
267
268 if (field->is_checkable)
269 ++checkable_field_count_;
270 } 270 }
271 271
272 std::string method = UTF16ToUTF8(form.method); 272 std::string method = UTF16ToUTF8(form.method);
273 if (StringToLowerASCII(method) == kFormMethodPost) { 273 if (StringToLowerASCII(method) == kFormMethodPost) {
274 method_ = POST; 274 method_ = POST;
275 } else { 275 } else {
276 // Either the method is 'get', or we don't know. In this case we default 276 // Either the method is 'get', or we don't know. In this case we default
277 // to GET. 277 // to GET.
278 method_ = GET; 278 method_ = GET;
279 } 279 }
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 AutofillField* field = *iter; 605 AutofillField* field = *iter;
606 if (field && field->IsFieldFillable()) 606 if (field && field->IsFieldFillable())
607 ++autofill_count_; 607 ++autofill_count_;
608 } 608 }
609 } 609 }
610 610
611 bool FormStructure::ShouldBeParsed(bool require_method_post) const { 611 bool FormStructure::ShouldBeParsed(bool require_method_post) const {
612 // Ignore counting checkable elements towards minimum number of elements 612 // Ignore counting checkable elements towards minimum number of elements
613 // required to parse. This avoids trying to crowdsource forms with few text 613 // required to parse. This avoids trying to crowdsource forms with few text
614 // or select elements. 614 // or select elements.
615 if ((field_count() - checkable_field_count()) < RequiredFillableFields()) 615 if (active_field_count() < RequiredFillableFields())
616 return false; 616 return false;
617 617
618 // Rule out http(s)://*/search?... 618 // Rule out http(s)://*/search?...
619 // e.g. http://www.google.com/search?q=... 619 // e.g. http://www.google.com/search?q=...
620 // http://search.yahoo.com/search?p=... 620 // http://search.yahoo.com/search?p=...
621 if (target_url_.path() == "/search") 621 if (target_url_.path() == "/search")
622 return false; 622 return false;
623 623
624 if (!IsAutocheckoutEnabled()) { 624 if (!IsAutocheckoutEnabled()) {
625 // Make sure there is at least one text field when Autocheckout is 625 // Make sure there is at least one text field when Autocheckout is
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 870
871 AutofillField* FormStructure::field(size_t index) { 871 AutofillField* FormStructure::field(size_t index) {
872 return const_cast<AutofillField*>( 872 return const_cast<AutofillField*>(
873 static_cast<const FormStructure*>(this)->field(index)); 873 static_cast<const FormStructure*>(this)->field(index));
874 } 874 }
875 875
876 size_t FormStructure::field_count() const { 876 size_t FormStructure::field_count() const {
877 return fields_.size(); 877 return fields_.size();
878 } 878 }
879 879
880 size_t FormStructure::checkable_field_count() const { 880 size_t FormStructure::active_field_count() const {
881 return checkable_field_count_; 881 return active_field_count_;
882 } 882 }
883 883
884 std::string FormStructure::server_experiment_id() const { 884 std::string FormStructure::server_experiment_id() const {
885 return server_experiment_id_; 885 return server_experiment_id_;
886 } 886 }
887 887
888 FormData FormStructure::ToFormData() const { 888 FormData FormStructure::ToFormData() const {
889 // |data.user_submitted| will always be false. 889 // |data.user_submitted| will always be false.
890 FormData data; 890 FormData data;
891 data.name = form_name_; 891 data.name = form_name_;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 buzz::QName(kXMLElementField)); 964 buzz::QName(kXMLElementField));
965 965
966 field_element->SetAttr(buzz::QName(kAttributeSignature), 966 field_element->SetAttr(buzz::QName(kAttributeSignature),
967 field->FieldSignature()); 967 field->FieldSignature());
968 field_element->SetAttr(buzz::QName(kAttributeAutofillType), 968 field_element->SetAttr(buzz::QName(kAttributeAutofillType),
969 base::IntToString(*field_type)); 969 base::IntToString(*field_type));
970 encompassing_xml_element->AddElement(field_element); 970 encompassing_xml_element->AddElement(field_element);
971 } 971 }
972 } else { 972 } else {
973 // Skip putting checkable fields in the request if Autocheckout is not 973 // Skip putting checkable fields in the request if Autocheckout is not
974 // enabled. 974 // enabled.
Ilya Sherman 2013/03/18 22:33:46 nit: Please update this comment.
Raman Kakilate 2013/03/18 23:01:54 Done.
975 if (field->is_checkable && !IsAutocheckoutEnabled()) 975 if ((field->is_checkable || field->form_control_type == "password") &&
976 !IsAutocheckoutEnabled())
976 continue; 977 continue;
977 978
978 buzz::XmlElement *field_element = new buzz::XmlElement( 979 buzz::XmlElement *field_element = new buzz::XmlElement(
979 buzz::QName(kXMLElementField)); 980 buzz::QName(kXMLElementField));
980 field_element->SetAttr(buzz::QName(kAttributeSignature), 981 field_element->SetAttr(buzz::QName(kAttributeSignature),
981 field->FieldSignature()); 982 field->FieldSignature());
982 encompassing_xml_element->AddElement(field_element); 983 encompassing_xml_element->AddElement(field_element);
983 } 984 }
984 } 985 }
985 return true; 986 return true;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 for (std::vector<AutofillField*>::iterator field = fields_.begin(); 1149 for (std::vector<AutofillField*>::iterator field = fields_.begin();
1149 field != fields_.end(); ++field) { 1150 field != fields_.end(); ++field) {
1150 AutofillType::FieldTypeGroup field_type_group = 1151 AutofillType::FieldTypeGroup field_type_group =
1151 AutofillType((*field)->type()).group(); 1152 AutofillType((*field)->type()).group();
1152 if (field_type_group == AutofillType::CREDIT_CARD) 1153 if (field_type_group == AutofillType::CREDIT_CARD)
1153 (*field)->set_section((*field)->section() + "-cc"); 1154 (*field)->set_section((*field)->section() + "-cc");
1154 else 1155 else
1155 (*field)->set_section((*field)->section() + "-default"); 1156 (*field)->set_section((*field)->section() + "-default");
1156 } 1157 }
1157 } 1158 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698