| 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/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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 // There is a race where a user can click once on the close button and | 259 // There is a race where a user can click once on the close button and |
| 260 // quickly click again on the list item before the item is removed (since | 260 // quickly click again on the list item before the item is removed (since |
| 261 // the list is not updated until the model tells the list an item has been | 261 // the list is not updated until the model tells the list an item has been |
| 262 // removed). This will activate the editor for a profile that has been | 262 // removed). This will activate the editor for a profile that has been |
| 263 // removed. Do nothing in that case. | 263 // removed. Do nothing in that case. |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 | 266 |
| 267 DictionaryValue address; | 267 DictionaryValue address; |
| 268 address.SetString("guid", profile->guid()); | 268 address.SetString("guid", profile->guid()); |
| 269 address.SetString("fullName", | 269 address.SetString("fullName", profile->GetFieldText(NAME_FULL)); |
| 270 profile->GetFieldText(AutofillType(NAME_FULL))); | 270 address.SetString("companyName", profile->GetFieldText(COMPANY_NAME)); |
| 271 address.SetString("companyName", | 271 address.SetString("addrLine1", profile->GetFieldText(ADDRESS_HOME_LINE1)); |
| 272 profile->GetFieldText(AutofillType(COMPANY_NAME))); | 272 address.SetString("addrLine2", profile->GetFieldText(ADDRESS_HOME_LINE2)); |
| 273 address.SetString("addrLine1", | 273 address.SetString("city", profile->GetFieldText(ADDRESS_HOME_CITY)); |
| 274 profile->GetFieldText(AutofillType(ADDRESS_HOME_LINE1))); | 274 address.SetString("state", profile->GetFieldText(ADDRESS_HOME_STATE)); |
| 275 address.SetString("addrLine2", | 275 address.SetString("postalCode", profile->GetFieldText(ADDRESS_HOME_ZIP)); |
| 276 profile->GetFieldText(AutofillType(ADDRESS_HOME_LINE2))); | 276 address.SetString("country", profile->CountryCode()); |
| 277 address.SetString("city", | 277 address.SetString("phone", profile->GetFieldText(PHONE_HOME_WHOLE_NUMBER)); |
| 278 profile->GetFieldText(AutofillType(ADDRESS_HOME_CITY))); | 278 address.SetString("fax", profile->GetFieldText(PHONE_FAX_WHOLE_NUMBER)); |
| 279 address.SetString("state", | 279 address.SetString("email", profile->GetFieldText(EMAIL_ADDRESS)); |
| 280 profile->GetFieldText(AutofillType(ADDRESS_HOME_STATE))); | |
| 281 address.SetString("postalCode", | |
| 282 profile->GetFieldText(AutofillType(ADDRESS_HOME_ZIP))); | |
| 283 address.SetString("country", | |
| 284 profile->CountryCode()); | |
| 285 address.SetString( | |
| 286 "phone", | |
| 287 profile->GetFieldText(AutofillType(PHONE_HOME_WHOLE_NUMBER))); | |
| 288 address.SetString( | |
| 289 "fax", | |
| 290 profile->GetFieldText(AutofillType(PHONE_FAX_WHOLE_NUMBER))); | |
| 291 address.SetString("email", | |
| 292 profile->GetFieldText(AutofillType(EMAIL_ADDRESS))); | |
| 293 | 280 |
| 294 web_ui_->CallJavascriptFunction("AutoFillOptions.editAddress", address); | 281 web_ui_->CallJavascriptFunction("AutoFillOptions.editAddress", address); |
| 295 } | 282 } |
| 296 | 283 |
| 297 void AutoFillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { | 284 void AutoFillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { |
| 298 DCHECK(personal_data_->IsDataLoaded()); | 285 DCHECK(personal_data_->IsDataLoaded()); |
| 299 | 286 |
| 300 std::string guid; | 287 std::string guid; |
| 301 if (!args->GetString(0, &guid)) { | 288 if (!args->GetString(0, &guid)) { |
| 302 NOTREACHED(); | 289 NOTREACHED(); |
| 303 return; | 290 return; |
| 304 } | 291 } |
| 305 | 292 |
| 306 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); | 293 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); |
| 307 if (!credit_card) { | 294 if (!credit_card) { |
| 308 // There is a race where a user can click once on the close button and | 295 // There is a race where a user can click once on the close button and |
| 309 // quickly click again on the list item before the item is removed (since | 296 // quickly click again on the list item before the item is removed (since |
| 310 // the list is not updated until the model tells the list an item has been | 297 // the list is not updated until the model tells the list an item has been |
| 311 // removed). This will activate the editor for a profile that has been | 298 // removed). This will activate the editor for a profile that has been |
| 312 // removed. Do nothing in that case. | 299 // removed. Do nothing in that case. |
| 313 return; | 300 return; |
| 314 } | 301 } |
| 315 | 302 |
| 316 DictionaryValue credit_card_data; | 303 DictionaryValue credit_card_data; |
| 317 credit_card_data.SetString("guid", credit_card->guid()); | 304 credit_card_data.SetString("guid", credit_card->guid()); |
| 318 credit_card_data.SetString( | 305 credit_card_data.SetString("nameOnCard", |
| 319 "nameOnCard", | 306 credit_card->GetFieldText(CREDIT_CARD_NAME)); |
| 320 credit_card->GetFieldText(AutofillType(CREDIT_CARD_NAME))); | 307 credit_card_data.SetString("creditCardNumber", |
| 321 credit_card_data.SetString( | 308 credit_card->GetFieldText(CREDIT_CARD_NUMBER)); |
| 322 "creditCardNumber", | 309 credit_card_data.SetString("expirationMonth", |
| 323 credit_card->GetFieldText(AutofillType(CREDIT_CARD_NUMBER))); | 310 credit_card->GetFieldText(CREDIT_CARD_EXP_MONTH)); |
| 324 credit_card_data.SetString( | |
| 325 "expirationMonth", | |
| 326 credit_card->GetFieldText(AutofillType(CREDIT_CARD_EXP_MONTH))); | |
| 327 credit_card_data.SetString( | 311 credit_card_data.SetString( |
| 328 "expirationYear", | 312 "expirationYear", |
| 329 credit_card->GetFieldText(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); | 313 credit_card->GetFieldText(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 330 | 314 |
| 331 web_ui_->CallJavascriptFunction("AutoFillOptions.editCreditCard", | 315 web_ui_->CallJavascriptFunction("AutoFillOptions.editCreditCard", |
| 332 credit_card_data); | 316 credit_card_data); |
| 333 } | 317 } |
| 334 | 318 |
| 335 void AutoFillOptionsHandler::SetAddress(const ListValue* args) { | 319 void AutoFillOptionsHandler::SetAddress(const ListValue* args) { |
| 336 if (!personal_data_->IsDataLoaded()) | 320 if (!personal_data_->IsDataLoaded()) |
| 337 return; | 321 return; |
| 338 | 322 |
| 339 std::string guid; | 323 std::string guid; |
| 340 if (!args->GetString(0, &guid)) { | 324 if (!args->GetString(0, &guid)) { |
| 341 NOTREACHED(); | 325 NOTREACHED(); |
| 342 return; | 326 return; |
| 343 } | 327 } |
| 344 | 328 |
| 345 AutofillProfile profile(guid); | 329 AutofillProfile profile(guid); |
| 346 | 330 |
| 347 std::string country_code; | 331 std::string country_code; |
| 348 string16 value; | 332 string16 value; |
| 349 if (args->GetString(1, &value)) | 333 if (args->GetString(1, &value)) |
| 350 profile.SetInfo(AutofillType(NAME_FULL), value); | 334 profile.SetInfo(NAME_FULL, value); |
| 351 if (args->GetString(2, &value)) | 335 if (args->GetString(2, &value)) |
| 352 profile.SetInfo(AutofillType(COMPANY_NAME), value); | 336 profile.SetInfo(COMPANY_NAME, value); |
| 353 if (args->GetString(3, &value)) | 337 if (args->GetString(3, &value)) |
| 354 profile.SetInfo(AutofillType(ADDRESS_HOME_LINE1), value); | 338 profile.SetInfo(ADDRESS_HOME_LINE1, value); |
| 355 if (args->GetString(4, &value)) | 339 if (args->GetString(4, &value)) |
| 356 profile.SetInfo(AutofillType(ADDRESS_HOME_LINE2), value); | 340 profile.SetInfo(ADDRESS_HOME_LINE2, value); |
| 357 if (args->GetString(5, &value)) | 341 if (args->GetString(5, &value)) |
| 358 profile.SetInfo(AutofillType(ADDRESS_HOME_CITY), value); | 342 profile.SetInfo(ADDRESS_HOME_CITY, value); |
| 359 if (args->GetString(6, &value)) | 343 if (args->GetString(6, &value)) |
| 360 profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), value); | 344 profile.SetInfo(ADDRESS_HOME_STATE, value); |
| 361 if (args->GetString(7, &value)) | 345 if (args->GetString(7, &value)) |
| 362 profile.SetInfo(AutofillType(ADDRESS_HOME_ZIP), value); | 346 profile.SetInfo(ADDRESS_HOME_ZIP, value); |
| 363 if (args->GetString(8, &country_code)) | 347 if (args->GetString(8, &country_code)) |
| 364 profile.SetCountryCode(country_code); | 348 profile.SetCountryCode(country_code); |
| 365 if (args->GetString(9, &value)) | 349 if (args->GetString(9, &value)) |
| 366 profile.SetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), value); | 350 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, value); |
| 367 if (args->GetString(10, &value)) | 351 if (args->GetString(10, &value)) |
| 368 profile.SetInfo(AutofillType(PHONE_FAX_WHOLE_NUMBER), value); | 352 profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, value); |
| 369 if (args->GetString(11, &value)) | 353 if (args->GetString(11, &value)) |
| 370 profile.SetInfo(AutofillType(EMAIL_ADDRESS), value); | 354 profile.SetInfo(EMAIL_ADDRESS, value); |
| 371 | 355 |
| 372 if (!guid::IsValidGUID(profile.guid())) { | 356 if (!guid::IsValidGUID(profile.guid())) { |
| 373 profile.set_guid(guid::GenerateGUID()); | 357 profile.set_guid(guid::GenerateGUID()); |
| 374 personal_data_->AddProfile(profile); | 358 personal_data_->AddProfile(profile); |
| 375 } else { | 359 } else { |
| 376 personal_data_->UpdateProfile(profile); | 360 personal_data_->UpdateProfile(profile); |
| 377 } | 361 } |
| 378 } | 362 } |
| 379 | 363 |
| 380 void AutoFillOptionsHandler::SetCreditCard(const ListValue* args) { | 364 void AutoFillOptionsHandler::SetCreditCard(const ListValue* args) { |
| 381 if (!personal_data_->IsDataLoaded()) | 365 if (!personal_data_->IsDataLoaded()) |
| 382 return; | 366 return; |
| 383 | 367 |
| 384 std::string guid; | 368 std::string guid; |
| 385 if (!args->GetString(0, &guid)) { | 369 if (!args->GetString(0, &guid)) { |
| 386 NOTREACHED(); | 370 NOTREACHED(); |
| 387 return; | 371 return; |
| 388 } | 372 } |
| 389 | 373 |
| 390 CreditCard credit_card(guid); | 374 CreditCard credit_card(guid); |
| 391 | 375 |
| 392 string16 value; | 376 string16 value; |
| 393 if (args->GetString(1, &value)) | 377 if (args->GetString(1, &value)) |
| 394 credit_card.SetInfo(AutofillType(CREDIT_CARD_NAME), value); | 378 credit_card.SetInfo(CREDIT_CARD_NAME, value); |
| 395 if (args->GetString(2, &value)) | 379 if (args->GetString(2, &value)) |
| 396 credit_card.SetInfo(AutofillType(CREDIT_CARD_NUMBER), value); | 380 credit_card.SetInfo(CREDIT_CARD_NUMBER, value); |
| 397 if (args->GetString(3, &value)) | 381 if (args->GetString(3, &value)) |
| 398 credit_card.SetInfo(AutofillType(CREDIT_CARD_EXP_MONTH), value); | 382 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, value); |
| 399 if (args->GetString(4, &value)) | 383 if (args->GetString(4, &value)) |
| 400 credit_card.SetInfo(AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), value); | 384 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, value); |
| 401 | 385 |
| 402 if (!guid::IsValidGUID(credit_card.guid())) { | 386 if (!guid::IsValidGUID(credit_card.guid())) { |
| 403 credit_card.set_guid(guid::GenerateGUID()); | 387 credit_card.set_guid(guid::GenerateGUID()); |
| 404 personal_data_->AddCreditCard(credit_card); | 388 personal_data_->AddCreditCard(credit_card); |
| 405 } else { | 389 } else { |
| 406 personal_data_->UpdateCreditCard(credit_card); | 390 personal_data_->UpdateCreditCard(credit_card); |
| 407 } | 391 } |
| 408 } | 392 } |
| OLD | NEW |