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_credit_card */)), | |
154 credit_card_form_event_logger_( | |
155 new AutofillMetrics::FormEventLogger(true /* is_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 AutofillType type = autofill_field->Type(); | |
476 bool is_filling_credit_card = (type.group() == CREDIT_CARD); | |
Evan Stade
2015/02/02 23:13:12
nit:
if (autofill_field->Type().group() == CRED
Walter Cacau
2015/02/03 00:47:40
Done.
| |
477 if (is_filling_credit_card) | |
478 credit_card_form_event_logger_->OnDidInteractWithAutofillableForm(); | |
479 else | |
480 address_form_event_logger_->OnDidInteractWithAutofillableForm(); | |
481 } | |
482 | |
483 if (is_autofill_possible && | |
461 driver_->RendererIsAvailable() && | 484 driver_->RendererIsAvailable() && |
462 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 485 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(); | 486 AutofillType type = autofill_field->Type(); |
466 bool is_filling_credit_card = (type.group() == CREDIT_CARD); | 487 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
467 if (is_filling_credit_card) { | 488 if (is_filling_credit_card) { |
468 suggestions = GetCreditCardSuggestions(field, type); | 489 suggestions = GetCreditCardSuggestions(field, type); |
469 } else { | 490 } else { |
470 suggestions = | 491 suggestions = |
471 GetProfileSuggestions(*form_structure, field, *autofill_field); | 492 GetProfileSuggestions(*form_structure, field, *autofill_field); |
472 } | 493 } |
473 | |
474 if (!suggestions.empty()) { | 494 if (!suggestions.empty()) { |
475 // Don't provide Autofill suggestions when Autofill is disabled, and don't | 495 // Don't provide Autofill suggestions when Autofill is disabled, and don't |
476 // provide credit card suggestions for non-HTTPS pages. However, provide a | 496 // provide credit card suggestions for non-HTTPS pages. However, provide a |
477 // warning to the user in these cases. | 497 // warning to the user in these cases. |
478 int warning = 0; | 498 int warning = 0; |
479 if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) { | 499 if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) { |
480 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; | 500 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; |
481 } | 501 } |
482 if (warning) { | 502 if (warning) { |
483 Suggestion warning_suggestion(l10n_util::GetStringUTF16(warning)); | 503 Suggestion warning_suggestion(l10n_util::GetStringUTF16(warning)); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 if (!download_manager_) | 840 if (!download_manager_) |
821 return false; | 841 return false; |
822 | 842 |
823 return download_manager_->StartUploadRequest(form_structure, | 843 return download_manager_->StartUploadRequest(form_structure, |
824 false /* was_autofilled */, | 844 false /* was_autofilled */, |
825 available_field_types); | 845 available_field_types); |
826 } | 846 } |
827 | 847 |
828 void AutofillManager::Reset() { | 848 void AutofillManager::Reset() { |
829 form_structures_.clear(); | 849 form_structures_.clear(); |
850 address_form_event_logger_.reset( | |
851 new AutofillMetrics::FormEventLogger(false /* is_credit_card */)); | |
852 credit_card_form_event_logger_.reset( | |
853 new AutofillMetrics::FormEventLogger(true /* is_credit_card */)); | |
830 has_logged_autofill_enabled_ = false; | 854 has_logged_autofill_enabled_ = false; |
831 has_logged_address_suggestions_count_ = false; | 855 has_logged_address_suggestions_count_ = false; |
832 did_show_suggestions_ = false; | 856 did_show_suggestions_ = false; |
833 user_did_type_ = false; | 857 user_did_type_ = false; |
834 user_did_autofill_ = false; | 858 user_did_autofill_ = false; |
835 user_did_edit_autofilled_field_ = false; | 859 user_did_edit_autofilled_field_ = false; |
836 unmasking_card_ = CreditCard(); | 860 unmasking_card_ = CreditCard(); |
837 unmasking_query_id_ = -1; | 861 unmasking_query_id_ = -1; |
838 unmasking_form_ = FormData(); | 862 unmasking_form_ = FormData(); |
839 unmasking_field_ = FormFieldData(); | 863 unmasking_field_ = FormFieldData(); |
840 forms_loaded_timestamps_.clear(); | 864 forms_loaded_timestamps_.clear(); |
841 initial_interaction_timestamp_ = TimeTicks(); | 865 initial_interaction_timestamp_ = TimeTicks(); |
842 external_delegate_->Reset(); | 866 external_delegate_->Reset(); |
843 } | 867 } |
844 | 868 |
845 AutofillManager::AutofillManager(AutofillDriver* driver, | 869 AutofillManager::AutofillManager(AutofillDriver* driver, |
846 AutofillClient* client, | 870 AutofillClient* client, |
847 PersonalDataManager* personal_data) | 871 PersonalDataManager* personal_data) |
848 : driver_(driver), | 872 : driver_(driver), |
849 client_(client), | 873 client_(client), |
850 app_locale_("en-US"), | 874 app_locale_("en-US"), |
851 personal_data_(personal_data), | 875 personal_data_(personal_data), |
852 autocomplete_history_manager_( | 876 autocomplete_history_manager_( |
853 new AutocompleteHistoryManager(driver, client)), | 877 new AutocompleteHistoryManager(driver, client)), |
878 address_form_event_logger_( | |
879 new AutofillMetrics::FormEventLogger(false /* is_credit_card */)), | |
880 credit_card_form_event_logger_( | |
881 new AutofillMetrics::FormEventLogger(true /* is_credit_card */)), | |
854 has_logged_autofill_enabled_(false), | 882 has_logged_autofill_enabled_(false), |
855 has_logged_address_suggestions_count_(false), | 883 has_logged_address_suggestions_count_(false), |
856 did_show_suggestions_(false), | 884 did_show_suggestions_(false), |
857 user_did_type_(false), | 885 user_did_type_(false), |
858 user_did_autofill_(false), | 886 user_did_autofill_(false), |
859 user_did_edit_autofilled_field_(false), | 887 user_did_edit_autofilled_field_(false), |
860 unmasking_query_id_(-1), | 888 unmasking_query_id_(-1), |
861 external_delegate_(NULL), | 889 external_delegate_(NULL), |
862 test_delegate_(NULL), | 890 test_delegate_(NULL), |
863 weak_ptr_factory_(this) { | 891 weak_ptr_factory_(this) { |
864 DCHECK(driver_); | 892 DCHECK(driver_); |
865 DCHECK(client_); | 893 DCHECK(client_); |
866 } | 894 } |
867 | 895 |
868 bool AutofillManager::RefreshDataModels() const { | 896 bool AutofillManager::RefreshDataModels() { |
869 if (!IsAutofillEnabled()) | 897 if (!IsAutofillEnabled()) |
870 return false; | 898 return false; |
871 | 899 |
872 // No autofill data to return if the profiles are empty. | 900 // No autofill data to return if the profiles are empty. |
873 if (personal_data_->GetProfiles().empty() && | 901 const std::vector<AutofillProfile*>& profiles = |
874 personal_data_->GetCreditCards().empty()) { | 902 personal_data_->GetProfiles(); |
903 const std::vector<CreditCard*>& credit_cards = | |
904 personal_data_->GetCreditCards(); | |
905 | |
906 // Updating the FormEventLoggers for addresses and credit cards. | |
907 { | |
908 bool is_server_data_available = false; | |
909 bool is_local_data_available = false; | |
910 for (CreditCard* credit_card : credit_cards) { | |
911 if (credit_card->record_type() == CreditCard::MASKED_SERVER_CARD || | |
912 credit_card->record_type() == CreditCard::FULL_SERVER_CARD) | |
Evan Stade
2015/02/02 23:13:12
curlies required
but not if you make it shorter b
Walter Cacau
2015/02/03 00:47:40
Done.
| |
913 is_server_data_available = true; | |
914 else | |
915 is_local_data_available = true; | |
916 } | |
917 credit_card_form_event_logger_->set_is_server_data_available( | |
918 is_server_data_available); | |
919 credit_card_form_event_logger_->set_is_local_data_available( | |
920 is_local_data_available); | |
921 } | |
922 { | |
923 bool is_server_data_available = false; | |
924 bool is_local_data_available = false; | |
925 for (AutofillProfile* profile : profiles) { | |
926 if (profile->record_type() == AutofillProfile::SERVER_PROFILE) | |
927 is_server_data_available = true; | |
928 else | |
929 is_local_data_available = true; | |
930 } | |
931 address_form_event_logger_->set_is_server_data_available( | |
932 is_server_data_available); | |
933 address_form_event_logger_->set_is_local_data_available( | |
934 is_local_data_available); | |
935 } | |
936 | |
937 if (profiles.empty() && credit_cards.empty()) { | |
Evan Stade
2015/02/02 23:13:12
nit: no curlies
Walter Cacau
2015/02/03 00:47:40
Done.
| |
875 return false; | 938 return false; |
876 } | 939 } |
877 | 940 |
878 return true; | 941 return true; |
879 } | 942 } |
880 | 943 |
881 bool AutofillManager::GetProfileOrCreditCard( | 944 bool AutofillManager::GetProfileOrCreditCard( |
882 int unique_id, | 945 int unique_id, |
883 const AutofillDataModel** data_model, | 946 const AutofillDataModel** data_model, |
884 size_t* variant, | 947 size_t* variant, |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1325 return false; | 1388 return false; |
1326 | 1389 |
1327 // Disregard forms that we wouldn't ever autofill in the first place. | 1390 // Disregard forms that we wouldn't ever autofill in the first place. |
1328 if (!form.ShouldBeParsed()) | 1391 if (!form.ShouldBeParsed()) |
1329 return false; | 1392 return false; |
1330 | 1393 |
1331 return true; | 1394 return true; |
1332 } | 1395 } |
1333 | 1396 |
1334 } // namespace autofill | 1397 } // namespace autofill |
OLD | NEW |