| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/dom_ui/options/autofill_options_handler.h" | 5 #include "chrome/browser/dom_ui/options/autofill_options_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/autofill/autofill_country.h" |
| 14 #include "chrome/browser/autofill/autofill_profile.h" | 15 #include "chrome/browser/autofill/autofill_profile.h" |
| 15 #include "chrome/browser/autofill/credit_card.h" | 16 #include "chrome/browser/autofill/credit_card.h" |
| 16 #include "chrome/browser/dom_ui/web_ui_util.h" | 17 #include "chrome/browser/dom_ui/web_ui_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/guid.h" | 19 #include "chrome/common/guid.h" |
| 19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 20 #include "grit/webkit_resources.h" | 21 #include "grit/webkit_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 | 23 |
| 24 using autofill::AutoFillCountry; |
| 25 |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 // Converts a credit card type to the appropriate resource ID of the CC icon. | 28 // Converts a credit card type to the appropriate resource ID of the CC icon. |
| 26 int CreditCardTypeToResourceID(const string16& type16) { | 29 int CreditCardTypeToResourceID(const string16& type16) { |
| 27 std::string type = UTF16ToUTF8(type16); | 30 std::string type = UTF16ToUTF8(type16); |
| 28 if (type == kAmericanExpressCard) | 31 if (type == kAmericanExpressCard) |
| 29 return IDR_AUTOFILL_CC_AMEX; | 32 return IDR_AUTOFILL_CC_AMEX; |
| 30 else if (type == kDinersCard) | 33 else if (type == kDinersCard) |
| 31 return IDR_AUTOFILL_CC_DINERS; | 34 return IDR_AUTOFILL_CC_DINERS; |
| 32 else if (type == kDiscoverCard) | 35 else if (type == kDiscoverCard) |
| 33 return IDR_AUTOFILL_CC_DISCOVER; | 36 return IDR_AUTOFILL_CC_DISCOVER; |
| 34 else if (type == kGenericCard) | 37 else if (type == kGenericCard) |
| 35 return IDR_AUTOFILL_CC_GENERIC; | 38 return IDR_AUTOFILL_CC_GENERIC; |
| 36 else if (type == kJCBCard) | 39 else if (type == kJCBCard) |
| 37 return IDR_AUTOFILL_CC_JCB; | 40 return IDR_AUTOFILL_CC_JCB; |
| 38 else if (type == kMasterCard) | 41 else if (type == kMasterCard) |
| 39 return IDR_AUTOFILL_CC_MASTERCARD; | 42 return IDR_AUTOFILL_CC_MASTERCARD; |
| 40 else if (type == kSoloCard) | 43 else if (type == kSoloCard) |
| 41 return IDR_AUTOFILL_CC_SOLO; | 44 return IDR_AUTOFILL_CC_SOLO; |
| 42 else if (type == kVisaCard) | 45 else if (type == kVisaCard) |
| 43 return IDR_AUTOFILL_CC_VISA; | 46 return IDR_AUTOFILL_CC_VISA; |
| 44 | 47 |
| 45 NOTREACHED(); | 48 NOTREACHED(); |
| 46 return 0; | 49 return 0; |
| 47 } | 50 } |
| 48 | 51 |
| 52 DictionaryValue* GetCountryDetails(AutoFillCountry country) { |
| 53 DictionaryValue* details = new DictionaryValue(); |
| 54 details->SetString("name", autofill::GetCountryName(country)); |
| 55 details->SetString("postalCodeLabel", autofill::GetPostalCodeLabel(country)); |
| 56 details->SetString("stateLabel", autofill::GetStateLabel(country)); |
| 57 return details; |
| 58 } |
| 59 |
| 60 DictionaryValue* GetCountryList() { |
| 61 DictionaryValue* countries = new DictionaryValue(); |
| 62 |
| 63 DictionaryValue* default_country = |
| 64 GetCountryDetails(autofill::CountryCodeToCountry(std::string())); |
| 65 default_country->SetString("name", std::string()); |
| 66 countries->Set(std::string(), default_country); |
| 67 |
| 68 for (size_t i = autofill::FIRST_COUNTRY; i < autofill::NUM_COUNTRIES; ++i) { |
| 69 AutoFillCountry country = static_cast<AutoFillCountry>(i); |
| 70 countries->Set(autofill::GetCountryCode(country), |
| 71 GetCountryDetails(country)); |
| 72 } |
| 73 |
| 74 return countries; |
| 75 } |
| 76 |
| 49 } // namespace | 77 } // namespace |
| 50 | 78 |
| 51 AutoFillOptionsHandler::AutoFillOptionsHandler() | 79 AutoFillOptionsHandler::AutoFillOptionsHandler() |
| 52 : personal_data_(NULL) { | 80 : personal_data_(NULL) { |
| 53 } | 81 } |
| 54 | 82 |
| 55 AutoFillOptionsHandler::~AutoFillOptionsHandler() { | 83 AutoFillOptionsHandler::~AutoFillOptionsHandler() { |
| 56 if (personal_data_) | 84 if (personal_data_) |
| 57 personal_data_->RemoveObserver(this); | 85 personal_data_->RemoveObserver(this); |
| 58 } | 86 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 localized_strings->SetString("companyNameLabel", | 168 localized_strings->SetString("companyNameLabel", |
| 141 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COMPANY_NAME)); | 169 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COMPANY_NAME)); |
| 142 localized_strings->SetString("addrLine1Label", | 170 localized_strings->SetString("addrLine1Label", |
| 143 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1)); | 171 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1)); |
| 144 localized_strings->SetString("addrLine2Label", | 172 localized_strings->SetString("addrLine2Label", |
| 145 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2)); | 173 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2)); |
| 146 localized_strings->SetString("cityLabel", | 174 localized_strings->SetString("cityLabel", |
| 147 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY)); | 175 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY)); |
| 148 localized_strings->SetString("stateLabel", | 176 localized_strings->SetString("stateLabel", |
| 149 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE)); | 177 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE)); |
| 150 localized_strings->SetString("zipCodeLabel", | 178 localized_strings->SetString("postalCodeLabel", |
| 151 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE)); | 179 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE)); |
| 152 localized_strings->SetString("countryLabel", | 180 localized_strings->SetString("countryLabel", |
| 153 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); | 181 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); |
| 154 localized_strings->SetString("countryLabel", | |
| 155 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); | |
| 156 localized_strings->SetString("phoneLabel", | 182 localized_strings->SetString("phoneLabel", |
| 157 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); | 183 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); |
| 158 localized_strings->SetString("faxLabel", | 184 localized_strings->SetString("faxLabel", |
| 159 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); | 185 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); |
| 160 localized_strings->SetString("emailLabel", | 186 localized_strings->SetString("emailLabel", |
| 161 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); | 187 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); |
| 188 |
| 189 localized_strings->Set("autofillCountryData", GetCountryList()); |
| 162 } | 190 } |
| 163 | 191 |
| 164 void AutoFillOptionsHandler::SetCreditCardOverlayStrings( | 192 void AutoFillOptionsHandler::SetCreditCardOverlayStrings( |
| 165 DictionaryValue* localized_strings) { | 193 DictionaryValue* localized_strings) { |
| 166 localized_strings->SetString("autoFillEditCreditCardTitle", | 194 localized_strings->SetString("autoFillEditCreditCardTitle", |
| 167 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); | 195 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); |
| 168 localized_strings->SetString("nameOnCardLabel", | 196 localized_strings->SetString("nameOnCardLabel", |
| 169 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); | 197 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); |
| 170 localized_strings->SetString("creditCardNumberLabel", | 198 localized_strings->SetString("creditCardNumberLabel", |
| 171 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); | 199 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 address->SetString("companyName", | 288 address->SetString("companyName", |
| 261 profile->GetFieldText(AutoFillType(COMPANY_NAME))); | 289 profile->GetFieldText(AutoFillType(COMPANY_NAME))); |
| 262 address->SetString("addrLine1", | 290 address->SetString("addrLine1", |
| 263 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))); | 291 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))); |
| 264 address->SetString("addrLine2", | 292 address->SetString("addrLine2", |
| 265 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))); | 293 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))); |
| 266 address->SetString("city", | 294 address->SetString("city", |
| 267 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY))); | 295 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY))); |
| 268 address->SetString("state", | 296 address->SetString("state", |
| 269 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE))); | 297 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE))); |
| 270 address->SetString("zipCode", | 298 address->SetString("postalCode", |
| 271 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))); | 299 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))); |
| 272 address->SetString("country", | 300 address->SetString("country", |
| 273 profile->GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); | 301 profile->GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); |
| 274 address->SetString( | 302 address->SetString( |
| 275 "phone", | 303 "phone", |
| 276 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); | 304 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); |
| 277 address->SetString( | 305 address->SetString( |
| 278 "fax", | 306 "fax", |
| 279 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); | 307 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); |
| 280 address->SetString("email", | 308 address->SetString("email", |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 if (args->GetString(4, &value)) | 423 if (args->GetString(4, &value)) |
| 396 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); | 424 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); |
| 397 | 425 |
| 398 if (!guid::IsValidGUID(credit_card.guid())) { | 426 if (!guid::IsValidGUID(credit_card.guid())) { |
| 399 credit_card.set_guid(guid::GenerateGUID()); | 427 credit_card.set_guid(guid::GenerateGUID()); |
| 400 personal_data_->AddCreditCard(credit_card); | 428 personal_data_->AddCreditCard(credit_card); |
| 401 } else { | 429 } else { |
| 402 personal_data_->UpdateCreditCard(credit_card); | 430 personal_data_->UpdateCreditCard(credit_card); |
| 403 } | 431 } |
| 404 } | 432 } |
| OLD | NEW |