OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/autofill_private/autofill_private_api.h" | 5 #include "chrome/browser/extensions/api/autofill_private/autofill_private_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 AutofillPrivateSaveAddressFunction::~AutofillPrivateSaveAddressFunction() {} | 171 AutofillPrivateSaveAddressFunction::~AutofillPrivateSaveAddressFunction() {} |
172 | 172 |
173 ExtensionFunction::ResponseAction AutofillPrivateSaveAddressFunction::Run() { | 173 ExtensionFunction::ResponseAction AutofillPrivateSaveAddressFunction::Run() { |
174 std::unique_ptr<api::autofill_private::SaveAddress::Params> parameters = | 174 std::unique_ptr<api::autofill_private::SaveAddress::Params> parameters = |
175 api::autofill_private::SaveAddress::Params::Create(*args_); | 175 api::autofill_private::SaveAddress::Params::Create(*args_); |
176 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 176 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
177 | 177 |
178 autofill::PersonalDataManager* personal_data = | 178 autofill::PersonalDataManager* personal_data = |
179 autofill::PersonalDataManagerFactory::GetForProfile( | 179 autofill::PersonalDataManagerFactory::GetForProfile( |
180 chrome_details_.GetProfile()); | 180 chrome_details_.GetProfile()); |
181 if (!personal_data || !personal_data->IsDataLoaded()) { | 181 if (!personal_data || !personal_data->IsDataLoaded()) |
182 SetError(kErrorDataUnavailable); | 182 return RespondNow(Error(kErrorDataUnavailable)); |
183 return RespondNow(NoArguments()); | |
184 } | |
185 | 183 |
186 api::autofill_private::AddressEntry* address = ¶meters->address; | 184 api::autofill_private::AddressEntry* address = ¶meters->address; |
187 | 185 |
188 std::string guid = address->guid ? *address->guid : ""; | 186 std::string guid = address->guid ? *address->guid : ""; |
189 autofill::AutofillProfile profile(guid, kSettingsOrigin); | 187 autofill::AutofillProfile profile(guid, kSettingsOrigin); |
190 | 188 |
191 // Strings from JavaScript use UTF-8 encoding. This container is used as an | 189 // Strings from JavaScript use UTF-8 encoding. This container is used as an |
192 // intermediate container for functions which require UTF-16 strings. | 190 // intermediate container for functions which require UTF-16 strings. |
193 std::vector<base::string16> string16Container; | 191 std::vector<base::string16> string16Container; |
194 | 192 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 ~AutofillPrivateSaveCreditCardFunction() {} | 358 ~AutofillPrivateSaveCreditCardFunction() {} |
361 | 359 |
362 ExtensionFunction::ResponseAction AutofillPrivateSaveCreditCardFunction::Run() { | 360 ExtensionFunction::ResponseAction AutofillPrivateSaveCreditCardFunction::Run() { |
363 std::unique_ptr<api::autofill_private::SaveCreditCard::Params> parameters = | 361 std::unique_ptr<api::autofill_private::SaveCreditCard::Params> parameters = |
364 api::autofill_private::SaveCreditCard::Params::Create(*args_); | 362 api::autofill_private::SaveCreditCard::Params::Create(*args_); |
365 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 363 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
366 | 364 |
367 autofill::PersonalDataManager* personal_data = | 365 autofill::PersonalDataManager* personal_data = |
368 autofill::PersonalDataManagerFactory::GetForProfile( | 366 autofill::PersonalDataManagerFactory::GetForProfile( |
369 chrome_details_.GetProfile()); | 367 chrome_details_.GetProfile()); |
370 if (!personal_data || !personal_data->IsDataLoaded()) { | 368 if (!personal_data || !personal_data->IsDataLoaded()) |
371 SetError(kErrorDataUnavailable); | 369 return RespondNow(Error(kErrorDataUnavailable)); |
372 return RespondNow(NoArguments()); | |
373 } | |
374 | 370 |
375 api::autofill_private::CreditCardEntry* card = ¶meters->card; | 371 api::autofill_private::CreditCardEntry* card = ¶meters->card; |
376 | 372 |
377 std::string guid = card->guid ? *card->guid : ""; | 373 std::string guid = card->guid ? *card->guid : ""; |
378 autofill::CreditCard credit_card(guid, kSettingsOrigin); | 374 autofill::CreditCard credit_card(guid, kSettingsOrigin); |
379 | 375 |
380 if (card->name) { | 376 if (card->name) { |
381 credit_card.SetRawInfo(autofill::CREDIT_CARD_NAME_FULL, | 377 credit_card.SetRawInfo(autofill::CREDIT_CARD_NAME_FULL, |
382 base::UTF8ToUTF16(*card->name)); | 378 base::UTF8ToUTF16(*card->name)); |
383 } | 379 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 AutofillPrivateRemoveEntryFunction::~AutofillPrivateRemoveEntryFunction() {} | 415 AutofillPrivateRemoveEntryFunction::~AutofillPrivateRemoveEntryFunction() {} |
420 | 416 |
421 ExtensionFunction::ResponseAction AutofillPrivateRemoveEntryFunction::Run() { | 417 ExtensionFunction::ResponseAction AutofillPrivateRemoveEntryFunction::Run() { |
422 std::unique_ptr<api::autofill_private::RemoveEntry::Params> parameters = | 418 std::unique_ptr<api::autofill_private::RemoveEntry::Params> parameters = |
423 api::autofill_private::RemoveEntry::Params::Create(*args_); | 419 api::autofill_private::RemoveEntry::Params::Create(*args_); |
424 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 420 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
425 | 421 |
426 autofill::PersonalDataManager* personal_data = | 422 autofill::PersonalDataManager* personal_data = |
427 autofill::PersonalDataManagerFactory::GetForProfile( | 423 autofill::PersonalDataManagerFactory::GetForProfile( |
428 chrome_details_.GetProfile()); | 424 chrome_details_.GetProfile()); |
429 if (!personal_data || !personal_data->IsDataLoaded()) { | 425 if (!personal_data || !personal_data->IsDataLoaded()) |
430 SetError(kErrorDataUnavailable); | 426 return RespondNow(Error(kErrorDataUnavailable)); |
431 return RespondNow(NoArguments()); | |
432 } | |
433 | 427 |
434 personal_data->RemoveByGUID(parameters->guid); | 428 personal_data->RemoveByGUID(parameters->guid); |
435 | 429 |
436 return RespondNow(NoArguments()); | 430 return RespondNow(NoArguments()); |
437 } | 431 } |
438 | 432 |
439 //////////////////////////////////////////////////////////////////////////////// | 433 //////////////////////////////////////////////////////////////////////////////// |
440 // AutofillPrivateValidatePhoneNumbersFunction | 434 // AutofillPrivateValidatePhoneNumbersFunction |
441 | 435 |
442 AutofillPrivateValidatePhoneNumbersFunction:: | 436 AutofillPrivateValidatePhoneNumbersFunction:: |
(...skipping 28 matching lines...) Expand all Loading... |
471 ~AutofillPrivateMaskCreditCardFunction() {} | 465 ~AutofillPrivateMaskCreditCardFunction() {} |
472 | 466 |
473 ExtensionFunction::ResponseAction AutofillPrivateMaskCreditCardFunction::Run() { | 467 ExtensionFunction::ResponseAction AutofillPrivateMaskCreditCardFunction::Run() { |
474 std::unique_ptr<api::autofill_private::MaskCreditCard::Params> parameters = | 468 std::unique_ptr<api::autofill_private::MaskCreditCard::Params> parameters = |
475 api::autofill_private::MaskCreditCard::Params::Create(*args_); | 469 api::autofill_private::MaskCreditCard::Params::Create(*args_); |
476 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 470 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
477 | 471 |
478 autofill::PersonalDataManager* personal_data = | 472 autofill::PersonalDataManager* personal_data = |
479 autofill::PersonalDataManagerFactory::GetForProfile( | 473 autofill::PersonalDataManagerFactory::GetForProfile( |
480 chrome_details_.GetProfile()); | 474 chrome_details_.GetProfile()); |
481 if (!personal_data || !personal_data->IsDataLoaded()) { | 475 if (!personal_data || !personal_data->IsDataLoaded()) |
482 SetError(kErrorDataUnavailable); | 476 return RespondNow(Error(kErrorDataUnavailable)); |
483 return RespondNow(NoArguments()); | |
484 } | |
485 | 477 |
486 personal_data->ResetFullServerCard(parameters->guid); | 478 personal_data->ResetFullServerCard(parameters->guid); |
487 | 479 |
488 return RespondNow(NoArguments()); | 480 return RespondNow(NoArguments()); |
489 } | 481 } |
490 | 482 |
491 //////////////////////////////////////////////////////////////////////////////// | 483 //////////////////////////////////////////////////////////////////////////////// |
492 // AutofillPrivateGetCreditCardListFunction | 484 // AutofillPrivateGetCreditCardListFunction |
493 | 485 |
494 AutofillPrivateGetCreditCardListFunction:: | 486 AutofillPrivateGetCreditCardListFunction:: |
(...skipping 13 matching lines...) Expand all Loading... |
508 | 500 |
509 autofill_util::CreditCardEntryList credit_card_list = | 501 autofill_util::CreditCardEntryList credit_card_list = |
510 autofill_util::GenerateCreditCardList(*personal_data); | 502 autofill_util::GenerateCreditCardList(*personal_data); |
511 | 503 |
512 return RespondNow( | 504 return RespondNow( |
513 ArgumentList(api::autofill_private::GetCreditCardList::Results::Create( | 505 ArgumentList(api::autofill_private::GetCreditCardList::Results::Create( |
514 credit_card_list))); | 506 credit_card_list))); |
515 } | 507 } |
516 | 508 |
517 } // namespace extensions | 509 } // namespace extensions |
OLD | NEW |