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

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

Issue 16212007: Implement the autofill UI for chromium powered android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue15097004
Patch Set: introduced java peer to AwAutofillManagerDelegate Created 7 years, 6 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 initial_interaction_timestamp_, 402 initial_interaction_timestamp_,
403 timestamp)); 403 timestamp));
404 } 404 }
405 405
406 return true; 406 return true;
407 } 407 }
408 408
409 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, 409 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms,
410 const TimeTicks& timestamp, 410 const TimeTicks& timestamp,
411 autofill::FormsSeenState state) { 411 autofill::FormsSeenState state) {
412
412 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; 413 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN;
413 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN; 414 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN;
414 // If new forms were added via AJAX or DHML, treat as new page. 415 // If new forms were added via AJAX or DHML, treat as new page.
415 if (is_post_document_load) 416 if (is_post_document_load)
416 Reset(); 417 Reset();
417 418
418 RenderViewHost* host = web_contents()->GetRenderViewHost(); 419 RenderViewHost* host = web_contents()->GetRenderViewHost();
419 if (!host) 420 if (!host)
420 return; 421 return;
421 422
422 if (!GetAutocheckoutURLPrefix().empty()) { 423 if (!GetAutocheckoutURLPrefix().empty()) {
423 // If whitelisted URL, fetch all the forms. 424 // If whitelisted URL, fetch all the forms.
424 if (has_more_forms) 425 if (has_more_forms)
425 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID())); 426 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID()));
426 if (!is_post_document_load) { 427 if (!is_post_document_load) {
427 host->Send( 428 host->Send(
428 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); 429 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID()));
429 } 430 }
430 // Now return early, as OnFormsSeen will get called again with all forms. 431 // Now return early, as OnFormsSeen will get called again with all forms.
431 if (has_more_forms) 432 if (has_more_forms)
432 return; 433 return;
433 } 434 }
434 435
435 autocheckout_manager_.OnFormsSeen(); 436 autocheckout_manager_.OnFormsSeen();
436 bool enabled = IsAutofillEnabled(); 437 bool enabled = IsAutofillEnabled();
437 if (!has_logged_autofill_enabled_) { 438 if (!has_logged_autofill_enabled_) {
438 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); 439 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled);
439 has_logged_autofill_enabled_ = true; 440 has_logged_autofill_enabled_ = true;
440 } 441 }
441
442 if (!enabled) 442 if (!enabled)
443 return; 443 return;
444 444
445 forms_loaded_timestamp_ = timestamp; 445 forms_loaded_timestamp_ = timestamp;
446 ParseForms(forms); 446 ParseForms(forms);
447 } 447 }
448 448
449 void AutofillManager::OnTextFieldDidChange(const FormData& form, 449 void AutofillManager::OnTextFieldDidChange(const FormData& form,
450 const FormFieldData& field, 450 const FormFieldData& field,
451 const TimeTicks& timestamp) { 451 const TimeTicks& timestamp) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 void AutofillManager::GetAutofillSuggestions( 512 void AutofillManager::GetAutofillSuggestions(
513 const FormData& form, 513 const FormData& form,
514 const FormFieldData& field, 514 const FormFieldData& field,
515 std::vector<base::string16>* values, 515 std::vector<base::string16>* values,
516 std::vector<base::string16>* labels, 516 std::vector<base::string16>* labels,
517 std::vector<string16>* icons, 517 std::vector<string16>* icons,
518 std::vector<int>* unique_ids) { 518 std::vector<int>* unique_ids) {
519 RenderViewHost* host = NULL; 519 RenderViewHost* host = NULL;
520 FormStructure* form_structure = NULL; 520 FormStructure* form_structure = NULL;
521 AutofillField* autofill_field = NULL; 521 AutofillField* autofill_field = NULL;
522 if (GetHost(&host) && 522 if (personal_data_ &&
523 GetHost(&host) &&
523 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && 524 GetCachedFormAndField(form, field, &form_structure, &autofill_field) &&
524 // Don't send suggestions for forms that aren't auto-fillable. 525 // Don't send suggestions for forms that aren't auto-fillable.
525 form_structure->IsAutofillable(false)) { 526 form_structure->IsAutofillable(false)) {
526 AutofillFieldType type = autofill_field->type(); 527 AutofillFieldType type = autofill_field->type();
527 bool is_filling_credit_card = 528 bool is_filling_credit_card =
528 (AutofillType(type).group() == AutofillType::CREDIT_CARD); 529 (AutofillType(type).group() == AutofillType::CREDIT_CARD);
529 if (is_filling_credit_card) { 530 if (is_filling_credit_card) {
530 GetCreditCardSuggestions( 531 GetCreditCardSuggestions(
531 field, type, values, labels, icons, unique_ids); 532 field, type, values, labels, icons, unique_ids);
532 } else { 533 } else {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 } 710 }
710 } 711 }
711 712
712 void AutofillManager::OnHideAutofillUi() { 713 void AutofillManager::OnHideAutofillUi() {
713 if (IsNativeUiEnabled()) 714 if (IsNativeUiEnabled())
714 manager_delegate_->HideAutofillPopup(); 715 manager_delegate_->HideAutofillPopup();
715 manager_delegate_->HideAutocheckoutBubble(); 716 manager_delegate_->HideAutocheckoutBubble();
716 } 717 }
717 718
718 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) { 719 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) {
720
721 if (!personal_data_)
722 return;
723
719 const AutofillDataModel* data_model = NULL; 724 const AutofillDataModel* data_model = NULL;
720 size_t variant = 0; 725 size_t variant = 0;
721 if (!GetProfileOrCreditCard(unique_id, &data_model, &variant)) { 726 if (!GetProfileOrCreditCard(unique_id, &data_model, &variant)) {
722 NOTREACHED(); 727 NOTREACHED();
723 return; 728 return;
724 } 729 }
725 730
726 // TODO(csharp): If we are dealing with a variant only the variant should 731 // TODO(csharp): If we are dealing with a variant only the variant should
727 // be deleted, instead of doing nothing. 732 // be deleted, instead of doing nothing.
728 // http://crbug.com/124211 733 // http://crbug.com/124211
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 external_delegate_->SetCurrentDataListValues(values, 793 external_delegate_->SetCurrentDataListValues(values,
789 labels, 794 labels,
790 icons, 795 icons,
791 unique_ids); 796 unique_ids);
792 } 797 }
793 } 798 }
794 799
795 void AutofillManager::OnRequestAutocomplete( 800 void AutofillManager::OnRequestAutocomplete(
796 const FormData& form, 801 const FormData& form,
797 const GURL& frame_url) { 802 const GURL& frame_url) {
803
798 if (!IsAutofillEnabled()) { 804 if (!IsAutofillEnabled()) {
799 ReturnAutocompleteResult(WebFormElement::AutocompleteResultErrorDisabled, 805 ReturnAutocompleteResult(WebFormElement::AutocompleteResultErrorDisabled,
800 FormData()); 806 FormData());
801 return; 807 return;
802 } 808 }
803 809
804 base::Callback<void(const FormStructure*, const std::string&)> callback = 810 base::Callback<void(const FormStructure*, const std::string&)> callback =
805 base::Bind(&AutofillManager::ReturnAutocompleteData, 811 base::Bind(&AutofillManager::ReturnAutocompleteData,
806 weak_ptr_factory_.GetWeakPtr()); 812 weak_ptr_factory_.GetWeakPtr());
807 ShowRequestAutocompleteDialog( 813 ShowRequestAutocompleteDialog(
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 if (!HasServerSpecifiedFieldTypes(*cached_form)) 965 if (!HasServerSpecifiedFieldTypes(*cached_form))
960 return; 966 return;
961 967
962 autocheckout_manager_.MaybeShowAutocheckoutBubble( 968 autocheckout_manager_.MaybeShowAutocheckoutBubble(
963 form.origin, 969 form.origin,
964 form.ssl_status, 970 form.ssl_status,
965 bounding_box); 971 bounding_box);
966 } 972 }
967 973
968 void AutofillManager::UploadFormData(const FormStructure& submitted_form) { 974 void AutofillManager::UploadFormData(const FormStructure& submitted_form) {
969 if (!download_manager_) 975 if (!download_manager_ || !personal_data_)
970 return; 976 return;
971 977
972 // Check if the form is among the forms that were recently auto-filled. 978 // Check if the form is among the forms that were recently auto-filled.
973 bool was_autofilled = false; 979 bool was_autofilled = false;
974 std::string form_signature = submitted_form.FormSignature(); 980 std::string form_signature = submitted_form.FormSignature();
975 for (std::list<std::string>::const_iterator it = 981 for (std::list<std::string>::const_iterator it =
976 autofilled_form_signatures_.begin(); 982 autofilled_form_signatures_.begin();
977 it != autofilled_form_signatures_.end() && !was_autofilled; 983 it != autofilled_form_signatures_.end() && !was_autofilled;
978 ++it) { 984 ++it) {
979 if (*it == form_signature) 985 if (*it == form_signature)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1037
1032 bool AutofillManager::GetHost(RenderViewHost** host) const { 1038 bool AutofillManager::GetHost(RenderViewHost** host) const {
1033 1039
1034 if (!IsAutofillEnabled()) 1040 if (!IsAutofillEnabled())
1035 return false; 1041 return false;
1036 1042
1037 if (!personal_data_) 1043 if (!personal_data_)
1038 return false; 1044 return false;
1039 1045
1040 // No autofill data to return if the profiles are empty. 1046 // No autofill data to return if the profiles are empty.
1041 if (personal_data_->GetProfiles().empty() && 1047 if (personal_data_ &&
1048 personal_data_->GetProfiles().empty() &&
1042 personal_data_->GetCreditCards().empty()) { 1049 personal_data_->GetCreditCards().empty()) {
1043 return false; 1050 return false;
1044 } 1051 }
1045 1052
1046 *host = web_contents()->GetRenderViewHost(); 1053 *host = web_contents()->GetRenderViewHost();
1047 if (!*host) 1054 if (!*host)
1048 return false; 1055 return false;
1049 1056
1050 return true; 1057 return true;
1051 } 1058 }
1052 1059
1053 bool AutofillManager::GetProfileOrCreditCard( 1060 bool AutofillManager::GetProfileOrCreditCard(
1054 int unique_id, 1061 int unique_id,
1055 const AutofillDataModel** data_model, 1062 const AutofillDataModel** data_model,
1056 size_t* variant) const { 1063 size_t* variant) const {
1064 if (!personal_data_)
1065 return false;
1066
1057 // Unpack the |unique_id| into component parts. 1067 // Unpack the |unique_id| into component parts.
1058 GUIDPair credit_card_guid; 1068 GUIDPair credit_card_guid;
1059 GUIDPair profile_guid; 1069 GUIDPair profile_guid;
1060 UnpackGUIDs(unique_id, &credit_card_guid, &profile_guid); 1070 UnpackGUIDs(unique_id, &credit_card_guid, &profile_guid);
1061 DCHECK(!base::IsValidGUID(credit_card_guid.first) || 1071 DCHECK(!base::IsValidGUID(credit_card_guid.first) ||
1062 !base::IsValidGUID(profile_guid.first)); 1072 !base::IsValidGUID(profile_guid.first));
1063 1073
1064 // Find the profile that matches the |profile_guid|, if one is specified. 1074 // Find the profile that matches the |profile_guid|, if one is specified.
1065 // Otherwise find the credit card that matches the |credit_card_guid|, 1075 // Otherwise find the credit card that matches the |credit_card_guid|,
1066 // if specified. 1076 // if specified.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 } 1206 }
1197 1207
1198 void AutofillManager::GetProfileSuggestions( 1208 void AutofillManager::GetProfileSuggestions(
1199 FormStructure* form, 1209 FormStructure* form,
1200 const FormFieldData& field, 1210 const FormFieldData& field,
1201 AutofillFieldType type, 1211 AutofillFieldType type,
1202 std::vector<base::string16>* values, 1212 std::vector<base::string16>* values,
1203 std::vector<base::string16>* labels, 1213 std::vector<base::string16>* labels,
1204 std::vector<base::string16>* icons, 1214 std::vector<base::string16>* icons,
1205 std::vector<int>* unique_ids) const { 1215 std::vector<int>* unique_ids) const {
1216
1217 if (!personal_data_)
1218 return;
1206 std::vector<AutofillFieldType> field_types(form->field_count()); 1219 std::vector<AutofillFieldType> field_types(form->field_count());
1207 for (size_t i = 0; i < form->field_count(); ++i) { 1220 for (size_t i = 0; i < form->field_count(); ++i) {
1208 field_types[i] = form->field(i)->type(); 1221 field_types[i] = form->field(i)->type();
1209 } 1222 }
1210 std::vector<GUIDPair> guid_pairs; 1223 std::vector<GUIDPair> guid_pairs;
1211 1224
1212 personal_data_->GetProfileSuggestions( 1225 personal_data_->GetProfileSuggestions(
1213 type, field.value, field.is_autofilled, field_types, 1226 type, field.value, field.is_autofilled, field_types,
1214 values, labels, icons, &guid_pairs); 1227 values, labels, icons, &guid_pairs);
1215 1228
1216 for (size_t i = 0; i < guid_pairs.size(); ++i) { 1229 for (size_t i = 0; i < guid_pairs.size(); ++i) {
1217 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), 1230 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0),
1218 guid_pairs[i])); 1231 guid_pairs[i]));
1219 } 1232 }
1220 } 1233 }
1221 1234
1222 void AutofillManager::GetCreditCardSuggestions( 1235 void AutofillManager::GetCreditCardSuggestions(
1223 const FormFieldData& field, 1236 const FormFieldData& field,
1224 AutofillFieldType type, 1237 AutofillFieldType type,
1225 std::vector<base::string16>* values, 1238 std::vector<base::string16>* values,
1226 std::vector<base::string16>* labels, 1239 std::vector<base::string16>* labels,
1227 std::vector<base::string16>* icons, 1240 std::vector<base::string16>* icons,
1228 std::vector<int>* unique_ids) const { 1241 std::vector<int>* unique_ids) const {
1242
1243 if (!personal_data_)
1244 return;
1245
1229 std::vector<GUIDPair> guid_pairs; 1246 std::vector<GUIDPair> guid_pairs;
1230 personal_data_->GetCreditCardSuggestions( 1247 personal_data_->GetCreditCardSuggestions(
1231 type, field.value, values, labels, icons, &guid_pairs); 1248 type, field.value, values, labels, icons, &guid_pairs);
1232 1249
1233 for (size_t i = 0; i < guid_pairs.size(); ++i) { 1250 for (size_t i = 0; i < guid_pairs.size(); ++i) {
1234 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); 1251 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0)));
1235 } 1252 }
1236 } 1253 }
1237 1254
1238 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { 1255 void AutofillManager::ParseForms(const std::vector<FormData>& forms) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 1357
1341 void AutofillManager::UpdateInitialInteractionTimestamp( 1358 void AutofillManager::UpdateInitialInteractionTimestamp(
1342 const TimeTicks& interaction_timestamp) { 1359 const TimeTicks& interaction_timestamp) {
1343 if (initial_interaction_timestamp_.is_null() || 1360 if (initial_interaction_timestamp_.is_null() ||
1344 interaction_timestamp < initial_interaction_timestamp_) { 1361 interaction_timestamp < initial_interaction_timestamp_) {
1345 initial_interaction_timestamp_ = interaction_timestamp; 1362 initial_interaction_timestamp_ = interaction_timestamp;
1346 } 1363 }
1347 } 1364 }
1348 1365
1349 } // namespace autofill 1366 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698