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( |
| 154 false /* is_credit_card */, |
| 155 false /* is_server_data_available */, |
| 156 false /* is_local_data_available */)), |
| 157 credit_card_form_event_logger_( |
| 158 new AutofillMetrics::FormEventLogger( |
| 159 true /* is_credit_card */, |
| 160 false /* is_server_data_available */, |
| 161 false /* is_local_data_available */)), |
152 has_logged_autofill_enabled_(false), | 162 has_logged_autofill_enabled_(false), |
153 has_logged_address_suggestions_count_(false), | 163 has_logged_address_suggestions_count_(false), |
| 164 has_logged_interacted_with_credit_card_form_(false), |
| 165 has_logged_interacted_with_address_form_(false), |
154 did_show_suggestions_(false), | 166 did_show_suggestions_(false), |
155 user_did_type_(false), | 167 user_did_type_(false), |
156 user_did_autofill_(false), | 168 user_did_autofill_(false), |
157 user_did_edit_autofilled_field_(false), | 169 user_did_edit_autofilled_field_(false), |
158 external_delegate_(NULL), | 170 external_delegate_(NULL), |
159 test_delegate_(NULL), | 171 test_delegate_(NULL), |
160 weak_ptr_factory_(this) { | 172 weak_ptr_factory_(this) { |
161 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { | 173 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { |
162 download_manager_.reset( | 174 download_manager_.reset( |
163 new AutofillDownloadManager(driver, client_->GetPrefs(), this)); | 175 new AutofillDownloadManager(driver, client_->GetPrefs(), this)); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) | 460 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) |
449 return; | 461 return; |
450 | 462 |
451 std::vector<Suggestion> suggestions; | 463 std::vector<Suggestion> suggestions; |
452 | 464 |
453 external_delegate_->OnQuery(query_id, | 465 external_delegate_->OnQuery(query_id, |
454 form, | 466 form, |
455 field, | 467 field, |
456 bounding_box, | 468 bounding_box, |
457 display_warning); | 469 display_warning); |
| 470 |
| 471 // Need to refresh models before using the form_event_loggers. |
| 472 bool is_autofill_possible = RefreshDataModels(); |
| 473 |
458 FormStructure* form_structure = NULL; | 474 FormStructure* form_structure = NULL; |
459 AutofillField* autofill_field = NULL; | 475 AutofillField* autofill_field = NULL; |
460 if (RefreshDataModels() && | 476 bool got_autofillable_form = |
| 477 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && |
| 478 // Don't send suggestions or track forms that aren't auto-fillable. |
| 479 form_structure->IsAutofillable(); |
| 480 |
| 481 // Logging interactions of forms that are autofillable. |
| 482 if (got_autofillable_form) { |
| 483 AutofillType type = autofill_field->Type(); |
| 484 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
| 485 if (is_filling_credit_card && |
| 486 !has_logged_interacted_with_credit_card_form_) { |
| 487 has_logged_interacted_with_credit_card_form_ = true; |
| 488 credit_card_form_event_logger_->Log(AutofillMetrics::INTERACTED_ONCE); |
| 489 } |
| 490 if (!is_filling_credit_card && !has_logged_interacted_with_address_form_) { |
| 491 has_logged_interacted_with_address_form_ = true; |
| 492 address_form_event_logger_->Log(AutofillMetrics::INTERACTED_ONCE); |
| 493 } |
| 494 } |
| 495 |
| 496 if (is_autofill_possible && |
461 driver_->RendererIsAvailable() && | 497 driver_->RendererIsAvailable() && |
462 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 498 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(); | 499 AutofillType type = autofill_field->Type(); |
466 bool is_filling_credit_card = (type.group() == CREDIT_CARD); | 500 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
467 if (is_filling_credit_card) { | 501 if (is_filling_credit_card) { |
468 suggestions = GetCreditCardSuggestions(field, type); | 502 suggestions = GetCreditCardSuggestions(field, type); |
469 } else { | 503 } else { |
470 suggestions = | 504 suggestions = |
471 GetProfileSuggestions(*form_structure, field, *autofill_field); | 505 GetProfileSuggestions(*form_structure, field, *autofill_field); |
472 } | 506 } |
473 | |
474 if (!suggestions.empty()) { | 507 if (!suggestions.empty()) { |
475 // Don't provide Autofill suggestions when Autofill is disabled, and don't | 508 // Don't provide Autofill suggestions when Autofill is disabled, and don't |
476 // provide credit card suggestions for non-HTTPS pages. However, provide a | 509 // provide credit card suggestions for non-HTTPS pages. However, provide a |
477 // warning to the user in these cases. | 510 // warning to the user in these cases. |
478 int warning = 0; | 511 int warning = 0; |
479 if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) { | 512 if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) { |
480 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; | 513 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; |
481 } | 514 } |
482 if (warning) { | 515 if (warning) { |
483 Suggestion warning_suggestion(l10n_util::GetStringUTF16(warning)); | 516 Suggestion warning_suggestion(l10n_util::GetStringUTF16(warning)); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 if (!download_manager_) | 853 if (!download_manager_) |
821 return false; | 854 return false; |
822 | 855 |
823 return download_manager_->StartUploadRequest(form_structure, | 856 return download_manager_->StartUploadRequest(form_structure, |
824 false /* was_autofilled */, | 857 false /* was_autofilled */, |
825 available_field_types); | 858 available_field_types); |
826 } | 859 } |
827 | 860 |
828 void AutofillManager::Reset() { | 861 void AutofillManager::Reset() { |
829 form_structures_.clear(); | 862 form_structures_.clear(); |
| 863 address_form_event_logger_.reset( |
| 864 new AutofillMetrics::FormEventLogger( |
| 865 false /* is_credit_card */, |
| 866 false /* is_server_data_available */, |
| 867 false /* is_local_data_available */)); |
| 868 credit_card_form_event_logger_.reset( |
| 869 new AutofillMetrics::FormEventLogger( |
| 870 true /* is_credit_card */, |
| 871 false /* is_server_data_available */, |
| 872 false /* is_local_data_available */)); |
830 has_logged_autofill_enabled_ = false; | 873 has_logged_autofill_enabled_ = false; |
831 has_logged_address_suggestions_count_ = false; | 874 has_logged_address_suggestions_count_ = false; |
| 875 has_logged_interacted_with_credit_card_form_ = false; |
| 876 has_logged_interacted_with_address_form_ = false; |
832 did_show_suggestions_ = false; | 877 did_show_suggestions_ = false; |
833 user_did_type_ = false; | 878 user_did_type_ = false; |
834 user_did_autofill_ = false; | 879 user_did_autofill_ = false; |
835 user_did_edit_autofilled_field_ = false; | 880 user_did_edit_autofilled_field_ = false; |
836 unmasking_card_ = CreditCard(); | 881 unmasking_card_ = CreditCard(); |
837 unmasking_query_id_ = -1; | 882 unmasking_query_id_ = -1; |
838 unmasking_form_ = FormData(); | 883 unmasking_form_ = FormData(); |
839 unmasking_field_ = FormFieldData(); | 884 unmasking_field_ = FormFieldData(); |
840 forms_loaded_timestamps_.clear(); | 885 forms_loaded_timestamps_.clear(); |
841 initial_interaction_timestamp_ = TimeTicks(); | 886 initial_interaction_timestamp_ = TimeTicks(); |
842 external_delegate_->Reset(); | 887 external_delegate_->Reset(); |
843 } | 888 } |
844 | 889 |
845 AutofillManager::AutofillManager(AutofillDriver* driver, | 890 AutofillManager::AutofillManager(AutofillDriver* driver, |
846 AutofillClient* client, | 891 AutofillClient* client, |
847 PersonalDataManager* personal_data) | 892 PersonalDataManager* personal_data) |
848 : driver_(driver), | 893 : driver_(driver), |
849 client_(client), | 894 client_(client), |
850 app_locale_("en-US"), | 895 app_locale_("en-US"), |
851 personal_data_(personal_data), | 896 personal_data_(personal_data), |
852 autocomplete_history_manager_( | 897 autocomplete_history_manager_( |
853 new AutocompleteHistoryManager(driver, client)), | 898 new AutocompleteHistoryManager(driver, client)), |
| 899 address_form_event_logger_( |
| 900 new AutofillMetrics::FormEventLogger( |
| 901 false /* is_credit_card */, |
| 902 false /* is_server_data_available */, |
| 903 false /* is_local_data_available */)), |
| 904 credit_card_form_event_logger_( |
| 905 new AutofillMetrics::FormEventLogger( |
| 906 true /* is_credit_card */, |
| 907 false /* is_server_data_available */, |
| 908 false /* is_local_data_available */)), |
854 has_logged_autofill_enabled_(false), | 909 has_logged_autofill_enabled_(false), |
855 has_logged_address_suggestions_count_(false), | 910 has_logged_address_suggestions_count_(false), |
| 911 has_logged_interacted_with_credit_card_form_(false), |
| 912 has_logged_interacted_with_address_form_(false), |
856 did_show_suggestions_(false), | 913 did_show_suggestions_(false), |
857 user_did_type_(false), | 914 user_did_type_(false), |
858 user_did_autofill_(false), | 915 user_did_autofill_(false), |
859 user_did_edit_autofilled_field_(false), | 916 user_did_edit_autofilled_field_(false), |
860 unmasking_query_id_(-1), | 917 unmasking_query_id_(-1), |
861 external_delegate_(NULL), | 918 external_delegate_(NULL), |
862 test_delegate_(NULL), | 919 test_delegate_(NULL), |
863 weak_ptr_factory_(this) { | 920 weak_ptr_factory_(this) { |
864 DCHECK(driver_); | 921 DCHECK(driver_); |
865 DCHECK(client_); | 922 DCHECK(client_); |
866 } | 923 } |
867 | 924 |
868 bool AutofillManager::RefreshDataModels() const { | 925 bool AutofillManager::RefreshDataModels() { |
869 if (!IsAutofillEnabled()) | 926 if (!IsAutofillEnabled()) |
870 return false; | 927 return false; |
871 | 928 |
872 // No autofill data to return if the profiles are empty. | 929 // No autofill data to return if the profiles are empty. |
873 if (personal_data_->GetProfiles().empty() && | 930 const std::vector<AutofillProfile*>& profiles = |
874 personal_data_->GetCreditCards().empty()) { | 931 personal_data_->GetProfiles(); |
| 932 const std::vector<CreditCard*>& credit_cards = |
| 933 personal_data_->GetCreditCards(); |
| 934 |
| 935 // Updating the FormEventLoggers for addresses and credit cards. |
| 936 { |
| 937 bool is_server_data_available = false; |
| 938 bool is_local_data_available = false; |
| 939 for (std::vector<CreditCard*>::const_iterator it = credit_cards.begin(); |
| 940 it != credit_cards.end(); ++it) { |
| 941 CreditCard *credit_card = *it; |
| 942 if (credit_card->record_type() == CreditCard::MASKED_SERVER_CARD || |
| 943 credit_card->record_type() == CreditCard::FULL_SERVER_CARD) { |
| 944 is_server_data_available = true; |
| 945 } |
| 946 if (credit_card->record_type() == CreditCard::LOCAL_CARD) { |
| 947 is_server_data_available = true; |
| 948 } |
| 949 } |
| 950 credit_card_form_event_logger_.reset( |
| 951 new AutofillMetrics::FormEventLogger( |
| 952 true /* is_credit_card */, |
| 953 is_server_data_available, |
| 954 is_local_data_available)); |
| 955 } |
| 956 { |
| 957 bool is_server_data_available = false; |
| 958 bool is_local_data_available = false; |
| 959 for (std::vector<AutofillProfile*>::const_iterator it = profiles.begin(); |
| 960 it != profiles.end(); ++it) { |
| 961 AutofillProfile *profile = *it; |
| 962 if (profile->record_type() == AutofillProfile::SERVER_PROFILE) { |
| 963 is_server_data_available = true; |
| 964 } |
| 965 if (profile->record_type() == AutofillProfile::LOCAL_PROFILE) { |
| 966 is_server_data_available = true; |
| 967 } |
| 968 } |
| 969 address_form_event_logger_.reset( |
| 970 new AutofillMetrics::FormEventLogger( |
| 971 false /* is_credit_card */, |
| 972 is_server_data_available, |
| 973 is_local_data_available)); |
| 974 } |
| 975 |
| 976 if (profiles.empty() && credit_cards.empty()) { |
875 return false; | 977 return false; |
876 } | 978 } |
877 | 979 |
878 return true; | 980 return true; |
879 } | 981 } |
880 | 982 |
881 bool AutofillManager::GetProfileOrCreditCard( | 983 bool AutofillManager::GetProfileOrCreditCard( |
882 int unique_id, | 984 int unique_id, |
883 const AutofillDataModel** data_model, | 985 const AutofillDataModel** data_model, |
884 size_t* variant, | 986 size_t* variant, |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 return false; | 1427 return false; |
1326 | 1428 |
1327 // Disregard forms that we wouldn't ever autofill in the first place. | 1429 // Disregard forms that we wouldn't ever autofill in the first place. |
1328 if (!form.ShouldBeParsed()) | 1430 if (!form.ShouldBeParsed()) |
1329 return false; | 1431 return false; |
1330 | 1432 |
1331 return true; | 1433 return true; |
1332 } | 1434 } |
1333 | 1435 |
1334 } // namespace autofill | 1436 } // namespace autofill |
OLD | NEW |