Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: chrome/browser/webui/options/autofill_options_handler.cc

Issue 6484022: Autofill i18n: Set postal code and state field labels based on the selected country. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Properly merged with ToT Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/webdata/web_database_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/webui/options/autofill_options_handler.h" 5 #include "chrome/browser/webui/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/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/webui/web_ui_util.h" 18 #include "chrome/browser/webui/web_ui_util.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
23 namespace { 24 namespace {
(...skipping 15 matching lines...) Expand all
39 return IDR_AUTOFILL_CC_MASTERCARD; 40 return IDR_AUTOFILL_CC_MASTERCARD;
40 else if (type == kSoloCard) 41 else if (type == kSoloCard)
41 return IDR_AUTOFILL_CC_SOLO; 42 return IDR_AUTOFILL_CC_SOLO;
42 else if (type == kVisaCard) 43 else if (type == kVisaCard)
43 return IDR_AUTOFILL_CC_VISA; 44 return IDR_AUTOFILL_CC_VISA;
44 45
45 NOTREACHED(); 46 NOTREACHED();
46 return 0; 47 return 0;
47 } 48 }
48 49
50 // Returns a dictionary that maps country codes to data for the country.
51 DictionaryValue* GetCountryData() {
52 std::string app_locale = AutoFillCountry::ApplicationLocale();
53 std::vector<std::string> country_codes;
54 AutoFillCountry::GetAvailableCountries(&country_codes);
55
56 DictionaryValue* country_data = new DictionaryValue();
57 for (size_t i = 0; i < country_codes.size(); ++i) {
58 const AutoFillCountry country(country_codes[i], app_locale);
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 localized_strings->SetString("fullNameLabel", 160 localized_strings->SetString("fullNameLabel",
139 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FULL_NAME)); 161 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FULL_NAME));
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",
149 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE));
150 localized_strings->SetString("zipCodeLabel",
151 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE));
152 localized_strings->SetString("countryLabel",
153 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY));
154 localized_strings->SetString("countryLabel", 170 localized_strings->SetString("countryLabel",
155 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); 171 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY));
156 localized_strings->SetString("phoneLabel", 172 localized_strings->SetString("phoneLabel",
157 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); 173 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE));
158 localized_strings->SetString("faxLabel", 174 localized_strings->SetString("faxLabel",
159 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); 175 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX));
160 localized_strings->SetString("emailLabel", 176 localized_strings->SetString("emailLabel",
161 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); 177 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL));
178
179 std::string app_locale = AutoFillCountry::ApplicationLocale();
180 std::string default_country_code =
181 AutoFillCountry::CountryCodeForLocale(app_locale);
182 localized_strings->SetString("defaultCountryCode", default_country_code);
183 localized_strings->Set("autofillCountryData", GetCountryData());
162 } 184 }
163 185
164 void AutoFillOptionsHandler::SetCreditCardOverlayStrings( 186 void AutoFillOptionsHandler::SetCreditCardOverlayStrings(
165 DictionaryValue* localized_strings) { 187 DictionaryValue* localized_strings) {
166 localized_strings->SetString("autoFillEditCreditCardTitle", 188 localized_strings->SetString("autoFillEditCreditCardTitle",
167 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); 189 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION));
168 localized_strings->SetString("nameOnCardLabel", 190 localized_strings->SetString("nameOnCardLabel",
169 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); 191 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD));
170 localized_strings->SetString("creditCardNumberLabel", 192 localized_strings->SetString("creditCardNumberLabel",
171 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); 193 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 address.SetString("companyName", 279 address.SetString("companyName",
258 profile->GetFieldText(AutoFillType(COMPANY_NAME))); 280 profile->GetFieldText(AutoFillType(COMPANY_NAME)));
259 address.SetString("addrLine1", 281 address.SetString("addrLine1",
260 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))); 282 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)));
261 address.SetString("addrLine2", 283 address.SetString("addrLine2",
262 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))); 284 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)));
263 address.SetString("city", 285 address.SetString("city",
264 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY))); 286 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY)));
265 address.SetString("state", 287 address.SetString("state",
266 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE))); 288 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE)));
267 address.SetString("zipCode", 289 address.SetString("postalCode",
268 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))); 290 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)));
269 address.SetString("country", 291 address.SetString("country",
270 profile->GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); 292 profile->CountryCode());
271 address.SetString( 293 address.SetString(
272 "phone", 294 "phone",
273 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); 295 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER)));
274 address.SetString( 296 address.SetString(
275 "fax", 297 "fax",
276 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); 298 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER)));
277 address.SetString("email", 299 address.SetString("email",
278 profile->GetFieldText(AutoFillType(EMAIL_ADDRESS))); 300 profile->GetFieldText(AutoFillType(EMAIL_ADDRESS)));
279 301
280 web_ui_->CallJavascriptFunction(L"AutoFillOptions.editAddress", address); 302 web_ui_->CallJavascriptFunction(L"AutoFillOptions.editAddress", address);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return; 347 return;
326 348
327 std::string guid; 349 std::string guid;
328 if (!args->GetString(0, &guid)) { 350 if (!args->GetString(0, &guid)) {
329 NOTREACHED(); 351 NOTREACHED();
330 return; 352 return;
331 } 353 }
332 354
333 AutoFillProfile profile(guid); 355 AutoFillProfile profile(guid);
334 356
357 std::string country_code;
335 string16 value; 358 string16 value;
336 if (args->GetString(1, &value)) 359 if (args->GetString(1, &value))
337 profile.SetInfo(AutoFillType(NAME_FULL), value); 360 profile.SetInfo(AutoFillType(NAME_FULL), value);
338 if (args->GetString(2, &value)) 361 if (args->GetString(2, &value))
339 profile.SetInfo(AutoFillType(COMPANY_NAME), value); 362 profile.SetInfo(AutoFillType(COMPANY_NAME), value);
340 if (args->GetString(3, &value)) 363 if (args->GetString(3, &value))
341 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), value); 364 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), value);
342 if (args->GetString(4, &value)) 365 if (args->GetString(4, &value))
343 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), value); 366 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), value);
344 if (args->GetString(5, &value)) 367 if (args->GetString(5, &value))
345 profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), value); 368 profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), value);
346 if (args->GetString(6, &value)) 369 if (args->GetString(6, &value))
347 profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), value); 370 profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), value);
348 if (args->GetString(7, &value)) 371 if (args->GetString(7, &value))
349 profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), value); 372 profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), value);
350 if (args->GetString(8, &value)) 373 if (args->GetString(8, &country_code))
351 profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), value); 374 profile.SetCountryCode(country_code);
352 if (args->GetString(9, &value)) 375 if (args->GetString(9, &value))
353 profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), value); 376 profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), value);
354 if (args->GetString(10, &value)) 377 if (args->GetString(10, &value))
355 profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), value); 378 profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), value);
356 if (args->GetString(11, &value)) 379 if (args->GetString(11, &value))
357 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), value); 380 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), value);
358 381
359 if (!guid::IsValidGUID(profile.guid())) { 382 if (!guid::IsValidGUID(profile.guid())) {
360 profile.set_guid(guid::GenerateGUID()); 383 profile.set_guid(guid::GenerateGUID());
361 personal_data_->AddProfile(profile); 384 personal_data_->AddProfile(profile);
(...skipping 24 matching lines...) Expand all
386 if (args->GetString(4, &value)) 409 if (args->GetString(4, &value))
387 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); 410 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value);
388 411
389 if (!guid::IsValidGUID(credit_card.guid())) { 412 if (!guid::IsValidGUID(credit_card.guid())) {
390 credit_card.set_guid(guid::GenerateGUID()); 413 credit_card.set_guid(guid::GenerateGUID());
391 personal_data_->AddCreditCard(credit_card); 414 personal_data_->AddCreditCard(credit_card);
392 } else { 415 } else {
393 personal_data_->UpdateCreditCard(credit_card); 416 personal_data_->UpdateCreditCard(credit_card);
394 } 417 }
395 } 418 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_database_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698