| 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_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/autofill/autofill_country.h" | 13 #include "chrome/browser/autofill/autofill_country.h" |
| 14 #include "chrome/browser/autofill/autofill_manager.h" | 14 #include "chrome/browser/autofill/autofill_manager.h" |
| 15 #include "chrome/browser/autofill/autofill_type.h" | 15 #include "chrome/browser/autofill/autofill_type.h" |
| 16 #include "chrome/browser/autofill/personal_data_manager.h" | 16 #include "chrome/browser/autofill/personal_data_manager.h" |
| 17 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 17 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 18 #include "chrome/browser/autofill/wallet/wallet_service_url.h" | 18 #include "chrome/browser/autofill/wallet/wallet_service_url.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 20 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 21 #include "chrome/common/form_data.h" | 21 #include "chrome/common/form_data.h" |
| 22 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
| 23 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
| 24 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/common/url_constants.h" | 28 #include "content/public/common/url_constants.h" |
| 29 #include "grit/chromium_strings.h" |
| 29 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 30 #include "net/base/cert_status_flags.h" | 31 #include "net/base/cert_status_flags.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 32 | 33 |
| 33 namespace autofill { | 34 namespace autofill { |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 // Returns true if |input| should be shown when |field| has been requested. | 38 // Returns true if |input| should be shown when |field| has been requested. |
| 38 bool InputTypeMatchesFieldType(const DetailInput& input, | 39 bool InputTypeMatchesFieldType(const DetailInput& input, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 string16 AutofillDialogControllerImpl::SignInText() const { | 248 string16 AutofillDialogControllerImpl::SignInText() const { |
| 248 // TODO(abodenha): real strings and l10n. | 249 // TODO(abodenha): real strings and l10n. |
| 249 return string16(ASCIIToUTF16("Sign in to use Google Wallet")); | 250 return string16(ASCIIToUTF16("Sign in to use Google Wallet")); |
| 250 } | 251 } |
| 251 | 252 |
| 252 string16 AutofillDialogControllerImpl::CancelSignInText() const { | 253 string16 AutofillDialogControllerImpl::CancelSignInText() const { |
| 253 // TODO(abodenha): real strings and l10n. | 254 // TODO(abodenha): real strings and l10n. |
| 254 return string16(ASCIIToUTF16("Don't sign in.")); | 255 return string16(ASCIIToUTF16("Don't sign in.")); |
| 255 } | 256 } |
| 256 | 257 |
| 258 string16 AutofillDialogControllerImpl::SaveLocallyText() const { |
| 259 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); |
| 260 } |
| 261 |
| 257 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( | 262 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( |
| 258 DialogSection section) const { | 263 DialogSection section) const { |
| 259 switch (section) { | 264 switch (section) { |
| 260 case SECTION_EMAIL: | 265 case SECTION_EMAIL: |
| 261 return requested_email_fields_; | 266 return requested_email_fields_; |
| 262 case SECTION_CC: | 267 case SECTION_CC: |
| 263 return requested_cc_fields_; | 268 return requested_cc_fields_; |
| 264 case SECTION_BILLING: | 269 case SECTION_BILLING: |
| 265 return requested_billing_fields_; | 270 return requested_billing_fields_; |
| 266 case SECTION_SHIPPING: | 271 case SECTION_SHIPPING: |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 FillFormStructureForSection(*form_group, variant, section, compare); | 671 FillFormStructureForSection(*form_group, variant, section, compare); |
| 667 } else { | 672 } else { |
| 668 // The user manually input data. | 673 // The user manually input data. |
| 669 DetailOutputMap output; | 674 DetailOutputMap output; |
| 670 view_->GetUserInput(section, &output); | 675 view_->GetUserInput(section, &output); |
| 671 | 676 |
| 672 // Save the info as new or edited data, then fill it into |form_structure_|. | 677 // Save the info as new or edited data, then fill it into |form_structure_|. |
| 673 if (section == SECTION_CC) { | 678 if (section == SECTION_CC) { |
| 674 CreditCard card; | 679 CreditCard card; |
| 675 FillFormGroupFromOutputs(output, &card); | 680 FillFormGroupFromOutputs(output, &card); |
| 676 manager->SaveImportedCreditCard(card); | 681 if (view_->SaveDetailsLocally()) |
| 682 manager->SaveImportedCreditCard(card); |
| 677 FillFormStructureForSection(card, 0, section, compare); | 683 FillFormStructureForSection(card, 0, section, compare); |
| 678 | 684 |
| 679 // CVC needs special-casing because the CreditCard class doesn't store | 685 // CVC needs special-casing because the CreditCard class doesn't store |
| 680 // or handle them. Fill it in directly from |output|. | 686 // or handle them. Fill it in directly from |output|. |
| 681 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 687 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
| 682 AutofillField* field = form_structure_.field(i); | 688 AutofillField* field = form_structure_.field(i); |
| 683 if (field->type() != CREDIT_CARD_VERIFICATION_CODE) | 689 if (field->type() != CREDIT_CARD_VERIFICATION_CODE) |
| 684 continue; | 690 continue; |
| 685 | 691 |
| 686 for (DetailOutputMap::iterator iter = output.begin(); | 692 for (DetailOutputMap::iterator iter = output.begin(); |
| 687 iter != output.end(); ++iter) { | 693 iter != output.end(); ++iter) { |
| 688 if (!iter->second.empty() && compare.Run(*iter->first, *field)) { | 694 if (!iter->second.empty() && compare.Run(*iter->first, *field)) { |
| 689 field->value = iter->second; | 695 field->value = iter->second; |
| 690 break; | 696 break; |
| 691 } | 697 } |
| 692 } | 698 } |
| 693 } | 699 } |
| 694 } else { | 700 } else { |
| 695 AutofillProfile profile; | 701 AutofillProfile profile; |
| 696 FillFormGroupFromOutputs(output, &profile); | 702 FillFormGroupFromOutputs(output, &profile); |
| 697 // TODO(estade): we should probably edit the existing profile in the cases | 703 // TODO(estade): we should probably edit the existing profile in the cases |
| 698 // where the input data is based on an existing profile (user clicked | 704 // where the input data is based on an existing profile (user clicked |
| 699 // "Edit" or autofill popup filled in the form). | 705 // "Edit" or autofill popup filled in the form). |
| 700 manager->SaveImportedProfile(profile); | 706 if (view_->SaveDetailsLocally()) |
| 707 manager->SaveImportedProfile(profile); |
| 701 FillFormStructureForSection(profile, 0, section, compare); | 708 FillFormStructureForSection(profile, 0, section, compare); |
| 702 } | 709 } |
| 703 } | 710 } |
| 704 } | 711 } |
| 705 | 712 |
| 706 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 713 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
| 707 FillOutputForSectionWithComparator(section, | 714 FillOutputForSectionWithComparator(section, |
| 708 base::Bind(DetailInputMatchesField)); | 715 base::Bind(DetailInputMatchesField)); |
| 709 } | 716 } |
| 710 | 717 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 } | 775 } |
| 769 | 776 |
| 770 void AutofillDialogControllerImpl::HidePopup() { | 777 void AutofillDialogControllerImpl::HidePopup() { |
| 771 if (popup_controller_) { | 778 if (popup_controller_) { |
| 772 popup_controller_->Hide(); | 779 popup_controller_->Hide(); |
| 773 ControllerDestroyed(); | 780 ControllerDestroyed(); |
| 774 } | 781 } |
| 775 } | 782 } |
| 776 | 783 |
| 777 } // namespace autofill | 784 } // namespace autofill |
| OLD | NEW |