| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return cc_field_http_warning_suggestion; | 212 return cc_field_http_warning_suggestion; |
| 213 } | 213 } |
| 214 | 214 |
| 215 } // namespace | 215 } // namespace |
| 216 | 216 |
| 217 AutofillManager::AutofillManager( | 217 AutofillManager::AutofillManager( |
| 218 AutofillDriver* driver, | 218 AutofillDriver* driver, |
| 219 AutofillClient* client, | 219 AutofillClient* client, |
| 220 const std::string& app_locale, | 220 const std::string& app_locale, |
| 221 AutofillDownloadManagerState enable_download_manager) | 221 AutofillDownloadManagerState enable_download_manager) |
| 222 : driver_(driver), | 222 : AutofillHandler(driver), |
| 223 client_(client), | 223 client_(client), |
| 224 payments_client_(base::MakeUnique<payments::PaymentsClient>( | 224 payments_client_(base::MakeUnique<payments::PaymentsClient>( |
| 225 driver->GetURLRequestContext(), | 225 driver->GetURLRequestContext(), |
| 226 this)), | 226 this)), |
| 227 app_locale_(app_locale), | 227 app_locale_(app_locale), |
| 228 personal_data_(client->GetPersonalDataManager()), | 228 personal_data_(client->GetPersonalDataManager()), |
| 229 autocomplete_history_manager_( | 229 autocomplete_history_manager_( |
| 230 base::MakeUnique<AutocompleteHistoryManager>(driver, client)), | 230 base::MakeUnique<AutocompleteHistoryManager>(driver, client)), |
| 231 form_interactions_ukm_logger_( | 231 form_interactions_ukm_logger_( |
| 232 base::MakeUnique<AutofillMetrics::FormInteractionsUkmLogger>( | 232 base::MakeUnique<AutofillMetrics::FormInteractionsUkmLogger>( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 256 autofill_assistant_(this), | 256 autofill_assistant_(this), |
| 257 #endif | 257 #endif |
| 258 weak_ptr_factory_(this) { | 258 weak_ptr_factory_(this) { |
| 259 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { | 259 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { |
| 260 download_manager_.reset(new AutofillDownloadManager(driver, this)); | 260 download_manager_.reset(new AutofillDownloadManager(driver, this)); |
| 261 } | 261 } |
| 262 CountryNames::SetLocaleString(app_locale_); | 262 CountryNames::SetLocaleString(app_locale_); |
| 263 if (personal_data_ && client_) | 263 if (personal_data_ && client_) |
| 264 personal_data_->OnSyncServiceInitialized(client_->GetSyncService()); | 264 personal_data_->OnSyncServiceInitialized(client_->GetSyncService()); |
| 265 | 265 |
| 266 if (personal_data_ && driver_) | 266 if (personal_data_ && driver) |
| 267 personal_data_->SetURLRequestContextGetter(driver_->GetURLRequestContext()); | 267 personal_data_->SetURLRequestContextGetter(driver->GetURLRequestContext()); |
| 268 } | 268 } |
| 269 | 269 |
| 270 AutofillManager::~AutofillManager() {} | 270 AutofillManager::~AutofillManager() {} |
| 271 | 271 |
| 272 // static | 272 // static |
| 273 void AutofillManager::RegisterProfilePrefs( | 273 void AutofillManager::RegisterProfilePrefs( |
| 274 user_prefs::PrefRegistrySyncable* registry) { | 274 user_prefs::PrefRegistrySyncable* registry) { |
| 275 // This pref is not synced because it's for a signin promo, which by | 275 // This pref is not synced because it's for a signin promo, which by |
| 276 // definition will not be synced. | 276 // definition will not be synced. |
| 277 registry->RegisterIntegerPref( | 277 registry->RegisterIntegerPref( |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 client_->GetPrefs()->SetInteger( | 362 client_->GetPrefs()->SetInteger( |
| 363 prefs::kAutofillCreditCardSigninPromoImpressionCount, | 363 prefs::kAutofillCreditCardSigninPromoImpressionCount, |
| 364 impression_count + 1); | 364 impression_count + 1); |
| 365 return true; | 365 return true; |
| 366 } | 366 } |
| 367 | 367 |
| 368 return false; | 368 return false; |
| 369 } | 369 } |
| 370 | 370 |
| 371 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, | 371 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, |
| 372 const TimeTicks& timestamp) { | 372 const TimeTicks timestamp) { |
| 373 if (!IsValidFormDataVector(forms)) | 373 if (!IsValidFormDataVector(forms)) |
| 374 return; | 374 return; |
| 375 | 375 |
| 376 if (!driver_->RendererIsAvailable()) | 376 if (!driver()->RendererIsAvailable()) |
| 377 return; | 377 return; |
| 378 | 378 |
| 379 bool enabled = IsAutofillEnabled(); | 379 bool enabled = IsAutofillEnabled(); |
| 380 if (!has_logged_autofill_enabled_) { | 380 if (!has_logged_autofill_enabled_) { |
| 381 AutofillMetrics::LogIsAutofillEnabledAtPageLoad(enabled); | 381 AutofillMetrics::LogIsAutofillEnabledAtPageLoad(enabled); |
| 382 has_logged_autofill_enabled_ = true; | 382 has_logged_autofill_enabled_ = true; |
| 383 } | 383 } |
| 384 | 384 |
| 385 if (!enabled) | 385 if (!enabled) |
| 386 return; | 386 return; |
| 387 | 387 |
| 388 for (const FormData& form : forms) { | 388 for (const FormData& form : forms) { |
| 389 forms_loaded_timestamps_[form] = timestamp; | 389 forms_loaded_timestamps_[form] = timestamp; |
| 390 } | 390 } |
| 391 | 391 |
| 392 ParseForms(forms); | 392 ParseForms(forms); |
| 393 } | 393 } |
| 394 | 394 |
| 395 bool AutofillManager::OnWillSubmitForm(const FormData& form, | 395 bool AutofillManager::OnWillSubmitFormImpl(const FormData& form, |
| 396 const TimeTicks& timestamp) { | 396 const TimeTicks timestamp) { |
| 397 if (!IsValidFormData(form)) | |
| 398 return false; | |
| 399 | |
| 400 // We will always give Autocomplete a chance to save the data. | 397 // We will always give Autocomplete a chance to save the data. |
| 401 std::unique_ptr<FormStructure> submitted_form = ValidateSubmittedForm(form); | 398 std::unique_ptr<FormStructure> submitted_form = ValidateSubmittedForm(form); |
| 402 if (!submitted_form) { | 399 if (!submitted_form) { |
| 403 autocomplete_history_manager_->OnWillSubmitForm(form); | 400 autocomplete_history_manager_->OnWillSubmitForm(form); |
| 404 return false; | 401 return false; |
| 405 } | 402 } |
| 406 | 403 |
| 407 // However, if Autofill has recognized a field as CVC, that shouldn't be | 404 // However, if Autofill has recognized a field as CVC, that shouldn't be |
| 408 // saved. | 405 // saved. |
| 409 FormData form_for_autocomplete = submitted_form->ToFormData(); | 406 FormData form_for_autocomplete = submitted_form->ToFormData(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // upload process. |pending_form_data_| is reset. | 506 // upload process. |pending_form_data_| is reset. |
| 510 std::unique_ptr<FormStructure> upload_form = | 507 std::unique_ptr<FormStructure> upload_form = |
| 511 ValidateSubmittedForm(*pending_form_data_); | 508 ValidateSubmittedForm(*pending_form_data_); |
| 512 pending_form_data_.reset(); | 509 pending_form_data_.reset(); |
| 513 if (!upload_form) | 510 if (!upload_form) |
| 514 return; | 511 return; |
| 515 | 512 |
| 516 StartUploadProcess(std::move(upload_form), TimeTicks::Now(), false); | 513 StartUploadProcess(std::move(upload_form), TimeTicks::Now(), false); |
| 517 } | 514 } |
| 518 | 515 |
| 519 void AutofillManager::OnTextFieldDidChange(const FormData& form, | 516 void AutofillManager::OnTextFieldDidChangeImpl(const FormData& form, |
| 520 const FormFieldData& field, | 517 const FormFieldData& field, |
| 521 const TimeTicks& timestamp) { | 518 const TimeTicks timestamp) { |
| 522 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) | |
| 523 return; | |
| 524 | |
| 525 if (test_delegate_) | 519 if (test_delegate_) |
| 526 test_delegate_->OnTextFieldChanged(); | 520 test_delegate_->OnTextFieldChanged(); |
| 527 | 521 |
| 528 FormStructure* form_structure = NULL; | 522 FormStructure* form_structure = NULL; |
| 529 AutofillField* autofill_field = NULL; | 523 AutofillField* autofill_field = NULL; |
| 530 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) | 524 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) |
| 531 return; | 525 return; |
| 532 | 526 |
| 533 UpdatePendingForm(form); | 527 UpdatePendingForm(form); |
| 534 | 528 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 554 } | 548 } |
| 555 | 549 |
| 556 UpdateInitialInteractionTimestamp(timestamp); | 550 UpdateInitialInteractionTimestamp(timestamp); |
| 557 } | 551 } |
| 558 | 552 |
| 559 bool AutofillManager::IsFormNonSecure(const FormData& form) const { | 553 bool AutofillManager::IsFormNonSecure(const FormData& form) const { |
| 560 return !client_->IsContextSecure() || | 554 return !client_->IsContextSecure() || |
| 561 (form.action.is_valid() && form.action.SchemeIs("http")); | 555 (form.action.is_valid() && form.action.SchemeIs("http")); |
| 562 } | 556 } |
| 563 | 557 |
| 564 void AutofillManager::OnQueryFormFieldAutofill(int query_id, | 558 void AutofillManager::OnQueryFormFieldAutofillImpl( |
| 565 const FormData& form, | 559 int query_id, |
| 566 const FormFieldData& field, | 560 const FormData& form, |
| 567 const gfx::RectF& bounding_box) { | 561 const FormFieldData& field, |
| 568 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) | 562 const gfx::RectF& transformed_box) { |
| 569 return; | |
| 570 | |
| 571 gfx::RectF transformed_box = | |
| 572 driver_->TransformBoundingBoxToViewportCoordinates(bounding_box); | |
| 573 | |
| 574 external_delegate_->OnQuery(query_id, form, field, transformed_box); | 563 external_delegate_->OnQuery(query_id, form, field, transformed_box); |
| 575 | 564 |
| 576 // Need to refresh models before using the form_event_loggers. | 565 // Need to refresh models before using the form_event_loggers. |
| 577 bool is_autofill_possible = RefreshDataModels(); | 566 bool is_autofill_possible = RefreshDataModels(); |
| 578 | 567 |
| 579 FormStructure* form_structure = NULL; | 568 FormStructure* form_structure = NULL; |
| 580 AutofillField* autofill_field = NULL; | 569 AutofillField* autofill_field = NULL; |
| 581 bool got_autofillable_form = | 570 bool got_autofillable_form = |
| 582 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 571 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && |
| 583 // Don't send suggestions or track forms that should not be parsed. | 572 // Don't send suggestions or track forms that should not be parsed. |
| 584 form_structure->ShouldBeParsed(); | 573 form_structure->ShouldBeParsed(); |
| 585 | 574 |
| 586 bool is_filling_credit_card = false; | 575 bool is_filling_credit_card = false; |
| 587 | 576 |
| 588 // Log interactions of forms that are autofillable. | 577 // Log interactions of forms that are autofillable. |
| 589 if (got_autofillable_form) { | 578 if (got_autofillable_form) { |
| 590 if (autofill_field->Type().group() == CREDIT_CARD) { | 579 if (autofill_field->Type().group() == CREDIT_CARD) { |
| 591 is_filling_credit_card = true; | 580 is_filling_credit_card = true; |
| 592 driver_->DidInteractWithCreditCardForm(); | 581 driver()->DidInteractWithCreditCardForm(); |
| 593 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); | 582 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); |
| 594 } else { | 583 } else { |
| 595 address_form_event_logger_->OnDidInteractWithAutofillableForm(); | 584 address_form_event_logger_->OnDidInteractWithAutofillableForm(); |
| 596 } | 585 } |
| 597 } | 586 } |
| 598 | 587 |
| 599 std::vector<Suggestion> suggestions; | 588 std::vector<Suggestion> suggestions; |
| 600 const bool is_context_secure = !IsFormNonSecure(form); | 589 const bool is_context_secure = !IsFormNonSecure(form); |
| 601 const bool is_http_warning_enabled = | 590 const bool is_http_warning_enabled = |
| 602 security_state::IsHttpWarningInFormEnabled(); | 591 security_state::IsHttpWarningInFormEnabled(); |
| 603 | 592 |
| 604 // TODO(rogerm): Early exit here on !driver_->RendererIsAvailable()? | 593 // TODO(rogerm): Early exit here on !driver()->RendererIsAvailable()? |
| 605 // We skip populating autofill data, but might generate warnings and or | 594 // We skip populating autofill data, but might generate warnings and or |
| 606 // signin promo to show over the unavailable renderer. That seems a mistake. | 595 // signin promo to show over the unavailable renderer. That seems a mistake. |
| 607 | 596 |
| 608 if (is_autofill_possible && | 597 if (is_autofill_possible && driver()->RendererIsAvailable() && |
| 609 driver_->RendererIsAvailable() && | |
| 610 got_autofillable_form) { | 598 got_autofillable_form) { |
| 611 // On desktop, don't return non credit card related suggestions for forms or | 599 // On desktop, don't return non credit card related suggestions for forms or |
| 612 // fields that have the "autocomplete" attribute set to off. | 600 // fields that have the "autocomplete" attribute set to off. |
| 613 if (IsDesktopPlatform() && !is_filling_credit_card && | 601 if (IsDesktopPlatform() && !is_filling_credit_card && |
| 614 !field.should_autocomplete) { | 602 !field.should_autocomplete) { |
| 615 return; | 603 return; |
| 616 } | 604 } |
| 617 if (is_filling_credit_card) { | 605 if (is_filling_credit_card) { |
| 618 suggestions = GetCreditCardSuggestions(field, autofill_field->Type()); | 606 suggestions = GetCreditCardSuggestions(field, autofill_field->Type()); |
| 619 } else { | 607 } else { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 int query_id, | 775 int query_id, |
| 788 const FormData& form, | 776 const FormData& form, |
| 789 const FormFieldData& field, | 777 const FormFieldData& field, |
| 790 int unique_id) { | 778 int unique_id) { |
| 791 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) | 779 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) |
| 792 return; | 780 return; |
| 793 | 781 |
| 794 // NOTE: RefreshDataModels may invalidate |data_model| because it causes the | 782 // NOTE: RefreshDataModels may invalidate |data_model| because it causes the |
| 795 // PersonalDataManager to reload Mac address book entries. Thus it must come | 783 // PersonalDataManager to reload Mac address book entries. Thus it must come |
| 796 // before GetProfile or GetCreditCard. | 784 // before GetProfile or GetCreditCard. |
| 797 if (!RefreshDataModels() || !driver_->RendererIsAvailable()) | 785 if (!RefreshDataModels() || !driver()->RendererIsAvailable()) |
| 798 return; | 786 return; |
| 799 | 787 |
| 800 const CreditCard* credit_card = nullptr; | 788 const CreditCard* credit_card = nullptr; |
| 801 const AutofillProfile* profile = nullptr; | 789 const AutofillProfile* profile = nullptr; |
| 802 if (GetCreditCard(unique_id, &credit_card)) | 790 if (GetCreditCard(unique_id, &credit_card)) |
| 803 FillOrPreviewCreditCardForm(action, query_id, form, field, *credit_card); | 791 FillOrPreviewCreditCardForm(action, query_id, form, field, *credit_card); |
| 804 else if (GetProfile(unique_id, &profile)) | 792 else if (GetProfile(unique_id, &profile)) |
| 805 FillOrPreviewProfileForm(action, query_id, form, field, *profile); | 793 FillOrPreviewProfileForm(action, query_id, form, field, *profile); |
| 806 } | 794 } |
| 807 | 795 |
| 808 void AutofillManager::FillCreditCardForm(int query_id, | 796 void AutofillManager::FillCreditCardForm(int query_id, |
| 809 const FormData& form, | 797 const FormData& form, |
| 810 const FormFieldData& field, | 798 const FormFieldData& field, |
| 811 const CreditCard& credit_card, | 799 const CreditCard& credit_card, |
| 812 const base::string16& cvc) { | 800 const base::string16& cvc) { |
| 813 if (!IsValidFormData(form) || !IsValidFormFieldData(field) || | 801 if (!IsValidFormData(form) || !IsValidFormFieldData(field) || |
| 814 !driver_->RendererIsAvailable()) { | 802 !driver()->RendererIsAvailable()) { |
| 815 return; | 803 return; |
| 816 } | 804 } |
| 817 | 805 |
| 818 FillOrPreviewDataModelForm(AutofillDriver::FORM_DATA_ACTION_FILL, query_id, | 806 FillOrPreviewDataModelForm(AutofillDriver::FORM_DATA_ACTION_FILL, query_id, |
| 819 form, field, credit_card, true, cvc); | 807 form, field, credit_card, true, cvc); |
| 820 } | 808 } |
| 821 | 809 |
| 822 void AutofillManager::OnFocusNoLongerOnForm() { | 810 void AutofillManager::OnFocusNoLongerOnForm() { |
| 823 ProcessPendingFormForUpload(); | 811 ProcessPendingFormForUpload(); |
| 824 } | 812 } |
| 825 | 813 |
| 826 void AutofillManager::OnDidPreviewAutofillFormData() { | 814 void AutofillManager::OnDidPreviewAutofillFormData() { |
| 827 if (test_delegate_) | 815 if (test_delegate_) |
| 828 test_delegate_->DidPreviewFormData(); | 816 test_delegate_->DidPreviewFormData(); |
| 829 } | 817 } |
| 830 | 818 |
| 831 void AutofillManager::OnDidFillAutofillFormData(const FormData& form, | 819 void AutofillManager::OnDidFillAutofillFormData(const FormData& form, |
| 832 const TimeTicks& timestamp) { | 820 const TimeTicks timestamp) { |
| 833 if (test_delegate_) | 821 if (test_delegate_) |
| 834 test_delegate_->DidFillFormData(); | 822 test_delegate_->DidFillFormData(); |
| 835 | 823 |
| 836 UpdatePendingForm(form); | 824 UpdatePendingForm(form); |
| 837 | 825 |
| 838 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL); | 826 AutofillMetrics::LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL); |
| 839 if (!user_did_autofill_) { | 827 if (!user_did_autofill_) { |
| 840 user_did_autofill_ = true; | 828 user_did_autofill_ = true; |
| 841 AutofillMetrics::LogUserHappinessMetric( | 829 AutofillMetrics::LogUserHappinessMetric( |
| 842 AutofillMetrics::USER_DID_AUTOFILL_ONCE); | 830 AutofillMetrics::USER_DID_AUTOFILL_ONCE); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 FormStructure::ParseQueryResponse(std::move(response), queried_forms, | 1009 FormStructure::ParseQueryResponse(std::move(response), queried_forms, |
| 1022 client_->GetRapporServiceImpl()); | 1010 client_->GetRapporServiceImpl()); |
| 1023 | 1011 |
| 1024 // Will log quality metrics for each FormStructure based on the presence of | 1012 // Will log quality metrics for each FormStructure based on the presence of |
| 1025 // autocomplete attributes, if available. | 1013 // autocomplete attributes, if available. |
| 1026 for (FormStructure* cur_form : queried_forms) | 1014 for (FormStructure* cur_form : queried_forms) |
| 1027 cur_form->LogQualityMetricsBasedOnAutocomplete(); | 1015 cur_form->LogQualityMetricsBasedOnAutocomplete(); |
| 1028 | 1016 |
| 1029 // Forward form structures to the password generation manager to detect | 1017 // Forward form structures to the password generation manager to detect |
| 1030 // account creation forms. | 1018 // account creation forms. |
| 1031 driver_->PropagateAutofillPredictions(queried_forms); | 1019 driver()->PropagateAutofillPredictions(queried_forms); |
| 1032 | 1020 |
| 1033 // If the corresponding flag is set, annotate forms with the predicted types. | 1021 // If the corresponding flag is set, annotate forms with the predicted types. |
| 1034 driver_->SendAutofillTypePredictionsToRenderer(queried_forms); | 1022 driver()->SendAutofillTypePredictionsToRenderer(queried_forms); |
| 1035 } | 1023 } |
| 1036 | 1024 |
| 1037 IdentityProvider* AutofillManager::GetIdentityProvider() { | 1025 IdentityProvider* AutofillManager::GetIdentityProvider() { |
| 1038 return client_->GetIdentityProvider(); | 1026 return client_->GetIdentityProvider(); |
| 1039 } | 1027 } |
| 1040 | 1028 |
| 1041 void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, | 1029 void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, |
| 1042 const std::string& real_pan) { | 1030 const std::string& real_pan) { |
| 1043 DCHECK(full_card_request_); | 1031 DCHECK(full_card_request_); |
| 1044 full_card_request_->OnDidGetRealPan(result, real_pan); | 1032 full_card_request_->OnDidGetRealPan(result, real_pan); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 | 1101 |
| 1114 void AutofillManager::OnFullCardRequestSucceeded(const CreditCard& card, | 1102 void AutofillManager::OnFullCardRequestSucceeded(const CreditCard& card, |
| 1115 const base::string16& cvc) { | 1103 const base::string16& cvc) { |
| 1116 credit_card_form_event_logger_->OnDidFillSuggestion(masked_card_); | 1104 credit_card_form_event_logger_->OnDidFillSuggestion(masked_card_); |
| 1117 FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_, | 1105 FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_, |
| 1118 card, cvc); | 1106 card, cvc); |
| 1119 masked_card_ = CreditCard(); | 1107 masked_card_ = CreditCard(); |
| 1120 } | 1108 } |
| 1121 | 1109 |
| 1122 void AutofillManager::OnFullCardRequestFailed() { | 1110 void AutofillManager::OnFullCardRequestFailed() { |
| 1123 driver_->RendererShouldClearPreviewedForm(); | 1111 driver()->RendererShouldClearPreviewedForm(); |
| 1124 } | 1112 } |
| 1125 | 1113 |
| 1126 void AutofillManager::ShowUnmaskPrompt( | 1114 void AutofillManager::ShowUnmaskPrompt( |
| 1127 const CreditCard& card, | 1115 const CreditCard& card, |
| 1128 AutofillClient::UnmaskCardReason reason, | 1116 AutofillClient::UnmaskCardReason reason, |
| 1129 base::WeakPtr<CardUnmaskDelegate> delegate) { | 1117 base::WeakPtr<CardUnmaskDelegate> delegate) { |
| 1130 client_->ShowUnmaskPrompt(card, reason, delegate); | 1118 client_->ShowUnmaskPrompt(card, reason, delegate); |
| 1131 } | 1119 } |
| 1132 | 1120 |
| 1133 void AutofillManager::OnUnmaskVerificationResult( | 1121 void AutofillManager::OnUnmaskVerificationResult( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 return ::autofill::IsAutofillEnabled(client_->GetPrefs()); | 1161 return ::autofill::IsAutofillEnabled(client_->GetPrefs()); |
| 1174 } | 1162 } |
| 1175 | 1163 |
| 1176 bool AutofillManager::IsCreditCardUploadEnabled() { | 1164 bool AutofillManager::IsCreditCardUploadEnabled() { |
| 1177 return ::autofill::IsCreditCardUploadEnabled( | 1165 return ::autofill::IsCreditCardUploadEnabled( |
| 1178 client_->GetPrefs(), client_->GetSyncService(), | 1166 client_->GetPrefs(), client_->GetSyncService(), |
| 1179 GetIdentityProvider()->GetActiveUsername()); | 1167 GetIdentityProvider()->GetActiveUsername()); |
| 1180 } | 1168 } |
| 1181 | 1169 |
| 1182 bool AutofillManager::ShouldUploadForm(const FormStructure& form) { | 1170 bool AutofillManager::ShouldUploadForm(const FormStructure& form) { |
| 1183 return IsAutofillEnabled() && !driver_->IsIncognito() && | 1171 return IsAutofillEnabled() && !driver()->IsIncognito() && |
| 1184 form.ShouldBeParsed() && | 1172 form.ShouldBeParsed() && |
| 1185 (form.active_field_count() >= kRequiredFieldsForUpload || | 1173 (form.active_field_count() >= kRequiredFieldsForUpload || |
| 1186 (form.all_fields_are_passwords() && | 1174 (form.all_fields_are_passwords() && |
| 1187 form.active_field_count() >= | 1175 form.active_field_count() >= |
| 1188 kRequiredFieldsForFormsWithOnlyPasswordFields)); | 1176 kRequiredFieldsForFormsWithOnlyPasswordFields)); |
| 1189 } | 1177 } |
| 1190 | 1178 |
| 1191 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { | 1179 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { |
| 1192 std::unique_ptr<CreditCard> imported_credit_card; | 1180 std::unique_ptr<CreditCard> imported_credit_card; |
| 1193 bool imported_credit_card_matches_masked_server_credit_card; | 1181 bool imported_credit_card_matches_masked_server_credit_card; |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 unmasking_form_ = FormData(); | 1577 unmasking_form_ = FormData(); |
| 1590 unmasking_field_ = FormFieldData(); | 1578 unmasking_field_ = FormFieldData(); |
| 1591 forms_loaded_timestamps_.clear(); | 1579 forms_loaded_timestamps_.clear(); |
| 1592 initial_interaction_timestamp_ = TimeTicks(); | 1580 initial_interaction_timestamp_ = TimeTicks(); |
| 1593 external_delegate_->Reset(); | 1581 external_delegate_->Reset(); |
| 1594 } | 1582 } |
| 1595 | 1583 |
| 1596 AutofillManager::AutofillManager(AutofillDriver* driver, | 1584 AutofillManager::AutofillManager(AutofillDriver* driver, |
| 1597 AutofillClient* client, | 1585 AutofillClient* client, |
| 1598 PersonalDataManager* personal_data) | 1586 PersonalDataManager* personal_data) |
| 1599 : driver_(driver), | 1587 : AutofillHandler(driver), |
| 1600 client_(client), | 1588 client_(client), |
| 1601 payments_client_(base::MakeUnique<payments::PaymentsClient>( | 1589 payments_client_(base::MakeUnique<payments::PaymentsClient>( |
| 1602 driver->GetURLRequestContext(), | 1590 driver->GetURLRequestContext(), |
| 1603 this)), | 1591 this)), |
| 1604 app_locale_("en-US"), | 1592 app_locale_("en-US"), |
| 1605 personal_data_(personal_data), | 1593 personal_data_(personal_data), |
| 1606 autocomplete_history_manager_( | 1594 autocomplete_history_manager_( |
| 1607 base::MakeUnique<AutocompleteHistoryManager>(driver, client)), | 1595 base::MakeUnique<AutocompleteHistoryManager>(driver, client)), |
| 1608 form_interactions_ukm_logger_( | 1596 form_interactions_ukm_logger_( |
| 1609 base::MakeUnique<AutofillMetrics::FormInteractionsUkmLogger>( | 1597 base::MakeUnique<AutofillMetrics::FormInteractionsUkmLogger>( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1622 user_did_type_(false), | 1610 user_did_type_(false), |
| 1623 user_did_autofill_(false), | 1611 user_did_autofill_(false), |
| 1624 user_did_edit_autofilled_field_(false), | 1612 user_did_edit_autofilled_field_(false), |
| 1625 unmasking_query_id_(-1), | 1613 unmasking_query_id_(-1), |
| 1626 external_delegate_(NULL), | 1614 external_delegate_(NULL), |
| 1627 test_delegate_(NULL), | 1615 test_delegate_(NULL), |
| 1628 #if defined(OS_ANDROID) || defined(OS_IOS) | 1616 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 1629 autofill_assistant_(this), | 1617 autofill_assistant_(this), |
| 1630 #endif | 1618 #endif |
| 1631 weak_ptr_factory_(this) { | 1619 weak_ptr_factory_(this) { |
| 1632 DCHECK(driver_); | 1620 DCHECK(driver); |
| 1633 DCHECK(client_); | 1621 DCHECK(client_); |
| 1634 CountryNames::SetLocaleString(app_locale_); | 1622 CountryNames::SetLocaleString(app_locale_); |
| 1635 } | 1623 } |
| 1636 | 1624 |
| 1637 bool AutofillManager::RefreshDataModels() { | 1625 bool AutofillManager::RefreshDataModels() { |
| 1638 if (!IsAutofillEnabled()) | 1626 if (!IsAutofillEnabled()) |
| 1639 return false; | 1627 return false; |
| 1640 | 1628 |
| 1641 // No autofill data to return if the profiles are empty. | 1629 // No autofill data to return if the profiles are empty. |
| 1642 const std::vector<AutofillProfile*>& profiles = | 1630 const std::vector<AutofillProfile*>& profiles = |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1759 } | 1747 } |
| 1760 break; | 1748 break; |
| 1761 } | 1749 } |
| 1762 } | 1750 } |
| 1763 | 1751 |
| 1764 // Note that this may invalidate |data_model|, particularly if it is a Mac | 1752 // Note that this may invalidate |data_model|, particularly if it is a Mac |
| 1765 // address book entry. | 1753 // address book entry. |
| 1766 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) | 1754 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) |
| 1767 personal_data_->RecordUseOf(data_model); | 1755 personal_data_->RecordUseOf(data_model); |
| 1768 | 1756 |
| 1769 driver_->SendFormDataToRenderer(query_id, action, result); | 1757 driver()->SendFormDataToRenderer(query_id, action, result); |
| 1770 return; | 1758 return; |
| 1771 } | 1759 } |
| 1772 | 1760 |
| 1773 DCHECK_EQ(form_structure->field_count(), form.fields.size()); | 1761 DCHECK_EQ(form_structure->field_count(), form.fields.size()); |
| 1774 for (size_t i = 0; i < form_structure->field_count(); ++i) { | 1762 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
| 1775 if (form_structure->field(i)->section() != autofill_field->section()) | 1763 if (form_structure->field(i)->section() != autofill_field->section()) |
| 1776 continue; | 1764 continue; |
| 1777 | 1765 |
| 1778 DCHECK(form_structure->field(i)->SameFieldAs(result.fields[i])); | 1766 DCHECK(form_structure->field(i)->SameFieldAs(result.fields[i])); |
| 1779 | 1767 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 // Only remember the last few forms that we've seen, both to avoid false | 1818 // Only remember the last few forms that we've seen, both to avoid false |
| 1831 // positives and to avoid wasting memory. | 1819 // positives and to avoid wasting memory. |
| 1832 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember) | 1820 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember) |
| 1833 autofilled_form_signatures_.pop_back(); | 1821 autofilled_form_signatures_.pop_back(); |
| 1834 | 1822 |
| 1835 // Note that this may invalidate |data_model|, particularly if it is a Mac | 1823 // Note that this may invalidate |data_model|, particularly if it is a Mac |
| 1836 // address book entry. | 1824 // address book entry. |
| 1837 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) | 1825 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) |
| 1838 personal_data_->RecordUseOf(data_model); | 1826 personal_data_->RecordUseOf(data_model); |
| 1839 | 1827 |
| 1840 driver_->SendFormDataToRenderer(query_id, action, result); | 1828 driver()->SendFormDataToRenderer(query_id, action, result); |
| 1841 } | 1829 } |
| 1842 | 1830 |
| 1843 std::unique_ptr<FormStructure> AutofillManager::ValidateSubmittedForm( | 1831 std::unique_ptr<FormStructure> AutofillManager::ValidateSubmittedForm( |
| 1844 const FormData& form) { | 1832 const FormData& form) { |
| 1845 std::unique_ptr<FormStructure> submitted_form( | 1833 std::unique_ptr<FormStructure> submitted_form( |
| 1846 base::MakeUnique<FormStructure>(form)); | 1834 base::MakeUnique<FormStructure>(form)); |
| 1847 if (!ShouldUploadForm(*submitted_form)) | 1835 if (!ShouldUploadForm(*submitted_form)) |
| 1848 return std::unique_ptr<FormStructure>(); | 1836 return std::unique_ptr<FormStructure>(); |
| 1849 | 1837 |
| 1850 // Ignore forms not present in our cache. These are typically forms with | 1838 // Ignore forms not present in our cache. These are typically forms with |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1953 // Note: We _must not_ remove the original version of the cached form from | 1941 // Note: We _must not_ remove the original version of the cached form from |
| 1954 // the list of |form_structures_|. Otherwise, we break parsing of the | 1942 // the list of |form_structures_|. Otherwise, we break parsing of the |
| 1955 // crowdsourcing server's response to our query. | 1943 // crowdsourcing server's response to our query. |
| 1956 if (!ParseForm(live_form, updated_form)) | 1944 if (!ParseForm(live_form, updated_form)) |
| 1957 return false; | 1945 return false; |
| 1958 | 1946 |
| 1959 if (cached_form) | 1947 if (cached_form) |
| 1960 (*updated_form)->UpdateFromCache(*cached_form, true); | 1948 (*updated_form)->UpdateFromCache(*cached_form, true); |
| 1961 | 1949 |
| 1962 // Annotate the updated form with its predicted types. | 1950 // Annotate the updated form with its predicted types. |
| 1963 driver_->SendAutofillTypePredictionsToRenderer({*updated_form}); | 1951 driver()->SendAutofillTypePredictionsToRenderer({*updated_form}); |
| 1964 | 1952 |
| 1965 return true; | 1953 return true; |
| 1966 } | 1954 } |
| 1967 | 1955 |
| 1968 std::vector<Suggestion> AutofillManager::GetProfileSuggestions( | 1956 std::vector<Suggestion> AutofillManager::GetProfileSuggestions( |
| 1969 const FormStructure& form, | 1957 const FormStructure& form, |
| 1970 const FormFieldData& field, | 1958 const FormFieldData& field, |
| 1971 const AutofillField& autofill_field) const { | 1959 const AutofillField& autofill_field) const { |
| 1972 address_form_event_logger_->OnDidPollSuggestions(field); | 1960 address_form_event_logger_->OnDidPollSuggestions(field); |
| 1973 | 1961 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 // Expired cards are last in the sorted order, so if the first one is | 2055 // Expired cards are last in the sorted order, so if the first one is |
| 2068 // expired, they all are. | 2056 // expired, they all are. |
| 2069 if (!cards.empty() && !cards.front()->IsExpired(AutofillClock::Now())) | 2057 if (!cards.empty() && !cards.front()->IsExpired(AutofillClock::Now())) |
| 2070 autofill_assistant_.ShowAssistForCreditCard(*cards.front()); | 2058 autofill_assistant_.ShowAssistForCreditCard(*cards.front()); |
| 2071 } | 2059 } |
| 2072 #endif | 2060 #endif |
| 2073 | 2061 |
| 2074 // For the |non_queryable_forms|, we have all the field type info we're ever | 2062 // For the |non_queryable_forms|, we have all the field type info we're ever |
| 2075 // going to get about them. For the other forms, we'll wait until we get a | 2063 // going to get about them. For the other forms, we'll wait until we get a |
| 2076 // response from the server. | 2064 // response from the server. |
| 2077 driver_->SendAutofillTypePredictionsToRenderer(non_queryable_forms); | 2065 driver()->SendAutofillTypePredictionsToRenderer(non_queryable_forms); |
| 2078 } | 2066 } |
| 2079 | 2067 |
| 2080 bool AutofillManager::ParseForm(const FormData& form, | 2068 bool AutofillManager::ParseForm(const FormData& form, |
| 2081 FormStructure** parsed_form_structure) { | 2069 FormStructure** parsed_form_structure) { |
| 2082 DCHECK(parsed_form_structure); | 2070 DCHECK(parsed_form_structure); |
| 2083 if (form_structures_.size() >= kMaxFormCacheSize) | 2071 if (form_structures_.size() >= kMaxFormCacheSize) |
| 2084 return false; | 2072 return false; |
| 2085 | 2073 |
| 2086 auto form_structure = base::MakeUnique<FormStructure>(form); | 2074 auto form_structure = base::MakeUnique<FormStructure>(form); |
| 2087 form_structure->ParseFieldTypesFromAutocompleteAttributes(); | 2075 form_structure->ParseFieldTypesFromAutocompleteAttributes(); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2367 #endif // ENABLE_FORM_DEBUG_DUMP | 2355 #endif // ENABLE_FORM_DEBUG_DUMP |
| 2368 | 2356 |
| 2369 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { | 2357 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { |
| 2370 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); | 2358 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); |
| 2371 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmRecorder(), | 2359 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmRecorder(), |
| 2372 pending_upload_request_url_, | 2360 pending_upload_request_url_, |
| 2373 upload_decision_metrics); | 2361 upload_decision_metrics); |
| 2374 } | 2362 } |
| 2375 | 2363 |
| 2376 } // namespace autofill | 2364 } // namespace autofill |
| OLD | NEW |