diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-13 20:38:57 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-13 20:38:57 +0000 |
commit | c47c9d80e93941924c8d6c5e4d7845971552b390 (patch) | |
tree | ba148e054621c580be7c6ca48c217de344f5eb04 /chrome/browser/dom_ui | |
parent | 4cd978f396db700a1fb3e2d6e081e76817264c9b (diff) | |
download | chromium_src-c47c9d80e93941924c8d6c5e4d7845971552b390.zip chromium_src-c47c9d80e93941924c8d6c5e4d7845971552b390.tar.gz chromium_src-c47c9d80e93941924c8d6c5e4d7845971552b390.tar.bz2 |
DOMUI: Implement adding and editing credit cards in the AutoFill page.
BUG=49094
TEST=none
Review URL: http://codereview.chromium.org/3308006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59276 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r-- | chrome/browser/dom_ui/autofill_options_handler.cc | 102 | ||||
-rw-r--r-- | chrome/browser/dom_ui/autofill_options_handler.h | 15 |
2 files changed, 114 insertions, 3 deletions
diff --git a/chrome/browser/dom_ui/autofill_options_handler.cc b/chrome/browser/dom_ui/autofill_options_handler.cc index 6ac6e0c..173e8b7 100644 --- a/chrome/browser/dom_ui/autofill_options_handler.cc +++ b/chrome/browser/dom_ui/autofill_options_handler.cc @@ -9,6 +9,7 @@ #include "app/l10n_util.h" #include "base/logging.h" #include "base/string16.h" +#include "base/string_number_conversions.h" #include "base/values.h" #include "chrome/browser/autofill/autofill_profile.h" #include "chrome/browser/autofill/credit_card.h" @@ -50,8 +51,12 @@ void AutoFillOptionsHandler::GetLocalizedValues( l10n_util::GetStringUTF16(IDS_AUTOFILL_HELP_LABEL)); localized_strings->SetString("addAddressTitle", l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_ADDRESS_CAPTION)); + localized_strings->SetString("editAddressTitle", + l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); localized_strings->SetString("addCreditCardTitle", l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_CREDITCARD_CAPTION)); + localized_strings->SetString("editCreditCardTitle", + l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); SetAddressOverlayStrings(localized_strings); SetCreditCardOverlayStrings(localized_strings); @@ -79,6 +84,14 @@ void AutoFillOptionsHandler::RegisterMessages() { NewCallback(this, &AutoFillOptionsHandler::RemoveAddress)); dom_ui_->RegisterMessageCallback( + "updateCreditCard", + NewCallback(this, &AutoFillOptionsHandler::UpdateCreditCard)); + + dom_ui_->RegisterMessageCallback( + "editCreditCard", + NewCallback(this, &AutoFillOptionsHandler::EditCreditCard)); + + dom_ui_->RegisterMessageCallback( "removeCreditCard", NewCallback(this, &AutoFillOptionsHandler::RemoveCreditCard)); } @@ -149,7 +162,7 @@ void AutoFillOptionsHandler::LoadAutoFillData() { i != personal_data_->profiles().end(); ++i) { DictionaryValue* address = new DictionaryValue(); address->SetString("label", (*i)->PreviewSummary()); - address->SetInteger("unique_id", (*i)->unique_id()); + address->SetInteger("uniqueID", (*i)->unique_id()); addresses.Append(address); } @@ -162,7 +175,7 @@ void AutoFillOptionsHandler::LoadAutoFillData() { i != personal_data_->credit_cards().end(); ++i) { DictionaryValue* credit_card = new DictionaryValue(); credit_card->SetString("label", (*i)->PreviewSummary()); - credit_card->SetInteger("unique_id", (*i)->unique_id()); + credit_card->SetInteger("uniqueID", (*i)->unique_id()); credit_cards.Append(credit_card); } @@ -287,6 +300,91 @@ void AutoFillOptionsHandler::RemoveAddress(const ListValue* args) { personal_data_->RemoveProfile(unique_id); } +void AutoFillOptionsHandler::UpdateCreditCard(const ListValue* args) { + if (!personal_data_->IsDataLoaded()) + return; + + int unique_id = 0; + if (!ExtractIntegerValue(args, &unique_id)) { + NOTREACHED(); + return; + } + + CreditCard credit_card; + credit_card.set_unique_id(unique_id); + + string16 value; + if (args->GetString(1, &value)) + credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), value); + if (args->GetString(2, &value)) { + int id = 0; + base::StringToInt(value, &id); + credit_card.set_billing_address_id(id); + } + if (args->GetString(3, &value)) + credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), value); + if (args->GetString(4, &value)) + credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), value); + if (args->GetString(5, &value)) + credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); + + if (unique_id == 0) + personal_data_->AddCreditCard(credit_card); + else + personal_data_->UpdateCreditCard(credit_card); +} + +void AutoFillOptionsHandler::EditCreditCard(const ListValue* args) { + if (!personal_data_->IsDataLoaded()) + return; + + int unique_id = 0; + if (!ExtractIntegerValue(args, &unique_id)) { + NOTREACHED(); + return; + } + + // TODO(jhawkins): Refactor and move this into PersonalDataManager. + CreditCard* credit_card = NULL; + for (std::vector<CreditCard*>::const_iterator iter = + personal_data_->credit_cards().begin(); + iter != personal_data_->credit_cards().end(); ++iter) { + if ((*iter)->unique_id() == unique_id) { + credit_card = *iter; + break; + } + } + + if (!credit_card) { + NOTREACHED(); + return; + } + + // TODO(jhawkins): This is hacky because we can't send DictionaryValue + // directly to CallJavascriptFunction(). + ListValue credit_card_list; + DictionaryValue* credit_card_data = new DictionaryValue(); + credit_card_data->SetInteger("uniqueID", credit_card->unique_id()); + credit_card_data->SetString( + "nameOnCard", + credit_card->GetFieldText(AutoFillType(CREDIT_CARD_NAME))); + credit_card_data->SetInteger( + "billingAddress", credit_card->billing_address_id()); + credit_card_data->SetString( + "creditCardNumber", + credit_card->GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))); + credit_card_data->SetString( + "expirationMonth", + credit_card->GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH))); + credit_card_data->SetString( + "expirationYear", + credit_card->GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); + credit_card_list.Append(credit_card_data); + + dom_ui_->CallJavascriptFunction(L"AutoFillOptions.editCreditCard", + credit_card_list); +} + void AutoFillOptionsHandler::RemoveCreditCard(const ListValue* args) { if (!personal_data_->IsDataLoaded()) return; diff --git a/chrome/browser/dom_ui/autofill_options_handler.h b/chrome/browser/dom_ui/autofill_options_handler.h index 7112c81..dabae6a 100644 --- a/chrome/browser/dom_ui/autofill_options_handler.h +++ b/chrome/browser/dom_ui/autofill_options_handler.h @@ -40,13 +40,26 @@ class AutoFillOptionsHandler : public OptionsPageUIHandler, // Loads the data from an address and sends this data back to the DOMUI to // show in the address editor. Called from DOMUI. - // |args| - an integer, the unique ID of the address to remove. + // |args| - an integer, the unique ID of the address to edit. void EditAddress(const ListValue* args); // Removes an address from the WebDatabase. Called from DOMUI. // |args| - an integer, the unique ID of the address to remove. void RemoveAddress(const ListValue* args); + // Adds or updates a credit card, depending on the unique ID of the credit + // card. If the unique ID is 0, a new credit card is added to the WebDatabase; + // otherwise, the credit card with the matching ID is updated. Called from + // DOMUI. + // |args| - an array containing the unique ID of the credit card followed by + // the credit card data. + void UpdateCreditCard(const ListValue* args); + + // Loads the data from a credit card and sends this data back to the DOMUI to + // show in the credit card editor. Called from DOMUI. + // |args| - an integer, the unique ID of the credit card to edit. + void EditCreditCard(const ListValue* args); + // Removes a credit card from the WebDatabase. Called from DOMUI. // |args| - an integer, the unique ID of the credit card to remove. void RemoveCreditCard(const ListValue* args); |