| OLD | NEW |
| 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/form_structure.h" | 5 #include "chrome/browser/autofill/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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 return PHONE_HOME_NUMBER; | 215 return PHONE_HOME_NUMBER; |
| 216 | 216 |
| 217 if (autocomplete_type == "email") | 217 if (autocomplete_type == "email") |
| 218 return EMAIL_ADDRESS; | 218 return EMAIL_ADDRESS; |
| 219 | 219 |
| 220 return UNKNOWN_TYPE; | 220 return UNKNOWN_TYPE; |
| 221 } | 221 } |
| 222 | 222 |
| 223 } // namespace | 223 } // namespace |
| 224 | 224 |
| 225 FormStructure::FormStructure(const FormData& form) | 225 FormStructure::FormStructure(const FormData& form, bool autocheckout_enabled) |
| 226 : form_name_(form.name), | 226 : form_name_(form.name), |
| 227 source_url_(form.origin), | 227 source_url_(form.origin), |
| 228 target_url_(form.action), | 228 target_url_(form.action), |
| 229 autofill_count_(0), | 229 autofill_count_(0), |
| 230 upload_required_(USE_UPLOAD_RATES), | 230 upload_required_(USE_UPLOAD_RATES), |
| 231 server_experiment_id_("no server response"), | 231 server_experiment_id_("no server response"), |
| 232 has_author_specified_types_(false) { | 232 has_author_specified_types_(false), |
| 233 autocheckout_enabled_(autocheckout_enabled) { |
| 233 // Copy the form fields. | 234 // Copy the form fields. |
| 234 std::map<string16, size_t> unique_names; | 235 std::map<string16, size_t> unique_names; |
| 235 for (std::vector<FormFieldData>::const_iterator field = | 236 for (std::vector<FormFieldData>::const_iterator field = |
| 236 form.fields.begin(); | 237 form.fields.begin(); |
| 237 field != form.fields.end(); field++) { | 238 field != form.fields.end(); field++) { |
| 238 // Add all supported form fields (including with empty names) to the | 239 // Add all supported form fields (including with empty names) to the |
| 239 // signature. This is a requirement for Autofill servers. | 240 // signature. This is a requirement for Autofill servers. |
| 240 form_signature_field_names_.append("&"); | 241 form_signature_field_names_.append("&"); |
| 241 form_signature_field_names_.append(UTF16ToUTF8(field->name)); | 242 form_signature_field_names_.append(UTF16ToUTF8(field->name)); |
| 242 | 243 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 516 } |
| 516 | 517 |
| 517 std::string form_string = scheme + "://" + host + "&" + | 518 std::string form_string = scheme + "://" + host + "&" + |
| 518 UTF16ToUTF8(form_name_) + | 519 UTF16ToUTF8(form_name_) + |
| 519 form_signature_field_names_; | 520 form_signature_field_names_; |
| 520 | 521 |
| 521 return Hash64Bit(form_string); | 522 return Hash64Bit(form_string); |
| 522 } | 523 } |
| 523 | 524 |
| 524 bool FormStructure::IsAutofillable(bool require_method_post) const { | 525 bool FormStructure::IsAutofillable(bool require_method_post) const { |
| 525 // TODO(ramankk): Remove this check once we have better way of identifying the | 526 if (autocheckout_enabled_) |
| 526 // cases to trigger experimental form filling. | |
| 527 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 528 switches::kEnableExperimentalFormFilling)) | |
| 529 return true; | 527 return true; |
| 530 | 528 |
| 531 if (autofill_count() < kRequiredFillableFields) | 529 if (autofill_count() < kRequiredFillableFields) |
| 532 return false; | 530 return false; |
| 533 | 531 |
| 534 return ShouldBeParsed(require_method_post); | 532 return ShouldBeParsed(require_method_post); |
| 535 } | 533 } |
| 536 | 534 |
| 537 void FormStructure::UpdateAutofillCount() { | 535 void FormStructure::UpdateAutofillCount() { |
| 538 autofill_count_ = 0; | 536 autofill_count_ = 0; |
| 539 for (std::vector<AutofillField*>::const_iterator iter = begin(); | 537 for (std::vector<AutofillField*>::const_iterator iter = begin(); |
| 540 iter != end(); ++iter) { | 538 iter != end(); ++iter) { |
| 541 AutofillField* field = *iter; | 539 AutofillField* field = *iter; |
| 542 if (field && field->IsFieldFillable()) | 540 if (field && field->IsFieldFillable()) |
| 543 ++autofill_count_; | 541 ++autofill_count_; |
| 544 } | 542 } |
| 545 } | 543 } |
| 546 | 544 |
| 547 bool FormStructure::ShouldBeParsed(bool require_method_post) const { | 545 bool FormStructure::ShouldBeParsed(bool require_method_post) const { |
| 548 // TODO(ramankk): Remove this check once we have better way of identifying the | 546 if (autocheckout_enabled_) |
| 549 // cases to trigger experimental form filling. | |
| 550 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 551 switches::kEnableExperimentalFormFilling)) | |
| 552 return true; | 547 return true; |
| 553 | 548 |
| 554 if (field_count() < kRequiredFillableFields) | 549 if (field_count() < kRequiredFillableFields) |
| 555 return false; | 550 return false; |
| 556 | 551 |
| 557 // Rule out http(s)://*/search?... | 552 // Rule out http(s)://*/search?... |
| 558 // e.g. http://www.google.com/search?q=... | 553 // e.g. http://www.google.com/search?q=... |
| 559 // http://search.yahoo.com/search?p=... | 554 // http://search.yahoo.com/search?p=... |
| 560 if (target_url_.path() == "/search") | 555 if (target_url_.path() == "/search") |
| 561 return false; | 556 return false; |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1066 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
| 1072 field != fields_.end(); ++field) { | 1067 field != fields_.end(); ++field) { |
| 1073 AutofillType::FieldTypeGroup field_type_group = | 1068 AutofillType::FieldTypeGroup field_type_group = |
| 1074 AutofillType((*field)->type()).group(); | 1069 AutofillType((*field)->type()).group(); |
| 1075 if (field_type_group == AutofillType::CREDIT_CARD) | 1070 if (field_type_group == AutofillType::CREDIT_CARD) |
| 1076 (*field)->set_section((*field)->section() + "-cc"); | 1071 (*field)->set_section((*field)->section() + "-cc"); |
| 1077 else | 1072 else |
| 1078 (*field)->set_section((*field)->section() + "-default"); | 1073 (*field)->set_section((*field)->section() + "-default"); |
| 1079 } | 1074 } |
| 1080 } | 1075 } |
| OLD | NEW |