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" |
| 17 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/dom_ui/web_ui_util.h" | 18 #include "chrome/browser/dom_ui/web_ui_util.h" |
17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/guid.h" | 20 #include "chrome/common/guid.h" |
19 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
20 #include "grit/webkit_resources.h" | 22 #include "grit/webkit_resources.h" |
21 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // Converts a credit card type to the appropriate resource ID of the CC icon. | 27 // Converts a credit card type to the appropriate resource ID of the CC icon. |
(...skipping 13 matching lines...) Expand all Loading... |
39 return IDR_AUTOFILL_CC_MASTERCARD; | 41 return IDR_AUTOFILL_CC_MASTERCARD; |
40 else if (type == kSoloCard) | 42 else if (type == kSoloCard) |
41 return IDR_AUTOFILL_CC_SOLO; | 43 return IDR_AUTOFILL_CC_SOLO; |
42 else if (type == kVisaCard) | 44 else if (type == kVisaCard) |
43 return IDR_AUTOFILL_CC_VISA; | 45 return IDR_AUTOFILL_CC_VISA; |
44 | 46 |
45 NOTREACHED(); | 47 NOTREACHED(); |
46 return 0; | 48 return 0; |
47 } | 49 } |
48 | 50 |
| 51 // Returns a dictionary that maps country codes to data for the country. |
| 52 DictionaryValue* GetCountryData() { |
| 53 std::vector<AutoFillCountry> countries; |
| 54 AutoFillCountry::GetAvailableCountries(&countries); |
| 55 |
| 56 DictionaryValue* country_data = new DictionaryValue(); |
| 57 for (size_t i = 0; i < countries.size(); ++i) { |
| 58 const AutoFillCountry& country = countries[i]; |
| 59 |
| 60 DictionaryValue* details = new DictionaryValue(); |
| 61 details->SetString("name", country.name()); |
| 62 details->SetString("postalCodeLabel", country.postal_code_label()); |
| 63 details->SetString("stateLabel", country.state_label()); |
| 64 |
| 65 country_data->Set(country.country_code(), details); |
| 66 } |
| 67 |
| 68 return country_data; |
| 69 } |
| 70 |
49 } // namespace | 71 } // namespace |
50 | 72 |
51 AutoFillOptionsHandler::AutoFillOptionsHandler() | 73 AutoFillOptionsHandler::AutoFillOptionsHandler() |
52 : personal_data_(NULL) { | 74 : personal_data_(NULL) { |
53 } | 75 } |
54 | 76 |
55 AutoFillOptionsHandler::~AutoFillOptionsHandler() { | 77 AutoFillOptionsHandler::~AutoFillOptionsHandler() { |
56 if (personal_data_) | 78 if (personal_data_) |
57 personal_data_->RemoveObserver(this); | 79 personal_data_->RemoveObserver(this); |
58 } | 80 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 localized_strings->SetString("companyNameLabel", | 162 localized_strings->SetString("companyNameLabel", |
141 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COMPANY_NAME)); | 163 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COMPANY_NAME)); |
142 localized_strings->SetString("addrLine1Label", | 164 localized_strings->SetString("addrLine1Label", |
143 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1)); | 165 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1)); |
144 localized_strings->SetString("addrLine2Label", | 166 localized_strings->SetString("addrLine2Label", |
145 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2)); | 167 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2)); |
146 localized_strings->SetString("cityLabel", | 168 localized_strings->SetString("cityLabel", |
147 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY)); | 169 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY)); |
148 localized_strings->SetString("stateLabel", | 170 localized_strings->SetString("stateLabel", |
149 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE)); | 171 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE)); |
150 localized_strings->SetString("zipCodeLabel", | 172 localized_strings->SetString("postalCodeLabel", |
151 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE)); | 173 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE)); |
152 localized_strings->SetString("countryLabel", | 174 localized_strings->SetString("countryLabel", |
153 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); | 175 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", | 176 localized_strings->SetString("phoneLabel", |
157 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); | 177 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); |
158 localized_strings->SetString("faxLabel", | 178 localized_strings->SetString("faxLabel", |
159 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); | 179 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); |
160 localized_strings->SetString("emailLabel", | 180 localized_strings->SetString("emailLabel", |
161 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); | 181 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); |
| 182 |
| 183 std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 184 std::string default_country_code = |
| 185 AutoFillCountry::CountryForLocale(app_locale).country_code(); |
| 186 |
| 187 localized_strings->SetString("defaultCountryCode", default_country_code); |
| 188 localized_strings->Set("autofillCountryData", GetCountryData()); |
162 } | 189 } |
163 | 190 |
164 void AutoFillOptionsHandler::SetCreditCardOverlayStrings( | 191 void AutoFillOptionsHandler::SetCreditCardOverlayStrings( |
165 DictionaryValue* localized_strings) { | 192 DictionaryValue* localized_strings) { |
166 localized_strings->SetString("autoFillEditCreditCardTitle", | 193 localized_strings->SetString("autoFillEditCreditCardTitle", |
167 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); | 194 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); |
168 localized_strings->SetString("nameOnCardLabel", | 195 localized_strings->SetString("nameOnCardLabel", |
169 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); | 196 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); |
170 localized_strings->SetString("creditCardNumberLabel", | 197 localized_strings->SetString("creditCardNumberLabel", |
171 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); | 198 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", | 287 address->SetString("companyName", |
261 profile->GetFieldText(AutoFillType(COMPANY_NAME))); | 288 profile->GetFieldText(AutoFillType(COMPANY_NAME))); |
262 address->SetString("addrLine1", | 289 address->SetString("addrLine1", |
263 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))); | 290 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))); |
264 address->SetString("addrLine2", | 291 address->SetString("addrLine2", |
265 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))); | 292 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))); |
266 address->SetString("city", | 293 address->SetString("city", |
267 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY))); | 294 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY))); |
268 address->SetString("state", | 295 address->SetString("state", |
269 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE))); | 296 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE))); |
270 address->SetString("zipCode", | 297 address->SetString("postalCode", |
271 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))); | 298 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))); |
272 address->SetString("country", | 299 address->SetString("country", |
273 profile->GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); | 300 profile->GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); |
274 address->SetString( | 301 address->SetString( |
275 "phone", | 302 "phone", |
276 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); | 303 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); |
277 address->SetString( | 304 address->SetString( |
278 "fax", | 305 "fax", |
279 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); | 306 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); |
280 address->SetString("email", | 307 address->SetString("email", |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 if (args->GetString(4, &value)) | 422 if (args->GetString(4, &value)) |
396 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); | 423 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); |
397 | 424 |
398 if (!guid::IsValidGUID(credit_card.guid())) { | 425 if (!guid::IsValidGUID(credit_card.guid())) { |
399 credit_card.set_guid(guid::GenerateGUID()); | 426 credit_card.set_guid(guid::GenerateGUID()); |
400 personal_data_->AddCreditCard(credit_card); | 427 personal_data_->AddCreditCard(credit_card); |
401 } else { | 428 } else { |
402 personal_data_->UpdateCreditCard(credit_card); | 429 personal_data_->UpdateCreditCard(credit_card); |
403 } | 430 } |
404 } | 431 } |
OLD | NEW |