Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: components/autofill/browser/autofill_manager.cc

Issue 15097004: Enable Autocomplete feature for chromium webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@setSaveFormData2
Patch Set: make personal_data_ optional Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/autofill/browser/autofill_manager.h" 5 #include "components/autofill/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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 316 }
317 317
318 bool AutofillManager::OnFormSubmitted(const FormData& form, 318 bool AutofillManager::OnFormSubmitted(const FormData& form,
319 const TimeTicks& timestamp) { 319 const TimeTicks& timestamp) {
320 // Let AutoComplete know as well. 320 // Let AutoComplete know as well.
321 autocomplete_history_manager_.OnFormSubmitted(form); 321 autocomplete_history_manager_.OnFormSubmitted(form);
322 322
323 if (!IsAutofillEnabled()) 323 if (!IsAutofillEnabled())
324 return false; 324 return false;
325 325
326 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) 326 if (external_delegate_ && external_delegate_->ShouldIgnoreFormData())
327 return false; 327 return false;
328 328
329 // Don't save data that was submitted through JavaScript. 329 // Don't save data that was submitted through JavaScript.
330 if (!form.user_submitted) 330 if (!form.user_submitted)
331 return false; 331 return false;
332 332
333 // If there is no personal_data_, nothing to do.
334 if (!personal_data_)
335 return false;
336
333 // Grab a copy of the form data. 337 // Grab a copy of the form data.
334 scoped_ptr<FormStructure> submitted_form( 338 scoped_ptr<FormStructure> submitted_form(
335 new FormStructure(form, GetAutocheckoutURLPrefix())); 339 new FormStructure(form, GetAutocheckoutURLPrefix()));
336 340
337 // Disregard forms that we wouldn't ever autofill in the first place. 341 // Disregard forms that we wouldn't ever autofill in the first place.
338 if (!submitted_form->ShouldBeParsed(true)) 342 if (!submitted_form->ShouldBeParsed(true))
339 return false; 343 return false;
340 344
341 // Ignore forms not present in our cache. These are typically forms with 345 // Ignore forms not present in our cache. These are typically forms with
342 // wonky JavaScript that also makes them not auto-fillable. 346 // wonky JavaScript that also makes them not auto-fillable.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 initial_interaction_timestamp_, 393 initial_interaction_timestamp_,
390 timestamp)); 394 timestamp));
391 } 395 }
392 396
393 return true; 397 return true;
394 } 398 }
395 399
396 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, 400 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms,
397 const TimeTicks& timestamp, 401 const TimeTicks& timestamp,
398 autofill::FormsSeenState state) { 402 autofill::FormsSeenState state) {
403
benm (inactive) 2013/05/23 12:02:21 nit: remove?
sgurun-gerrit only 2013/05/23 17:10:01 Done.
399 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; 404 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN;
400 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN; 405 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN;
401 // If new forms were added via AJAX or DHML, treat as new page. 406 // If new forms were added via AJAX or DHML, treat as new page.
402 if (is_post_document_load) 407 if (is_post_document_load)
403 Reset(); 408 Reset();
404 409
405 RenderViewHost* host = web_contents()->GetRenderViewHost(); 410 RenderViewHost* host = web_contents()->GetRenderViewHost();
406 if (!host) 411 if (!host)
407 return; 412 return;
408 413
409 if (!GetAutocheckoutURLPrefix().empty()) { 414 if (!GetAutocheckoutURLPrefix().empty()) {
410 // If whitelisted URL, fetch all the forms. 415 // If whitelisted URL, fetch all the forms.
411 if (has_more_forms) 416 if (has_more_forms)
412 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID())); 417 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID()));
413 if (!is_post_document_load) { 418 if (!is_post_document_load) {
414 host->Send( 419 host->Send(
415 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); 420 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID()));
416 } 421 }
417 // Now return early, as OnFormsSeen will get called again with all forms. 422 // Now return early, as OnFormsSeen will get called again with all forms.
418 if (has_more_forms) 423 if (has_more_forms)
419 return; 424 return;
420 } 425 }
421 426
422 autocheckout_manager_.OnFormsSeen(); 427 autocheckout_manager_.OnFormsSeen();
423 bool enabled = IsAutofillEnabled(); 428 bool enabled = IsAutofillEnabled();
424 if (!has_logged_autofill_enabled_) { 429 if (!has_logged_autofill_enabled_) {
425 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); 430 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled);
426 has_logged_autofill_enabled_ = true; 431 has_logged_autofill_enabled_ = true;
427 } 432 }
428
429 if (!enabled) 433 if (!enabled)
430 return; 434 return;
431 435
432 forms_loaded_timestamp_ = timestamp; 436 forms_loaded_timestamp_ = timestamp;
433 ParseForms(forms); 437 ParseForms(forms);
434 } 438 }
435 439
436 void AutofillManager::OnTextFieldDidChange(const FormData& form, 440 void AutofillManager::OnTextFieldDidChange(const FormData& form,
437 const FormFieldData& field, 441 const FormFieldData& field,
438 const TimeTicks& timestamp) { 442 const TimeTicks& timestamp) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 std::vector<int> unique_ids; 479 std::vector<int> unique_ids;
476 480
477 if (external_delegate_) { 481 if (external_delegate_) {
478 external_delegate_->OnQuery(query_id, 482 external_delegate_->OnQuery(query_id,
479 form, 483 form,
480 field, 484 field,
481 bounding_box, 485 bounding_box,
482 display_warning); 486 display_warning);
483 } 487 }
484 488
489 if (personal_data_) {
490 OnQueryFormFieldAutofillPersonalData(query_id,
491 form,
492 field,
493 &values,
494 &labels,
495 &icons,
496 &unique_ids);
497 }
498 // Add the results from AutoComplete. They come back asynchronously, so we
499 // hand off what we generated and they will send the results back to the
500 // renderer.
501 autocomplete_history_manager_.OnGetAutocompleteSuggestions(
502 query_id, field.name, field.value, values, labels, icons, unique_ids);
503 }
504
505 void AutofillManager::OnQueryFormFieldAutofillPersonalData(
506 int query_id,
507 const FormData& form,
508 const FormFieldData& field,
509 std::vector<base::string16>* values,
510 std::vector<base::string16>* labels,
511 std::vector<string16>* icons,
512 std::vector<int>* unique_ids) {
485 RenderViewHost* host = NULL; 513 RenderViewHost* host = NULL;
486 FormStructure* form_structure = NULL; 514 FormStructure* form_structure = NULL;
487 AutofillField* autofill_field = NULL; 515 AutofillField* autofill_field = NULL;
488 if (GetHost(&host) && 516 if (GetHost(&host) &&
489 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && 517 GetCachedFormAndField(form, field, &form_structure, &autofill_field) &&
490 // Don't send suggestions for forms that aren't auto-fillable. 518 // Don't send suggestions for forms that aren't auto-fillable.
491 form_structure->IsAutofillable(false)) { 519 form_structure->IsAutofillable(false)) {
492 AutofillFieldType type = autofill_field->type(); 520 AutofillFieldType type = autofill_field->type();
493 bool is_filling_credit_card = 521 bool is_filling_credit_card =
494 (AutofillType(type).group() == AutofillType::CREDIT_CARD); 522 (AutofillType(type).group() == AutofillType::CREDIT_CARD);
495 if (is_filling_credit_card) { 523 if (is_filling_credit_card) {
496 GetCreditCardSuggestions( 524 GetCreditCardSuggestions(
497 field, type, &values, &labels, &icons, &unique_ids); 525 field, type, values, labels, icons, unique_ids);
498 } else { 526 } else {
499 GetProfileSuggestions( 527 GetProfileSuggestions(
500 form_structure, field, type, &values, &labels, &icons, &unique_ids); 528 form_structure, field, type, values, labels, icons, unique_ids);
501 } 529 }
502 530
503 DCHECK_EQ(values.size(), labels.size()); 531 DCHECK_EQ(values->size(), labels->size());
504 DCHECK_EQ(values.size(), icons.size()); 532 DCHECK_EQ(values->size(), icons->size());
505 DCHECK_EQ(values.size(), unique_ids.size()); 533 DCHECK_EQ(values->size(), unique_ids->size());
506 534
507 if (!values.empty()) { 535 if (!values->empty()) {
508 // Don't provide Autofill suggestions when Autofill is disabled, and don't 536 // Don't provide Autofill suggestions when Autofill is disabled, and don't
509 // provide credit card suggestions for non-HTTPS pages. However, provide a 537 // provide credit card suggestions for non-HTTPS pages. However, provide a
510 // warning to the user in these cases. 538 // warning to the user in these cases.
511 int warning = 0; 539 int warning = 0;
512 if (!form_structure->IsAutofillable(true)) 540 if (!form_structure->IsAutofillable(true))
513 warning = IDS_AUTOFILL_WARNING_FORM_DISABLED; 541 warning = IDS_AUTOFILL_WARNING_FORM_DISABLED;
514 else if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) 542 else if (is_filling_credit_card && !FormIsHTTPS(*form_structure))
515 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; 543 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION;
516 if (warning) { 544 if (warning) {
517 values.assign(1, l10n_util::GetStringUTF16(warning)); 545 values->assign(1, l10n_util::GetStringUTF16(warning));
518 labels.assign(1, base::string16()); 546 labels->assign(1, base::string16());
519 icons.assign(1, base::string16()); 547 icons->assign(1, base::string16());
520 unique_ids.assign(1, 548 unique_ids->assign(1,
521 WebKit::WebAutofillClient::MenuItemIDWarningMessage); 549 WebKit::WebAutofillClient::MenuItemIDWarningMessage);
522 } else { 550 } else {
523 bool section_is_autofilled = 551 bool section_is_autofilled =
524 SectionIsAutofilled(*form_structure, form, 552 SectionIsAutofilled(*form_structure, form,
525 autofill_field->section()); 553 autofill_field->section());
526 if (section_is_autofilled) { 554 if (section_is_autofilled) {
527 // If the relevant section is auto-filled and the renderer is querying 555 // If the relevant section is auto-filled and the renderer is querying
528 // for suggestions, then the user is editing the value of a field. 556 // for suggestions, then the user is editing the value of a field.
529 // In this case, mimic autocomplete: don't display labels or icons, 557 // In this case, mimic autocomplete: don't display labels or icons,
530 // as that information is redundant. 558 // as that information is redundant.
531 labels.assign(labels.size(), base::string16()); 559 labels->assign(labels->size(), base::string16());
532 icons.assign(icons.size(), base::string16()); 560 icons->assign(icons->size(), base::string16());
533 } 561 }
534 562
535 // When filling credit card suggestions, the values and labels are 563 // When filling credit card suggestions, the values and labels are
536 // typically obfuscated, which makes detecting duplicates hard. Since 564 // typically obfuscated, which makes detecting duplicates hard. Since
537 // duplicates only tend to be a problem when filling address forms 565 // duplicates only tend to be a problem when filling address forms
538 // anyway, only don't de-dup credit card suggestions. 566 // anyway, only don't de-dup credit card suggestions.
539 if (!is_filling_credit_card) 567 if (!is_filling_credit_card)
540 RemoveDuplicateSuggestions(&values, &labels, &icons, &unique_ids); 568 RemoveDuplicateSuggestions(values, labels, icons, unique_ids);
541 569
542 // The first time we show suggestions on this page, log the number of 570 // The first time we show suggestions on this page, log the number of
543 // suggestions shown. 571 // suggestions shown.
544 if (!has_logged_address_suggestions_count_ && !section_is_autofilled) { 572 if (!has_logged_address_suggestions_count_ && !section_is_autofilled) {
545 metric_logger_->LogAddressSuggestionsCount(values.size()); 573 metric_logger_->LogAddressSuggestionsCount(values->size());
546 has_logged_address_suggestions_count_ = true; 574 has_logged_address_suggestions_count_ = true;
547 } 575 }
548 } 576 }
549 } 577 }
550 } 578 }
551
552 // Add the results from AutoComplete. They come back asynchronously, so we
553 // hand off what we generated and they will send the results back to the
554 // renderer.
555 autocomplete_history_manager_.OnGetAutocompleteSuggestions(
556 query_id, field.name, field.value, values, labels, icons, unique_ids);
557 } 579 }
558 580
559 void AutofillManager::OnFillAutofillFormData(int query_id, 581 void AutofillManager::OnFillAutofillFormData(int query_id,
560 const FormData& form, 582 const FormData& form,
561 const FormFieldData& field, 583 const FormFieldData& field,
562 int unique_id) { 584 int unique_id) {
563 RenderViewHost* host = NULL; 585 RenderViewHost* host = NULL;
564 const AutofillDataModel* data_model = NULL; 586 const AutofillDataModel* data_model = NULL;
565 size_t variant = 0; 587 size_t variant = 0;
566 FormStructure* form_structure = NULL; 588 FormStructure* form_structure = NULL;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 } 703 }
682 } 704 }
683 705
684 void AutofillManager::OnHideAutofillUi() { 706 void AutofillManager::OnHideAutofillUi() {
685 if (IsNativeUiEnabled()) 707 if (IsNativeUiEnabled())
686 manager_delegate_->HideAutofillPopup(); 708 manager_delegate_->HideAutofillPopup();
687 manager_delegate_->HideAutocheckoutBubble(); 709 manager_delegate_->HideAutocheckoutBubble();
688 } 710 }
689 711
690 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) { 712 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) {
713
714 if (!personal_data_)
715 return;
716
691 const AutofillDataModel* data_model = NULL; 717 const AutofillDataModel* data_model = NULL;
692 size_t variant = 0; 718 size_t variant = 0;
693 if (!GetProfileOrCreditCard(unique_id, &data_model, &variant)) { 719 if (!GetProfileOrCreditCard(unique_id, &data_model, &variant)) {
694 NOTREACHED(); 720 NOTREACHED();
695 return; 721 return;
696 } 722 }
697 723
698 // TODO(csharp): If we are dealing with a variant only the variant should 724 // TODO(csharp): If we are dealing with a variant only the variant should
699 // be deleted, instead of doing nothing. 725 // be deleted, instead of doing nothing.
700 // http://crbug.com/124211 726 // http://crbug.com/124211
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 external_delegate_->SetCurrentDataListValues(values, 786 external_delegate_->SetCurrentDataListValues(values,
761 labels, 787 labels,
762 icons, 788 icons,
763 unique_ids); 789 unique_ids);
764 } 790 }
765 } 791 }
766 792
767 void AutofillManager::OnRequestAutocomplete( 793 void AutofillManager::OnRequestAutocomplete(
768 const FormData& form, 794 const FormData& form,
769 const GURL& frame_url) { 795 const GURL& frame_url) {
796
benm (inactive) 2013/05/23 12:02:21 nit: remove
sgurun-gerrit only 2013/05/23 17:10:01 Done.
770 if (!IsAutofillEnabled()) { 797 if (!IsAutofillEnabled()) {
771 ReturnAutocompleteResult(WebFormElement::AutocompleteResultErrorDisabled, 798 ReturnAutocompleteResult(WebFormElement::AutocompleteResultErrorDisabled,
772 FormData()); 799 FormData());
773 return; 800 return;
774 } 801 }
775 802
776 base::Callback<void(const FormStructure*, const std::string&)> callback = 803 base::Callback<void(const FormStructure*, const std::string&)> callback =
777 base::Bind(&AutofillManager::ReturnAutocompleteData, 804 base::Bind(&AutofillManager::ReturnAutocompleteData,
778 weak_ptr_factory_.GetWeakPtr()); 805 weak_ptr_factory_.GetWeakPtr());
779 ShowRequestAutocompleteDialog( 806 ShowRequestAutocompleteDialog(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 } 869 }
843 870
844 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { 871 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) {
845 autocheckout_manager_.OnClickFailed(status); 872 autocheckout_manager_.OnClickFailed(status);
846 } 873 }
847 874
848 void AutofillManager::OnMaybeShowAutocheckoutBubble( 875 void AutofillManager::OnMaybeShowAutocheckoutBubble(
849 const GURL& source_url, 876 const GURL& source_url,
850 const content::SSLStatus& ssl_status, 877 const content::SSLStatus& ssl_status,
851 const gfx::RectF& bounding_box) { 878 const gfx::RectF& bounding_box) {
879
benm (inactive) 2013/05/23 12:02:21 nit: remove
sgurun-gerrit only 2013/05/23 17:10:01 Done.
852 if (!IsAutofillEnabled()) 880 if (!IsAutofillEnabled())
853 return; 881 return;
854 882
855 autocheckout_manager_.MaybeShowAutocheckoutBubble( 883 autocheckout_manager_.MaybeShowAutocheckoutBubble(
856 source_url, 884 source_url,
857 ssl_status, 885 ssl_status,
858 bounding_box); 886 bounding_box);
859 } 887 }
860 888
861 std::string AutofillManager::GetAutocheckoutURLPrefix() const { 889 std::string AutofillManager::GetAutocheckoutURLPrefix() const {
862 if (!web_contents()) 890 if (!web_contents())
863 return std::string(); 891 return std::string();
864 892
865 autofill::autocheckout::WhitelistManager* whitelist_manager = 893 autofill::autocheckout::WhitelistManager* whitelist_manager =
866 manager_delegate_->GetAutocheckoutWhitelistManager(); 894 manager_delegate_->GetAutocheckoutWhitelistManager();
867 895
868 return whitelist_manager->GetMatchedURLPrefix(web_contents()->GetURL()); 896 return whitelist_manager ?
897 whitelist_manager->GetMatchedURLPrefix(web_contents()->GetURL()) :
898 std::string();
869 } 899 }
870 900
871 bool AutofillManager::IsAutofillEnabled() const { 901 bool AutofillManager::IsAutofillEnabled() const {
872 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); 902 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
873 } 903 }
874 904
875 void AutofillManager::SendAutofillTypePredictions( 905 void AutofillManager::SendAutofillTypePredictions(
876 const std::vector<FormStructure*>& forms) const { 906 const std::vector<FormStructure*>& forms) const {
877 if (!CommandLine::ForCurrentProcess()->HasSwitch( 907 if (!CommandLine::ForCurrentProcess()->HasSwitch(
878 switches::kShowAutofillTypePredictions)) 908 switches::kShowAutofillTypePredictions))
879 return; 909 return;
880 910
881 RenderViewHost* host = web_contents()->GetRenderViewHost(); 911 RenderViewHost* host = web_contents()->GetRenderViewHost();
882 if (!host) 912 if (!host)
883 return; 913 return;
884 914
885 std::vector<FormDataPredictions> type_predictions; 915 std::vector<FormDataPredictions> type_predictions;
886 FormStructure::GetFieldTypePredictions(forms, &type_predictions); 916 FormStructure::GetFieldTypePredictions(forms, &type_predictions);
887 host->Send( 917 host->Send(
888 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), 918 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(),
889 type_predictions)); 919 type_predictions));
890 } 920 }
891 921
892 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { 922 void AutofillManager::ImportFormData(const FormStructure& submitted_form) {
893 const CreditCard* imported_credit_card; 923 const CreditCard* imported_credit_card;
924
925 if (!personal_data_)
926 return;
927
894 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) 928 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card))
895 return; 929 return;
896 930
897 // If credit card information was submitted, we need to confirm whether to 931 // If credit card information was submitted, we need to confirm whether to
898 // save it. 932 // save it.
899 if (imported_credit_card) { 933 if (imported_credit_card) {
900 manager_delegate_->ConfirmSaveCreditCard( 934 manager_delegate_->ConfirmSaveCreditCard(
901 *metric_logger_, 935 *metric_logger_,
902 *imported_credit_card, 936 *imported_credit_card,
903 base::Bind(&PersonalDataManager::SaveImportedCreditCard, 937 base::Bind(&PersonalDataManager::SaveImportedCreditCard,
(...skipping 13 matching lines...) Expand all
917 submitted_form->LogQualityMetrics(*metric_logger_, 951 submitted_form->LogQualityMetrics(*metric_logger_,
918 load_time, 952 load_time,
919 interaction_time, 953 interaction_time,
920 submission_time); 954 submission_time);
921 955
922 if (submitted_form->ShouldBeCrowdsourced()) 956 if (submitted_form->ShouldBeCrowdsourced())
923 UploadFormData(*submitted_form); 957 UploadFormData(*submitted_form);
924 } 958 }
925 959
926 void AutofillManager::UploadFormData(const FormStructure& submitted_form) { 960 void AutofillManager::UploadFormData(const FormStructure& submitted_form) {
927 if (!download_manager_) 961 if (!download_manager_ || !personal_data_)
928 return; 962 return;
929 963
930 // Check if the form is among the forms that were recently auto-filled. 964 // Check if the form is among the forms that were recently auto-filled.
931 bool was_autofilled = false; 965 bool was_autofilled = false;
932 std::string form_signature = submitted_form.FormSignature(); 966 std::string form_signature = submitted_form.FormSignature();
933 for (std::list<std::string>::const_iterator it = 967 for (std::list<std::string>::const_iterator it =
934 autofilled_form_signatures_.begin(); 968 autofilled_form_signatures_.begin();
935 it != autofilled_form_signatures_.end() && !was_autofilled; 969 it != autofilled_form_signatures_.end() && !was_autofilled;
936 ++it) { 970 ++it) {
937 if (*it == form_signature) 971 if (*it == form_signature)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 } 1018 }
985 1019
986 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { 1020 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) {
987 metric_logger_.reset(metric_logger); 1021 metric_logger_.reset(metric_logger);
988 } 1022 }
989 1023
990 bool AutofillManager::GetHost(RenderViewHost** host) const { 1024 bool AutofillManager::GetHost(RenderViewHost** host) const {
991 if (!IsAutofillEnabled()) 1025 if (!IsAutofillEnabled())
992 return false; 1026 return false;
993 1027
1028 if (!personal_data_)
1029 return false;
1030
994 // No autofill data to return if the profiles are empty. 1031 // No autofill data to return if the profiles are empty.
995 if (personal_data_->GetProfiles().empty() && 1032 if (personal_data_->GetProfiles().empty() &&
996 personal_data_->GetCreditCards().empty()) { 1033 personal_data_->GetCreditCards().empty()) {
997 return false; 1034 return false;
998 } 1035 }
999 1036
1000 *host = web_contents()->GetRenderViewHost(); 1037 *host = web_contents()->GetRenderViewHost();
1001 if (!*host) 1038 if (!*host)
1002 return false; 1039 return false;
1003 1040
1004 return true; 1041 return true;
1005 } 1042 }
1006 1043
1007 bool AutofillManager::GetProfileOrCreditCard( 1044 bool AutofillManager::GetProfileOrCreditCard(
1008 int unique_id, 1045 int unique_id,
1009 const AutofillDataModel** data_model, 1046 const AutofillDataModel** data_model,
1010 size_t* variant) const { 1047 size_t* variant) const {
1048 if (!personal_data_)
1049 return false;
1050
1011 // Unpack the |unique_id| into component parts. 1051 // Unpack the |unique_id| into component parts.
1012 GUIDPair credit_card_guid; 1052 GUIDPair credit_card_guid;
1013 GUIDPair profile_guid; 1053 GUIDPair profile_guid;
1014 UnpackGUIDs(unique_id, &credit_card_guid, &profile_guid); 1054 UnpackGUIDs(unique_id, &credit_card_guid, &profile_guid);
1015 DCHECK(!base::IsValidGUID(credit_card_guid.first) || 1055 DCHECK(!base::IsValidGUID(credit_card_guid.first) ||
1016 !base::IsValidGUID(profile_guid.first)); 1056 !base::IsValidGUID(profile_guid.first));
1017 1057
1018 // Find the profile that matches the |profile_guid|, if one is specified. 1058 // Find the profile that matches the |profile_guid|, if one is specified.
1019 // Otherwise find the credit card that matches the |credit_card_guid|, 1059 // Otherwise find the credit card that matches the |credit_card_guid|,
1020 // if specified. 1060 // if specified.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 } 1190 }
1151 1191
1152 void AutofillManager::GetProfileSuggestions( 1192 void AutofillManager::GetProfileSuggestions(
1153 FormStructure* form, 1193 FormStructure* form,
1154 const FormFieldData& field, 1194 const FormFieldData& field,
1155 AutofillFieldType type, 1195 AutofillFieldType type,
1156 std::vector<base::string16>* values, 1196 std::vector<base::string16>* values,
1157 std::vector<base::string16>* labels, 1197 std::vector<base::string16>* labels,
1158 std::vector<base::string16>* icons, 1198 std::vector<base::string16>* icons,
1159 std::vector<int>* unique_ids) const { 1199 std::vector<int>* unique_ids) const {
1200
1201 if (!personal_data_)
1202 return;
1160 std::vector<AutofillFieldType> field_types(form->field_count()); 1203 std::vector<AutofillFieldType> field_types(form->field_count());
1161 for (size_t i = 0; i < form->field_count(); ++i) { 1204 for (size_t i = 0; i < form->field_count(); ++i) {
1162 field_types[i] = form->field(i)->type(); 1205 field_types[i] = form->field(i)->type();
1163 } 1206 }
1164 std::vector<GUIDPair> guid_pairs; 1207 std::vector<GUIDPair> guid_pairs;
1165 1208
1166 personal_data_->GetProfileSuggestions( 1209 personal_data_->GetProfileSuggestions(
1167 type, field.value, field.is_autofilled, field_types, 1210 type, field.value, field.is_autofilled, field_types,
1168 values, labels, icons, &guid_pairs); 1211 values, labels, icons, &guid_pairs);
1169 1212
1170 for (size_t i = 0; i < guid_pairs.size(); ++i) { 1213 for (size_t i = 0; i < guid_pairs.size(); ++i) {
1171 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), 1214 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0),
1172 guid_pairs[i])); 1215 guid_pairs[i]));
1173 } 1216 }
1174 } 1217 }
1175 1218
1176 void AutofillManager::GetCreditCardSuggestions( 1219 void AutofillManager::GetCreditCardSuggestions(
1177 const FormFieldData& field, 1220 const FormFieldData& field,
1178 AutofillFieldType type, 1221 AutofillFieldType type,
1179 std::vector<base::string16>* values, 1222 std::vector<base::string16>* values,
1180 std::vector<base::string16>* labels, 1223 std::vector<base::string16>* labels,
1181 std::vector<base::string16>* icons, 1224 std::vector<base::string16>* icons,
1182 std::vector<int>* unique_ids) const { 1225 std::vector<int>* unique_ids) const {
1226
1227 if (!personal_data_)
1228 return;
1229
1183 std::vector<GUIDPair> guid_pairs; 1230 std::vector<GUIDPair> guid_pairs;
1184 personal_data_->GetCreditCardSuggestions( 1231 personal_data_->GetCreditCardSuggestions(
1185 type, field.value, values, labels, icons, &guid_pairs); 1232 type, field.value, values, labels, icons, &guid_pairs);
1186 1233
1187 for (size_t i = 0; i < guid_pairs.size(); ++i) { 1234 for (size_t i = 0; i < guid_pairs.size(); ++i) {
1188 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); 1235 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0)));
1189 } 1236 }
1190 } 1237 }
1191 1238
1192 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { 1239 void AutofillManager::ParseForms(const std::vector<FormData>& forms) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 1341
1295 void AutofillManager::UpdateInitialInteractionTimestamp( 1342 void AutofillManager::UpdateInitialInteractionTimestamp(
1296 const TimeTicks& interaction_timestamp) { 1343 const TimeTicks& interaction_timestamp) {
1297 if (initial_interaction_timestamp_.is_null() || 1344 if (initial_interaction_timestamp_.is_null() ||
1298 interaction_timestamp < initial_interaction_timestamp_) { 1345 interaction_timestamp < initial_interaction_timestamp_) {
1299 initial_interaction_timestamp_ = interaction_timestamp; 1346 initial_interaction_timestamp_ = interaction_timestamp;
1300 } 1347 }
1301 } 1348 }
1302 1349
1303 } // namespace autofill 1350 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698