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