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

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

Issue 243013004: i18n address editing in chrome://settings/autofillEditAddress. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Manual templates. Created 6 years, 8 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
OLDNEW
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/webui/options/autofill_options_handler.h" 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "chrome/browser/autofill/personal_data_manager_factory.h" 18 #include "chrome/browser/autofill/personal_data_manager_factory.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/autofill/country_combobox_model.h" 21 #include "chrome/browser/ui/autofill/country_combobox_model.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "components/autofill/core/browser/autofill_country.h" 23 #include "components/autofill/core/browser/autofill_country.h"
23 #include "components/autofill/core/browser/autofill_profile.h" 24 #include "components/autofill/core/browser/autofill_profile.h"
24 #include "components/autofill/core/browser/credit_card.h" 25 #include "components/autofill/core/browser/credit_card.h"
25 #include "components/autofill/core/browser/personal_data_manager.h" 26 #include "components/autofill/core/browser/personal_data_manager.h"
26 #include "components/autofill/core/browser/phone_number_i18n.h" 27 #include "components/autofill/core/browser/phone_number_i18n.h"
27 #include "components/autofill/core/common/autofill_constants.h" 28 #include "components/autofill/core/common/autofill_constants.h"
28 #include "content/public/browser/web_ui.h" 29 #include "content/public/browser/web_ui.h"
29 #include "grit/component_strings.h" 30 #include "grit/component_strings.h"
30 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
32 #include "grit/libaddressinput_strings.h"
33 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui.h"
34 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_ui_component.h"
31 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/webui/web_ui_util.h" 36 #include "ui/base/webui/web_ui_util.h"
33 37
34 using autofill::AutofillCountry; 38 using autofill::AutofillCountry;
35 using autofill::ServerFieldType; 39 using autofill::ServerFieldType;
36 using autofill::AutofillProfile; 40 using autofill::AutofillProfile;
37 using autofill::CreditCard; 41 using autofill::CreditCard;
38 using autofill::PersonalDataManager; 42 using autofill::PersonalDataManager;
43 using i18n::addressinput::AddressUiComponent;
39 44
40 namespace { 45 namespace {
41 46
42 const char kSettingsOrigin[] = "Chrome settings"; 47 const char kSettingsOrigin[] = "Chrome settings";
43 48
49 static const char kFullNameField[] = "fullName";
50 static const char kCompanyNameField[] = "companyName";
51 static const char kAddressLineField[] = "addrLines";
52 static const char kDependentLocalityField[] = "dependentLocality";
53 static const char kCityField[] = "city";
54 static const char kStateField[] = "state";
55 static const char kPostalCodeField[] = "postalCode";
56 static const char kSortingCodeField[] = "sortingCode";
57 static const char kCountryField[] = "country";
58
59 // Fills |components| with the address UI components that should be used to
60 // input an address for |country_code| when UI BCP 47 language code is
61 // |ui_language_code|. If |components_language_code| is not NULL, then sets it
62 // to the BCP 47 language code that should be used to format the address for
63 // display.
64 void GetAddressComponents(const std::string& country_code,
65 const std::string& ui_language_code,
66 base::ListValue* address_components,
67 std::string* components_language_code) {
68 DCHECK(address_components);
69
70 std::vector<AddressUiComponent> components =
71 i18n::addressinput::BuildComponents(
72 country_code, ui_language_code, components_language_code);
73 if (components.empty()) {
74 static const char kDefaultCountryCode[] = "US";
75 components = i18n::addressinput::BuildComponents(
76 kDefaultCountryCode, ui_language_code, components_language_code);
77 }
78 DCHECK(!components.empty());
79
80 base::ListValue* line = NULL;
81 static const char kField[] = "field";
82 static const char kLength[] = "length";
83 for (size_t i = 0; i < components.size(); ++i) {
84 if (i == 0 ||
85 components[i - 1].length_hint == AddressUiComponent::HINT_LONG ||
86 components[i].length_hint == AddressUiComponent::HINT_LONG) {
87 line = new base::ListValue;
88 address_components->Append(line);
89 }
90
91 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue);
92 component->SetString(
93 "name", l10n_util::GetStringUTF16(components[i].name_id));
94
95 switch (components[i].field) {
96 case i18n::addressinput::COUNTRY:
97 component->SetString(kField, kCountryField);
98 break;
99 case i18n::addressinput::ADMIN_AREA:
100 component->SetString(kField, kStateField);
101 break;
102 case i18n::addressinput::LOCALITY:
103 component->SetString(kField, kCityField);
104 break;
105 case i18n::addressinput::DEPENDENT_LOCALITY:
106 component->SetString(kField, kDependentLocalityField);
107 break;
108 case i18n::addressinput::SORTING_CODE:
109 component->SetString(kField, kSortingCodeField);
110 break;
111 case i18n::addressinput::POSTAL_CODE:
112 component->SetString(kField, kPostalCodeField);
113 break;
114 case i18n::addressinput::STREET_ADDRESS:
115 component->SetString(kField, kAddressLineField);
116 break;
117 case i18n::addressinput::ORGANIZATION:
118 component->SetString(kField, kCompanyNameField);
119 break;
120 case i18n::addressinput::RECIPIENT:
121 component->SetString(kField, kFullNameField);
122 break;
123 }
124
125 switch (components[i].length_hint) {
126 case AddressUiComponent::HINT_LONG:
127 component->SetString(kLength, "long");
128 break;
129 case AddressUiComponent::HINT_SHORT:
130 component->SetString(kLength, "short");
131 break;
132 }
133
134 line->Append(component.release());
135 }
136 }
137
44 // Sets data related to the country <select>. 138 // Sets data related to the country <select>.
45 void SetCountryData(const PersonalDataManager& manager, 139 void SetCountryData(const PersonalDataManager& manager,
46 base::DictionaryValue* localized_strings) { 140 base::DictionaryValue* localized_strings) {
47 autofill::CountryComboboxModel model( 141 autofill::CountryComboboxModel model(
48 manager, base::Callback<bool(const std::string&)>()); 142 manager, base::Callback<bool(const std::string&)>());
49 const std::vector<AutofillCountry*>& countries = model.countries(); 143 const std::vector<AutofillCountry*>& countries = model.countries();
50 localized_strings->SetString("defaultCountryCode", 144 localized_strings->SetString("defaultCountryCode",
51 countries.front()->country_code()); 145 countries.front()->country_code());
52 146
53 // An ordered list of options to show in the <select>. 147 // An ordered list of options to show in the <select>.
54 scoped_ptr<base::ListValue> country_list(new base::ListValue()); 148 scoped_ptr<base::ListValue> country_list(new base::ListValue());
55 // A dictionary of postal code and state info, keyed on country code.
56 scoped_ptr<base::DictionaryValue> country_data(new base::DictionaryValue());
57 for (size_t i = 0; i < countries.size(); ++i) { 149 for (size_t i = 0; i < countries.size(); ++i) {
58 scoped_ptr<base::DictionaryValue> option_details( 150 scoped_ptr<base::DictionaryValue> option_details(
59 new base::DictionaryValue()); 151 new base::DictionaryValue());
60 option_details->SetString("name", model.GetItemAt(i)); 152 option_details->SetString("name", model.GetItemAt(i));
61 option_details->SetString( 153 option_details->SetString(
62 "value", 154 "value",
63 countries[i] ? countries[i]->country_code() : "separator"); 155 countries[i] ? countries[i]->country_code() : "separator");
64 country_list->Append(option_details.release()); 156 country_list->Append(option_details.release());
65
66 if (!countries[i])
67 continue;
68
69 scoped_ptr<base::DictionaryValue> details(new base::DictionaryValue());
70 details->SetString("postalCodeLabel", countries[i]->postal_code_label());
71 details->SetString("stateLabel", countries[i]->state_label());
72 country_data->Set(countries[i]->country_code(), details.release());
73
74 } 157 }
75 localized_strings->Set("autofillCountrySelectList", country_list.release()); 158 localized_strings->Set("autofillCountrySelectList", country_list.release());
76 localized_strings->Set("autofillCountryData", country_data.release()); 159
160 scoped_ptr<base::ListValue> defaultCountryComponents(new base::ListValue);
161 std::string defaultCountryLanguageCode;
162 GetAddressComponents(countries.front()->country_code(),
163 g_browser_process->GetApplicationLocale(),
164 defaultCountryComponents.get(),
165 &defaultCountryLanguageCode);
166 localized_strings->Set("autofillDefaultCountryComponents",
167 defaultCountryComponents.release());
168 localized_strings->SetString("autofillDefaultCountryLanguageCode",
169 defaultCountryLanguageCode);
77 } 170 }
78 171
79 // Get the multi-valued element for |type| and return it in |ListValue| form. 172 // Get the multi-valued element for |type| and return it in |ListValue| form.
80 void GetValueList(const AutofillProfile& profile, 173 void GetValueList(const AutofillProfile& profile,
81 ServerFieldType type, 174 ServerFieldType type,
82 scoped_ptr<base::ListValue>* list) { 175 scoped_ptr<base::ListValue>* list) {
83 list->reset(new base::ListValue); 176 list->reset(new base::ListValue);
84 177
85 std::vector<base::string16> values; 178 std::vector<base::string16> values;
86 profile.GetRawMultiInfo(type, &values); 179 profile.GetRawMultiInfo(type, &values);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 392
300 web_ui()->RegisterMessageCallback( 393 web_ui()->RegisterMessageCallback(
301 "removeData", 394 "removeData",
302 base::Bind(&AutofillOptionsHandler::RemoveData, 395 base::Bind(&AutofillOptionsHandler::RemoveData,
303 base::Unretained(this))); 396 base::Unretained(this)));
304 web_ui()->RegisterMessageCallback( 397 web_ui()->RegisterMessageCallback(
305 "loadAddressEditor", 398 "loadAddressEditor",
306 base::Bind(&AutofillOptionsHandler::LoadAddressEditor, 399 base::Bind(&AutofillOptionsHandler::LoadAddressEditor,
307 base::Unretained(this))); 400 base::Unretained(this)));
308 web_ui()->RegisterMessageCallback( 401 web_ui()->RegisterMessageCallback(
402 "loadAddressEditorComponents",
403 base::Bind(&AutofillOptionsHandler::LoadAddressEditorComponents,
404 base::Unretained(this)));
405 web_ui()->RegisterMessageCallback(
309 "loadCreditCardEditor", 406 "loadCreditCardEditor",
310 base::Bind(&AutofillOptionsHandler::LoadCreditCardEditor, 407 base::Bind(&AutofillOptionsHandler::LoadCreditCardEditor,
311 base::Unretained(this))); 408 base::Unretained(this)));
312 web_ui()->RegisterMessageCallback( 409 web_ui()->RegisterMessageCallback(
313 "setAddress", 410 "setAddress",
314 base::Bind(&AutofillOptionsHandler::SetAddress, base::Unretained(this))); 411 base::Bind(&AutofillOptionsHandler::SetAddress, base::Unretained(this)));
315 web_ui()->RegisterMessageCallback( 412 web_ui()->RegisterMessageCallback(
316 "setCreditCard", 413 "setCreditCard",
317 base::Bind(&AutofillOptionsHandler::SetCreditCard, 414 base::Bind(&AutofillOptionsHandler::SetCreditCard,
318 base::Unretained(this))); 415 base::Unretained(this)));
(...skipping 12 matching lines...) Expand all
331 void AutofillOptionsHandler::SetAddressOverlayStrings( 428 void AutofillOptionsHandler::SetAddressOverlayStrings(
332 base::DictionaryValue* localized_strings) { 429 base::DictionaryValue* localized_strings) {
333 localized_strings->SetString("autofillEditAddressTitle", 430 localized_strings->SetString("autofillEditAddressTitle",
334 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); 431 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION));
335 localized_strings->SetString("autofillFirstNameLabel", 432 localized_strings->SetString("autofillFirstNameLabel",
336 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_FIRST_NAME)); 433 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_FIRST_NAME));
337 localized_strings->SetString("autofillMiddleNameLabel", 434 localized_strings->SetString("autofillMiddleNameLabel",
338 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_MIDDLE_NAME)); 435 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_MIDDLE_NAME));
339 localized_strings->SetString("autofillLastNameLabel", 436 localized_strings->SetString("autofillLastNameLabel",
340 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_LAST_NAME)); 437 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_LAST_NAME));
341 localized_strings->SetString("autofillCompanyNameLabel", 438 localized_strings->SetString("autofillAddrLinesLabel",
342 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COMPANY_NAME)); 439 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_I18N_ADDRESS_LINE1_LABEL));
343 localized_strings->SetString("autofillAddrLine1Label",
344 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADDRESS_LINE_1));
345 localized_strings->SetString("autofillAddrLine2Label",
346 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADDRESS_LINE_2));
347 localized_strings->SetString("autofillCityLabel",
348 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CITY));
349 localized_strings->SetString("autofillCountryLabel", 440 localized_strings->SetString("autofillCountryLabel",
350 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY)); 441 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL));
351 localized_strings->SetString("autofillPhoneLabel", 442 localized_strings->SetString("autofillPhoneLabel",
352 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); 443 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE));
353 localized_strings->SetString("autofillEmailLabel", 444 localized_strings->SetString("autofillEmailLabel",
354 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); 445 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL));
355 localized_strings->SetString("autofillAddFirstNamePlaceholder", 446 localized_strings->SetString("autofillAddFirstNamePlaceholder",
356 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_FIRST_NAME)); 447 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_FIRST_NAME));
357 localized_strings->SetString("autofillAddMiddleNamePlaceholder", 448 localized_strings->SetString("autofillAddMiddleNamePlaceholder",
358 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_MIDDLE_NAME)); 449 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_MIDDLE_NAME));
359 localized_strings->SetString("autofillAddLastNamePlaceholder", 450 localized_strings->SetString("autofillAddLastNamePlaceholder",
360 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_LAST_NAME)); 451 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_LAST_NAME));
361 localized_strings->SetString("autofillAddPhonePlaceholder", 452 localized_strings->SetString("autofillAddPhonePlaceholder",
362 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); 453 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE));
363 localized_strings->SetString("autofillAddEmailPlaceholder", 454 localized_strings->SetString("autofillAddEmailPlaceholder",
364 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); 455 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL));
456 localized_strings->SetString("autofillAddAddrLinePlaceholder",
457 l10n_util::GetStringUTF16(
458 IDS_AUTOFILL_FIELD_LABEL_ADD_STREET_ADDRESS_LINE));
365 SetCountryData(*personal_data_, localized_strings); 459 SetCountryData(*personal_data_, localized_strings);
366 } 460 }
367 461
368 void AutofillOptionsHandler::SetCreditCardOverlayStrings( 462 void AutofillOptionsHandler::SetCreditCardOverlayStrings(
369 base::DictionaryValue* localized_strings) { 463 base::DictionaryValue* localized_strings) {
370 localized_strings->SetString("autofillEditCreditCardTitle", 464 localized_strings->SetString("autofillEditCreditCardTitle",
371 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); 465 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION));
372 localized_strings->SetString("nameOnCardLabel", 466 localized_strings->SetString("nameOnCardLabel",
373 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD)); 467 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD));
374 localized_strings->SetString("creditCardNumberLabel", 468 localized_strings->SetString("creditCardNumberLabel",
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // the list is not updated until the model tells the list an item has been 539 // the list is not updated until the model tells the list an item has been
446 // removed). This will activate the editor for a profile that has been 540 // removed). This will activate the editor for a profile that has been
447 // removed. Do nothing in that case. 541 // removed. Do nothing in that case.
448 return; 542 return;
449 } 543 }
450 544
451 base::DictionaryValue address; 545 base::DictionaryValue address;
452 address.SetString("guid", profile->guid()); 546 address.SetString("guid", profile->guid());
453 scoped_ptr<base::ListValue> list; 547 scoped_ptr<base::ListValue> list;
454 GetNameList(*profile, &list); 548 GetNameList(*profile, &list);
455 address.Set("fullName", list.release()); 549 address.Set(kFullNameField, list.release());
456 address.SetString("companyName", profile->GetRawInfo(autofill::COMPANY_NAME)); 550 address.SetString(
457 address.SetString("addrLine1", 551 kCompanyNameField, profile->GetRawInfo(autofill::COMPANY_NAME));
458 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE1)); 552
459 address.SetString("addrLine2", 553 std::vector<base::string16> street_address;
460 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE2)); 554 base::SplitString(profile->GetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS),
461 address.SetString("city", profile->GetRawInfo(autofill::ADDRESS_HOME_CITY)); 555 '\n', &street_address);
462 address.SetString("state", profile->GetRawInfo(autofill::ADDRESS_HOME_STATE)); 556 scoped_ptr<base::ListValue> street_address_list(new base::ListValue);
463 address.SetString("postalCode", 557 street_address_list->AppendStrings(street_address);
558 address.Set(kAddressLineField, street_address_list.release());
559
560 address.SetString(
561 kCityField, profile->GetRawInfo(autofill::ADDRESS_HOME_CITY));
562 address.SetString(
563 kStateField, profile->GetRawInfo(autofill::ADDRESS_HOME_STATE));
564 address.SetString(
565 kDependentLocalityField,
566 profile->GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY));
567 address.SetString(kSortingCodeField,
568 profile->GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE));
569 address.SetString(kPostalCodeField,
464 profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP)); 570 profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP));
465 address.SetString("country", 571 address.SetString(kCountryField,
466 profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); 572 profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
467 GetValueList(*profile, autofill::PHONE_HOME_WHOLE_NUMBER, &list); 573 GetValueList(*profile, autofill::PHONE_HOME_WHOLE_NUMBER, &list);
468 address.Set("phone", list.release()); 574 address.Set("phone", list.release());
469 GetValueList(*profile, autofill::EMAIL_ADDRESS, &list); 575 GetValueList(*profile, autofill::EMAIL_ADDRESS, &list);
470 address.Set("email", list.release()); 576 address.Set("email", list.release());
577 address.SetString("languageCode", profile->language_code());
578
579 scoped_ptr<base::ListValue> components(new base::ListValue);
580 GetAddressComponents(
581 UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)),
582 profile->language_code(), components.get(), NULL);
583 address.Set("components", components.release());
471 584
472 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); 585 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address);
473 } 586 }
474 587
588 void AutofillOptionsHandler::LoadAddressEditorComponents(
589 const base::ListValue* args) {
590 std::string country_code;
591 if (!args->GetString(0, &country_code)) {
592 NOTREACHED();
593 return;
594 }
595
596 base::DictionaryValue input;
597 scoped_ptr<base::ListValue> components(new base::ListValue);
598 std::string language_code;
599 GetAddressComponents(country_code, g_browser_process->GetApplicationLocale(),
600 components.get(), &language_code);
601 input.Set("components", components.release());
602 input.SetString("languageCode", language_code);
603
604 web_ui()->CallJavascriptFunction(
605 "AutofillEditAddressOverlay.loadAddressComponents", input);
606 }
607
475 void AutofillOptionsHandler::LoadCreditCardEditor(const base::ListValue* args) { 608 void AutofillOptionsHandler::LoadCreditCardEditor(const base::ListValue* args) {
476 DCHECK(IsPersonalDataLoaded()); 609 DCHECK(IsPersonalDataLoaded());
477 610
478 std::string guid; 611 std::string guid;
479 if (!args->GetString(0, &guid)) { 612 if (!args->GetString(0, &guid)) {
480 NOTREACHED(); 613 NOTREACHED();
481 return; 614 return;
482 } 615 }
483 616
484 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); 617 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 649
517 std::string guid; 650 std::string guid;
518 if (!args->GetString(0, &guid)) { 651 if (!args->GetString(0, &guid)) {
519 NOTREACHED(); 652 NOTREACHED();
520 return; 653 return;
521 } 654 }
522 655
523 AutofillProfile profile(guid, kSettingsOrigin); 656 AutofillProfile profile(guid, kSettingsOrigin);
524 657
525 std::string country_code; 658 std::string country_code;
659 std::string language_code;
526 base::string16 value; 660 base::string16 value;
527 const base::ListValue* list_value; 661 const base::ListValue* list_value;
528 if (args->GetList(1, &list_value)) 662 if (args->GetList(1, &list_value))
529 SetNameList(list_value, &profile); 663 SetNameList(list_value, &profile);
530 664
531 if (args->GetString(2, &value)) 665 if (args->GetString(2, &value))
532 profile.SetRawInfo(autofill::COMPANY_NAME, value); 666 profile.SetRawInfo(autofill::COMPANY_NAME, value);
533 667
534 if (args->GetString(3, &value)) 668 if (args->GetList(3, &list_value)) {
535 profile.SetRawInfo(autofill::ADDRESS_HOME_LINE1, value); 669 std::vector<base::string16> street_address;
670 for (size_t i = 0; i < list_value->GetSize(); ++i) {
671 if (list_value->GetString(i, &value))
672 street_address.push_back(value);
673 }
674 profile.SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS,
675 JoinString(street_address, '\n'));
676 }
536 677
537 if (args->GetString(4, &value)) 678 if (args->GetString(4, &value))
538 profile.SetRawInfo(autofill::ADDRESS_HOME_LINE2, value); 679 profile.SetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, value);
539 680
540 if (args->GetString(5, &value)) 681 if (args->GetString(5, &value))
541 profile.SetRawInfo(autofill::ADDRESS_HOME_CITY, value); 682 profile.SetRawInfo(autofill::ADDRESS_HOME_CITY, value);
542 683
543 if (args->GetString(6, &value)) 684 if (args->GetString(6, &value))
544 profile.SetRawInfo(autofill::ADDRESS_HOME_STATE, value); 685 profile.SetRawInfo(autofill::ADDRESS_HOME_STATE, value);
545 686
546 if (args->GetString(7, &value)) 687 if (args->GetString(7, &value))
547 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, value); 688 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, value);
548 689
549 if (args->GetString(8, &country_code)) 690 if (args->GetString(8, &value))
691 profile.SetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE, value);
692
693 if (args->GetString(9, &country_code))
550 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY, 694 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY,
551 base::ASCIIToUTF16(country_code)); 695 base::ASCIIToUTF16(country_code));
552 696
553 if (args->GetList(9, &list_value)) 697 if (args->GetList(10, &list_value))
554 SetValueList(list_value, autofill::PHONE_HOME_WHOLE_NUMBER, &profile); 698 SetValueList(list_value, autofill::PHONE_HOME_WHOLE_NUMBER, &profile);
555 699
556 if (args->GetList(10, &list_value)) 700 if (args->GetList(11, &list_value))
557 SetValueList(list_value, autofill::EMAIL_ADDRESS, &profile); 701 SetValueList(list_value, autofill::EMAIL_ADDRESS, &profile);
558 702
703 if (args->GetString(12, &language_code))
704 profile.set_language_code(language_code);
705
559 if (!base::IsValidGUID(profile.guid())) { 706 if (!base::IsValidGUID(profile.guid())) {
560 profile.set_guid(base::GenerateGUID()); 707 profile.set_guid(base::GenerateGUID());
561 personal_data_->AddProfile(profile); 708 personal_data_->AddProfile(profile);
562 } else { 709 } else {
563 personal_data_->UpdateProfile(profile); 710 personal_data_->UpdateProfile(profile);
564 } 711 }
565 } 712 }
566 713
567 void AutofillOptionsHandler::SetCreditCard(const base::ListValue* args) { 714 void AutofillOptionsHandler::SetCreditCard(const base::ListValue* args) {
568 if (!IsPersonalDataLoaded()) 715 if (!IsPersonalDataLoaded())
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 752
606 web_ui()->CallJavascriptFunction( 753 web_ui()->CallJavascriptFunction(
607 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); 754 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value);
608 } 755 }
609 756
610 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { 757 bool AutofillOptionsHandler::IsPersonalDataLoaded() const {
611 return personal_data_ && personal_data_->IsDataLoaded(); 758 return personal_data_ && personal_data_->IsDataLoaded();
612 } 759 }
613 760
614 } // namespace options 761 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698