Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/dom_ui/options/autofill_options_handler.h" | 5 #include "chrome/browser/dom_ui/options/autofill_options_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/autofill/autofill_country.h" | |
| 14 #include "chrome/browser/autofill/autofill_profile.h" | 15 #include "chrome/browser/autofill/autofill_profile.h" |
| 15 #include "chrome/browser/autofill/credit_card.h" | 16 #include "chrome/browser/autofill/credit_card.h" |
| 16 #include "chrome/browser/dom_ui/web_ui_util.h" | 17 #include "chrome/browser/dom_ui/web_ui_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/guid.h" | 19 #include "chrome/common/guid.h" |
| 19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 20 #include "grit/webkit_resources.h" | 21 #include "grit/webkit_resources.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 39 return IDR_AUTOFILL_CC_MASTERCARD; | 40 return IDR_AUTOFILL_CC_MASTERCARD; |
| 40 else if (type == kSoloCard) | 41 else if (type == kSoloCard) |
| 41 return IDR_AUTOFILL_CC_SOLO; | 42 return IDR_AUTOFILL_CC_SOLO; |
| 42 else if (type == kVisaCard) | 43 else if (type == kVisaCard) |
| 43 return IDR_AUTOFILL_CC_VISA; | 44 return IDR_AUTOFILL_CC_VISA; |
| 44 | 45 |
| 45 NOTREACHED(); | 46 NOTREACHED(); |
| 46 return 0; | 47 return 0; |
| 47 } | 48 } |
| 48 | 49 |
| 50 // Returns a dictionary that maps country codes to data for the country. | |
| 51 DictionaryValue* GetCountryData() { | |
| 52 std::vector<AutoFillCountry> countries; | |
| 53 AutoFillCountry::GetAvailableCountries(&countries); | |
| 54 | |
| 55 DictionaryValue* country_data = new DictionaryValue(); | |
| 56 for (size_t i = 0; i < countries.size(); ++i) { | |
| 57 const AutoFillCountry& country = countries[i]; | |
| 58 | |
| 59 DictionaryValue* details = new DictionaryValue(); | |
| 60 details->SetString("name", country.name()); | |
| 61 details->SetString("postalCodeLabel", country.postal_code_label()); | |
| 62 details->SetString("stateLabel", country.state_label()); | |
| 63 | |
| 64 country_data->Set(country.country_code(), details); | |
| 65 } | |
| 66 | |
| 67 return country_data; | |
| 68 } | |
| 69 | |
| 49 } // namespace | 70 } // namespace |
| 50 | 71 |
| 51 AutoFillOptionsHandler::AutoFillOptionsHandler() | 72 AutoFillOptionsHandler::AutoFillOptionsHandler() |
| 52 : personal_data_(NULL) { | 73 : personal_data_(NULL) { |
| 53 } | 74 } |
| 54 | 75 |
| 55 AutoFillOptionsHandler::~AutoFillOptionsHandler() { | 76 AutoFillOptionsHandler::~AutoFillOptionsHandler() { |
| 56 if (personal_data_) | 77 if (personal_data_) |
| 57 personal_data_->RemoveObserver(this); | 78 personal_data_->RemoveObserver(this); |
| 58 } | 79 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 void AutoFillOptionsHandler::OnPersonalDataChanged() { | 151 void AutoFillOptionsHandler::OnPersonalDataChanged() { |
| 131 LoadAutoFillData(); | 152 LoadAutoFillData(); |
| 132 } | 153 } |
| 133 | 154 |
| 134 void AutoFillOptionsHandler::SetAddressOverlayStrings( | 155 void AutoFillOptionsHandler::SetAddressOverlayStrings( |
| 135 DictionaryValue* localized_strings) { | 156 DictionaryValue* localized_strings) { |
| 136 localized_strings->SetString("autoFillEditAddressTitle", | 157 localized_strings->SetString("autoFillEditAddressTitle", |
| 137 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); | 158 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); |
| 138 localized_strings->SetString("fullNameLabel", | 159 localized_strings->SetString("fullNameLabel", |
| 139 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FULL_NAME)); | 160 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FULL_NAME)); |
| 161 localized_strings->SetString("country-label", | |
|
dhollowa
2011/02/17 00:55:28
As discussed... country should follow other addres
Ilya Sherman
2011/02/17 23:09:11
Done.
| |
| 162 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); | |
| 140 localized_strings->SetString("companyNameLabel", | 163 localized_strings->SetString("companyNameLabel", |
| 141 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COMPANY_NAME)); | 164 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COMPANY_NAME)); |
| 142 localized_strings->SetString("addrLine1Label", | 165 localized_strings->SetString("addrLine1Label", |
| 143 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1)); | 166 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1)); |
| 144 localized_strings->SetString("addrLine2Label", | 167 localized_strings->SetString("addrLine2Label", |
| 145 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2)); | 168 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2)); |
| 146 localized_strings->SetString("cityLabel", | 169 localized_strings->SetString("cityLabel", |
| 147 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY)); | 170 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CITY)); |
| 148 localized_strings->SetString("stateLabel", | |
| 149 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_STATE)); | |
| 150 localized_strings->SetString("zipCodeLabel", | |
| 151 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ZIP_CODE)); | |
| 152 localized_strings->SetString("countryLabel", | |
| 153 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); | |
| 154 localized_strings->SetString("countryLabel", | |
| 155 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_COUNTRY)); | |
| 156 localized_strings->SetString("phoneLabel", | 171 localized_strings->SetString("phoneLabel", |
| 157 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); | 172 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PHONE)); |
| 158 localized_strings->SetString("faxLabel", | 173 localized_strings->SetString("faxLabel", |
| 159 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); | 174 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_FAX)); |
| 160 localized_strings->SetString("emailLabel", | 175 localized_strings->SetString("emailLabel", |
| 161 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); | 176 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EMAIL)); |
| 177 | |
| 178 std::string default_country_code = AutoFillCountry::DefaultCountryCode(); | |
| 179 localized_strings->SetString("defaultCountryCode", default_country_code); | |
| 180 localized_strings->Set("autofillCountryData", GetCountryData()); | |
| 162 } | 181 } |
| 163 | 182 |
| 164 void AutoFillOptionsHandler::SetCreditCardOverlayStrings( | 183 void AutoFillOptionsHandler::SetCreditCardOverlayStrings( |
| 165 DictionaryValue* localized_strings) { | 184 DictionaryValue* localized_strings) { |
| 166 localized_strings->SetString("autoFillEditCreditCardTitle", | 185 localized_strings->SetString("autoFillEditCreditCardTitle", |
| 167 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); | 186 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); |
| 168 localized_strings->SetString("nameOnCardLabel", | 187 localized_strings->SetString("nameOnCardLabel", |
| 169 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); | 188 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); |
| 170 localized_strings->SetString("creditCardNumberLabel", | 189 localized_strings->SetString("creditCardNumberLabel", |
| 171 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); | 190 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 // the list is not updated until the model tells the list an item has been | 266 // the list is not updated until the model tells the list an item has been |
| 248 // removed). This will activate the editor for a profile that has been | 267 // removed). This will activate the editor for a profile that has been |
| 249 // removed. Do nothing in that case. | 268 // removed. Do nothing in that case. |
| 250 return; | 269 return; |
| 251 } | 270 } |
| 252 | 271 |
| 253 DictionaryValue address; | 272 DictionaryValue address; |
| 254 address.SetString("guid", profile->guid()); | 273 address.SetString("guid", profile->guid()); |
| 255 address.SetString("fullName", | 274 address.SetString("fullName", |
| 256 profile->GetFieldText(AutoFillType(NAME_FULL))); | 275 profile->GetFieldText(AutoFillType(NAME_FULL))); |
| 276 address.SetString("country", | |
| 277 profile->CountryCode()); | |
| 257 address.SetString("companyName", | 278 address.SetString("companyName", |
| 258 profile->GetFieldText(AutoFillType(COMPANY_NAME))); | 279 profile->GetFieldText(AutoFillType(COMPANY_NAME))); |
| 259 address.SetString("addrLine1", | 280 address.SetString("addrLine1", |
| 260 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))); | 281 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE1))); |
| 261 address.SetString("addrLine2", | 282 address.SetString("addrLine2", |
| 262 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))); | 283 profile->GetFieldText(AutoFillType(ADDRESS_HOME_LINE2))); |
| 263 address.SetString("city", | 284 address.SetString("city", |
| 264 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY))); | 285 profile->GetFieldText(AutoFillType(ADDRESS_HOME_CITY))); |
| 265 address.SetString("state", | 286 address.SetString("state", |
| 266 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE))); | 287 profile->GetFieldText(AutoFillType(ADDRESS_HOME_STATE))); |
| 267 address.SetString("zipCode", | 288 address.SetString("postal-code", |
| 268 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))); | 289 profile->GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))); |
| 269 address.SetString("country", | |
| 270 profile->GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))); | |
| 271 address.SetString( | 290 address.SetString( |
| 272 "phone", | 291 "phone", |
| 273 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); | 292 profile->GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER))); |
| 274 address.SetString( | 293 address.SetString( |
| 275 "fax", | 294 "fax", |
| 276 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); | 295 profile->GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER))); |
| 277 address.SetString("email", | 296 address.SetString("email", |
| 278 profile->GetFieldText(AutoFillType(EMAIL_ADDRESS))); | 297 profile->GetFieldText(AutoFillType(EMAIL_ADDRESS))); |
| 279 | 298 |
| 280 web_ui_->CallJavascriptFunction(L"AutoFillOptions.editAddress", address); | 299 web_ui_->CallJavascriptFunction(L"AutoFillOptions.editAddress", address); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 return; | 344 return; |
| 326 | 345 |
| 327 std::string guid; | 346 std::string guid; |
| 328 if (!args->GetString(0, &guid)) { | 347 if (!args->GetString(0, &guid)) { |
| 329 NOTREACHED(); | 348 NOTREACHED(); |
| 330 return; | 349 return; |
| 331 } | 350 } |
| 332 | 351 |
| 333 AutoFillProfile profile(guid); | 352 AutoFillProfile profile(guid); |
| 334 | 353 |
| 354 std::string country_code; | |
| 335 string16 value; | 355 string16 value; |
| 336 if (args->GetString(1, &value)) | 356 if (args->GetString(1, &value)) |
| 337 profile.SetInfo(AutoFillType(NAME_FULL), value); | 357 profile.SetInfo(AutoFillType(NAME_FULL), value); |
| 338 if (args->GetString(2, &value)) | 358 if (args->GetString(2, &country_code)) |
| 359 profile.SetCountryCode(country_code); | |
| 360 if (args->GetString(3, &value)) | |
| 339 profile.SetInfo(AutoFillType(COMPANY_NAME), value); | 361 profile.SetInfo(AutoFillType(COMPANY_NAME), value); |
| 340 if (args->GetString(3, &value)) | 362 if (args->GetString(4, &value)) |
| 341 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), value); | 363 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), value); |
| 342 if (args->GetString(4, &value)) | 364 if (args->GetString(5, &value)) |
| 343 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), value); | 365 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), value); |
| 344 if (args->GetString(5, &value)) | 366 if (args->GetString(6, &value)) |
| 345 profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), value); | 367 profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), value); |
| 346 if (args->GetString(6, &value)) | 368 if (args->GetString(7, &value)) |
| 347 profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), value); | 369 profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), value); |
| 348 if (args->GetString(7, &value)) | 370 if (args->GetString(8, &value)) |
| 349 profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), value); | 371 profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), value); |
| 350 if (args->GetString(8, &value)) | |
| 351 profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), value); | |
| 352 if (args->GetString(9, &value)) | 372 if (args->GetString(9, &value)) |
| 353 profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), value); | 373 profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), value); |
| 354 if (args->GetString(10, &value)) | 374 if (args->GetString(10, &value)) |
| 355 profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), value); | 375 profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), value); |
| 356 if (args->GetString(11, &value)) | 376 if (args->GetString(11, &value)) |
| 357 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), value); | 377 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), value); |
| 358 | 378 |
| 359 if (!guid::IsValidGUID(profile.guid())) { | 379 if (!guid::IsValidGUID(profile.guid())) { |
| 360 profile.set_guid(guid::GenerateGUID()); | 380 profile.set_guid(guid::GenerateGUID()); |
| 361 personal_data_->AddProfile(profile); | 381 personal_data_->AddProfile(profile); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 386 if (args->GetString(4, &value)) | 406 if (args->GetString(4, &value)) |
| 387 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); | 407 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); |
| 388 | 408 |
| 389 if (!guid::IsValidGUID(credit_card.guid())) { | 409 if (!guid::IsValidGUID(credit_card.guid())) { |
| 390 credit_card.set_guid(guid::GenerateGUID()); | 410 credit_card.set_guid(guid::GenerateGUID()); |
| 391 personal_data_->AddCreditCard(credit_card); | 411 personal_data_->AddCreditCard(credit_card); |
| 392 } else { | 412 } else { |
| 393 personal_data_->UpdateCreditCard(credit_card); | 413 personal_data_->UpdateCreditCard(credit_card); |
| 394 } | 414 } |
| 395 } | 415 } |
| OLD | NEW |