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

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: 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;
39 43
40 namespace { 44 namespace {
41 45
42 const char kSettingsOrigin[] = "Chrome settings"; 46 const char kSettingsOrigin[] = "Chrome settings";
43 47
44 // Sets data related to the country <select>. 48 // Sets data related to the country <select>.
45 void SetCountryData(const PersonalDataManager& manager, 49 void SetCountryData(const PersonalDataManager& manager,
46 base::DictionaryValue* localized_strings) { 50 base::DictionaryValue* localized_strings) {
47 autofill::CountryComboboxModel model( 51 autofill::CountryComboboxModel model(
48 manager, base::Callback<bool(const std::string&)>()); 52 manager, base::Callback<bool(const std::string&)>());
49 const std::vector<AutofillCountry*>& countries = model.countries(); 53 const std::vector<AutofillCountry*>& countries = model.countries();
50 localized_strings->SetString("defaultCountryCode", 54 localized_strings->SetString("defaultCountryCode",
51 countries.front()->country_code()); 55 countries.front()->country_code());
52 56
53 // An ordered list of options to show in the <select>. 57 // An ordered list of options to show in the <select>.
54 scoped_ptr<base::ListValue> country_list(new base::ListValue()); 58 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) { 59 for (size_t i = 0; i < countries.size(); ++i) {
58 scoped_ptr<base::DictionaryValue> option_details( 60 scoped_ptr<base::DictionaryValue> option_details(
59 new base::DictionaryValue()); 61 new base::DictionaryValue());
60 option_details->SetString("name", model.GetItemAt(i)); 62 option_details->SetString("name", model.GetItemAt(i));
61 option_details->SetString( 63 option_details->SetString(
62 "value", 64 "value",
63 countries[i] ? countries[i]->country_code() : "separator"); 65 countries[i] ? countries[i]->country_code() : "separator");
64 country_list->Append(option_details.release()); 66 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 } 67 }
75 localized_strings->Set("autofillCountrySelectList", country_list.release()); 68 localized_strings->Set("autofillCountrySelectList", country_list.release());
76 localized_strings->Set("autofillCountryData", country_data.release()); 69 }
70
71 // Fills |components| with the address UI components that should be used to
72 // input an address for |country_code| when UI BCP 47 language code is
73 // |ui_language_code|. If |components_language_code| is not NULL, then sets it
74 // the BCP 47 language code that should be used to format the address for
75 // display.
76 void GetAddressComponents(const std::string& country_code,
77 const std::string& ui_language_code,
78 base::ListValue* address_components,
79 std::string* components_language_code) {
80 DCHECK(address_components);
81 std::vector<i18n::addressinput::AddressUiComponent> components =
82 i18n::addressinput::BuildComponents(
83 country_code, ui_language_code, components_language_code);
84 if (components.empty()) {
85 static const char kDefaultCountryCode[] = "US";
86 components = i18n::addressinput::BuildComponents(
87 kDefaultCountryCode, ui_language_code, components_language_code);
88 }
89 DCHECK(!components.empty());
90 static const char kField[] = "field";
91 static const char kLengthHint[] = "length";
92 for (std::vector<i18n::addressinput::AddressUiComponent>::const_iterator it =
93 components.begin();
94 it != components.end(); ++it) {
95 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue);
96 switch (it->field) {
97 case i18n::addressinput::COUNTRY:
98 component->SetString(kField, "country");
99 break;
100 case i18n::addressinput::ADMIN_AREA:
101 component->SetString(kField, "admin-area");
102 break;
103 case i18n::addressinput::LOCALITY:
104 component->SetString(kField, "locality");
105 break;
106 case i18n::addressinput::DEPENDENT_LOCALITY:
107 component->SetString(kField, "dependent-locality");
108 break;
109 case i18n::addressinput::SORTING_CODE:
110 component->SetString(kField, "sorting-code");
111 break;
112 case i18n::addressinput::POSTAL_CODE:
113 component->SetString(kField, "postal-code");
114 break;
115 case i18n::addressinput::STREET_ADDRESS:
116 component->SetString(kField, "street-address");
117 break;
118 case i18n::addressinput::ORGANIZATION:
119 component->SetString(kField, "organization");
120 break;
121 case i18n::addressinput::RECIPIENT:
122 component->SetString(kField, "recipient");
123 break;
124 }
125 component->SetString("name", l10n_util::GetStringUTF16(it->name_id));
126 switch (it->length_hint) {
127 case i18n::addressinput::AddressUiComponent::HINT_SHORT:
128 component->SetString(kLengthHint, "short");
129 break;
130 case i18n::addressinput::AddressUiComponent::HINT_LONG:
131 component->SetString(kLengthHint, "long");
132 break;
133 }
134 address_components->Append(component.release());
135 }
77 } 136 }
Evan Stade 2014/04/22 00:51:58 vertical whitespace in this function
please use gerrit instead 2014/04/24 20:10:59 Done.
78 137
79 // Get the multi-valued element for |type| and return it in |ListValue| form. 138 // Get the multi-valued element for |type| and return it in |ListValue| form.
80 void GetValueList(const AutofillProfile& profile, 139 void GetValueList(const AutofillProfile& profile,
81 ServerFieldType type, 140 ServerFieldType type,
82 scoped_ptr<base::ListValue>* list) { 141 scoped_ptr<base::ListValue>* list) {
83 list->reset(new base::ListValue); 142 list->reset(new base::ListValue);
84 143
85 std::vector<base::string16> values; 144 std::vector<base::string16> values;
86 profile.GetRawMultiInfo(type, &values); 145 profile.GetRawMultiInfo(type, &values);
87 146
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 358
300 web_ui()->RegisterMessageCallback( 359 web_ui()->RegisterMessageCallback(
301 "removeData", 360 "removeData",
302 base::Bind(&AutofillOptionsHandler::RemoveData, 361 base::Bind(&AutofillOptionsHandler::RemoveData,
303 base::Unretained(this))); 362 base::Unretained(this)));
304 web_ui()->RegisterMessageCallback( 363 web_ui()->RegisterMessageCallback(
305 "loadAddressEditor", 364 "loadAddressEditor",
306 base::Bind(&AutofillOptionsHandler::LoadAddressEditor, 365 base::Bind(&AutofillOptionsHandler::LoadAddressEditor,
307 base::Unretained(this))); 366 base::Unretained(this)));
308 web_ui()->RegisterMessageCallback( 367 web_ui()->RegisterMessageCallback(
368 "loadAddressEditorComponents",
369 base::Bind(&AutofillOptionsHandler::LoadAddressEditorComponents,
370 base::Unretained(this)));
371 web_ui()->RegisterMessageCallback(
309 "loadCreditCardEditor", 372 "loadCreditCardEditor",
310 base::Bind(&AutofillOptionsHandler::LoadCreditCardEditor, 373 base::Bind(&AutofillOptionsHandler::LoadCreditCardEditor,
311 base::Unretained(this))); 374 base::Unretained(this)));
312 web_ui()->RegisterMessageCallback( 375 web_ui()->RegisterMessageCallback(
313 "setAddress", 376 "setAddress",
314 base::Bind(&AutofillOptionsHandler::SetAddress, base::Unretained(this))); 377 base::Bind(&AutofillOptionsHandler::SetAddress, base::Unretained(this)));
315 web_ui()->RegisterMessageCallback( 378 web_ui()->RegisterMessageCallback(
316 "setCreditCard", 379 "setCreditCard",
317 base::Bind(&AutofillOptionsHandler::SetCreditCard, 380 base::Bind(&AutofillOptionsHandler::SetCreditCard,
318 base::Unretained(this))); 381 base::Unretained(this)));
(...skipping 12 matching lines...) Expand all
331 void AutofillOptionsHandler::SetAddressOverlayStrings( 394 void AutofillOptionsHandler::SetAddressOverlayStrings(
332 base::DictionaryValue* localized_strings) { 395 base::DictionaryValue* localized_strings) {
333 localized_strings->SetString("autofillEditAddressTitle", 396 localized_strings->SetString("autofillEditAddressTitle",
334 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); 397 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION));
335 localized_strings->SetString("autofillFirstNameLabel", 398 localized_strings->SetString("autofillFirstNameLabel",
336 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_FIRST_NAME)); 399 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_FIRST_NAME));
337 localized_strings->SetString("autofillMiddleNameLabel", 400 localized_strings->SetString("autofillMiddleNameLabel",
338 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_MIDDLE_NAME)); 401 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_MIDDLE_NAME));
339 localized_strings->SetString("autofillLastNameLabel", 402 localized_strings->SetString("autofillLastNameLabel",
340 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_LAST_NAME)); 403 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_LAST_NAME));
341 localized_strings->SetString("autofillCompanyNameLabel",
342 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COMPANY_NAME));
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", 404 localized_strings->SetString("autofillCountryLabel",
350 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY)); 405 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL));
351 localized_strings->SetString("autofillPhoneLabel", 406 localized_strings->SetString("autofillPhoneLabel",
352 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); 407 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE));
353 localized_strings->SetString("autofillEmailLabel", 408 localized_strings->SetString("autofillEmailLabel",
354 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); 409 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL));
355 localized_strings->SetString("autofillAddFirstNamePlaceholder", 410 localized_strings->SetString("autofillAddFirstNamePlaceholder",
356 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_FIRST_NAME)); 411 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_FIRST_NAME));
357 localized_strings->SetString("autofillAddMiddleNamePlaceholder", 412 localized_strings->SetString("autofillAddMiddleNamePlaceholder",
358 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_MIDDLE_NAME)); 413 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_MIDDLE_NAME));
359 localized_strings->SetString("autofillAddLastNamePlaceholder", 414 localized_strings->SetString("autofillAddLastNamePlaceholder",
360 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_LAST_NAME)); 415 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_LAST_NAME));
361 localized_strings->SetString("autofillAddPhonePlaceholder", 416 localized_strings->SetString("autofillAddPhonePlaceholder",
362 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); 417 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE));
363 localized_strings->SetString("autofillAddEmailPlaceholder", 418 localized_strings->SetString("autofillAddEmailPlaceholder",
364 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); 419 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL));
420 localized_strings->SetString("addStreetAddressLinePlaceholder",
421 l10n_util::GetStringUTF16(
422 IDS_AUTOFILL_FIELD_LABEL_ADD_STREET_ADDRESS_LINE));
365 SetCountryData(*personal_data_, localized_strings); 423 SetCountryData(*personal_data_, localized_strings);
366 } 424 }
367 425
368 void AutofillOptionsHandler::SetCreditCardOverlayStrings( 426 void AutofillOptionsHandler::SetCreditCardOverlayStrings(
369 base::DictionaryValue* localized_strings) { 427 base::DictionaryValue* localized_strings) {
370 localized_strings->SetString("autofillEditCreditCardTitle", 428 localized_strings->SetString("autofillEditCreditCardTitle",
371 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); 429 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION));
372 localized_strings->SetString("nameOnCardLabel", 430 localized_strings->SetString("nameOnCardLabel",
373 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD)); 431 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD));
374 localized_strings->SetString("creditCardNumberLabel", 432 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 503 // 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 504 // removed). This will activate the editor for a profile that has been
447 // removed. Do nothing in that case. 505 // removed. Do nothing in that case.
448 return; 506 return;
449 } 507 }
450 508
451 base::DictionaryValue address; 509 base::DictionaryValue address;
452 address.SetString("guid", profile->guid()); 510 address.SetString("guid", profile->guid());
453 scoped_ptr<base::ListValue> list; 511 scoped_ptr<base::ListValue> list;
454 GetNameList(*profile, &list); 512 GetNameList(*profile, &list);
455 address.Set("fullName", list.release()); 513 address.Set("recipient", list.release());
456 address.SetString("companyName", profile->GetRawInfo(autofill::COMPANY_NAME)); 514 address.SetString(
457 address.SetString("addrLine1", 515 "organization", profile->GetRawInfo(autofill::COMPANY_NAME));
458 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE1)); 516
459 address.SetString("addrLine2", 517 std::vector<base::string16> street_address;
460 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE2)); 518 base::SplitString(profile->GetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS),
461 address.SetString("city", profile->GetRawInfo(autofill::ADDRESS_HOME_CITY)); 519 '\n', &street_address);
462 address.SetString("state", profile->GetRawInfo(autofill::ADDRESS_HOME_STATE)); 520 scoped_ptr<base::ListValue> street_address_list(new base::ListValue);
521 street_address_list->AppendStrings(street_address);
522 address.Set("streetAddress", street_address_list.release());
523
524 address.SetString(
525 "locality", profile->GetRawInfo(autofill::ADDRESS_HOME_CITY));
526 address.SetString(
527 "adminArea", profile->GetRawInfo(autofill::ADDRESS_HOME_STATE));
528 address.SetString(
529 "dependentLocality",
530 profile->GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY));
531 address.SetString("sortingCode",
532 profile->GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE));
463 address.SetString("postalCode", 533 address.SetString("postalCode",
464 profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP)); 534 profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP));
465 address.SetString("country", 535 address.SetString("country",
466 profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); 536 profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY));
467 GetValueList(*profile, autofill::PHONE_HOME_WHOLE_NUMBER, &list); 537 GetValueList(*profile, autofill::PHONE_HOME_WHOLE_NUMBER, &list);
468 address.Set("phone", list.release()); 538 address.Set("phone", list.release());
469 GetValueList(*profile, autofill::EMAIL_ADDRESS, &list); 539 GetValueList(*profile, autofill::EMAIL_ADDRESS, &list);
470 address.Set("email", list.release()); 540 address.Set("email", list.release());
541 address.SetString("languageCode", profile->language_code());
542
543 scoped_ptr<base::ListValue> components(new base::ListValue);
544 GetAddressComponents(
545 UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)),
546 profile->language_code(), components.get(), NULL);
547 address.Set("components", components.release());
471 548
472 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); 549 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address);
473 } 550 }
474 551
552 void AutofillOptionsHandler::LoadAddressEditorComponents(
553 const base::ListValue* args) {
554 std::string country_code;
555 if (!args->GetString(0, &country_code)) {
556 NOTREACHED();
557 return;
558 }
559
560 base::DictionaryValue input;
561 scoped_ptr<base::ListValue> components(new base::ListValue);
562 std::string language_code;
563 GetAddressComponents(country_code, g_browser_process->GetApplicationLocale(),
564 components.get(), &language_code);
565 input.Set("components", components.release());
566 input.SetString("languageCode", language_code);
567
568 web_ui()->CallJavascriptFunction(
569 "AutofillEditAddressOverlay.loadAddressComponents", input);
570 }
571
475 void AutofillOptionsHandler::LoadCreditCardEditor(const base::ListValue* args) { 572 void AutofillOptionsHandler::LoadCreditCardEditor(const base::ListValue* args) {
476 DCHECK(IsPersonalDataLoaded()); 573 DCHECK(IsPersonalDataLoaded());
477 574
478 std::string guid; 575 std::string guid;
479 if (!args->GetString(0, &guid)) { 576 if (!args->GetString(0, &guid)) {
480 NOTREACHED(); 577 NOTREACHED();
481 return; 578 return;
482 } 579 }
483 580
484 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); 581 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 613
517 std::string guid; 614 std::string guid;
518 if (!args->GetString(0, &guid)) { 615 if (!args->GetString(0, &guid)) {
519 NOTREACHED(); 616 NOTREACHED();
520 return; 617 return;
521 } 618 }
522 619
523 AutofillProfile profile(guid, kSettingsOrigin); 620 AutofillProfile profile(guid, kSettingsOrigin);
524 621
525 std::string country_code; 622 std::string country_code;
623 std::string language_code;
526 base::string16 value; 624 base::string16 value;
527 const base::ListValue* list_value; 625 const base::ListValue* list_value;
528 if (args->GetList(1, &list_value)) 626 if (args->GetList(1, &list_value))
529 SetNameList(list_value, &profile); 627 SetNameList(list_value, &profile);
530 628
531 if (args->GetString(2, &value)) 629 if (args->GetString(2, &value))
532 profile.SetRawInfo(autofill::COMPANY_NAME, value); 630 profile.SetRawInfo(autofill::COMPANY_NAME, value);
533 631
534 if (args->GetString(3, &value)) 632 if (args->GetList(3, &list_value)) {
535 profile.SetRawInfo(autofill::ADDRESS_HOME_LINE1, value); 633 std::vector<base::string16> street_address;
634 for (size_t i = 0; i < list_value->GetSize(); ++i) {
635 if (list_value->GetString(i, &value))
636 street_address.push_back(value);
637 }
638 profile.SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS,
639 JoinString(street_address, '\n'));
640 }
536 641
537 if (args->GetString(4, &value)) 642 if (args->GetString(4, &value))
538 profile.SetRawInfo(autofill::ADDRESS_HOME_LINE2, value); 643 profile.SetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, value);
539 644
540 if (args->GetString(5, &value)) 645 if (args->GetString(5, &value))
541 profile.SetRawInfo(autofill::ADDRESS_HOME_CITY, value); 646 profile.SetRawInfo(autofill::ADDRESS_HOME_CITY, value);
542 647
543 if (args->GetString(6, &value)) 648 if (args->GetString(6, &value))
544 profile.SetRawInfo(autofill::ADDRESS_HOME_STATE, value); 649 profile.SetRawInfo(autofill::ADDRESS_HOME_STATE, value);
545 650
546 if (args->GetString(7, &value)) 651 if (args->GetString(7, &value))
547 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, value); 652 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, value);
548 653
549 if (args->GetString(8, &country_code)) 654 if (args->GetString(8, &value))
655 profile.SetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE, value);
656
657 if (args->GetString(9, &country_code))
550 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY, 658 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY,
551 base::ASCIIToUTF16(country_code)); 659 base::ASCIIToUTF16(country_code));
552 660
553 if (args->GetList(9, &list_value)) 661 if (args->GetList(10, &list_value))
554 SetValueList(list_value, autofill::PHONE_HOME_WHOLE_NUMBER, &profile); 662 SetValueList(list_value, autofill::PHONE_HOME_WHOLE_NUMBER, &profile);
555 663
556 if (args->GetList(10, &list_value)) 664 if (args->GetList(11, &list_value))
557 SetValueList(list_value, autofill::EMAIL_ADDRESS, &profile); 665 SetValueList(list_value, autofill::EMAIL_ADDRESS, &profile);
558 666
667 if (args->GetString(12, &language_code))
668 profile.set_language_code(language_code);
669
559 if (!base::IsValidGUID(profile.guid())) { 670 if (!base::IsValidGUID(profile.guid())) {
560 profile.set_guid(base::GenerateGUID()); 671 profile.set_guid(base::GenerateGUID());
561 personal_data_->AddProfile(profile); 672 personal_data_->AddProfile(profile);
562 } else { 673 } else {
563 personal_data_->UpdateProfile(profile); 674 personal_data_->UpdateProfile(profile);
564 } 675 }
565 } 676 }
566 677
567 void AutofillOptionsHandler::SetCreditCard(const base::ListValue* args) { 678 void AutofillOptionsHandler::SetCreditCard(const base::ListValue* args) {
568 if (!IsPersonalDataLoaded()) 679 if (!IsPersonalDataLoaded())
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 716
606 web_ui()->CallJavascriptFunction( 717 web_ui()->CallJavascriptFunction(
607 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); 718 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value);
608 } 719 }
609 720
610 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { 721 bool AutofillOptionsHandler::IsPersonalDataLoaded() const {
611 return personal_data_ && personal_data_->IsDataLoaded(); 722 return personal_data_ && personal_data_->IsDataLoaded();
612 } 723 }
613 724
614 } // namespace options 725 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698