| 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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 } | 769 } |
| 770 | 770 |
| 771 // TODO(ahutter): Remove this once Autocheckout is implemented on other | 771 // TODO(ahutter): Remove this once Autocheckout is implemented on other |
| 772 // platforms. See http://crbug.com/173416. | 772 // platforms. See http://crbug.com/173416. |
| 773 #if defined(TOOLKIT_VIEWS) | 773 #if defined(TOOLKIT_VIEWS) |
| 774 if (!GetAutocheckoutURLPrefix().empty()) | 774 if (!GetAutocheckoutURLPrefix().empty()) |
| 775 autocheckout_manager_.OnLoadedPageMetaData(page_meta_data.Pass()); | 775 autocheckout_manager_.OnLoadedPageMetaData(page_meta_data.Pass()); |
| 776 #endif // #if defined(TOOLKIT_VIEWS) | 776 #endif // #if defined(TOOLKIT_VIEWS) |
| 777 | 777 |
| 778 // If the corresponding flag is set, annotate forms with the predicted types. | 778 // If the corresponding flag is set, annotate forms with the predicted types. |
| 779 SendAutofillTypePredictions(form_structures_.get()); | 779 driver_->SendAutofillTypePredictionsToRenderer(form_structures_.get()); |
| 780 } | 780 } |
| 781 | 781 |
| 782 void AutofillManager::OnDidEndTextFieldEditing() { | 782 void AutofillManager::OnDidEndTextFieldEditing() { |
| 783 if (external_delegate_) | 783 if (external_delegate_) |
| 784 external_delegate_->DidEndTextFieldEditing(); | 784 external_delegate_->DidEndTextFieldEditing(); |
| 785 } | 785 } |
| 786 | 786 |
| 787 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { | 787 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { |
| 788 autocheckout_manager_.OnClickFailed(status); | 788 autocheckout_manager_.OnClickFailed(status); |
| 789 } | 789 } |
| 790 | 790 |
| 791 std::string AutofillManager::GetAutocheckoutURLPrefix() const { | 791 std::string AutofillManager::GetAutocheckoutURLPrefix() const { |
| 792 if (!driver_->GetWebContents()) | 792 if (!driver_->GetWebContents()) |
| 793 return std::string(); | 793 return std::string(); |
| 794 | 794 |
| 795 autofill::autocheckout::WhitelistManager* whitelist_manager = | 795 autofill::autocheckout::WhitelistManager* whitelist_manager = |
| 796 manager_delegate_->GetAutocheckoutWhitelistManager(); | 796 manager_delegate_->GetAutocheckoutWhitelistManager(); |
| 797 | 797 |
| 798 return whitelist_manager ? whitelist_manager->GetMatchedURLPrefix( | 798 return whitelist_manager ? whitelist_manager->GetMatchedURLPrefix( |
| 799 driver_->GetWebContents()->GetURL()) : std::string(); | 799 driver_->GetWebContents()->GetURL()) : std::string(); |
| 800 } | 800 } |
| 801 | 801 |
| 802 bool AutofillManager::IsAutofillEnabled() const { | 802 bool AutofillManager::IsAutofillEnabled() const { |
| 803 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 803 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
| 804 } | 804 } |
| 805 | 805 |
| 806 void AutofillManager::SendAutofillTypePredictions( | |
| 807 const std::vector<FormStructure*>& forms) const { | |
| 808 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 809 switches::kShowAutofillTypePredictions)) | |
| 810 return; | |
| 811 | |
| 812 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); | |
| 813 if (!host) | |
| 814 return; | |
| 815 | |
| 816 std::vector<FormDataPredictions> type_predictions; | |
| 817 FormStructure::GetFieldTypePredictions(forms, &type_predictions); | |
| 818 host->Send( | |
| 819 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), | |
| 820 type_predictions)); | |
| 821 } | |
| 822 | |
| 823 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { | 806 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { |
| 824 const CreditCard* imported_credit_card; | 807 const CreditCard* imported_credit_card; |
| 825 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) | 808 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) |
| 826 return; | 809 return; |
| 827 | 810 |
| 828 // If credit card information was submitted, we need to confirm whether to | 811 // If credit card information was submitted, we need to confirm whether to |
| 829 // save it. | 812 // save it. |
| 830 if (imported_credit_card) { | 813 if (imported_credit_card) { |
| 831 manager_delegate_->ConfirmSaveCreditCard( | 814 manager_delegate_->ConfirmSaveCreditCard( |
| 832 *metric_logger_, | 815 *metric_logger_, |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 } | 1076 } |
| 1094 } | 1077 } |
| 1095 | 1078 |
| 1096 // Note: We _must not_ remove the original version of the cached form from | 1079 // Note: We _must not_ remove the original version of the cached form from |
| 1097 // the list of |form_structures_|. Otherwise, we break parsing of the | 1080 // the list of |form_structures_|. Otherwise, we break parsing of the |
| 1098 // crowdsourcing server's response to our query. | 1081 // crowdsourcing server's response to our query. |
| 1099 } | 1082 } |
| 1100 | 1083 |
| 1101 // Annotate the updated form with its predicted types. | 1084 // Annotate the updated form with its predicted types. |
| 1102 std::vector<FormStructure*> forms(1, *updated_form); | 1085 std::vector<FormStructure*> forms(1, *updated_form); |
| 1103 SendAutofillTypePredictions(forms); | 1086 driver_->SendAutofillTypePredictionsToRenderer(forms); |
| 1104 | 1087 |
| 1105 return true; | 1088 return true; |
| 1106 } | 1089 } |
| 1107 | 1090 |
| 1108 void AutofillManager::GetProfileSuggestions( | 1091 void AutofillManager::GetProfileSuggestions( |
| 1109 FormStructure* form, | 1092 FormStructure* form, |
| 1110 const FormFieldData& field, | 1093 const FormFieldData& field, |
| 1111 AutofillFieldType type, | 1094 AutofillFieldType type, |
| 1112 std::vector<base::string16>* values, | 1095 std::vector<base::string16>* values, |
| 1113 std::vector<base::string16>* labels, | 1096 std::vector<base::string16>* labels, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 iter != non_queryable_forms.end(); ++iter) { | 1165 iter != non_queryable_forms.end(); ++iter) { |
| 1183 form_structures_.push_back(*iter); | 1166 form_structures_.push_back(*iter); |
| 1184 } | 1167 } |
| 1185 | 1168 |
| 1186 if (!form_structures_.empty()) | 1169 if (!form_structures_.empty()) |
| 1187 metric_logger_->LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED); | 1170 metric_logger_->LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED); |
| 1188 | 1171 |
| 1189 // For the |non_queryable_forms|, we have all the field type info we're ever | 1172 // For the |non_queryable_forms|, we have all the field type info we're ever |
| 1190 // going to get about them. For the other forms, we'll wait until we get a | 1173 // going to get about them. For the other forms, we'll wait until we get a |
| 1191 // response from the server. | 1174 // response from the server. |
| 1192 SendAutofillTypePredictions(non_queryable_forms); | 1175 driver_->SendAutofillTypePredictionsToRenderer(non_queryable_forms); |
| 1193 } | 1176 } |
| 1194 | 1177 |
| 1195 int AutofillManager::GUIDToID(const GUIDPair& guid) const { | 1178 int AutofillManager::GUIDToID(const GUIDPair& guid) const { |
| 1196 if (!base::IsValidGUID(guid.first)) | 1179 if (!base::IsValidGUID(guid.first)) |
| 1197 return 0; | 1180 return 0; |
| 1198 | 1181 |
| 1199 std::map<GUIDPair, int>::const_iterator iter = guid_id_map_.find(guid); | 1182 std::map<GUIDPair, int>::const_iterator iter = guid_id_map_.find(guid); |
| 1200 if (iter == guid_id_map_.end()) { | 1183 if (iter == guid_id_map_.end()) { |
| 1201 int id = guid_id_map_.size() + 1; | 1184 int id = guid_id_map_.size() + 1; |
| 1202 guid_id_map_[guid] = id; | 1185 guid_id_map_[guid] = id; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 | 1233 |
| 1251 void AutofillManager::UpdateInitialInteractionTimestamp( | 1234 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1252 const TimeTicks& interaction_timestamp) { | 1235 const TimeTicks& interaction_timestamp) { |
| 1253 if (initial_interaction_timestamp_.is_null() || | 1236 if (initial_interaction_timestamp_.is_null() || |
| 1254 interaction_timestamp < initial_interaction_timestamp_) { | 1237 interaction_timestamp < initial_interaction_timestamp_) { |
| 1255 initial_interaction_timestamp_ = interaction_timestamp; | 1238 initial_interaction_timestamp_ = interaction_timestamp; |
| 1256 } | 1239 } |
| 1257 } | 1240 } |
| 1258 | 1241 |
| 1259 } // namespace autofill | 1242 } // namespace autofill |
| OLD | NEW |