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 24 matching lines...) Expand all Loading... |
35 #include "chrome/browser/autofill/password_generator.h" | 35 #include "chrome/browser/autofill/password_generator.h" |
36 #include "chrome/browser/autofill/personal_data_manager.h" | 36 #include "chrome/browser/autofill/personal_data_manager.h" |
37 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 37 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
38 #include "chrome/browser/autofill/phone_number.h" | 38 #include "chrome/browser/autofill/phone_number.h" |
39 #include "chrome/browser/autofill/phone_number_i18n.h" | 39 #include "chrome/browser/autofill/phone_number_i18n.h" |
40 #include "chrome/browser/autofill/select_control_handler.h" | 40 #include "chrome/browser/autofill/select_control_handler.h" |
41 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 41 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
42 #include "chrome/common/autofill_messages.h" | 42 #include "chrome/common/autofill_messages.h" |
43 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
44 #include "chrome/common/chrome_switches.h" | 44 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/form_data.h" |
| 46 #include "chrome/common/form_data_predictions.h" |
| 47 #include "chrome/common/form_field_data.h" |
| 48 #include "chrome/common/password_form_fill_data.h" |
45 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
46 #include "chrome/common/url_constants.h" | 50 #include "chrome/common/url_constants.h" |
47 #include "content/public/browser/browser_context.h" | 51 #include "content/public/browser/browser_context.h" |
48 #include "content/public/browser/browser_thread.h" | 52 #include "content/public/browser/browser_thread.h" |
49 #include "content/public/browser/notification_service.h" | 53 #include "content/public/browser/notification_service.h" |
50 #include "content/public/browser/notification_source.h" | 54 #include "content/public/browser/notification_source.h" |
51 #include "content/public/browser/render_view_host.h" | 55 #include "content/public/browser/render_view_host.h" |
52 #include "content/public/browser/web_contents.h" | 56 #include "content/public/browser/web_contents.h" |
53 #include "googleurl/src/gurl.h" | 57 #include "googleurl/src/gurl.h" |
54 #include "grit/generated_resources.h" | 58 #include "grit/generated_resources.h" |
55 #include "ipc/ipc_message_macros.h" | 59 #include "ipc/ipc_message_macros.h" |
56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 60 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
57 #include "ui/base/l10n/l10n_util.h" | 61 #include "ui/base/l10n/l10n_util.h" |
58 #include "ui/gfx/rect.h" | 62 #include "ui/gfx/rect.h" |
59 #include "webkit/forms/form_data.h" | |
60 #include "webkit/forms/form_data_predictions.h" | |
61 #include "webkit/forms/form_field.h" | |
62 #include "webkit/forms/password_form_dom_manager.h" | |
63 | 63 |
64 using base::TimeTicks; | 64 using base::TimeTicks; |
65 using content::BrowserThread; | 65 using content::BrowserThread; |
66 using content::RenderViewHost; | 66 using content::RenderViewHost; |
67 using switches::kEnableAutofillFeedback; | 67 using switches::kEnableAutofillFeedback; |
68 using webkit::forms::FormData; | |
69 using webkit::forms::FormDataPredictions; | |
70 using webkit::forms::FormField; | |
71 | 68 |
72 namespace { | 69 namespace { |
73 | 70 |
74 // We only send a fraction of the forms to upload server. | 71 // We only send a fraction of the forms to upload server. |
75 // The rate for positive/negative matches potentially could be different. | 72 // The rate for positive/negative matches potentially could be different. |
76 const double kAutofillPositiveUploadRateDefaultValue = 0.20; | 73 const double kAutofillPositiveUploadRateDefaultValue = 0.20; |
77 const double kAutofillNegativeUploadRateDefaultValue = 0.20; | 74 const double kAutofillNegativeUploadRateDefaultValue = 0.20; |
78 | 75 |
79 const size_t kMaxRecentFormSignaturesToRemember = 3; | 76 const size_t kMaxRecentFormSignaturesToRemember = 3; |
80 | 77 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 431 } |
435 | 432 |
436 if (!enabled) | 433 if (!enabled) |
437 return; | 434 return; |
438 | 435 |
439 forms_loaded_timestamp_ = timestamp; | 436 forms_loaded_timestamp_ = timestamp; |
440 ParseForms(forms); | 437 ParseForms(forms); |
441 } | 438 } |
442 | 439 |
443 void AutofillManager::OnTextFieldDidChange(const FormData& form, | 440 void AutofillManager::OnTextFieldDidChange(const FormData& form, |
444 const FormField& field, | 441 const FormFieldData& field, |
445 const TimeTicks& timestamp) { | 442 const TimeTicks& timestamp) { |
446 FormStructure* form_structure = NULL; | 443 FormStructure* form_structure = NULL; |
447 AutofillField* autofill_field = NULL; | 444 AutofillField* autofill_field = NULL; |
448 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) | 445 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) |
449 return; | 446 return; |
450 | 447 |
451 if (!user_did_type_) { | 448 if (!user_did_type_) { |
452 user_did_type_ = true; | 449 user_did_type_ = true; |
453 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE); | 450 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE); |
454 } | 451 } |
455 | 452 |
456 if (autofill_field->is_autofilled) { | 453 if (autofill_field->is_autofilled) { |
457 autofill_field->is_autofilled = false; | 454 autofill_field->is_autofilled = false; |
458 metric_logger_->LogUserHappinessMetric( | 455 metric_logger_->LogUserHappinessMetric( |
459 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD); | 456 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD); |
460 | 457 |
461 if (!user_did_edit_autofilled_field_) { | 458 if (!user_did_edit_autofilled_field_) { |
462 user_did_edit_autofilled_field_ = true; | 459 user_did_edit_autofilled_field_ = true; |
463 metric_logger_->LogUserHappinessMetric( | 460 metric_logger_->LogUserHappinessMetric( |
464 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE); | 461 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE); |
465 } | 462 } |
466 } | 463 } |
467 | 464 |
468 UpdateInitialInteractionTimestamp(timestamp); | 465 UpdateInitialInteractionTimestamp(timestamp); |
469 } | 466 } |
470 | 467 |
471 void AutofillManager::OnQueryFormFieldAutofill(int query_id, | 468 void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
472 const FormData& form, | 469 const FormData& form, |
473 const FormField& field, | 470 const FormFieldData& field, |
474 const gfx::Rect& bounding_box, | 471 const gfx::Rect& bounding_box, |
475 bool display_warning) { | 472 bool display_warning) { |
476 std::vector<string16> values; | 473 std::vector<string16> values; |
477 std::vector<string16> labels; | 474 std::vector<string16> labels; |
478 std::vector<string16> icons; | 475 std::vector<string16> icons; |
479 std::vector<int> unique_ids; | 476 std::vector<int> unique_ids; |
480 | 477 |
481 if (external_delegate_) { | 478 if (external_delegate_) { |
482 external_delegate_->OnQuery(query_id, | 479 external_delegate_->OnQuery(query_id, |
483 form, | 480 form, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 // Add the results from AutoComplete. They come back asynchronously, so we | 554 // Add the results from AutoComplete. They come back asynchronously, so we |
558 // hand off what we generated and they will send the results back to the | 555 // hand off what we generated and they will send the results back to the |
559 // renderer. | 556 // renderer. |
560 AutocompleteHistoryManager::FromWebContents(tab_contents_->web_contents())-> | 557 AutocompleteHistoryManager::FromWebContents(tab_contents_->web_contents())-> |
561 OnGetAutocompleteSuggestions( | 558 OnGetAutocompleteSuggestions( |
562 query_id, field.name, field.value, values, labels, icons, unique_ids); | 559 query_id, field.name, field.value, values, labels, icons, unique_ids); |
563 } | 560 } |
564 | 561 |
565 void AutofillManager::OnFillAutofillFormData(int query_id, | 562 void AutofillManager::OnFillAutofillFormData(int query_id, |
566 const FormData& form, | 563 const FormData& form, |
567 const FormField& field, | 564 const FormFieldData& field, |
568 int unique_id) { | 565 int unique_id) { |
569 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles(); | 566 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles(); |
570 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); | 567 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); |
571 const AutofillProfile* profile = NULL; | 568 const AutofillProfile* profile = NULL; |
572 const CreditCard* credit_card = NULL; | 569 const CreditCard* credit_card = NULL; |
573 size_t variant = 0; | 570 size_t variant = 0; |
574 RenderViewHost* host = NULL; | 571 RenderViewHost* host = NULL; |
575 FormStructure* form_structure = NULL; | 572 FormStructure* form_structure = NULL; |
576 AutofillField* autofill_field = NULL; | 573 AutofillField* autofill_field = NULL; |
577 if (!GetProfileOrCreditCard(unique_id, profiles, credit_cards, &profile, | 574 if (!GetProfileOrCreditCard(unique_id, profiles, credit_cards, &profile, |
578 &credit_card, &variant) || | 575 &credit_card, &variant) || |
579 !GetHost(profiles, credit_cards, &host) || | 576 !GetHost(profiles, credit_cards, &host) || |
580 !GetCachedFormAndField(form, field, &form_structure, &autofill_field)) | 577 !GetCachedFormAndField(form, field, &form_structure, &autofill_field)) |
581 return; | 578 return; |
582 | 579 |
583 DCHECK(host); | 580 DCHECK(host); |
584 DCHECK(form_structure); | 581 DCHECK(form_structure); |
585 DCHECK(autofill_field); | 582 DCHECK(autofill_field); |
586 DCHECK(profile || credit_card); | 583 DCHECK(profile || credit_card); |
587 | 584 |
588 FormData result = form; | 585 FormData result = form; |
589 | 586 |
590 // If the relevant section is auto-filled, we should fill |field| but not the | 587 // If the relevant section is auto-filled, we should fill |field| but not the |
591 // rest of the form. | 588 // rest of the form. |
592 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) { | 589 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) { |
593 for (std::vector<FormField>::iterator iter = result.fields.begin(); | 590 for (std::vector<FormFieldData>::iterator iter = result.fields.begin(); |
594 iter != result.fields.end(); ++iter) { | 591 iter != result.fields.end(); ++iter) { |
595 if ((*iter) == field) { | 592 if ((*iter) == field) { |
596 AutofillFieldType field_type = autofill_field->type(); | 593 AutofillFieldType field_type = autofill_field->type(); |
597 if (profile) { | 594 if (profile) { |
598 DCHECK_NE(AutofillType::CREDIT_CARD, | 595 DCHECK_NE(AutofillType::CREDIT_CARD, |
599 AutofillType(field_type).group()); | 596 AutofillType(field_type).group()); |
600 FillFormField(*profile, *autofill_field, variant, &(*iter)); | 597 FillFormField(*profile, *autofill_field, variant, &(*iter)); |
601 } else { | 598 } else { |
602 DCHECK_EQ(AutofillType::CREDIT_CARD, | 599 DCHECK_EQ(AutofillType::CREDIT_CARD, |
603 AutofillType(field_type).group()); | 600 AutofillType(field_type).group()); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 } | 706 } |
710 | 707 |
711 void AutofillManager::OnHideAutofillPopup() { | 708 void AutofillManager::OnHideAutofillPopup() { |
712 if (external_delegate_) | 709 if (external_delegate_) |
713 external_delegate_->HideAutofillPopup(); | 710 external_delegate_->HideAutofillPopup(); |
714 } | 711 } |
715 | 712 |
716 void AutofillManager::OnShowPasswordGenerationPopup( | 713 void AutofillManager::OnShowPasswordGenerationPopup( |
717 const gfx::Rect& bounds, | 714 const gfx::Rect& bounds, |
718 int max_length, | 715 int max_length, |
719 const webkit::forms::PasswordForm& form) { | 716 const content::PasswordForm& form) { |
720 password_generator_.reset(new autofill::PasswordGenerator(max_length)); | 717 password_generator_.reset(new autofill::PasswordGenerator(max_length)); |
721 manager_delegate_->ShowPasswordGenerationBubble( | 718 manager_delegate_->ShowPasswordGenerationBubble( |
722 bounds, form, password_generator_.get()); | 719 bounds, form, password_generator_.get()); |
723 } | 720 } |
724 | 721 |
725 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) { | 722 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) { |
726 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles(); | 723 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles(); |
727 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); | 724 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); |
728 const AutofillProfile* profile = NULL; | 725 const AutofillProfile* profile = NULL; |
729 const CreditCard* credit_card = NULL; | 726 const CreditCard* credit_card = NULL; |
(...skipping 10 matching lines...) Expand all Loading... |
740 if (variant != 0) | 737 if (variant != 0) |
741 return; | 738 return; |
742 | 739 |
743 if (profile) | 740 if (profile) |
744 personal_data_->RemoveProfile(profile->guid()); | 741 personal_data_->RemoveProfile(profile->guid()); |
745 else | 742 else |
746 personal_data_->RemoveCreditCard(credit_card->guid()); | 743 personal_data_->RemoveCreditCard(credit_card->guid()); |
747 } | 744 } |
748 | 745 |
749 void AutofillManager::OnAddPasswordFormMapping( | 746 void AutofillManager::OnAddPasswordFormMapping( |
750 const webkit::forms::FormField& form, | 747 const FormFieldData& form, |
751 const webkit::forms::PasswordFormFillData& fill_data) { | 748 const PasswordFormFillData& fill_data) { |
752 if (external_delegate_) | 749 if (external_delegate_) |
753 external_delegate_->AddPasswordFormMapping(form, fill_data); | 750 external_delegate_->AddPasswordFormMapping(form, fill_data); |
754 } | 751 } |
755 | 752 |
756 void AutofillManager::OnShowPasswordSuggestions( | 753 void AutofillManager::OnShowPasswordSuggestions( |
757 const webkit::forms::FormField& field, | 754 const FormFieldData& field, |
758 const gfx::Rect& bounds, | 755 const gfx::Rect& bounds, |
759 const std::vector<string16>& suggestions) { | 756 const std::vector<string16>& suggestions) { |
760 if (external_delegate_) | 757 if (external_delegate_) |
761 external_delegate_->OnShowPasswordSuggestions(suggestions, field, bounds); | 758 external_delegate_->OnShowPasswordSuggestions(suggestions, field, bounds); |
762 } | 759 } |
763 | 760 |
764 void AutofillManager::OnSetDataList(const std::vector<string16>& values, | 761 void AutofillManager::OnSetDataList(const std::vector<string16>& values, |
765 const std::vector<string16>& labels, | 762 const std::vector<string16>& labels, |
766 const std::vector<string16>& icons, | 763 const std::vector<string16>& icons, |
767 const std::vector<int>& unique_ids) { | 764 const std::vector<int>& unique_ids) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 } | 994 } |
998 } | 995 } |
999 | 996 |
1000 if (!(*form_structure)) | 997 if (!(*form_structure)) |
1001 return false; | 998 return false; |
1002 | 999 |
1003 return true; | 1000 return true; |
1004 } | 1001 } |
1005 | 1002 |
1006 bool AutofillManager::GetCachedFormAndField(const FormData& form, | 1003 bool AutofillManager::GetCachedFormAndField(const FormData& form, |
1007 const FormField& field, | 1004 const FormFieldData& field, |
1008 FormStructure** form_structure, | 1005 FormStructure** form_structure, |
1009 AutofillField** autofill_field) { | 1006 AutofillField** autofill_field) { |
1010 // Find the FormStructure that corresponds to |form|. | 1007 // Find the FormStructure that corresponds to |form|. |
1011 // If we do not have this form in our cache but it is parseable, we'll add it | 1008 // If we do not have this form in our cache but it is parseable, we'll add it |
1012 // in the call to |UpdateCachedForm()|. | 1009 // in the call to |UpdateCachedForm()|. |
1013 if (!FindCachedForm(form, form_structure) && | 1010 if (!FindCachedForm(form, form_structure) && |
1014 !FormStructure(form).ShouldBeParsed(false)) { | 1011 !FormStructure(form).ShouldBeParsed(false)) { |
1015 return false; | 1012 return false; |
1016 } | 1013 } |
1017 | 1014 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 | 1083 |
1087 // Annotate the updated form with its predicted types. | 1084 // Annotate the updated form with its predicted types. |
1088 std::vector<FormStructure*> forms(1, *updated_form); | 1085 std::vector<FormStructure*> forms(1, *updated_form); |
1089 SendAutofillTypePredictions(forms); | 1086 SendAutofillTypePredictions(forms); |
1090 | 1087 |
1091 return true; | 1088 return true; |
1092 } | 1089 } |
1093 | 1090 |
1094 void AutofillManager::GetProfileSuggestions( | 1091 void AutofillManager::GetProfileSuggestions( |
1095 FormStructure* form, | 1092 FormStructure* form, |
1096 const FormField& field, | 1093 const FormFieldData& field, |
1097 AutofillFieldType type, | 1094 AutofillFieldType type, |
1098 std::vector<string16>* values, | 1095 std::vector<string16>* values, |
1099 std::vector<string16>* labels, | 1096 std::vector<string16>* labels, |
1100 std::vector<string16>* icons, | 1097 std::vector<string16>* icons, |
1101 std::vector<int>* unique_ids) const { | 1098 std::vector<int>* unique_ids) const { |
1102 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles(); | 1099 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles(); |
1103 if (!field.is_autofilled) { | 1100 if (!field.is_autofilled) { |
1104 std::vector<AutofillProfile*> matched_profiles; | 1101 std::vector<AutofillProfile*> matched_profiles; |
1105 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); | 1102 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); |
1106 iter != profiles.end(); ++iter) { | 1103 iter != profiles.end(); ++iter) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 // No labels for previously filled fields. | 1170 // No labels for previously filled fields. |
1174 labels->resize(values->size()); | 1171 labels->resize(values->size()); |
1175 | 1172 |
1176 // No icons for profile suggestions. | 1173 // No icons for profile suggestions. |
1177 icons->resize(values->size()); | 1174 icons->resize(values->size()); |
1178 } | 1175 } |
1179 } | 1176 } |
1180 | 1177 |
1181 void AutofillManager::GetCreditCardSuggestions( | 1178 void AutofillManager::GetCreditCardSuggestions( |
1182 FormStructure* form, | 1179 FormStructure* form, |
1183 const FormField& field, | 1180 const FormFieldData& field, |
1184 AutofillFieldType type, | 1181 AutofillFieldType type, |
1185 std::vector<string16>* values, | 1182 std::vector<string16>* values, |
1186 std::vector<string16>* labels, | 1183 std::vector<string16>* labels, |
1187 std::vector<string16>* icons, | 1184 std::vector<string16>* icons, |
1188 std::vector<int>* unique_ids) const { | 1185 std::vector<int>* unique_ids) const { |
1189 for (std::vector<CreditCard*>::const_iterator iter = | 1186 for (std::vector<CreditCard*>::const_iterator iter = |
1190 personal_data_->credit_cards().begin(); | 1187 personal_data_->credit_cards().begin(); |
1191 iter != personal_data_->credit_cards().end(); ++iter) { | 1188 iter != personal_data_->credit_cards().end(); ++iter) { |
1192 CreditCard* credit_card = *iter; | 1189 CreditCard* credit_card = *iter; |
1193 | 1190 |
(...skipping 18 matching lines...) Expand all Loading... |
1212 labels->push_back(label); | 1209 labels->push_back(label); |
1213 icons->push_back(UTF8ToUTF16(credit_card->type())); | 1210 icons->push_back(UTF8ToUTF16(credit_card->type())); |
1214 unique_ids->push_back(PackGUIDs(GUIDPair(credit_card->guid(), 0), | 1211 unique_ids->push_back(PackGUIDs(GUIDPair(credit_card->guid(), 0), |
1215 GUIDPair(std::string(), 0))); | 1212 GUIDPair(std::string(), 0))); |
1216 } | 1213 } |
1217 } | 1214 } |
1218 } | 1215 } |
1219 | 1216 |
1220 void AutofillManager::FillCreditCardFormField(const CreditCard& credit_card, | 1217 void AutofillManager::FillCreditCardFormField(const CreditCard& credit_card, |
1221 AutofillFieldType type, | 1218 AutofillFieldType type, |
1222 FormField* field) { | 1219 FormFieldData* field) { |
1223 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(type).group()); | 1220 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(type).group()); |
1224 DCHECK(field); | 1221 DCHECK(field); |
1225 | 1222 |
1226 if (field->form_control_type == ASCIIToUTF16("select-one")) { | 1223 if (field->form_control_type == ASCIIToUTF16("select-one")) { |
1227 autofill::FillSelectControl(credit_card, type, field); | 1224 autofill::FillSelectControl(credit_card, type, field); |
1228 } else if (field->form_control_type == ASCIIToUTF16("month")) { | 1225 } else if (field->form_control_type == ASCIIToUTF16("month")) { |
1229 // HTML5 input="month" consists of year-month. | 1226 // HTML5 input="month" consists of year-month. |
1230 string16 year = | 1227 string16 year = |
1231 credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 1228 credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
1232 string16 month = credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_MONTH); | 1229 string16 month = credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_MONTH); |
1233 if (!year.empty() && !month.empty()) { | 1230 if (!year.empty() && !month.empty()) { |
1234 // Fill the value only if |credit_card| includes both year and month | 1231 // Fill the value only if |credit_card| includes both year and month |
1235 // information. | 1232 // information. |
1236 field->value = year + ASCIIToUTF16("-") + month; | 1233 field->value = year + ASCIIToUTF16("-") + month; |
1237 } | 1234 } |
1238 } else { | 1235 } else { |
1239 field->value = credit_card.GetCanonicalizedInfo(type); | 1236 field->value = credit_card.GetCanonicalizedInfo(type); |
1240 } | 1237 } |
1241 } | 1238 } |
1242 | 1239 |
1243 void AutofillManager::FillFormField(const AutofillProfile& profile, | 1240 void AutofillManager::FillFormField(const AutofillProfile& profile, |
1244 const AutofillField& cached_field, | 1241 const AutofillField& cached_field, |
1245 size_t variant, | 1242 size_t variant, |
1246 FormField* field) { | 1243 FormFieldData* field) { |
1247 AutofillFieldType type = cached_field.type(); | 1244 AutofillFieldType type = cached_field.type(); |
1248 DCHECK_NE(AutofillType::CREDIT_CARD, AutofillType(type).group()); | 1245 DCHECK_NE(AutofillType::CREDIT_CARD, AutofillType(type).group()); |
1249 DCHECK(field); | 1246 DCHECK(field); |
1250 | 1247 |
1251 if (type == PHONE_HOME_NUMBER) { | 1248 if (type == PHONE_HOME_NUMBER) { |
1252 FillPhoneNumberField(profile, cached_field, variant, field); | 1249 FillPhoneNumberField(profile, cached_field, variant, field); |
1253 } else { | 1250 } else { |
1254 if (field->form_control_type == ASCIIToUTF16("select-one")) { | 1251 if (field->form_control_type == ASCIIToUTF16("select-one")) { |
1255 autofill::FillSelectControl(profile, type, field); | 1252 autofill::FillSelectControl(profile, type, field); |
1256 } else { | 1253 } else { |
1257 std::vector<string16> values; | 1254 std::vector<string16> values; |
1258 profile.GetCanonicalizedMultiInfo(type, &values); | 1255 profile.GetCanonicalizedMultiInfo(type, &values); |
1259 if (variant >= values.size()) { | 1256 if (variant >= values.size()) { |
1260 // If the variant is unavailable, bail. This case is reachable, for | 1257 // If the variant is unavailable, bail. This case is reachable, for |
1261 // example if Sync updates a profile during the filling process. | 1258 // example if Sync updates a profile during the filling process. |
1262 return; | 1259 return; |
1263 } | 1260 } |
1264 | 1261 |
1265 field->value = values[variant]; | 1262 field->value = values[variant]; |
1266 } | 1263 } |
1267 } | 1264 } |
1268 } | 1265 } |
1269 | 1266 |
1270 void AutofillManager::FillPhoneNumberField(const AutofillProfile& profile, | 1267 void AutofillManager::FillPhoneNumberField(const AutofillProfile& profile, |
1271 const AutofillField& cached_field, | 1268 const AutofillField& cached_field, |
1272 size_t variant, | 1269 size_t variant, |
1273 FormField* field) { | 1270 FormFieldData* field) { |
1274 std::vector<string16> values; | 1271 std::vector<string16> values; |
1275 profile.GetCanonicalizedMultiInfo(cached_field.type(), &values); | 1272 profile.GetCanonicalizedMultiInfo(cached_field.type(), &values); |
1276 DCHECK(variant < values.size()); | 1273 DCHECK(variant < values.size()); |
1277 | 1274 |
1278 // If we are filling a phone number, check to see if the size field | 1275 // If we are filling a phone number, check to see if the size field |
1279 // matches the "prefix" or "suffix" sizes and fill accordingly. | 1276 // matches the "prefix" or "suffix" sizes and fill accordingly. |
1280 string16 number = values[variant]; | 1277 string16 number = values[variant]; |
1281 if (number.length() == | 1278 if (number.length() == |
1282 (PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength)) { | 1279 (PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength)) { |
1283 if (cached_field.phone_part() == AutofillField::PHONE_PREFIX || | 1280 if (cached_field.phone_part() == AutofillField::PHONE_PREFIX || |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 *profile_guid = IDToGUID(profile_id); | 1386 *profile_guid = IDToGUID(profile_id); |
1390 } | 1387 } |
1391 | 1388 |
1392 void AutofillManager::UpdateInitialInteractionTimestamp( | 1389 void AutofillManager::UpdateInitialInteractionTimestamp( |
1393 const TimeTicks& interaction_timestamp) { | 1390 const TimeTicks& interaction_timestamp) { |
1394 if (initial_interaction_timestamp_.is_null() || | 1391 if (initial_interaction_timestamp_.is_null() || |
1395 interaction_timestamp < initial_interaction_timestamp_) { | 1392 interaction_timestamp < initial_interaction_timestamp_) { |
1396 initial_interaction_timestamp_ = interaction_timestamp; | 1393 initial_interaction_timestamp_ = interaction_timestamp; |
1397 } | 1394 } |
1398 } | 1395 } |
OLD | NEW |