| 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> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/guid.h" | 16 #include "base/guid.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
| 23 #include "components/autofill/content/browser/autocheckout/whitelist_manager.h" | |
| 24 #include "components/autofill/content/browser/autocheckout_manager.h" | |
| 25 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 23 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
| 26 #include "components/autofill/core/browser/autofill_data_model.h" | 24 #include "components/autofill/core/browser/autofill_data_model.h" |
| 27 #include "components/autofill/core/browser/autofill_driver.h" | 25 #include "components/autofill/core/browser/autofill_driver.h" |
| 28 #include "components/autofill/core/browser/autofill_external_delegate.h" | 26 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 29 #include "components/autofill/core/browser/autofill_field.h" | 27 #include "components/autofill/core/browser/autofill_field.h" |
| 30 #include "components/autofill/core/browser/autofill_manager_delegate.h" | 28 #include "components/autofill/core/browser/autofill_manager_delegate.h" |
| 31 #include "components/autofill/core/browser/autofill_manager_test_delegate.h" | 29 #include "components/autofill/core/browser/autofill_manager_test_delegate.h" |
| 32 #include "components/autofill/core/browser/autofill_metrics.h" | 30 #include "components/autofill/core/browser/autofill_metrics.h" |
| 33 #include "components/autofill/core/browser/autofill_profile.h" | 31 #include "components/autofill/core/browser/autofill_profile.h" |
| 34 #include "components/autofill/core/browser/autofill_type.h" | 32 #include "components/autofill/core/browser/autofill_type.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 AutofillDriver* driver, | 181 AutofillDriver* driver, |
| 184 autofill::AutofillManagerDelegate* delegate, | 182 autofill::AutofillManagerDelegate* delegate, |
| 185 const std::string& app_locale, | 183 const std::string& app_locale, |
| 186 AutofillDownloadManagerState enable_download_manager) | 184 AutofillDownloadManagerState enable_download_manager) |
| 187 : driver_(driver), | 185 : driver_(driver), |
| 188 manager_delegate_(delegate), | 186 manager_delegate_(delegate), |
| 189 app_locale_(app_locale), | 187 app_locale_(app_locale), |
| 190 personal_data_(delegate->GetPersonalDataManager()), | 188 personal_data_(delegate->GetPersonalDataManager()), |
| 191 autocomplete_history_manager_( | 189 autocomplete_history_manager_( |
| 192 new AutocompleteHistoryManager(driver, delegate)), | 190 new AutocompleteHistoryManager(driver, delegate)), |
| 193 autocheckout_manager_(this), | |
| 194 metric_logger_(new AutofillMetrics), | 191 metric_logger_(new AutofillMetrics), |
| 195 has_logged_autofill_enabled_(false), | 192 has_logged_autofill_enabled_(false), |
| 196 has_logged_address_suggestions_count_(false), | 193 has_logged_address_suggestions_count_(false), |
| 197 did_show_suggestions_(false), | 194 did_show_suggestions_(false), |
| 198 user_did_type_(false), | 195 user_did_type_(false), |
| 199 user_did_autofill_(false), | 196 user_did_autofill_(false), |
| 200 user_did_edit_autofilled_field_(false), | 197 user_did_edit_autofilled_field_(false), |
| 201 external_delegate_(NULL), | 198 external_delegate_(NULL), |
| 202 test_delegate_(NULL), | 199 test_delegate_(NULL), |
| 203 weak_ptr_factory_(this) { | 200 weak_ptr_factory_(this) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 return false; | 252 return false; |
| 256 | 253 |
| 257 if (driver_->GetWebContents()->GetBrowserContext()->IsOffTheRecord()) | 254 if (driver_->GetWebContents()->GetBrowserContext()->IsOffTheRecord()) |
| 258 return false; | 255 return false; |
| 259 | 256 |
| 260 // Don't save data that was submitted through JavaScript. | 257 // Don't save data that was submitted through JavaScript. |
| 261 if (!form.user_submitted) | 258 if (!form.user_submitted) |
| 262 return false; | 259 return false; |
| 263 | 260 |
| 264 // Grab a copy of the form data. | 261 // Grab a copy of the form data. |
| 265 scoped_ptr<FormStructure> submitted_form( | 262 scoped_ptr<FormStructure> submitted_form(new FormStructure(form)); |
| 266 new FormStructure(form, GetAutocheckoutURLPrefix())); | |
| 267 | 263 |
| 268 // Disregard forms that we wouldn't ever autofill in the first place. | 264 // Disregard forms that we wouldn't ever autofill in the first place. |
| 269 if (!submitted_form->ShouldBeParsed(true)) | 265 if (!submitted_form->ShouldBeParsed(true)) |
| 270 return false; | 266 return false; |
| 271 | 267 |
| 272 // Ignore forms not present in our cache. These are typically forms with | 268 // Ignore forms not present in our cache. These are typically forms with |
| 273 // wonky JavaScript that also makes them not auto-fillable. | 269 // wonky JavaScript that also makes them not auto-fillable. |
| 274 FormStructure* cached_submitted_form; | 270 FormStructure* cached_submitted_form; |
| 275 if (!FindCachedForm(form, &cached_submitted_form)) | 271 if (!FindCachedForm(form, &cached_submitted_form)) |
| 276 return false; | 272 return false; |
| 277 | 273 |
| 278 submitted_form->UpdateFromCache(*cached_submitted_form); | 274 submitted_form->UpdateFromCache(*cached_submitted_form); |
| 279 // Don't prompt the user to save data entered by Autocheckout. | 275 if (submitted_form->IsAutofillable(true)) |
| 280 if (submitted_form->IsAutofillable(true) && | |
| 281 !submitted_form->filled_by_autocheckout()) | |
| 282 ImportFormData(*submitted_form); | 276 ImportFormData(*submitted_form); |
| 283 | 277 |
| 284 // Only upload server statistics and UMA metrics if at least some local data | 278 // Only upload server statistics and UMA metrics if at least some local data |
| 285 // is available to use as a baseline. | 279 // is available to use as a baseline. |
| 286 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); | 280 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
| 287 const std::vector<CreditCard*>& credit_cards = | 281 const std::vector<CreditCard*>& credit_cards = |
| 288 personal_data_->GetCreditCards(); | 282 personal_data_->GetCreditCards(); |
| 289 if (!profiles.empty() || !credit_cards.empty()) { | 283 if (!profiles.empty() || !credit_cards.empty()) { |
| 290 // Copy the profile and credit card data, so that it can be accessed on a | 284 // Copy the profile and credit card data, so that it can be accessed on a |
| 291 // separate thread. | 285 // separate thread. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 321 timestamp)); | 315 timestamp)); |
| 322 } | 316 } |
| 323 | 317 |
| 324 return true; | 318 return true; |
| 325 } | 319 } |
| 326 | 320 |
| 327 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, | 321 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, |
| 328 const TimeTicks& timestamp, | 322 const TimeTicks& timestamp, |
| 329 autofill::FormsSeenState state) { | 323 autofill::FormsSeenState state) { |
| 330 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; | 324 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; |
| 331 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN; | 325 // If new forms were added dynamically, treat as a new page. |
| 332 // If new forms were added dynamically, and the autocheckout manager | 326 if (is_post_document_load) |
| 333 // doesn't tell us to ignore ajax on this page, treat as a new page. | |
| 334 if (is_post_document_load) { | |
| 335 if (autocheckout_manager_.ShouldIgnoreAjax()) | |
| 336 return; | |
| 337 | |
| 338 Reset(); | 327 Reset(); |
| 339 } | |
| 340 | 328 |
| 341 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); | 329 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); |
| 342 if (!host) | 330 if (!host) |
| 343 return; | 331 return; |
| 344 | 332 |
| 345 if (!GetAutocheckoutURLPrefix().empty()) { | |
| 346 // If whitelisted URL, fetch all the forms. | |
| 347 if (has_more_forms) | |
| 348 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID())); | |
| 349 if (!is_post_document_load) { | |
| 350 host->Send( | |
| 351 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); | |
| 352 } | |
| 353 // Now return early, as OnFormsSeen will get called again with all forms. | |
| 354 if (has_more_forms) | |
| 355 return; | |
| 356 } | |
| 357 | |
| 358 autocheckout_manager_.OnFormsSeen(); | |
| 359 bool enabled = IsAutofillEnabled(); | 333 bool enabled = IsAutofillEnabled(); |
| 360 if (!has_logged_autofill_enabled_) { | 334 if (!has_logged_autofill_enabled_) { |
| 361 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); | 335 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); |
| 362 has_logged_autofill_enabled_ = true; | 336 has_logged_autofill_enabled_ = true; |
| 363 } | 337 } |
| 364 | 338 |
| 365 if (!enabled) | 339 if (!enabled) |
| 366 return; | 340 return; |
| 367 | 341 |
| 368 forms_loaded_timestamp_ = timestamp; | 342 forms_loaded_timestamp_ = timestamp; |
| 369 ParseForms(forms); | 343 ParseForms(forms); |
| 370 } | 344 } |
| 371 | 345 |
| 372 void AutofillManager::OnTextFieldDidChange(const FormData& form, | 346 void AutofillManager::OnTextFieldDidChange(const FormData& form, |
| 373 const FormFieldData& field, | 347 const FormFieldData& field, |
| 374 const TimeTicks& timestamp) { | 348 const TimeTicks& timestamp) { |
| 375 FormStructure* form_structure = NULL; | 349 FormStructure* form_structure = NULL; |
| 376 AutofillField* autofill_field = NULL; | 350 AutofillField* autofill_field = NULL; |
| 377 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) | 351 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) |
| 378 return; | 352 return; |
| 379 | 353 |
| 380 if (!user_did_type_) { | 354 if (!user_did_type_) { |
| 381 autocheckout_manager_.set_should_show_bubble(false); | |
| 382 user_did_type_ = true; | 355 user_did_type_ = true; |
| 383 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE); | 356 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE); |
| 384 } | 357 } |
| 385 | 358 |
| 386 if (autofill_field->is_autofilled) { | 359 if (autofill_field->is_autofilled) { |
| 387 autofill_field->is_autofilled = false; | 360 autofill_field->is_autofilled = false; |
| 388 metric_logger_->LogUserHappinessMetric( | 361 metric_logger_->LogUserHappinessMetric( |
| 389 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD); | 362 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD); |
| 390 | 363 |
| 391 if (!user_did_edit_autofilled_field_) { | 364 if (!user_did_edit_autofilled_field_) { |
| 392 user_did_edit_autofilled_field_ = true; | 365 user_did_edit_autofilled_field_ = true; |
| 393 metric_logger_->LogUserHappinessMetric( | 366 metric_logger_->LogUserHappinessMetric( |
| 394 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE); | 367 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE); |
| 395 } | 368 } |
| 396 } | 369 } |
| 397 | 370 |
| 398 UpdateInitialInteractionTimestamp(timestamp); | 371 UpdateInitialInteractionTimestamp(timestamp); |
| 399 } | 372 } |
| 400 | 373 |
| 401 void AutofillManager::OnQueryFormFieldAutofill(int query_id, | 374 void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
| 402 const FormData& form, | 375 const FormData& form, |
| 403 const FormFieldData& field, | 376 const FormFieldData& field, |
| 404 const gfx::RectF& bounding_box, | 377 const gfx::RectF& bounding_box, |
| 405 bool display_warning) { | 378 bool display_warning) { |
| 406 if (autocheckout_manager_.is_autocheckout_bubble_showing()) | |
| 407 return; | |
| 408 | |
| 409 std::vector<base::string16> values; | 379 std::vector<base::string16> values; |
| 410 std::vector<base::string16> labels; | 380 std::vector<base::string16> labels; |
| 411 std::vector<base::string16> icons; | 381 std::vector<base::string16> icons; |
| 412 std::vector<int> unique_ids; | 382 std::vector<int> unique_ids; |
| 413 | 383 |
| 414 external_delegate_->OnQuery(query_id, | 384 external_delegate_->OnQuery(query_id, |
| 415 form, | 385 form, |
| 416 field, | 386 field, |
| 417 bounding_box, | 387 bounding_box, |
| 418 display_warning); | 388 display_warning); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE); | 579 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE); |
| 610 } | 580 } |
| 611 } | 581 } |
| 612 } | 582 } |
| 613 | 583 |
| 614 void AutofillManager::OnHideAutofillUI() { | 584 void AutofillManager::OnHideAutofillUI() { |
| 615 if (!IsAutofillEnabled()) | 585 if (!IsAutofillEnabled()) |
| 616 return; | 586 return; |
| 617 | 587 |
| 618 manager_delegate_->HideAutofillPopup(); | 588 manager_delegate_->HideAutofillPopup(); |
| 619 manager_delegate_->HideAutocheckoutBubble(); | |
| 620 } | 589 } |
| 621 | 590 |
| 622 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) { | 591 void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) { |
| 623 const AutofillDataModel* data_model = NULL; | 592 const AutofillDataModel* data_model = NULL; |
| 624 size_t variant = 0; | 593 size_t variant = 0; |
| 625 if (!GetProfileOrCreditCard(unique_id, &data_model, &variant)) { | 594 if (!GetProfileOrCreditCard(unique_id, &data_model, &variant)) { |
| 626 NOTREACHED(); | 595 NOTREACHED(); |
| 627 return; | 596 return; |
| 628 } | 597 } |
| 629 | 598 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 ReturnAutocompleteResult(WebFormElement::AutocompleteResultErrorCancel, | 697 ReturnAutocompleteResult(WebFormElement::AutocompleteResultErrorCancel, |
| 729 FormData()); | 698 FormData()); |
| 730 } else { | 699 } else { |
| 731 ReturnAutocompleteResult(WebFormElement::AutocompleteResultSuccess, | 700 ReturnAutocompleteResult(WebFormElement::AutocompleteResultSuccess, |
| 732 result->ToFormData()); | 701 result->ToFormData()); |
| 733 } | 702 } |
| 734 } | 703 } |
| 735 | 704 |
| 736 void AutofillManager::OnLoadedServerPredictions( | 705 void AutofillManager::OnLoadedServerPredictions( |
| 737 const std::string& response_xml) { | 706 const std::string& response_xml) { |
| 738 scoped_ptr<autofill::AutocheckoutPageMetaData> page_meta_data( | |
| 739 new autofill::AutocheckoutPageMetaData()); | |
| 740 | |
| 741 // Parse and store the server predictions. | 707 // Parse and store the server predictions. |
| 742 FormStructure::ParseQueryResponse(response_xml, | 708 FormStructure::ParseQueryResponse(response_xml, |
| 743 form_structures_.get(), | 709 form_structures_.get(), |
| 744 page_meta_data.get(), | |
| 745 *metric_logger_); | 710 *metric_logger_); |
| 746 | 711 |
| 747 if (page_meta_data->IsInAutofillableFlow()) { | |
| 748 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); | |
| 749 if (host) | |
| 750 host->Send(new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); | |
| 751 } | |
| 752 | |
| 753 // TODO(ahutter): Remove this once Autocheckout is implemented on other | |
| 754 // platforms. See http://crbug.com/173416. | |
| 755 #if defined(TOOLKIT_VIEWS) | |
| 756 if (!GetAutocheckoutURLPrefix().empty()) | |
| 757 autocheckout_manager_.OnLoadedPageMetaData(page_meta_data.Pass()); | |
| 758 #endif // #if defined(TOOLKIT_VIEWS) | |
| 759 | |
| 760 // If the corresponding flag is set, annotate forms with the predicted types. | 712 // If the corresponding flag is set, annotate forms with the predicted types. |
| 761 driver_->SendAutofillTypePredictionsToRenderer(form_structures_.get()); | 713 driver_->SendAutofillTypePredictionsToRenderer(form_structures_.get()); |
| 762 } | 714 } |
| 763 | 715 |
| 764 void AutofillManager::OnDidEndTextFieldEditing() { | 716 void AutofillManager::OnDidEndTextFieldEditing() { |
| 765 external_delegate_->DidEndTextFieldEditing(); | 717 external_delegate_->DidEndTextFieldEditing(); |
| 766 } | 718 } |
| 767 | 719 |
| 768 void AutofillManager::OnAutocheckoutPageCompleted( | |
| 769 autofill::AutocheckoutStatus status) { | |
| 770 autocheckout_manager_.OnAutocheckoutPageCompleted(status); | |
| 771 } | |
| 772 | |
| 773 std::string AutofillManager::GetAutocheckoutURLPrefix() const { | |
| 774 if (!driver_->GetWebContents()) | |
| 775 return std::string(); | |
| 776 | |
| 777 autofill::autocheckout::WhitelistManager* whitelist_manager = | |
| 778 manager_delegate_->GetAutocheckoutWhitelistManager(); | |
| 779 | |
| 780 return whitelist_manager ? whitelist_manager->GetMatchedURLPrefix( | |
| 781 driver_->GetWebContents()->GetURL()) : std::string(); | |
| 782 } | |
| 783 | |
| 784 bool AutofillManager::IsAutofillEnabled() const { | 720 bool AutofillManager::IsAutofillEnabled() const { |
| 785 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 721 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
| 786 } | 722 } |
| 787 | 723 |
| 788 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { | 724 void AutofillManager::ImportFormData(const FormStructure& submitted_form) { |
| 789 const CreditCard* imported_credit_card; | 725 const CreditCard* imported_credit_card; |
| 790 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) | 726 if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) |
| 791 return; | 727 return; |
| 792 | 728 |
| 793 // If credit card information was submitted, we need to confirm whether to | 729 // If credit card information was submitted, we need to confirm whether to |
| (...skipping 18 matching lines...) Expand all Loading... |
| 812 const TimeTicks& submission_time) { | 748 const TimeTicks& submission_time) { |
| 813 submitted_form->LogQualityMetrics(*metric_logger_, | 749 submitted_form->LogQualityMetrics(*metric_logger_, |
| 814 load_time, | 750 load_time, |
| 815 interaction_time, | 751 interaction_time, |
| 816 submission_time); | 752 submission_time); |
| 817 | 753 |
| 818 if (submitted_form->ShouldBeCrowdsourced()) | 754 if (submitted_form->ShouldBeCrowdsourced()) |
| 819 UploadFormData(*submitted_form); | 755 UploadFormData(*submitted_form); |
| 820 } | 756 } |
| 821 | 757 |
| 822 void AutofillManager::OnMaybeShowAutocheckoutBubble( | |
| 823 const FormData& form, | |
| 824 const gfx::RectF& bounding_box) { | |
| 825 if (!IsAutofillEnabled()) | |
| 826 return; | |
| 827 | |
| 828 // Don't show bubble if corresponding FormStructure doesn't have anything to | |
| 829 // autofill. | |
| 830 FormStructure* cached_form; | |
| 831 if (!FindCachedForm(form, &cached_form)) | |
| 832 return; | |
| 833 | |
| 834 // Don't offer Autocheckout bubble if Autofill server is not aware of this | |
| 835 // form in the context of Autocheckout experiment. | |
| 836 if (!HasServerSpecifiedFieldTypes(*cached_form)) | |
| 837 return; | |
| 838 | |
| 839 autocheckout_manager_.MaybeShowAutocheckoutBubble(form.origin, bounding_box); | |
| 840 } | |
| 841 | |
| 842 void AutofillManager::UploadFormData(const FormStructure& submitted_form) { | 758 void AutofillManager::UploadFormData(const FormStructure& submitted_form) { |
| 843 if (!download_manager_) | 759 if (!download_manager_) |
| 844 return; | 760 return; |
| 845 | 761 |
| 846 // Check if the form is among the forms that were recently auto-filled. | 762 // Check if the form is among the forms that were recently auto-filled. |
| 847 bool was_autofilled = false; | 763 bool was_autofilled = false; |
| 848 std::string form_signature = submitted_form.FormSignature(); | 764 std::string form_signature = submitted_form.FormSignature(); |
| 849 for (std::list<std::string>::const_iterator it = | 765 for (std::list<std::string>::const_iterator it = |
| 850 autofilled_form_signatures_.begin(); | 766 autofilled_form_signatures_.begin(); |
| 851 it != autofilled_form_signatures_.end() && !was_autofilled; | 767 it != autofilled_form_signatures_.end() && !was_autofilled; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 876 | 792 |
| 877 AutofillManager::AutofillManager(AutofillDriver* driver, | 793 AutofillManager::AutofillManager(AutofillDriver* driver, |
| 878 autofill::AutofillManagerDelegate* delegate, | 794 autofill::AutofillManagerDelegate* delegate, |
| 879 PersonalDataManager* personal_data) | 795 PersonalDataManager* personal_data) |
| 880 : driver_(driver), | 796 : driver_(driver), |
| 881 manager_delegate_(delegate), | 797 manager_delegate_(delegate), |
| 882 app_locale_("en-US"), | 798 app_locale_("en-US"), |
| 883 personal_data_(personal_data), | 799 personal_data_(personal_data), |
| 884 autocomplete_history_manager_( | 800 autocomplete_history_manager_( |
| 885 new AutocompleteHistoryManager(driver, delegate)), | 801 new AutocompleteHistoryManager(driver, delegate)), |
| 886 autocheckout_manager_(this), | |
| 887 metric_logger_(new AutofillMetrics), | 802 metric_logger_(new AutofillMetrics), |
| 888 has_logged_autofill_enabled_(false), | 803 has_logged_autofill_enabled_(false), |
| 889 has_logged_address_suggestions_count_(false), | 804 has_logged_address_suggestions_count_(false), |
| 890 did_show_suggestions_(false), | 805 did_show_suggestions_(false), |
| 891 user_did_type_(false), | 806 user_did_type_(false), |
| 892 user_did_autofill_(false), | 807 user_did_autofill_(false), |
| 893 user_did_edit_autofilled_field_(false), | 808 user_did_edit_autofilled_field_(false), |
| 894 external_delegate_(NULL), | 809 external_delegate_(NULL), |
| 895 test_delegate_(NULL), | 810 test_delegate_(NULL), |
| 896 weak_ptr_factory_(this) { | 811 weak_ptr_factory_(this) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 } | 891 } |
| 977 | 892 |
| 978 bool AutofillManager::GetCachedFormAndField(const FormData& form, | 893 bool AutofillManager::GetCachedFormAndField(const FormData& form, |
| 979 const FormFieldData& field, | 894 const FormFieldData& field, |
| 980 FormStructure** form_structure, | 895 FormStructure** form_structure, |
| 981 AutofillField** autofill_field) { | 896 AutofillField** autofill_field) { |
| 982 // Find the FormStructure that corresponds to |form|. | 897 // Find the FormStructure that corresponds to |form|. |
| 983 // If we do not have this form in our cache but it is parseable, we'll add it | 898 // If we do not have this form in our cache but it is parseable, we'll add it |
| 984 // in the call to |UpdateCachedForm()|. | 899 // in the call to |UpdateCachedForm()|. |
| 985 if (!FindCachedForm(form, form_structure) && | 900 if (!FindCachedForm(form, form_structure) && |
| 986 !FormStructure(form, GetAutocheckoutURLPrefix()).ShouldBeParsed(false)) { | 901 !FormStructure(form).ShouldBeParsed(false)) { |
| 987 return false; | 902 return false; |
| 988 } | 903 } |
| 989 | 904 |
| 990 // Update the cached form to reflect any dynamic changes to the form data, if | 905 // Update the cached form to reflect any dynamic changes to the form data, if |
| 991 // necessary. | 906 // necessary. |
| 992 if (!UpdateCachedForm(form, *form_structure, form_structure)) | 907 if (!UpdateCachedForm(form, *form_structure, form_structure)) |
| 993 return false; | 908 return false; |
| 994 | 909 |
| 995 // No data to return if there are no auto-fillable fields. | 910 // No data to return if there are no auto-fillable fields. |
| 996 if (!(*form_structure)->autofill_count()) | 911 if (!(*form_structure)->autofill_count()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1023 needs_update = *cached_form->field(i) != live_form.fields[i]; | 938 needs_update = *cached_form->field(i) != live_form.fields[i]; |
| 1024 } | 939 } |
| 1025 | 940 |
| 1026 if (!needs_update) | 941 if (!needs_update) |
| 1027 return true; | 942 return true; |
| 1028 | 943 |
| 1029 if (form_structures_.size() >= kMaxFormCacheSize) | 944 if (form_structures_.size() >= kMaxFormCacheSize) |
| 1030 return false; | 945 return false; |
| 1031 | 946 |
| 1032 // Add the new or updated form to our cache. | 947 // Add the new or updated form to our cache. |
| 1033 form_structures_.push_back( | 948 form_structures_.push_back(new FormStructure(live_form)); |
| 1034 new FormStructure(live_form, GetAutocheckoutURLPrefix())); | |
| 1035 *updated_form = *form_structures_.rbegin(); | 949 *updated_form = *form_structures_.rbegin(); |
| 1036 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); | 950 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); |
| 1037 | 951 |
| 1038 // If we have cached data, propagate it to the updated form. | 952 // If we have cached data, propagate it to the updated form. |
| 1039 if (cached_form) { | 953 if (cached_form) { |
| 1040 std::map<base::string16, const AutofillField*> cached_fields; | 954 std::map<base::string16, const AutofillField*> cached_fields; |
| 1041 for (size_t i = 0; i < cached_form->field_count(); ++i) { | 955 for (size_t i = 0; i < cached_form->field_count(); ++i) { |
| 1042 const AutofillField* field = cached_form->field(i); | 956 const AutofillField* field = cached_form->field(i); |
| 1043 cached_fields[field->unique_name()] = field; | 957 cached_fields[field->unique_name()] = field; |
| 1044 } | 958 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 personal_data_->GetCreditCardSuggestions( | 1014 personal_data_->GetCreditCardSuggestions( |
| 1101 type, field.value, values, labels, icons, &guid_pairs); | 1015 type, field.value, values, labels, icons, &guid_pairs); |
| 1102 | 1016 |
| 1103 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1017 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
| 1104 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); | 1018 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |
| 1105 } | 1019 } |
| 1106 } | 1020 } |
| 1107 | 1021 |
| 1108 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1022 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
| 1109 std::vector<FormStructure*> non_queryable_forms; | 1023 std::vector<FormStructure*> non_queryable_forms; |
| 1110 std::string autocheckout_url_prefix = GetAutocheckoutURLPrefix(); | |
| 1111 for (std::vector<FormData>::const_iterator iter = forms.begin(); | 1024 for (std::vector<FormData>::const_iterator iter = forms.begin(); |
| 1112 iter != forms.end(); ++iter) { | 1025 iter != forms.end(); ++iter) { |
| 1113 scoped_ptr<FormStructure> form_structure( | 1026 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); |
| 1114 new FormStructure(*iter, autocheckout_url_prefix)); | |
| 1115 if (!form_structure->ShouldBeParsed(false)) | 1027 if (!form_structure->ShouldBeParsed(false)) |
| 1116 continue; | 1028 continue; |
| 1117 | 1029 |
| 1118 form_structure->DetermineHeuristicTypes(*metric_logger_); | 1030 form_structure->DetermineHeuristicTypes(*metric_logger_); |
| 1119 | 1031 |
| 1120 // Set aside forms with method GET or author-specified types, so that they | 1032 // Set aside forms with method GET or author-specified types, so that they |
| 1121 // are not included in the query to the server. | 1033 // are not included in the query to the server. |
| 1122 if (form_structure->ShouldBeCrowdsourced()) | 1034 if (form_structure->ShouldBeCrowdsourced()) |
| 1123 form_structures_.push_back(form_structure.release()); | 1035 form_structures_.push_back(form_structure.release()); |
| 1124 else | 1036 else |
| 1125 non_queryable_forms.push_back(form_structure.release()); | 1037 non_queryable_forms.push_back(form_structure.release()); |
| 1126 } | 1038 } |
| 1127 | 1039 |
| 1128 if (form_structures_.empty()) { | 1040 if (!form_structures_.empty() && download_manager_) { |
| 1129 // Call OnLoadedPageMetaData with no page metadata immediately if there is | |
| 1130 // no form in the page. This give |autocheckout_manager| a chance to | |
| 1131 // terminate Autocheckout and send Autocheckout status. | |
| 1132 autocheckout_manager_.OnLoadedPageMetaData( | |
| 1133 scoped_ptr<autofill::AutocheckoutPageMetaData>()); | |
| 1134 } else if (download_manager_) { | |
| 1135 // Query the server if we have at least one of the forms were parsed. | 1041 // Query the server if we have at least one of the forms were parsed. |
| 1136 download_manager_->StartQueryRequest(form_structures_.get(), | 1042 download_manager_->StartQueryRequest(form_structures_.get(), |
| 1137 *metric_logger_); | 1043 *metric_logger_); |
| 1138 } | 1044 } |
| 1139 | 1045 |
| 1140 for (std::vector<FormStructure*>::const_iterator iter = | 1046 for (std::vector<FormStructure*>::const_iterator iter = |
| 1141 non_queryable_forms.begin(); | 1047 non_queryable_forms.begin(); |
| 1142 iter != non_queryable_forms.end(); ++iter) { | 1048 iter != non_queryable_forms.end(); ++iter) { |
| 1143 form_structures_.push_back(*iter); | 1049 form_structures_.push_back(*iter); |
| 1144 } | 1050 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 | 1116 |
| 1211 void AutofillManager::UpdateInitialInteractionTimestamp( | 1117 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1212 const TimeTicks& interaction_timestamp) { | 1118 const TimeTicks& interaction_timestamp) { |
| 1213 if (initial_interaction_timestamp_.is_null() || | 1119 if (initial_interaction_timestamp_.is_null() || |
| 1214 interaction_timestamp < initial_interaction_timestamp_) { | 1120 interaction_timestamp < initial_interaction_timestamp_) { |
| 1215 initial_interaction_timestamp_ = interaction_timestamp; | 1121 initial_interaction_timestamp_ = interaction_timestamp; |
| 1216 } | 1122 } |
| 1217 } | 1123 } |
| 1218 | 1124 |
| 1219 } // namespace autofill | 1125 } // namespace autofill |
| OLD | NEW |