OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 #include "content/public/browser/render_view_host.h" | 56 #include "content/public/browser/render_view_host.h" |
57 #include "content/public/browser/web_contents.h" | 57 #include "content/public/browser/web_contents.h" |
58 #include "googleurl/src/gurl.h" | 58 #include "googleurl/src/gurl.h" |
59 #include "grit/generated_resources.h" | 59 #include "grit/generated_resources.h" |
60 #include "ipc/ipc_message_macros.h" | 60 #include "ipc/ipc_message_macros.h" |
61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 61 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 62 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
63 #include "ui/base/l10n/l10n_util.h" | 63 #include "ui/base/l10n/l10n_util.h" |
64 #include "ui/gfx/rect.h" | 64 #include "ui/gfx/rect.h" |
65 | 65 |
66 typedef PersonalDataManager::GUIDPair GUIDPair; | |
66 using base::TimeTicks; | 67 using base::TimeTicks; |
67 using content::BrowserThread; | 68 using content::BrowserThread; |
68 using content::RenderViewHost; | 69 using content::RenderViewHost; |
69 | 70 |
70 namespace { | 71 namespace { |
71 | 72 |
72 const char* kAutofillManagerWebContentsUserDataKey = "web_contents_autofill"; | 73 const char* kAutofillManagerWebContentsUserDataKey = "web_contents_autofill"; |
73 | 74 |
74 // We only send a fraction of the forms to upload server. | 75 // We only send a fraction of the forms to upload server. |
75 // The rate for positive/negative matches potentially could be different. | 76 // The rate for positive/negative matches potentially could be different. |
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1122 } | 1123 } |
1123 | 1124 |
1124 void AutofillManager::GetProfileSuggestions( | 1125 void AutofillManager::GetProfileSuggestions( |
1125 FormStructure* form, | 1126 FormStructure* form, |
1126 const FormFieldData& field, | 1127 const FormFieldData& field, |
1127 AutofillFieldType type, | 1128 AutofillFieldType type, |
1128 std::vector<string16>* values, | 1129 std::vector<string16>* values, |
1129 std::vector<string16>* labels, | 1130 std::vector<string16>* labels, |
1130 std::vector<string16>* icons, | 1131 std::vector<string16>* icons, |
1131 std::vector<int>* unique_ids) const { | 1132 std::vector<int>* unique_ids) const { |
1132 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 1133 std::vector<AutofillFieldType> field_types(form->field_count()); |
1133 const std::string app_locale = AutofillCountry::ApplicationLocale(); | 1134 for (size_t i = 0; i < form->field_count(); ++i) { |
1134 if (!field.is_autofilled) { | 1135 field_types[i] = form->field(i)->type(); |
1135 std::vector<AutofillProfile*> matched_profiles; | 1136 } |
1136 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); | 1137 std::vector<GUIDPair> guid_pairs; |
1137 iter != profiles.end(); ++iter) { | |
1138 AutofillProfile* profile = *iter; | |
1139 | 1138 |
1140 // The value of the stored data for this field type in the |profile|. | 1139 personal_data_->GetProfileSuggestions( |
1141 std::vector<string16> multi_values; | 1140 type, field.value, field.is_autofilled, field_types, |
1142 profile->GetMultiInfo(type, app_locale, &multi_values); | 1141 values, labels, icons, &guid_pairs); |
1143 | 1142 |
1144 for (size_t i = 0; i < multi_values.size(); ++i) { | 1143 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
1145 if (!multi_values[i].empty() && | 1144 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), |
1146 StartsWith(multi_values[i], field.value, false)) { | 1145 guid_pairs[i])); |
Ilya Sherman
2012/12/20 21:57:42
This diff is not related to this CL...
| |
1147 matched_profiles.push_back(profile); | |
1148 values->push_back(multi_values[i]); | |
1149 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), | |
1150 GUIDPair(profile->guid(), i))); | |
1151 } | |
1152 } | |
1153 } | |
1154 | |
1155 std::vector<AutofillFieldType> form_fields; | |
1156 form_fields.reserve(form->field_count()); | |
1157 for (std::vector<AutofillField*>::const_iterator iter = form->begin(); | |
1158 iter != form->end(); ++iter) { | |
1159 form_fields.push_back((*iter)->type()); | |
1160 } | |
1161 | |
1162 AutofillProfile::CreateInferredLabels(&matched_profiles, &form_fields, | |
1163 type, 1, labels); | |
1164 | |
1165 // No icons for profile suggestions. | |
1166 icons->resize(values->size()); | |
1167 } else { | |
1168 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); | |
1169 iter != profiles.end(); ++iter) { | |
1170 AutofillProfile* profile = *iter; | |
1171 | |
1172 // The value of the stored data for this field type in the |profile|. | |
1173 std::vector<string16> multi_values; | |
1174 profile->GetMultiInfo(type, app_locale, &multi_values); | |
1175 | |
1176 for (size_t i = 0; i < multi_values.size(); ++i) { | |
1177 if (multi_values[i].empty()) | |
1178 continue; | |
1179 string16 profile_value_lower_case(StringToLowerASCII(multi_values[i])); | |
1180 string16 field_value_lower_case(StringToLowerASCII(field.value)); | |
1181 // Phone numbers could be split in US forms, so field value could be | |
1182 // either prefix or suffix of the phone. | |
1183 bool matched_phones = false; | |
1184 if (type == PHONE_HOME_NUMBER && !field_value_lower_case.empty() && | |
1185 (profile_value_lower_case.find(field_value_lower_case) != | |
1186 string16::npos)) { | |
1187 matched_phones = true; | |
1188 } | |
1189 if (matched_phones || | |
1190 profile_value_lower_case == field_value_lower_case) { | |
1191 for (size_t j = 0; j < multi_values.size(); ++j) { | |
1192 if (!multi_values[j].empty()) { | |
1193 values->push_back(multi_values[j]); | |
1194 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), | |
1195 GUIDPair(profile->guid(), j))); | |
1196 } | |
1197 } | |
1198 // We've added all the values for this profile so move on to the next. | |
1199 break; | |
1200 } | |
1201 } | |
1202 } | |
1203 | |
1204 // No labels for previously filled fields. | |
1205 labels->resize(values->size()); | |
1206 | |
1207 // No icons for profile suggestions. | |
1208 icons->resize(values->size()); | |
1209 } | 1146 } |
1210 } | 1147 } |
1211 | 1148 |
1212 void AutofillManager::GetCreditCardSuggestions( | 1149 void AutofillManager::GetCreditCardSuggestions( |
1213 FormStructure* form, | 1150 FormStructure* form, |
1214 const FormFieldData& field, | 1151 const FormFieldData& field, |
1215 AutofillFieldType type, | 1152 AutofillFieldType type, |
1216 std::vector<string16>* values, | 1153 std::vector<string16>* values, |
1217 std::vector<string16>* labels, | 1154 std::vector<string16>* labels, |
1218 std::vector<string16>* icons, | 1155 std::vector<string16>* icons, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1295 if (iter == guid_id_map_.end()) { | 1232 if (iter == guid_id_map_.end()) { |
1296 int id = guid_id_map_.size() + 1; | 1233 int id = guid_id_map_.size() + 1; |
1297 guid_id_map_[guid] = id; | 1234 guid_id_map_[guid] = id; |
1298 id_guid_map_[id] = guid; | 1235 id_guid_map_[id] = guid; |
1299 return id; | 1236 return id; |
1300 } else { | 1237 } else { |
1301 return iter->second; | 1238 return iter->second; |
1302 } | 1239 } |
1303 } | 1240 } |
1304 | 1241 |
1305 const AutofillManager::GUIDPair AutofillManager::IDToGUID(int id) const { | 1242 const GUIDPair AutofillManager::IDToGUID(int id) const { |
1306 if (id == 0) | 1243 if (id == 0) |
1307 return GUIDPair(std::string(), 0); | 1244 return GUIDPair(std::string(), 0); |
1308 | 1245 |
1309 std::map<int, GUIDPair>::const_iterator iter = id_guid_map_.find(id); | 1246 std::map<int, GUIDPair>::const_iterator iter = id_guid_map_.find(id); |
1310 if (iter == id_guid_map_.end()) { | 1247 if (iter == id_guid_map_.end()) { |
1311 NOTREACHED(); | 1248 NOTREACHED(); |
1312 return GUIDPair(std::string(), 0); | 1249 return GUIDPair(std::string(), 0); |
1313 } | 1250 } |
1314 | 1251 |
1315 return iter->second; | 1252 return iter->second; |
(...skipping 27 matching lines...) Expand all Loading... | |
1343 *profile_guid = IDToGUID(profile_id); | 1280 *profile_guid = IDToGUID(profile_id); |
1344 } | 1281 } |
1345 | 1282 |
1346 void AutofillManager::UpdateInitialInteractionTimestamp( | 1283 void AutofillManager::UpdateInitialInteractionTimestamp( |
1347 const TimeTicks& interaction_timestamp) { | 1284 const TimeTicks& interaction_timestamp) { |
1348 if (initial_interaction_timestamp_.is_null() || | 1285 if (initial_interaction_timestamp_.is_null() || |
1349 interaction_timestamp < initial_interaction_timestamp_) { | 1286 interaction_timestamp < initial_interaction_timestamp_) { |
1350 initial_interaction_timestamp_ = interaction_timestamp; | 1287 initial_interaction_timestamp_ = interaction_timestamp; |
1351 } | 1288 } |
1352 } | 1289 } |
OLD | NEW |