| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "components/autofill/core/browser/autofill_country.h" | 22 #include "components/autofill/core/browser/autofill_country.h" |
| 23 #include "components/autofill/core/browser/autofill_profile.h" | 23 #include "components/autofill/core/browser/autofill_profile.h" |
| 24 #include "components/autofill/core/browser/credit_card.h" | 24 #include "components/autofill/core/browser/credit_card.h" |
| 25 #include "components/autofill/core/browser/personal_data_manager.h" | 25 #include "components/autofill/core/browser/personal_data_manager.h" |
| 26 #include "components/autofill/core/browser/phone_number_i18n.h" | 26 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 27 #include "components/autofill/core/common/autofill_constants.h" | 27 #include "components/autofill/core/common/autofill_constants.h" |
| 28 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
| 29 #include "grit/component_strings.h" | 29 #include "grit/component_strings.h" |
| 30 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 31 #include "grit/libaddressinput_strings.h" |
| 32 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" |
| 33 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui_component.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/webui/web_ui_util.h" | 35 #include "ui/base/webui/web_ui_util.h" |
| 33 | 36 |
| 34 using autofill::AutofillCountry; | 37 using autofill::AutofillCountry; |
| 35 using autofill::ServerFieldType; | 38 using autofill::ServerFieldType; |
| 36 using autofill::AutofillProfile; | 39 using autofill::AutofillProfile; |
| 37 using autofill::CreditCard; | 40 using autofill::CreditCard; |
| 38 using autofill::PersonalDataManager; | 41 using autofill::PersonalDataManager; |
| 42 using i18n::addressinput::AddressUiComponent; |
| 39 | 43 |
| 40 namespace { | 44 namespace { |
| 41 | 45 |
| 42 const char kSettingsOrigin[] = "Chrome settings"; | 46 const char kSettingsOrigin[] = "Chrome settings"; |
| 43 | 47 |
| 48 static const char kFullNameField[] = "fullName"; |
| 49 static const char kCompanyNameField[] = "companyName"; |
| 50 static const char kAddressLineField[] = "addrLines"; |
| 51 static const char kDependentLocalityField[] = "dependentLocality"; |
| 52 static const char kCityField[] = "city"; |
| 53 static const char kStateField[] = "state"; |
| 54 static const char kPostalCodeField[] = "postalCode"; |
| 55 static const char kSortingCodeField[] = "sortingCode"; |
| 56 static const char kCountryField[] = "country"; |
| 57 |
| 58 static const char kComponents[] = "components"; |
| 59 static const char kLanguageCode[] = "languageCode"; |
| 60 |
| 61 // Fills |components| with the address UI components that should be used to |
| 62 // input an address for |country_code| when UI BCP 47 language code is |
| 63 // |ui_language_code|. If |components_language_code| is not NULL, then sets it |
| 64 // to the BCP 47 language code that should be used to format the address for |
| 65 // display. |
| 66 void GetAddressComponents(const std::string& country_code, |
| 67 const std::string& ui_language_code, |
| 68 base::ListValue* address_components, |
| 69 std::string* components_language_code) { |
| 70 DCHECK(address_components); |
| 71 |
| 72 std::vector<AddressUiComponent> components = |
| 73 i18n::addressinput::BuildComponents( |
| 74 country_code, ui_language_code, components_language_code); |
| 75 if (components.empty()) { |
| 76 static const char kDefaultCountryCode[] = "US"; |
| 77 components = i18n::addressinput::BuildComponents( |
| 78 kDefaultCountryCode, ui_language_code, components_language_code); |
| 79 } |
| 80 DCHECK(!components.empty()); |
| 81 |
| 82 base::ListValue* line = NULL; |
| 83 static const char kField[] = "field"; |
| 84 static const char kLength[] = "length"; |
| 85 for (size_t i = 0; i < components.size(); ++i) { |
| 86 if (i == 0 || |
| 87 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || |
| 88 components[i].length_hint == AddressUiComponent::HINT_LONG) { |
| 89 line = new base::ListValue; |
| 90 address_components->Append(line); |
| 91 } |
| 92 |
| 93 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue); |
| 94 component->SetString( |
| 95 "name", l10n_util::GetStringUTF16(components[i].name_id)); |
| 96 |
| 97 switch (components[i].field) { |
| 98 case i18n::addressinput::COUNTRY: |
| 99 component->SetString(kField, kCountryField); |
| 100 break; |
| 101 case i18n::addressinput::ADMIN_AREA: |
| 102 component->SetString(kField, kStateField); |
| 103 break; |
| 104 case i18n::addressinput::LOCALITY: |
| 105 component->SetString(kField, kCityField); |
| 106 break; |
| 107 case i18n::addressinput::DEPENDENT_LOCALITY: |
| 108 component->SetString(kField, kDependentLocalityField); |
| 109 break; |
| 110 case i18n::addressinput::SORTING_CODE: |
| 111 component->SetString(kField, kSortingCodeField); |
| 112 break; |
| 113 case i18n::addressinput::POSTAL_CODE: |
| 114 component->SetString(kField, kPostalCodeField); |
| 115 break; |
| 116 case i18n::addressinput::STREET_ADDRESS: |
| 117 component->SetString(kField, kAddressLineField); |
| 118 break; |
| 119 case i18n::addressinput::ORGANIZATION: |
| 120 component->SetString(kField, kCompanyNameField); |
| 121 break; |
| 122 case i18n::addressinput::RECIPIENT: |
| 123 component->SetString(kField, kFullNameField); |
| 124 component->SetString( |
| 125 "placeholder", |
| 126 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_NAME)); |
| 127 break; |
| 128 } |
| 129 |
| 130 switch (components[i].length_hint) { |
| 131 case AddressUiComponent::HINT_LONG: |
| 132 component->SetString(kLength, "long"); |
| 133 break; |
| 134 case AddressUiComponent::HINT_SHORT: |
| 135 component->SetString(kLength, "short"); |
| 136 break; |
| 137 } |
| 138 |
| 139 line->Append(component.release()); |
| 140 } |
| 141 } |
| 142 |
| 44 // Sets data related to the country <select>. | 143 // Sets data related to the country <select>. |
| 45 void SetCountryData(const PersonalDataManager& manager, | 144 void SetCountryData(const PersonalDataManager& manager, |
| 46 base::DictionaryValue* localized_strings) { | 145 base::DictionaryValue* localized_strings) { |
| 47 autofill::CountryComboboxModel model( | 146 autofill::CountryComboboxModel model( |
| 48 manager, base::Callback<bool(const std::string&)>()); | 147 manager, base::Callback<bool(const std::string&)>()); |
| 49 const std::vector<AutofillCountry*>& countries = model.countries(); | 148 const std::vector<AutofillCountry*>& countries = model.countries(); |
| 50 localized_strings->SetString("defaultCountryCode", | 149 localized_strings->SetString("defaultCountryCode", |
| 51 countries.front()->country_code()); | 150 countries.front()->country_code()); |
| 52 | 151 |
| 53 // An ordered list of options to show in the <select>. | 152 // An ordered list of options to show in the <select>. |
| 54 scoped_ptr<base::ListValue> country_list(new base::ListValue()); | 153 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) { | 154 for (size_t i = 0; i < countries.size(); ++i) { |
| 58 scoped_ptr<base::DictionaryValue> option_details( | 155 scoped_ptr<base::DictionaryValue> option_details( |
| 59 new base::DictionaryValue()); | 156 new base::DictionaryValue()); |
| 60 option_details->SetString("name", model.GetItemAt(i)); | 157 option_details->SetString("name", model.GetItemAt(i)); |
| 61 option_details->SetString( | 158 option_details->SetString( |
| 62 "value", | 159 "value", |
| 63 countries[i] ? countries[i]->country_code() : "separator"); | 160 countries[i] ? countries[i]->country_code() : "separator"); |
| 64 country_list->Append(option_details.release()); | 161 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 } | 162 } |
| 75 localized_strings->Set("autofillCountrySelectList", country_list.release()); | 163 localized_strings->Set("autofillCountrySelectList", country_list.release()); |
| 76 localized_strings->Set("autofillCountryData", country_data.release()); | 164 |
| 165 scoped_ptr<base::ListValue> defaultCountryComponents(new base::ListValue); |
| 166 std::string defaultCountryLanguageCode; |
| 167 GetAddressComponents(countries.front()->country_code(), |
| 168 g_browser_process->GetApplicationLocale(), |
| 169 defaultCountryComponents.get(), |
| 170 &defaultCountryLanguageCode); |
| 171 localized_strings->Set("autofillDefaultCountryComponents", |
| 172 defaultCountryComponents.release()); |
| 173 localized_strings->SetString("autofillDefaultCountryLanguageCode", |
| 174 defaultCountryLanguageCode); |
| 77 } | 175 } |
| 78 | 176 |
| 79 // Get the multi-valued element for |type| and return it in |ListValue| form. | 177 // Get the multi-valued element for |type| and return it in |ListValue| form. |
| 80 void GetValueList(const AutofillProfile& profile, | 178 void GetValueList(const AutofillProfile& profile, |
| 81 ServerFieldType type, | 179 ServerFieldType type, |
| 82 scoped_ptr<base::ListValue>* list) { | 180 scoped_ptr<base::ListValue>* list) { |
| 83 list->reset(new base::ListValue); | 181 list->reset(new base::ListValue); |
| 84 | 182 |
| 85 std::vector<base::string16> values; | 183 std::vector<base::string16> values; |
| 86 profile.GetRawMultiInfo(type, &values); | 184 profile.GetRawMultiInfo(type, &values); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 100 AutofillProfile* profile) { | 198 AutofillProfile* profile) { |
| 101 std::vector<base::string16> values(list->GetSize()); | 199 std::vector<base::string16> values(list->GetSize()); |
| 102 for (size_t i = 0; i < list->GetSize(); ++i) { | 200 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 103 base::string16 value; | 201 base::string16 value; |
| 104 if (list->GetString(i, &value)) | 202 if (list->GetString(i, &value)) |
| 105 values[i] = value; | 203 values[i] = value; |
| 106 } | 204 } |
| 107 profile->SetRawMultiInfo(type, values); | 205 profile->SetRawMultiInfo(type, values); |
| 108 } | 206 } |
| 109 | 207 |
| 110 // Get the multi-valued element for |type| and return it in |ListValue| form. | |
| 111 void GetNameList(const AutofillProfile& profile, | |
| 112 scoped_ptr<base::ListValue>* names) { | |
| 113 names->reset(new base::ListValue); | |
| 114 | |
| 115 std::vector<base::string16> first_names; | |
| 116 std::vector<base::string16> middle_names; | |
| 117 std::vector<base::string16> last_names; | |
| 118 profile.GetRawMultiInfo(autofill::NAME_FIRST, &first_names); | |
| 119 profile.GetRawMultiInfo(autofill::NAME_MIDDLE, &middle_names); | |
| 120 profile.GetRawMultiInfo(autofill::NAME_LAST, &last_names); | |
| 121 DCHECK_EQ(first_names.size(), middle_names.size()); | |
| 122 DCHECK_EQ(first_names.size(), last_names.size()); | |
| 123 | |
| 124 // |GetRawMultiInfo()| always returns at least one, potentially empty, item. | |
| 125 if (first_names.size() == 1 && first_names.front().empty() && | |
| 126 middle_names.front().empty() && last_names.front().empty()) { | |
| 127 return; | |
| 128 } | |
| 129 | |
| 130 for (size_t i = 0; i < first_names.size(); ++i) { | |
| 131 base::ListValue* name = new base::ListValue; // owned by |list| | |
| 132 name->Set(0, new base::StringValue(first_names[i])); | |
| 133 name->Set(1, new base::StringValue(middle_names[i])); | |
| 134 name->Set(2, new base::StringValue(last_names[i])); | |
| 135 (*names)->Set(i, name); | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 // Set the multi-valued element for |type| from input |list| values. | |
| 140 void SetNameList(const base::ListValue* names, AutofillProfile* profile) { | |
| 141 const size_t size = names->GetSize(); | |
| 142 std::vector<base::string16> first_names(size); | |
| 143 std::vector<base::string16> middle_names(size); | |
| 144 std::vector<base::string16> last_names(size); | |
| 145 | |
| 146 for (size_t i = 0; i < size; ++i) { | |
| 147 const base::ListValue* name; | |
| 148 bool success = names->GetList(i, &name); | |
| 149 DCHECK(success); | |
| 150 | |
| 151 base::string16 first_name; | |
| 152 success = name->GetString(0, &first_name); | |
| 153 DCHECK(success); | |
| 154 first_names[i] = first_name; | |
| 155 | |
| 156 base::string16 middle_name; | |
| 157 success = name->GetString(1, &middle_name); | |
| 158 DCHECK(success); | |
| 159 middle_names[i] = middle_name; | |
| 160 | |
| 161 base::string16 last_name; | |
| 162 success = name->GetString(2, &last_name); | |
| 163 DCHECK(success); | |
| 164 last_names[i] = last_name; | |
| 165 } | |
| 166 | |
| 167 profile->SetRawMultiInfo(autofill::NAME_FIRST, first_names); | |
| 168 profile->SetRawMultiInfo(autofill::NAME_MIDDLE, middle_names); | |
| 169 profile->SetRawMultiInfo(autofill::NAME_LAST, last_names); | |
| 170 } | |
| 171 | |
| 172 // Pulls the phone number |index|, |phone_number_list|, and |country_code| from | 208 // Pulls the phone number |index|, |phone_number_list|, and |country_code| from |
| 173 // the |args| input. | 209 // the |args| input. |
| 174 void ExtractPhoneNumberInformation(const base::ListValue* args, | 210 void ExtractPhoneNumberInformation(const base::ListValue* args, |
| 175 size_t* index, | 211 size_t* index, |
| 176 const base::ListValue** phone_number_list, | 212 const base::ListValue** phone_number_list, |
| 177 std::string* country_code) { | 213 std::string* country_code) { |
| 178 // Retrieve index as a |double|, as that is how it comes across from | 214 // Retrieve index as a |double|, as that is how it comes across from |
| 179 // JavaScript. | 215 // JavaScript. |
| 180 double number = 0.0; | 216 double number = 0.0; |
| 181 if (!args->GetDouble(0, &number)) { | 217 if (!args->GetDouble(0, &number)) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 335 |
| 300 web_ui()->RegisterMessageCallback( | 336 web_ui()->RegisterMessageCallback( |
| 301 "removeData", | 337 "removeData", |
| 302 base::Bind(&AutofillOptionsHandler::RemoveData, | 338 base::Bind(&AutofillOptionsHandler::RemoveData, |
| 303 base::Unretained(this))); | 339 base::Unretained(this))); |
| 304 web_ui()->RegisterMessageCallback( | 340 web_ui()->RegisterMessageCallback( |
| 305 "loadAddressEditor", | 341 "loadAddressEditor", |
| 306 base::Bind(&AutofillOptionsHandler::LoadAddressEditor, | 342 base::Bind(&AutofillOptionsHandler::LoadAddressEditor, |
| 307 base::Unretained(this))); | 343 base::Unretained(this))); |
| 308 web_ui()->RegisterMessageCallback( | 344 web_ui()->RegisterMessageCallback( |
| 345 "loadAddressEditorComponents", |
| 346 base::Bind(&AutofillOptionsHandler::LoadAddressEditorComponents, |
| 347 base::Unretained(this))); |
| 348 web_ui()->RegisterMessageCallback( |
| 309 "loadCreditCardEditor", | 349 "loadCreditCardEditor", |
| 310 base::Bind(&AutofillOptionsHandler::LoadCreditCardEditor, | 350 base::Bind(&AutofillOptionsHandler::LoadCreditCardEditor, |
| 311 base::Unretained(this))); | 351 base::Unretained(this))); |
| 312 web_ui()->RegisterMessageCallback( | 352 web_ui()->RegisterMessageCallback( |
| 313 "setAddress", | 353 "setAddress", |
| 314 base::Bind(&AutofillOptionsHandler::SetAddress, base::Unretained(this))); | 354 base::Bind(&AutofillOptionsHandler::SetAddress, base::Unretained(this))); |
| 315 web_ui()->RegisterMessageCallback( | 355 web_ui()->RegisterMessageCallback( |
| 316 "setCreditCard", | 356 "setCreditCard", |
| 317 base::Bind(&AutofillOptionsHandler::SetCreditCard, | 357 base::Bind(&AutofillOptionsHandler::SetCreditCard, |
| 318 base::Unretained(this))); | 358 base::Unretained(this))); |
| 319 web_ui()->RegisterMessageCallback( | 359 web_ui()->RegisterMessageCallback( |
| 320 "validatePhoneNumbers", | 360 "validatePhoneNumbers", |
| 321 base::Bind(&AutofillOptionsHandler::ValidatePhoneNumbers, | 361 base::Bind(&AutofillOptionsHandler::ValidatePhoneNumbers, |
| 322 base::Unretained(this))); | 362 base::Unretained(this))); |
| 323 } | 363 } |
| 324 | 364 |
| 325 ///////////////////////////////////////////////////////////////////////////// | 365 ///////////////////////////////////////////////////////////////////////////// |
| 326 // PersonalDataManagerObserver implementation: | 366 // PersonalDataManagerObserver implementation: |
| 327 void AutofillOptionsHandler::OnPersonalDataChanged() { | 367 void AutofillOptionsHandler::OnPersonalDataChanged() { |
| 328 LoadAutofillData(); | 368 LoadAutofillData(); |
| 329 } | 369 } |
| 330 | 370 |
| 331 void AutofillOptionsHandler::SetAddressOverlayStrings( | 371 void AutofillOptionsHandler::SetAddressOverlayStrings( |
| 332 base::DictionaryValue* localized_strings) { | 372 base::DictionaryValue* localized_strings) { |
| 333 localized_strings->SetString("autofillEditAddressTitle", | 373 localized_strings->SetString("autofillEditAddressTitle", |
| 334 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); | 374 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); |
| 335 localized_strings->SetString("autofillFirstNameLabel", | |
| 336 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_FIRST_NAME)); | |
| 337 localized_strings->SetString("autofillMiddleNameLabel", | |
| 338 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_MIDDLE_NAME)); | |
| 339 localized_strings->SetString("autofillLastNameLabel", | |
| 340 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", | 375 localized_strings->SetString("autofillCountryLabel", |
| 350 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_COUNTRY)); | 376 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL)); |
| 351 localized_strings->SetString("autofillPhoneLabel", | 377 localized_strings->SetString("autofillPhoneLabel", |
| 352 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); | 378 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); |
| 353 localized_strings->SetString("autofillEmailLabel", | 379 localized_strings->SetString("autofillEmailLabel", |
| 354 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); | 380 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); |
| 355 localized_strings->SetString("autofillAddFirstNamePlaceholder", | |
| 356 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_FIRST_NAME)); | |
| 357 localized_strings->SetString("autofillAddMiddleNamePlaceholder", | |
| 358 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_MIDDLE_NAME)); | |
| 359 localized_strings->SetString("autofillAddLastNamePlaceholder", | |
| 360 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_LAST_NAME)); | |
| 361 localized_strings->SetString("autofillAddPhonePlaceholder", | 381 localized_strings->SetString("autofillAddPhonePlaceholder", |
| 362 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); | 382 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); |
| 363 localized_strings->SetString("autofillAddEmailPlaceholder", | 383 localized_strings->SetString("autofillAddEmailPlaceholder", |
| 364 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); | 384 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); |
| 365 SetCountryData(*personal_data_, localized_strings); | 385 SetCountryData(*personal_data_, localized_strings); |
| 366 } | 386 } |
| 367 | 387 |
| 368 void AutofillOptionsHandler::SetCreditCardOverlayStrings( | 388 void AutofillOptionsHandler::SetCreditCardOverlayStrings( |
| 369 base::DictionaryValue* localized_strings) { | 389 base::DictionaryValue* localized_strings) { |
| 370 localized_strings->SetString("autofillEditCreditCardTitle", | 390 localized_strings->SetString("autofillEditCreditCardTitle", |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 // quickly click again on the list item before the item is removed (since | 464 // quickly click again on the list item before the item is removed (since |
| 445 // the list is not updated until the model tells the list an item has been | 465 // 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 | 466 // removed). This will activate the editor for a profile that has been |
| 447 // removed. Do nothing in that case. | 467 // removed. Do nothing in that case. |
| 448 return; | 468 return; |
| 449 } | 469 } |
| 450 | 470 |
| 451 base::DictionaryValue address; | 471 base::DictionaryValue address; |
| 452 address.SetString("guid", profile->guid()); | 472 address.SetString("guid", profile->guid()); |
| 453 scoped_ptr<base::ListValue> list; | 473 scoped_ptr<base::ListValue> list; |
| 454 GetNameList(*profile, &list); | 474 GetValueList(*profile, autofill::NAME_FULL, &list); |
| 455 address.Set("fullName", list.release()); | 475 address.Set(kFullNameField, list.release()); |
| 456 address.SetString("companyName", profile->GetRawInfo(autofill::COMPANY_NAME)); | 476 address.SetString( |
| 457 address.SetString("addrLine1", | 477 kCompanyNameField, profile->GetRawInfo(autofill::COMPANY_NAME)); |
| 458 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE1)); | 478 address.SetString(kAddressLineField, |
| 459 address.SetString("addrLine2", | 479 profile->GetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS)); |
| 460 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE2)); | 480 address.SetString( |
| 461 address.SetString("city", profile->GetRawInfo(autofill::ADDRESS_HOME_CITY)); | 481 kCityField, profile->GetRawInfo(autofill::ADDRESS_HOME_CITY)); |
| 462 address.SetString("state", profile->GetRawInfo(autofill::ADDRESS_HOME_STATE)); | 482 address.SetString( |
| 463 address.SetString("postalCode", | 483 kStateField, profile->GetRawInfo(autofill::ADDRESS_HOME_STATE)); |
| 484 address.SetString( |
| 485 kDependentLocalityField, |
| 486 profile->GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY)); |
| 487 address.SetString(kSortingCodeField, |
| 488 profile->GetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE)); |
| 489 address.SetString(kPostalCodeField, |
| 464 profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP)); | 490 profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP)); |
| 465 address.SetString("country", | 491 address.SetString(kCountryField, |
| 466 profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | 492 profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |
| 467 GetValueList(*profile, autofill::PHONE_HOME_WHOLE_NUMBER, &list); | 493 GetValueList(*profile, autofill::PHONE_HOME_WHOLE_NUMBER, &list); |
| 468 address.Set("phone", list.release()); | 494 address.Set("phone", list.release()); |
| 469 GetValueList(*profile, autofill::EMAIL_ADDRESS, &list); | 495 GetValueList(*profile, autofill::EMAIL_ADDRESS, &list); |
| 470 address.Set("email", list.release()); | 496 address.Set("email", list.release()); |
| 497 address.SetString(kLanguageCode, profile->language_code()); |
| 498 |
| 499 scoped_ptr<base::ListValue> components(new base::ListValue); |
| 500 GetAddressComponents( |
| 501 UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), |
| 502 profile->language_code(), components.get(), NULL); |
| 503 address.Set(kComponents, components.release()); |
| 471 | 504 |
| 472 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); | 505 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); |
| 473 } | 506 } |
| 474 | 507 |
| 508 void AutofillOptionsHandler::LoadAddressEditorComponents( |
| 509 const base::ListValue* args) { |
| 510 std::string country_code; |
| 511 if (!args->GetString(0, &country_code)) { |
| 512 NOTREACHED(); |
| 513 return; |
| 514 } |
| 515 |
| 516 base::DictionaryValue input; |
| 517 scoped_ptr<base::ListValue> components(new base::ListValue); |
| 518 std::string language_code; |
| 519 GetAddressComponents(country_code, g_browser_process->GetApplicationLocale(), |
| 520 components.get(), &language_code); |
| 521 input.Set(kComponents, components.release()); |
| 522 input.SetString(kLanguageCode, language_code); |
| 523 |
| 524 web_ui()->CallJavascriptFunction( |
| 525 "AutofillEditAddressOverlay.loadAddressComponents", input); |
| 526 } |
| 527 |
| 475 void AutofillOptionsHandler::LoadCreditCardEditor(const base::ListValue* args) { | 528 void AutofillOptionsHandler::LoadCreditCardEditor(const base::ListValue* args) { |
| 476 DCHECK(IsPersonalDataLoaded()); | 529 DCHECK(IsPersonalDataLoaded()); |
| 477 | 530 |
| 478 std::string guid; | 531 std::string guid; |
| 479 if (!args->GetString(0, &guid)) { | 532 if (!args->GetString(0, &guid)) { |
| 480 NOTREACHED(); | 533 NOTREACHED(); |
| 481 return; | 534 return; |
| 482 } | 535 } |
| 483 | 536 |
| 484 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); | 537 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 507 credit_card->GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 560 credit_card->GetRawInfo(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 508 | 561 |
| 509 web_ui()->CallJavascriptFunction("AutofillOptions.editCreditCard", | 562 web_ui()->CallJavascriptFunction("AutofillOptions.editCreditCard", |
| 510 credit_card_data); | 563 credit_card_data); |
| 511 } | 564 } |
| 512 | 565 |
| 513 void AutofillOptionsHandler::SetAddress(const base::ListValue* args) { | 566 void AutofillOptionsHandler::SetAddress(const base::ListValue* args) { |
| 514 if (!IsPersonalDataLoaded()) | 567 if (!IsPersonalDataLoaded()) |
| 515 return; | 568 return; |
| 516 | 569 |
| 570 int arg_counter = 0; |
| 517 std::string guid; | 571 std::string guid; |
| 518 if (!args->GetString(0, &guid)) { | 572 if (!args->GetString(arg_counter++, &guid)) { |
| 519 NOTREACHED(); | 573 NOTREACHED(); |
| 520 return; | 574 return; |
| 521 } | 575 } |
| 522 | 576 |
| 523 AutofillProfile profile(guid, kSettingsOrigin); | 577 AutofillProfile profile(guid, kSettingsOrigin); |
| 524 | 578 |
| 525 std::string country_code; | |
| 526 base::string16 value; | 579 base::string16 value; |
| 527 const base::ListValue* list_value; | 580 const base::ListValue* list_value; |
| 528 if (args->GetList(1, &list_value)) | 581 if (args->GetList(arg_counter++, &list_value)) |
| 529 SetNameList(list_value, &profile); | 582 SetValueList(list_value, autofill::NAME_FULL, &profile); |
| 530 | 583 |
| 531 if (args->GetString(2, &value)) | 584 if (args->GetString(arg_counter++, &value)) |
| 532 profile.SetRawInfo(autofill::COMPANY_NAME, value); | 585 profile.SetRawInfo(autofill::COMPANY_NAME, value); |
| 533 | 586 |
| 534 if (args->GetString(3, &value)) | 587 if (args->GetString(arg_counter++, &value)) |
| 535 profile.SetRawInfo(autofill::ADDRESS_HOME_LINE1, value); | 588 profile.SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS, value); |
| 536 | 589 |
| 537 if (args->GetString(4, &value)) | 590 if (args->GetString(arg_counter++, &value)) |
| 538 profile.SetRawInfo(autofill::ADDRESS_HOME_LINE2, value); | 591 profile.SetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, value); |
| 539 | 592 |
| 540 if (args->GetString(5, &value)) | 593 if (args->GetString(arg_counter++, &value)) |
| 541 profile.SetRawInfo(autofill::ADDRESS_HOME_CITY, value); | 594 profile.SetRawInfo(autofill::ADDRESS_HOME_CITY, value); |
| 542 | 595 |
| 543 if (args->GetString(6, &value)) | 596 if (args->GetString(arg_counter++, &value)) |
| 544 profile.SetRawInfo(autofill::ADDRESS_HOME_STATE, value); | 597 profile.SetRawInfo(autofill::ADDRESS_HOME_STATE, value); |
| 545 | 598 |
| 546 if (args->GetString(7, &value)) | 599 if (args->GetString(arg_counter++, &value)) |
| 547 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, value); | 600 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, value); |
| 548 | 601 |
| 549 if (args->GetString(8, &country_code)) | 602 if (args->GetString(arg_counter++, &value)) |
| 550 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY, | 603 profile.SetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE, value); |
| 551 base::ASCIIToUTF16(country_code)); | |
| 552 | 604 |
| 553 if (args->GetList(9, &list_value)) | 605 if (args->GetString(arg_counter++, &value)) |
| 606 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY, value); |
| 607 |
| 608 if (args->GetList(arg_counter++, &list_value)) |
| 554 SetValueList(list_value, autofill::PHONE_HOME_WHOLE_NUMBER, &profile); | 609 SetValueList(list_value, autofill::PHONE_HOME_WHOLE_NUMBER, &profile); |
| 555 | 610 |
| 556 if (args->GetList(10, &list_value)) | 611 if (args->GetList(arg_counter++, &list_value)) |
| 557 SetValueList(list_value, autofill::EMAIL_ADDRESS, &profile); | 612 SetValueList(list_value, autofill::EMAIL_ADDRESS, &profile); |
| 558 | 613 |
| 614 if (args->GetString(arg_counter++, &value)) |
| 615 profile.set_language_code(base::UTF16ToUTF8(value)); |
| 616 |
| 559 if (!base::IsValidGUID(profile.guid())) { | 617 if (!base::IsValidGUID(profile.guid())) { |
| 560 profile.set_guid(base::GenerateGUID()); | 618 profile.set_guid(base::GenerateGUID()); |
| 561 personal_data_->AddProfile(profile); | 619 personal_data_->AddProfile(profile); |
| 562 } else { | 620 } else { |
| 563 personal_data_->UpdateProfile(profile); | 621 personal_data_->UpdateProfile(profile); |
| 564 } | 622 } |
| 565 } | 623 } |
| 566 | 624 |
| 567 void AutofillOptionsHandler::SetCreditCard(const base::ListValue* args) { | 625 void AutofillOptionsHandler::SetCreditCard(const base::ListValue* args) { |
| 568 if (!IsPersonalDataLoaded()) | 626 if (!IsPersonalDataLoaded()) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 | 663 |
| 606 web_ui()->CallJavascriptFunction( | 664 web_ui()->CallJavascriptFunction( |
| 607 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 665 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
| 608 } | 666 } |
| 609 | 667 |
| 610 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 668 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
| 611 return personal_data_ && personal_data_->IsDataLoaded(); | 669 return personal_data_ && personal_data_->IsDataLoaded(); |
| 612 } | 670 } |
| 613 | 671 |
| 614 } // namespace options | 672 } // namespace options |
| OLD | NEW |