| 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/ui/autofill/autofill_dialog_controller.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/autofill/autofill_manager.h" | 9 #include "chrome/browser/autofill/autofill_manager.h" |
| 10 #include "chrome/browser/autofill/personal_data_manager.h" | 10 #include "chrome/browser/autofill/personal_data_manager.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 field.type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || | 28 field.type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || |
| 29 field.type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || | 29 field.type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || |
| 30 field.type() == CREDIT_CARD_EXP_MONTH) { | 30 field.type() == CREDIT_CARD_EXP_MONTH) { |
| 31 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | 31 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
| 32 input.type == CREDIT_CARD_EXP_MONTH; | 32 input.type == CREDIT_CARD_EXP_MONTH; |
| 33 } | 33 } |
| 34 | 34 |
| 35 return input.type == field.type(); | 35 return input.type == field.type(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Returns true if |input| should be used for a site-requested |field|. If | |
| 39 // non-empty, |section_suffix| overrides the section specified by |input|. | |
| 40 bool DetailInputMatchesFieldWithSection(const std::string& section_suffix, | |
| 41 const DetailInput& input, | |
| 42 const AutofillField& field) { | |
| 43 bool right_section = section_suffix.empty() || | |
| 44 EndsWith(field.section(), section_suffix, false); | |
| 45 return InputTypeMatchesFieldType(input, field) && right_section; | |
| 46 } | |
| 47 | |
| 48 // Returns true if |input| should be used for a site-requested |field|. | 38 // Returns true if |input| should be used for a site-requested |field|. |
| 49 bool DetailInputMatchesField(const DetailInput& input, | 39 bool DetailInputMatchesField(const DetailInput& input, |
| 50 const AutofillField& field) { | 40 const AutofillField& field) { |
| 51 std::string section_suffix = input.section_suffix ? input.section_suffix : ""; | 41 bool right_section = !input.section_suffix || |
| 52 return DetailInputMatchesFieldWithSection(section_suffix, input, field); | 42 EndsWith(field.section(), input.section_suffix, false); |
| 43 return InputTypeMatchesFieldType(input, field) && right_section; |
| 44 } |
| 45 |
| 46 // Returns true if |input| should be used to fill a site-requested |field| which |
| 47 // is notated with a "shipping" tag, for use when the user has decided to use |
| 48 // the billing address as the shipping address. |
| 49 bool DetailInputMatchesShippingField(const DetailInput& input, |
| 50 const AutofillField& field) { |
| 51 if (input.section_suffix && |
| 52 std::string(input.section_suffix) == "billing") { |
| 53 return InputTypeMatchesFieldType(input, field); |
| 54 } |
| 55 |
| 56 if (field.type() == NAME_FULL) |
| 57 return input.type == CREDIT_CARD_NAME; |
| 58 |
| 59 return DetailInputMatchesField(input, field); |
| 53 } | 60 } |
| 54 | 61 |
| 55 // Looks through |input_template| for the types in |requested_data|. Appends | 62 // Looks through |input_template| for the types in |requested_data|. Appends |
| 56 // DetailInput values to |inputs|. | 63 // DetailInput values to |inputs|. |
| 57 void FilterInputs(const FormStructure& form_structure, | 64 void FilterInputs(const FormStructure& form_structure, |
| 58 const DetailInput* input_template, | 65 const DetailInput* input_template, |
| 59 size_t template_size, | 66 size_t template_size, |
| 60 DetailInputs* inputs) { | 67 DetailInputs* inputs) { |
| 61 for (size_t i = 0; i < template_size; ++i) { | 68 for (size_t i = 0; i < template_size; ++i) { |
| 62 const DetailInput* input = &input_template[i]; | 69 const DetailInput* input = &input_template[i]; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 316 } |
| 310 | 317 |
| 311 void AutofillDialogController::ViewClosed(DialogAction action) { | 318 void AutofillDialogController::ViewClosed(DialogAction action) { |
| 312 if (action == ACTION_SUBMIT) { | 319 if (action == ACTION_SUBMIT) { |
| 313 FillOutputForSection(SECTION_EMAIL); | 320 FillOutputForSection(SECTION_EMAIL); |
| 314 FillOutputForSection(SECTION_CC); | 321 FillOutputForSection(SECTION_CC); |
| 315 FillOutputForSection(SECTION_BILLING); | 322 FillOutputForSection(SECTION_BILLING); |
| 316 if (view_->UseBillingForShipping()) { | 323 if (view_->UseBillingForShipping()) { |
| 317 FillOutputForSectionWithComparator( | 324 FillOutputForSectionWithComparator( |
| 318 SECTION_BILLING, | 325 SECTION_BILLING, |
| 319 base::Bind(DetailInputMatchesFieldWithSection, "shipping")); | 326 base::Bind(DetailInputMatchesShippingField)); |
| 327 FillOutputForSectionWithComparator( |
| 328 SECTION_CC, |
| 329 base::Bind(DetailInputMatchesShippingField)); |
| 320 } else { | 330 } else { |
| 321 FillOutputForSection(SECTION_SHIPPING); | 331 FillOutputForSection(SECTION_SHIPPING); |
| 322 } | 332 } |
| 323 } | 333 } |
| 324 | 334 |
| 325 callback_.Run(&form_structure_); | 335 callback_.Run(&form_structure_); |
| 326 delete this; | 336 delete this; |
| 327 } | 337 } |
| 328 | 338 |
| 329 void AutofillDialogController::GenerateComboboxModels() { | 339 void AutofillDialogController::GenerateComboboxModels() { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 return &suggested_billing_; | 460 return &suggested_billing_; |
| 451 case SECTION_SHIPPING: | 461 case SECTION_SHIPPING: |
| 452 return &suggested_shipping_; | 462 return &suggested_shipping_; |
| 453 } | 463 } |
| 454 | 464 |
| 455 NOTREACHED(); | 465 NOTREACHED(); |
| 456 return NULL; | 466 return NULL; |
| 457 } | 467 } |
| 458 | 468 |
| 459 } // namespace autofill | 469 } // namespace autofill |
| OLD | NEW |