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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 | 1100 |
1113 void AutofillManager::OnFullCardRequestSucceeded(const CreditCard& card, | 1101 void AutofillManager::OnFullCardRequestSucceeded(const CreditCard& card, |
1114 const base::string16& cvc) { | 1102 const base::string16& cvc) { |
1115 credit_card_form_event_logger_->OnDidFillSuggestion(masked_card_); | 1103 credit_card_form_event_logger_->OnDidFillSuggestion(masked_card_); |
1116 FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_, | 1104 FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_, |
1117 card, cvc); | 1105 card, cvc); |
1118 masked_card_ = CreditCard(); | 1106 masked_card_ = CreditCard(); |
1119 } | 1107 } |
1120 | 1108 |
1121 void AutofillManager::OnFullCardRequestFailed() { | 1109 void AutofillManager::OnFullCardRequestFailed() { |
1122 driver_->RendererShouldClearPreviewedForm(); | 1110 driver()->RendererShouldClearPreviewedForm(); |
1123 } | 1111 } |
1124 | 1112 |
1125 void AutofillManager::ShowUnmaskPrompt( | 1113 void AutofillManager::ShowUnmaskPrompt( |
1126 const CreditCard& card, | 1114 const CreditCard& card, |
1127 AutofillClient::UnmaskCardReason reason, | 1115 AutofillClient::UnmaskCardReason reason, |
1128 base::WeakPtr<CardUnmaskDelegate> delegate) { | 1116 base::WeakPtr<CardUnmaskDelegate> delegate) { |
1129 client_->ShowUnmaskPrompt(card, reason, delegate); | 1117 client_->ShowUnmaskPrompt(card, reason, delegate); |
1130 } | 1118 } |
1131 | 1119 |
1132 void AutofillManager::OnUnmaskVerificationResult( | 1120 void AutofillManager::OnUnmaskVerificationResult( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 return ::autofill::IsAutofillEnabled(client_->GetPrefs()); | 1160 return ::autofill::IsAutofillEnabled(client_->GetPrefs()); |
1173 } | 1161 } |
1174 | 1162 |
1175 bool AutofillManager::IsCreditCardUploadEnabled() { | 1163 bool AutofillManager::IsCreditCardUploadEnabled() { |
1176 return ::autofill::IsCreditCardUploadEnabled( | 1164 return ::autofill::IsCreditCardUploadEnabled( |
1177 client_->GetPrefs(), client_->GetSyncService(), | 1165 client_->GetPrefs(), client_->GetSyncService(), |
1178 GetIdentityProvider()->GetActiveUsername()); | 1166 GetIdentityProvider()->GetActiveUsername()); |
1179 } | 1167 } |
1180 | 1168 |
1181 bool AutofillManager::ShouldUploadForm(const FormStructure& form) { | 1169 bool AutofillManager::ShouldUploadForm(const FormStructure& form) { |
1182 return IsAutofillEnabled() && !driver_->IsIncognito() && | 1170 return IsAutofillEnabled() && !driver()->IsIncognito() && |
1183 form.ShouldBeParsed() && | 1171 form.ShouldBeParsed() && |
1184 (form.active_field_count() >= kRequiredFieldsForUpload || | 1172 (form.active_field_count() >= kRequiredFieldsForUpload || |
1185 (form.all_fields_are_passwords() && | 1173 (form.all_fields_are_passwords() && |
1186 form.active_field_count() >= | 1174 form.active_field_count() >= |
1187 kRequiredFieldsForFormsWithOnlyPasswordFields)); | 1175 kRequiredFieldsForFormsWithOnlyPasswordFields)); |
1188 } | 1176 } |
1189 | 1177 |
1190 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { | 1178 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { |
1191 std::unique_ptr<CreditCard> imported_credit_card; | 1179 std::unique_ptr<CreditCard> imported_credit_card; |
1192 bool imported_credit_card_matches_masked_server_credit_card; | 1180 bool imported_credit_card_matches_masked_server_credit_card; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 unmasking_form_ = FormData(); | 1544 unmasking_form_ = FormData(); |
1557 unmasking_field_ = FormFieldData(); | 1545 unmasking_field_ = FormFieldData(); |
1558 forms_loaded_timestamps_.clear(); | 1546 forms_loaded_timestamps_.clear(); |
1559 initial_interaction_timestamp_ = TimeTicks(); | 1547 initial_interaction_timestamp_ = TimeTicks(); |
1560 external_delegate_->Reset(); | 1548 external_delegate_->Reset(); |
1561 } | 1549 } |
1562 | 1550 |
1563 AutofillManager::AutofillManager(AutofillDriver* driver, | 1551 AutofillManager::AutofillManager(AutofillDriver* driver, |
1564 AutofillClient* client, | 1552 AutofillClient* client, |
1565 PersonalDataManager* personal_data) | 1553 PersonalDataManager* personal_data) |
1566 : driver_(driver), | 1554 : AutofillHandler(driver), |
1567 client_(client), | 1555 client_(client), |
1568 payments_client_(base::MakeUnique<payments::PaymentsClient>( | 1556 payments_client_(base::MakeUnique<payments::PaymentsClient>( |
1569 driver->GetURLRequestContext(), | 1557 driver->GetURLRequestContext(), |
1570 this)), | 1558 this)), |
1571 app_locale_("en-US"), | 1559 app_locale_("en-US"), |
1572 personal_data_(personal_data), | 1560 personal_data_(personal_data), |
1573 autocomplete_history_manager_( | 1561 autocomplete_history_manager_( |
1574 base::MakeUnique<AutocompleteHistoryManager>(driver, client)), | 1562 base::MakeUnique<AutocompleteHistoryManager>(driver, client)), |
1575 form_interactions_ukm_logger_( | 1563 form_interactions_ukm_logger_( |
1576 base::MakeUnique<AutofillMetrics::FormInteractionsUkmLogger>( | 1564 base::MakeUnique<AutofillMetrics::FormInteractionsUkmLogger>( |
(...skipping 12 matching lines...) Expand all Loading... |
1589 user_did_type_(false), | 1577 user_did_type_(false), |
1590 user_did_autofill_(false), | 1578 user_did_autofill_(false), |
1591 user_did_edit_autofilled_field_(false), | 1579 user_did_edit_autofilled_field_(false), |
1592 unmasking_query_id_(-1), | 1580 unmasking_query_id_(-1), |
1593 external_delegate_(NULL), | 1581 external_delegate_(NULL), |
1594 test_delegate_(NULL), | 1582 test_delegate_(NULL), |
1595 #if defined(OS_ANDROID) || defined(OS_IOS) | 1583 #if defined(OS_ANDROID) || defined(OS_IOS) |
1596 autofill_assistant_(this), | 1584 autofill_assistant_(this), |
1597 #endif | 1585 #endif |
1598 weak_ptr_factory_(this) { | 1586 weak_ptr_factory_(this) { |
1599 DCHECK(driver_); | 1587 DCHECK(driver); |
1600 DCHECK(client_); | 1588 DCHECK(client_); |
1601 CountryNames::SetLocaleString(app_locale_); | 1589 CountryNames::SetLocaleString(app_locale_); |
1602 } | 1590 } |
1603 | 1591 |
1604 bool AutofillManager::RefreshDataModels() { | 1592 bool AutofillManager::RefreshDataModels() { |
1605 if (!IsAutofillEnabled()) | 1593 if (!IsAutofillEnabled()) |
1606 return false; | 1594 return false; |
1607 | 1595 |
1608 // No autofill data to return if the profiles are empty. | 1596 // No autofill data to return if the profiles are empty. |
1609 const std::vector<AutofillProfile*>& profiles = | 1597 const std::vector<AutofillProfile*>& profiles = |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 } | 1714 } |
1727 break; | 1715 break; |
1728 } | 1716 } |
1729 } | 1717 } |
1730 | 1718 |
1731 // Note that this may invalidate |data_model|, particularly if it is a Mac | 1719 // Note that this may invalidate |data_model|, particularly if it is a Mac |
1732 // address book entry. | 1720 // address book entry. |
1733 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) | 1721 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) |
1734 personal_data_->RecordUseOf(data_model); | 1722 personal_data_->RecordUseOf(data_model); |
1735 | 1723 |
1736 driver_->SendFormDataToRenderer(query_id, action, result); | 1724 driver()->SendFormDataToRenderer(query_id, action, result); |
1737 return; | 1725 return; |
1738 } | 1726 } |
1739 | 1727 |
1740 DCHECK_EQ(form_structure->field_count(), form.fields.size()); | 1728 DCHECK_EQ(form_structure->field_count(), form.fields.size()); |
1741 for (size_t i = 0; i < form_structure->field_count(); ++i) { | 1729 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
1742 if (form_structure->field(i)->section() != autofill_field->section()) | 1730 if (form_structure->field(i)->section() != autofill_field->section()) |
1743 continue; | 1731 continue; |
1744 | 1732 |
1745 DCHECK(form_structure->field(i)->SameFieldAs(result.fields[i])); | 1733 DCHECK(form_structure->field(i)->SameFieldAs(result.fields[i])); |
1746 | 1734 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 // Only remember the last few forms that we've seen, both to avoid false | 1785 // Only remember the last few forms that we've seen, both to avoid false |
1798 // positives and to avoid wasting memory. | 1786 // positives and to avoid wasting memory. |
1799 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember) | 1787 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember) |
1800 autofilled_form_signatures_.pop_back(); | 1788 autofilled_form_signatures_.pop_back(); |
1801 | 1789 |
1802 // Note that this may invalidate |data_model|, particularly if it is a Mac | 1790 // Note that this may invalidate |data_model|, particularly if it is a Mac |
1803 // address book entry. | 1791 // address book entry. |
1804 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) | 1792 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) |
1805 personal_data_->RecordUseOf(data_model); | 1793 personal_data_->RecordUseOf(data_model); |
1806 | 1794 |
1807 driver_->SendFormDataToRenderer(query_id, action, result); | 1795 driver()->SendFormDataToRenderer(query_id, action, result); |
1808 } | 1796 } |
1809 | 1797 |
1810 std::unique_ptr<FormStructure> AutofillManager::ValidateSubmittedForm( | 1798 std::unique_ptr<FormStructure> AutofillManager::ValidateSubmittedForm( |
1811 const FormData& form) { | 1799 const FormData& form) { |
1812 std::unique_ptr<FormStructure> submitted_form( | 1800 std::unique_ptr<FormStructure> submitted_form( |
1813 base::MakeUnique<FormStructure>(form)); | 1801 base::MakeUnique<FormStructure>(form)); |
1814 if (!ShouldUploadForm(*submitted_form)) | 1802 if (!ShouldUploadForm(*submitted_form)) |
1815 return std::unique_ptr<FormStructure>(); | 1803 return std::unique_ptr<FormStructure>(); |
1816 | 1804 |
1817 // Ignore forms not present in our cache. These are typically forms with | 1805 // 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... |
1920 // Note: We _must not_ remove the original version of the cached form from | 1908 // Note: We _must not_ remove the original version of the cached form from |
1921 // the list of |form_structures_|. Otherwise, we break parsing of the | 1909 // the list of |form_structures_|. Otherwise, we break parsing of the |
1922 // crowdsourcing server's response to our query. | 1910 // crowdsourcing server's response to our query. |
1923 if (!ParseForm(live_form, updated_form)) | 1911 if (!ParseForm(live_form, updated_form)) |
1924 return false; | 1912 return false; |
1925 | 1913 |
1926 if (cached_form) | 1914 if (cached_form) |
1927 (*updated_form)->UpdateFromCache(*cached_form, true); | 1915 (*updated_form)->UpdateFromCache(*cached_form, true); |
1928 | 1916 |
1929 // Annotate the updated form with its predicted types. | 1917 // Annotate the updated form with its predicted types. |
1930 driver_->SendAutofillTypePredictionsToRenderer({*updated_form}); | 1918 driver()->SendAutofillTypePredictionsToRenderer({*updated_form}); |
1931 | 1919 |
1932 return true; | 1920 return true; |
1933 } | 1921 } |
1934 | 1922 |
1935 std::vector<Suggestion> AutofillManager::GetProfileSuggestions( | 1923 std::vector<Suggestion> AutofillManager::GetProfileSuggestions( |
1936 const FormStructure& form, | 1924 const FormStructure& form, |
1937 const FormFieldData& field, | 1925 const FormFieldData& field, |
1938 const AutofillField& autofill_field) const { | 1926 const AutofillField& autofill_field) const { |
1939 address_form_event_logger_->OnDidPollSuggestions(field); | 1927 address_form_event_logger_->OnDidPollSuggestions(field); |
1940 | 1928 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2034 // Expired cards are last in the sorted order, so if the first one is | 2022 // Expired cards are last in the sorted order, so if the first one is |
2035 // expired, they all are. | 2023 // expired, they all are. |
2036 if (!cards.empty() && !cards.front()->IsExpired(AutofillClock::Now())) | 2024 if (!cards.empty() && !cards.front()->IsExpired(AutofillClock::Now())) |
2037 autofill_assistant_.ShowAssistForCreditCard(*cards.front()); | 2025 autofill_assistant_.ShowAssistForCreditCard(*cards.front()); |
2038 } | 2026 } |
2039 #endif | 2027 #endif |
2040 | 2028 |
2041 // For the |non_queryable_forms|, we have all the field type info we're ever | 2029 // For the |non_queryable_forms|, we have all the field type info we're ever |
2042 // going to get about them. For the other forms, we'll wait until we get a | 2030 // going to get about them. For the other forms, we'll wait until we get a |
2043 // response from the server. | 2031 // response from the server. |
2044 driver_->SendAutofillTypePredictionsToRenderer(non_queryable_forms); | 2032 driver()->SendAutofillTypePredictionsToRenderer(non_queryable_forms); |
2045 } | 2033 } |
2046 | 2034 |
2047 bool AutofillManager::ParseForm(const FormData& form, | 2035 bool AutofillManager::ParseForm(const FormData& form, |
2048 FormStructure** parsed_form_structure) { | 2036 FormStructure** parsed_form_structure) { |
2049 DCHECK(parsed_form_structure); | 2037 DCHECK(parsed_form_structure); |
2050 if (form_structures_.size() >= kMaxFormCacheSize) | 2038 if (form_structures_.size() >= kMaxFormCacheSize) |
2051 return false; | 2039 return false; |
2052 | 2040 |
2053 auto form_structure = base::MakeUnique<FormStructure>(form); | 2041 auto form_structure = base::MakeUnique<FormStructure>(form); |
2054 form_structure->ParseFieldTypesFromAutocompleteAttributes(); | 2042 form_structure->ParseFieldTypesFromAutocompleteAttributes(); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2334 #endif // ENABLE_FORM_DEBUG_DUMP | 2322 #endif // ENABLE_FORM_DEBUG_DUMP |
2335 | 2323 |
2336 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { | 2324 void AutofillManager::LogCardUploadDecisions(int upload_decision_metrics) { |
2337 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); | 2325 AutofillMetrics::LogCardUploadDecisionMetrics(upload_decision_metrics); |
2338 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(), | 2326 AutofillMetrics::LogCardUploadDecisionsUkm(client_->GetUkmService(), |
2339 pending_upload_request_url_, | 2327 pending_upload_request_url_, |
2340 upload_decision_metrics); | 2328 upload_decision_metrics); |
2341 } | 2329 } |
2342 | 2330 |
2343 } // namespace autofill | 2331 } // namespace autofill |
OLD | NEW |