| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/autofill/autofill_manager.h" | 5 #include "chrome/browser/autofill/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> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/string16.h" | 17 #include "base/string16.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/autocomplete_history_manager.h" | 20 #include "chrome/browser/autocomplete_history_manager.h" |
| 21 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 21 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 22 #include "chrome/browser/autofill/autofill_external_delegate.h" |
| 22 #include "chrome/browser/autofill/autofill_feedback_infobar_delegate.h" | 23 #include "chrome/browser/autofill/autofill_feedback_infobar_delegate.h" |
| 23 #include "chrome/browser/autofill/autofill_external_delegate.h" | |
| 24 #include "chrome/browser/autofill/autofill_field.h" | 24 #include "chrome/browser/autofill/autofill_field.h" |
| 25 #include "chrome/browser/autofill/autofill_metrics.h" | 25 #include "chrome/browser/autofill/autofill_metrics.h" |
| 26 #include "chrome/browser/autofill/autofill_profile.h" | 26 #include "chrome/browser/autofill/autofill_profile.h" |
| 27 #include "chrome/browser/autofill/autofill_type.h" | 27 #include "chrome/browser/autofill/autofill_type.h" |
| 28 #include "chrome/browser/autofill/credit_card.h" | 28 #include "chrome/browser/autofill/credit_card.h" |
| 29 #include "chrome/browser/autofill/form_structure.h" | 29 #include "chrome/browser/autofill/form_structure.h" |
| 30 #include "chrome/browser/autofill/personal_data_manager.h" | 30 #include "chrome/browser/autofill/personal_data_manager.h" |
| 31 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 31 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 32 #include "chrome/browser/autofill/phone_number.h" | 32 #include "chrome/browser/autofill/phone_number.h" |
| 33 #include "chrome/browser/autofill/phone_number_i18n.h" | 33 #include "chrome/browser/autofill/phone_number_i18n.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 47 #include "content/browser/renderer_host/render_view_host.h" | 47 #include "content/browser/renderer_host/render_view_host.h" |
| 48 #include "content/browser/tab_contents/tab_contents.h" | 48 #include "content/browser/tab_contents/tab_contents.h" |
| 49 #include "content/public/browser/browser_thread.h" | 49 #include "content/public/browser/browser_thread.h" |
| 50 #include "content/public/browser/notification_service.h" | 50 #include "content/public/browser/notification_service.h" |
| 51 #include "content/public/browser/notification_source.h" | 51 #include "content/public/browser/notification_source.h" |
| 52 #include "googleurl/src/gurl.h" | 52 #include "googleurl/src/gurl.h" |
| 53 #include "grit/generated_resources.h" | 53 #include "grit/generated_resources.h" |
| 54 #include "ipc/ipc_message_macros.h" | 54 #include "ipc/ipc_message_macros.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 56 #include "ui/gfx/rect.h" | 56 #include "ui/gfx/rect.h" |
| 57 #include "webkit/glue/form_data.h" | 57 #include "webkit/forms/form_data.h" |
| 58 #include "webkit/glue/form_data_predictions.h" | 58 #include "webkit/forms/form_data_predictions.h" |
| 59 #include "webkit/glue/form_field.h" | 59 #include "webkit/forms/form_field.h" |
| 60 | 60 |
| 61 using base::TimeTicks; | 61 using base::TimeTicks; |
| 62 using content::BrowserThread; | 62 using content::BrowserThread; |
| 63 using switches::kEnableAutofillFeedback; | 63 using switches::kEnableAutofillFeedback; |
| 64 using webkit_glue::FormData; | 64 using webkit::forms::FormData; |
| 65 using webkit_glue::FormDataPredictions; | 65 using webkit::forms::FormDataPredictions; |
| 66 using webkit_glue::FormField; | 66 using webkit::forms::FormField; |
| 67 | 67 |
| 68 namespace { | 68 namespace { |
| 69 | 69 |
| 70 // We only send a fraction of the forms to upload server. | 70 // We only send a fraction of the forms to upload server. |
| 71 // The rate for positive/negative matches potentially could be different. | 71 // The rate for positive/negative matches potentially could be different. |
| 72 const double kAutofillPositiveUploadRateDefaultValue = 0.20; | 72 const double kAutofillPositiveUploadRateDefaultValue = 0.20; |
| 73 const double kAutofillNegativeUploadRateDefaultValue = 0.20; | 73 const double kAutofillNegativeUploadRateDefaultValue = 0.20; |
| 74 | 74 |
| 75 const size_t kMaxRecentFormSignaturesToRemember = 3; | 75 const size_t kMaxRecentFormSignaturesToRemember = 3; |
| 76 | 76 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 values->swap(values_copy); | 108 values->swap(values_copy); |
| 109 labels->swap(labels_copy); | 109 labels->swap(labels_copy); |
| 110 icons->swap(icons_copy); | 110 icons->swap(icons_copy); |
| 111 unique_ids->swap(unique_ids_copy); | 111 unique_ids->swap(unique_ids_copy); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Precondition: |form_structure| and |form| should correspond to the same | 114 // Precondition: |form_structure| and |form| should correspond to the same |
| 115 // logical form. Returns true if any field in the given |section| within |form| | 115 // logical form. Returns true if any field in the given |section| within |form| |
| 116 // is auto-filled. | 116 // is auto-filled. |
| 117 bool SectionIsAutofilled(const FormStructure& form_structure, | 117 bool SectionIsAutofilled(const FormStructure& form_structure, |
| 118 const webkit_glue::FormData& form, | 118 const FormData& form, |
| 119 const string16& section) { | 119 const string16& section) { |
| 120 DCHECK_EQ(form_structure.field_count(), form.fields.size()); | 120 DCHECK_EQ(form_structure.field_count(), form.fields.size()); |
| 121 for (size_t i = 0; i < form_structure.field_count(); ++i) { | 121 for (size_t i = 0; i < form_structure.field_count(); ++i) { |
| 122 if (form_structure.field(i)->section() == section && | 122 if (form_structure.field(i)->section() == section && |
| 123 form.fields[i].is_autofilled) { | 123 form.fields[i].is_autofilled) { |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 return false; | 128 return false; |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 labels->push_back(label); | 1123 labels->push_back(label); |
| 1124 icons->push_back(UTF8ToUTF16(credit_card->type())); | 1124 icons->push_back(UTF8ToUTF16(credit_card->type())); |
| 1125 unique_ids->push_back(PackGUIDs(GUIDPair(credit_card->guid(), 0), | 1125 unique_ids->push_back(PackGUIDs(GUIDPair(credit_card->guid(), 0), |
| 1126 GUIDPair(std::string(), 0))); | 1126 GUIDPair(std::string(), 0))); |
| 1127 } | 1127 } |
| 1128 } | 1128 } |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 void AutofillManager::FillCreditCardFormField(const CreditCard& credit_card, | 1131 void AutofillManager::FillCreditCardFormField(const CreditCard& credit_card, |
| 1132 AutofillFieldType type, | 1132 AutofillFieldType type, |
| 1133 webkit_glue::FormField* field) { | 1133 FormField* field) { |
| 1134 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(type).group()); | 1134 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(type).group()); |
| 1135 DCHECK(field); | 1135 DCHECK(field); |
| 1136 | 1136 |
| 1137 if (field->form_control_type == ASCIIToUTF16("select-one")) { | 1137 if (field->form_control_type == ASCIIToUTF16("select-one")) { |
| 1138 autofill::FillSelectControl(credit_card, type, field); | 1138 autofill::FillSelectControl(credit_card, type, field); |
| 1139 } else if (field->form_control_type == ASCIIToUTF16("month")) { | 1139 } else if (field->form_control_type == ASCIIToUTF16("month")) { |
| 1140 // HTML5 input="month" consists of year-month. | 1140 // HTML5 input="month" consists of year-month. |
| 1141 string16 year = | 1141 string16 year = |
| 1142 credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 1142 credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
| 1143 string16 month = credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_MONTH); | 1143 string16 month = credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_MONTH); |
| 1144 if (!year.empty() && !month.empty()) { | 1144 if (!year.empty() && !month.empty()) { |
| 1145 // Fill the value only if |credit_card| includes both year and month | 1145 // Fill the value only if |credit_card| includes both year and month |
| 1146 // information. | 1146 // information. |
| 1147 field->value = year + ASCIIToUTF16("-") + month; | 1147 field->value = year + ASCIIToUTF16("-") + month; |
| 1148 } | 1148 } |
| 1149 } else { | 1149 } else { |
| 1150 field->value = credit_card.GetCanonicalizedInfo(type); | 1150 field->value = credit_card.GetCanonicalizedInfo(type); |
| 1151 } | 1151 } |
| 1152 } | 1152 } |
| 1153 | 1153 |
| 1154 void AutofillManager::FillFormField(const AutofillProfile& profile, | 1154 void AutofillManager::FillFormField(const AutofillProfile& profile, |
| 1155 const AutofillField& cached_field, | 1155 const AutofillField& cached_field, |
| 1156 size_t variant, | 1156 size_t variant, |
| 1157 webkit_glue::FormField* field) { | 1157 FormField* field) { |
| 1158 AutofillFieldType type = cached_field.type(); | 1158 AutofillFieldType type = cached_field.type(); |
| 1159 DCHECK_NE(AutofillType::CREDIT_CARD, AutofillType(type).group()); | 1159 DCHECK_NE(AutofillType::CREDIT_CARD, AutofillType(type).group()); |
| 1160 DCHECK(field); | 1160 DCHECK(field); |
| 1161 | 1161 |
| 1162 if (type == PHONE_HOME_NUMBER) { | 1162 if (type == PHONE_HOME_NUMBER) { |
| 1163 FillPhoneNumberField(profile, cached_field, variant, field); | 1163 FillPhoneNumberField(profile, cached_field, variant, field); |
| 1164 } else { | 1164 } else { |
| 1165 if (field->form_control_type == ASCIIToUTF16("select-one")) { | 1165 if (field->form_control_type == ASCIIToUTF16("select-one")) { |
| 1166 autofill::FillSelectControl(profile, type, field); | 1166 autofill::FillSelectControl(profile, type, field); |
| 1167 } else { | 1167 } else { |
| 1168 std::vector<string16> values; | 1168 std::vector<string16> values; |
| 1169 profile.GetCanonicalizedMultiInfo(type, &values); | 1169 profile.GetCanonicalizedMultiInfo(type, &values); |
| 1170 if (variant >= values.size()) { | 1170 if (variant >= values.size()) { |
| 1171 // If the variant is unavailable, bail. This case is reachable, for | 1171 // If the variant is unavailable, bail. This case is reachable, for |
| 1172 // example if Sync updates a profile during the filling process. | 1172 // example if Sync updates a profile during the filling process. |
| 1173 return; | 1173 return; |
| 1174 } | 1174 } |
| 1175 | 1175 |
| 1176 field->value = values[variant]; | 1176 field->value = values[variant]; |
| 1177 } | 1177 } |
| 1178 } | 1178 } |
| 1179 } | 1179 } |
| 1180 | 1180 |
| 1181 void AutofillManager::FillPhoneNumberField(const AutofillProfile& profile, | 1181 void AutofillManager::FillPhoneNumberField(const AutofillProfile& profile, |
| 1182 const AutofillField& cached_field, | 1182 const AutofillField& cached_field, |
| 1183 size_t variant, | 1183 size_t variant, |
| 1184 webkit_glue::FormField* field) { | 1184 FormField* field) { |
| 1185 std::vector<string16> values; | 1185 std::vector<string16> values; |
| 1186 profile.GetCanonicalizedMultiInfo(cached_field.type(), &values); | 1186 profile.GetCanonicalizedMultiInfo(cached_field.type(), &values); |
| 1187 DCHECK(variant < values.size()); | 1187 DCHECK(variant < values.size()); |
| 1188 | 1188 |
| 1189 // If we are filling a phone number, check to see if the size field | 1189 // If we are filling a phone number, check to see if the size field |
| 1190 // matches the "prefix" or "suffix" sizes and fill accordingly. | 1190 // matches the "prefix" or "suffix" sizes and fill accordingly. |
| 1191 string16 number = values[variant]; | 1191 string16 number = values[variant]; |
| 1192 if (number.length() == | 1192 if (number.length() == |
| 1193 (PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength)) { | 1193 (PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength)) { |
| 1194 if (cached_field.phone_part() == AutofillField::PHONE_PREFIX || | 1194 if (cached_field.phone_part() == AutofillField::PHONE_PREFIX || |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 *profile_guid = IDToGUID(profile_id); | 1300 *profile_guid = IDToGUID(profile_id); |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 void AutofillManager::UpdateInitialInteractionTimestamp( | 1303 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1304 const TimeTicks& interaction_timestamp) { | 1304 const TimeTicks& interaction_timestamp) { |
| 1305 if (initial_interaction_timestamp_.is_null() || | 1305 if (initial_interaction_timestamp_.is_null() || |
| 1306 interaction_timestamp < initial_interaction_timestamp_) { | 1306 interaction_timestamp < initial_interaction_timestamp_) { |
| 1307 initial_interaction_timestamp_ = interaction_timestamp; | 1307 initial_interaction_timestamp_ = interaction_timestamp; |
| 1308 } | 1308 } |
| 1309 } | 1309 } |
| OLD | NEW |