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 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 AutofillDriver* driver, | 142 AutofillDriver* driver, |
143 AutofillClient* client, | 143 AutofillClient* client, |
144 const std::string& app_locale, | 144 const std::string& app_locale, |
145 AutofillDownloadManagerState enable_download_manager) | 145 AutofillDownloadManagerState enable_download_manager) |
146 : driver_(driver), | 146 : driver_(driver), |
147 client_(client), | 147 client_(client), |
148 app_locale_(app_locale), | 148 app_locale_(app_locale), |
149 personal_data_(client->GetPersonalDataManager()), | 149 personal_data_(client->GetPersonalDataManager()), |
150 autocomplete_history_manager_( | 150 autocomplete_history_manager_( |
151 new AutocompleteHistoryManager(driver, client)), | 151 new AutocompleteHistoryManager(driver, client)), |
| 152 address_form_event_logger_( |
| 153 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)), |
| 154 credit_card_form_event_logger_( |
| 155 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)), |
152 has_logged_autofill_enabled_(false), | 156 has_logged_autofill_enabled_(false), |
153 has_logged_address_suggestions_count_(false), | 157 has_logged_address_suggestions_count_(false), |
154 did_show_suggestions_(false), | 158 did_show_suggestions_(false), |
155 user_did_type_(false), | 159 user_did_type_(false), |
156 user_did_autofill_(false), | 160 user_did_autofill_(false), |
157 user_did_edit_autofilled_field_(false), | 161 user_did_edit_autofilled_field_(false), |
158 external_delegate_(NULL), | 162 external_delegate_(NULL), |
159 test_delegate_(NULL), | 163 test_delegate_(NULL), |
160 weak_ptr_factory_(this) { | 164 weak_ptr_factory_(this) { |
161 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { | 165 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) | 452 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) |
449 return; | 453 return; |
450 | 454 |
451 std::vector<Suggestion> suggestions; | 455 std::vector<Suggestion> suggestions; |
452 | 456 |
453 external_delegate_->OnQuery(query_id, | 457 external_delegate_->OnQuery(query_id, |
454 form, | 458 form, |
455 field, | 459 field, |
456 bounding_box, | 460 bounding_box, |
457 display_warning); | 461 display_warning); |
| 462 |
| 463 // Need to refresh models before using the form_event_loggers. |
| 464 bool is_autofill_possible = RefreshDataModels(); |
| 465 |
458 FormStructure* form_structure = NULL; | 466 FormStructure* form_structure = NULL; |
459 AutofillField* autofill_field = NULL; | 467 AutofillField* autofill_field = NULL; |
460 if (RefreshDataModels() && | 468 bool got_autofillable_form = |
| 469 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && |
| 470 // Don't send suggestions or track forms that aren't auto-fillable. |
| 471 form_structure->IsAutofillable(); |
| 472 |
| 473 // Logging interactions of forms that are autofillable. |
| 474 if (got_autofillable_form) { |
| 475 if (autofill_field->Type().group() == CREDIT_CARD) |
| 476 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); |
| 477 else |
| 478 address_form_event_logger_->OnDidInteractWithAutofillableForm(); |
| 479 } |
| 480 |
| 481 if (is_autofill_possible && |
461 driver_->RendererIsAvailable() && | 482 driver_->RendererIsAvailable() && |
462 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 483 got_autofillable_form) { |
463 // Don't send suggestions for forms that aren't auto-fillable. | |
464 form_structure->IsAutofillable()) { | |
465 AutofillType type = autofill_field->Type(); | 484 AutofillType type = autofill_field->Type(); |
466 bool is_filling_credit_card = (type.group() == CREDIT_CARD); | 485 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
467 if (is_filling_credit_card) { | 486 if (is_filling_credit_card) { |
468 suggestions = GetCreditCardSuggestions(field, type); | 487 suggestions = GetCreditCardSuggestions(field, type); |
469 } else { | 488 } else { |
470 suggestions = | 489 suggestions = |
471 GetProfileSuggestions(*form_structure, field, *autofill_field); | 490 GetProfileSuggestions(*form_structure, field, *autofill_field); |
472 } | 491 } |
473 | |
474 if (!suggestions.empty()) { | 492 if (!suggestions.empty()) { |
475 // Don't provide Autofill suggestions when Autofill is disabled, and don't | 493 // Don't provide Autofill suggestions when Autofill is disabled, and don't |
476 // provide credit card suggestions for non-HTTPS pages. However, provide a | 494 // provide credit card suggestions for non-HTTPS pages. However, provide a |
477 // warning to the user in these cases. | 495 // warning to the user in these cases. |
478 int warning = 0; | 496 int warning = 0; |
479 if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) { | 497 if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) { |
480 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; | 498 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; |
481 } | 499 } |
482 if (warning) { | 500 if (warning) { |
483 Suggestion warning_suggestion(l10n_util::GetStringUTF16(warning)); | 501 Suggestion warning_suggestion(l10n_util::GetStringUTF16(warning)); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 if (!download_manager_) | 838 if (!download_manager_) |
821 return false; | 839 return false; |
822 | 840 |
823 return download_manager_->StartUploadRequest(form_structure, | 841 return download_manager_->StartUploadRequest(form_structure, |
824 false /* was_autofilled */, | 842 false /* was_autofilled */, |
825 available_field_types); | 843 available_field_types); |
826 } | 844 } |
827 | 845 |
828 void AutofillManager::Reset() { | 846 void AutofillManager::Reset() { |
829 form_structures_.clear(); | 847 form_structures_.clear(); |
| 848 address_form_event_logger_.reset( |
| 849 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)); |
| 850 credit_card_form_event_logger_.reset( |
| 851 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)); |
830 has_logged_autofill_enabled_ = false; | 852 has_logged_autofill_enabled_ = false; |
831 has_logged_address_suggestions_count_ = false; | 853 has_logged_address_suggestions_count_ = false; |
832 did_show_suggestions_ = false; | 854 did_show_suggestions_ = false; |
833 user_did_type_ = false; | 855 user_did_type_ = false; |
834 user_did_autofill_ = false; | 856 user_did_autofill_ = false; |
835 user_did_edit_autofilled_field_ = false; | 857 user_did_edit_autofilled_field_ = false; |
836 unmasking_card_ = CreditCard(); | 858 unmasking_card_ = CreditCard(); |
837 unmasking_query_id_ = -1; | 859 unmasking_query_id_ = -1; |
838 unmasking_form_ = FormData(); | 860 unmasking_form_ = FormData(); |
839 unmasking_field_ = FormFieldData(); | 861 unmasking_field_ = FormFieldData(); |
840 forms_loaded_timestamps_.clear(); | 862 forms_loaded_timestamps_.clear(); |
841 initial_interaction_timestamp_ = TimeTicks(); | 863 initial_interaction_timestamp_ = TimeTicks(); |
842 external_delegate_->Reset(); | 864 external_delegate_->Reset(); |
843 } | 865 } |
844 | 866 |
845 AutofillManager::AutofillManager(AutofillDriver* driver, | 867 AutofillManager::AutofillManager(AutofillDriver* driver, |
846 AutofillClient* client, | 868 AutofillClient* client, |
847 PersonalDataManager* personal_data) | 869 PersonalDataManager* personal_data) |
848 : driver_(driver), | 870 : driver_(driver), |
849 client_(client), | 871 client_(client), |
850 app_locale_("en-US"), | 872 app_locale_("en-US"), |
851 personal_data_(personal_data), | 873 personal_data_(personal_data), |
852 autocomplete_history_manager_( | 874 autocomplete_history_manager_( |
853 new AutocompleteHistoryManager(driver, client)), | 875 new AutocompleteHistoryManager(driver, client)), |
| 876 address_form_event_logger_( |
| 877 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)), |
| 878 credit_card_form_event_logger_( |
| 879 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)), |
854 has_logged_autofill_enabled_(false), | 880 has_logged_autofill_enabled_(false), |
855 has_logged_address_suggestions_count_(false), | 881 has_logged_address_suggestions_count_(false), |
856 did_show_suggestions_(false), | 882 did_show_suggestions_(false), |
857 user_did_type_(false), | 883 user_did_type_(false), |
858 user_did_autofill_(false), | 884 user_did_autofill_(false), |
859 user_did_edit_autofilled_field_(false), | 885 user_did_edit_autofilled_field_(false), |
860 unmasking_query_id_(-1), | 886 unmasking_query_id_(-1), |
861 external_delegate_(NULL), | 887 external_delegate_(NULL), |
862 test_delegate_(NULL), | 888 test_delegate_(NULL), |
863 weak_ptr_factory_(this) { | 889 weak_ptr_factory_(this) { |
864 DCHECK(driver_); | 890 DCHECK(driver_); |
865 DCHECK(client_); | 891 DCHECK(client_); |
866 } | 892 } |
867 | 893 |
868 bool AutofillManager::RefreshDataModels() const { | 894 bool AutofillManager::RefreshDataModels() { |
869 if (!IsAutofillEnabled()) | 895 if (!IsAutofillEnabled()) |
870 return false; | 896 return false; |
871 | 897 |
872 // No autofill data to return if the profiles are empty. | 898 // No autofill data to return if the profiles are empty. |
873 if (personal_data_->GetProfiles().empty() && | 899 const std::vector<AutofillProfile*>& profiles = |
874 personal_data_->GetCreditCards().empty()) { | 900 personal_data_->GetProfiles(); |
| 901 const std::vector<CreditCard*>& credit_cards = |
| 902 personal_data_->GetCreditCards(); |
| 903 |
| 904 // Updating the FormEventLoggers for addresses and credit cards. |
| 905 { |
| 906 bool is_server_data_available = false; |
| 907 bool is_local_data_available = false; |
| 908 for (CreditCard* credit_card : credit_cards) { |
| 909 if (credit_card->record_type() == CreditCard::LOCAL_CARD) |
| 910 is_local_data_available = true; |
| 911 else |
| 912 is_server_data_available = true; |
| 913 } |
| 914 credit_card_form_event_logger_->set_is_server_data_available( |
| 915 is_server_data_available); |
| 916 credit_card_form_event_logger_->set_is_local_data_available( |
| 917 is_local_data_available); |
| 918 } |
| 919 { |
| 920 bool is_server_data_available = false; |
| 921 bool is_local_data_available = false; |
| 922 for (AutofillProfile* profile : profiles) { |
| 923 if (profile->record_type() == AutofillProfile::LOCAL_PROFILE) |
| 924 is_local_data_available = true; |
| 925 else |
| 926 is_server_data_available = true; |
| 927 } |
| 928 address_form_event_logger_->set_is_server_data_available( |
| 929 is_server_data_available); |
| 930 address_form_event_logger_->set_is_local_data_available( |
| 931 is_local_data_available); |
| 932 } |
| 933 |
| 934 if (profiles.empty() && credit_cards.empty()) |
875 return false; | 935 return false; |
876 } | |
877 | 936 |
878 return true; | 937 return true; |
879 } | 938 } |
880 | 939 |
881 bool AutofillManager::GetProfileOrCreditCard( | 940 bool AutofillManager::GetProfileOrCreditCard( |
882 int unique_id, | 941 int unique_id, |
883 const AutofillDataModel** data_model, | 942 const AutofillDataModel** data_model, |
884 size_t* variant, | 943 size_t* variant, |
885 bool* is_credit_card) const { | 944 bool* is_credit_card) const { |
886 // Unpack the |unique_id| into component parts. | 945 // Unpack the |unique_id| into component parts. |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 return false; | 1384 return false; |
1326 | 1385 |
1327 // Disregard forms that we wouldn't ever autofill in the first place. | 1386 // Disregard forms that we wouldn't ever autofill in the first place. |
1328 if (!form.ShouldBeParsed()) | 1387 if (!form.ShouldBeParsed()) |
1329 return false; | 1388 return false; |
1330 | 1389 |
1331 return true; | 1390 return true; |
1332 } | 1391 } |
1333 | 1392 |
1334 } // namespace autofill | 1393 } // namespace autofill |
OLD | NEW |