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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 if (!form.user_submitted) | 321 if (!form.user_submitted) |
322 return false; | 322 return false; |
323 | 323 |
324 // Ignore forms not present in our cache. These are typically forms with | 324 // Ignore forms not present in our cache. These are typically forms with |
325 // wonky JavaScript that also makes them not auto-fillable. | 325 // wonky JavaScript that also makes them not auto-fillable. |
326 FormStructure* cached_submitted_form; | 326 FormStructure* cached_submitted_form; |
327 if (!FindCachedForm(form, &cached_submitted_form)) | 327 if (!FindCachedForm(form, &cached_submitted_form)) |
328 return false; | 328 return false; |
329 | 329 |
330 submitted_form->UpdateFromCache(*cached_submitted_form); | 330 submitted_form->UpdateFromCache(*cached_submitted_form); |
331 if (submitted_form->IsAutofillable(true)) | 331 if (submitted_form->IsAutofillable()) |
332 ImportFormData(*submitted_form); | 332 ImportFormData(*submitted_form); |
333 | 333 |
334 // Only upload server statistics and UMA metrics if at least some local data | 334 // Only upload server statistics and UMA metrics if at least some local data |
335 // is available to use as a baseline. | 335 // is available to use as a baseline. |
336 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 336 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
337 const std::vector<CreditCard*>& credit_cards = | 337 const std::vector<CreditCard*>& credit_cards = |
338 personal_data_->GetCreditCards(); | 338 personal_data_->GetCreditCards(); |
339 if (!profiles.empty() || !credit_cards.empty()) { | 339 if (!profiles.empty() || !credit_cards.empty()) { |
340 // Copy the profile and credit card data, so that it can be accessed on a | 340 // Copy the profile and credit card data, so that it can be accessed on a |
341 // separate thread. | 341 // separate thread. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 form, | 446 form, |
447 field, | 447 field, |
448 bounding_box, | 448 bounding_box, |
449 display_warning); | 449 display_warning); |
450 FormStructure* form_structure = NULL; | 450 FormStructure* form_structure = NULL; |
451 AutofillField* autofill_field = NULL; | 451 AutofillField* autofill_field = NULL; |
452 if (RefreshDataModels() && | 452 if (RefreshDataModels() && |
453 driver_->RendererIsAvailable() && | 453 driver_->RendererIsAvailable() && |
454 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 454 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && |
455 // Don't send suggestions for forms that aren't auto-fillable. | 455 // Don't send suggestions for forms that aren't auto-fillable. |
456 form_structure->IsAutofillable(false)) { | 456 form_structure->IsAutofillable()) { |
457 AutofillType type = autofill_field->Type(); | 457 AutofillType type = autofill_field->Type(); |
458 bool is_filling_credit_card = (type.group() == CREDIT_CARD); | 458 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
459 if (is_filling_credit_card) { | 459 if (is_filling_credit_card) { |
460 GetCreditCardSuggestions( | 460 GetCreditCardSuggestions( |
461 field, type, &values, &labels, &icons, &unique_ids); | 461 field, type, &values, &labels, &icons, &unique_ids); |
462 } else { | 462 } else { |
463 GetProfileSuggestions( | 463 GetProfileSuggestions( |
464 form_structure, field, type, &values, &labels, &icons, &unique_ids); | 464 form_structure, field, type, &values, &labels, &icons, &unique_ids); |
465 } | 465 } |
466 | 466 |
467 DCHECK_EQ(values.size(), labels.size()); | 467 DCHECK_EQ(values.size(), labels.size()); |
468 DCHECK_EQ(values.size(), icons.size()); | 468 DCHECK_EQ(values.size(), icons.size()); |
469 DCHECK_EQ(values.size(), unique_ids.size()); | 469 DCHECK_EQ(values.size(), unique_ids.size()); |
470 | 470 |
471 if (!values.empty()) { | 471 if (!values.empty()) { |
472 // Don't provide Autofill suggestions when Autofill is disabled, and don't | 472 // Don't provide Autofill suggestions when Autofill is disabled, and don't |
473 // provide credit card suggestions for non-HTTPS pages. However, provide a | 473 // provide credit card suggestions for non-HTTPS pages. However, provide a |
474 // warning to the user in these cases. | 474 // warning to the user in these cases. |
475 int warning = 0; | 475 int warning = 0; |
476 if (!form_structure->IsAutofillable(true)) | 476 if (!form_structure->IsAutofillable()) |
477 warning = IDS_AUTOFILL_WARNING_FORM_DISABLED; | 477 warning = IDS_AUTOFILL_WARNING_FORM_DISABLED; |
478 else if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) | 478 else if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) |
479 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; | 479 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; |
480 if (warning) { | 480 if (warning) { |
481 values.assign(1, l10n_util::GetStringUTF16(warning)); | 481 values.assign(1, l10n_util::GetStringUTF16(warning)); |
482 labels.assign(1, base::string16()); | 482 labels.assign(1, base::string16()); |
483 icons.assign(1, base::string16()); | 483 icons.assign(1, base::string16()); |
484 unique_ids.assign(1, POPUP_ITEM_ID_WARNING_MESSAGE); | 484 unique_ids.assign(1, POPUP_ITEM_ID_WARNING_MESSAGE); |
485 } else { | 485 } else { |
486 bool section_is_autofilled = | 486 bool section_is_autofilled = |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 } | 971 } |
972 | 972 |
973 bool AutofillManager::GetCachedFormAndField(const FormData& form, | 973 bool AutofillManager::GetCachedFormAndField(const FormData& form, |
974 const FormFieldData& field, | 974 const FormFieldData& field, |
975 FormStructure** form_structure, | 975 FormStructure** form_structure, |
976 AutofillField** autofill_field) { | 976 AutofillField** autofill_field) { |
977 // Find the FormStructure that corresponds to |form|. | 977 // Find the FormStructure that corresponds to |form|. |
978 // If we do not have this form in our cache but it is parseable, we'll add it | 978 // If we do not have this form in our cache but it is parseable, we'll add it |
979 // in the call to |UpdateCachedForm()|. | 979 // in the call to |UpdateCachedForm()|. |
980 if (!FindCachedForm(form, form_structure) && | 980 if (!FindCachedForm(form, form_structure) && |
981 !FormStructure(form).ShouldBeParsed(false)) { | 981 !FormStructure(form).ShouldBeParsed()) { |
982 return false; | 982 return false; |
983 } | 983 } |
984 | 984 |
985 // Update the cached form to reflect any dynamic changes to the form data, if | 985 // Update the cached form to reflect any dynamic changes to the form data, if |
986 // necessary. | 986 // necessary. |
987 if (!UpdateCachedForm(form, *form_structure, form_structure)) | 987 if (!UpdateCachedForm(form, *form_structure, form_structure)) |
988 return false; | 988 return false; |
989 | 989 |
990 // No data to return if there are no auto-fillable fields. | 990 // No data to return if there are no auto-fillable fields. |
991 if (!(*form_structure)->autofill_count()) | 991 if (!(*form_structure)->autofill_count()) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1098 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
1099 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); | 1099 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |
1100 } | 1100 } |
1101 } | 1101 } |
1102 | 1102 |
1103 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1103 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
1104 std::vector<FormStructure*> non_queryable_forms; | 1104 std::vector<FormStructure*> non_queryable_forms; |
1105 for (std::vector<FormData>::const_iterator iter = forms.begin(); | 1105 for (std::vector<FormData>::const_iterator iter = forms.begin(); |
1106 iter != forms.end(); ++iter) { | 1106 iter != forms.end(); ++iter) { |
1107 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); | 1107 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); |
1108 if (!form_structure->ShouldBeParsed(false)) | 1108 if (!form_structure->ShouldBeParsed()) |
1109 continue; | 1109 continue; |
1110 | 1110 |
1111 form_structure->DetermineHeuristicTypes(*metric_logger_); | 1111 form_structure->DetermineHeuristicTypes(*metric_logger_); |
1112 | 1112 |
1113 // Set aside forms with method GET or author-specified types, so that they | 1113 // Set aside forms with method GET or author-specified types, so that they |
1114 // are not included in the query to the server. | 1114 // are not included in the query to the server. |
1115 if (form_structure->ShouldBeCrowdsourced()) | 1115 if (form_structure->ShouldBeCrowdsourced()) |
1116 form_structures_.push_back(form_structure.release()); | 1116 form_structures_.push_back(form_structure.release()); |
1117 else | 1117 else |
1118 non_queryable_forms.push_back(form_structure.release()); | 1118 non_queryable_forms.push_back(form_structure.release()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 } | 1204 } |
1205 | 1205 |
1206 bool AutofillManager::ShouldUploadForm(const FormStructure& form) { | 1206 bool AutofillManager::ShouldUploadForm(const FormStructure& form) { |
1207 if (!IsAutofillEnabled()) | 1207 if (!IsAutofillEnabled()) |
1208 return false; | 1208 return false; |
1209 | 1209 |
1210 if (driver_->IsOffTheRecord()) | 1210 if (driver_->IsOffTheRecord()) |
1211 return false; | 1211 return false; |
1212 | 1212 |
1213 // Disregard forms that we wouldn't ever autofill in the first place. | 1213 // Disregard forms that we wouldn't ever autofill in the first place. |
1214 if (!form.ShouldBeParsed(true)) | 1214 if (!form.ShouldBeParsed()) |
1215 return false; | 1215 return false; |
1216 | 1216 |
1217 return true; | 1217 return true; |
1218 } | 1218 } |
1219 | 1219 |
1220 } // namespace autofill | 1220 } // namespace autofill |
OLD | NEW |