| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "content/public/browser/render_view_host.h" | 50 #include "content/public/browser/render_view_host.h" |
| 51 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
| 52 #include "googleurl/src/gurl.h" | 52 #include "googleurl/src/gurl.h" |
| 53 #include "grit/generated_resources.h" | 53 #include "grit/generated_resources.h" |
| 54 #include "ipc/ipc_message_macros.h" | 54 #include "ipc/ipc_message_macros.h" |
| 55 #include "ui/base/l10n/l10n_util.h" | 55 #include "ui/base/l10n/l10n_util.h" |
| 56 #include "ui/gfx/rect.h" | 56 #include "ui/gfx/rect.h" |
| 57 #include "webkit/forms/form_data.h" | 57 #include "webkit/forms/form_data.h" |
| 58 #include "webkit/forms/form_data_predictions.h" | 58 #include "webkit/forms/form_data_predictions.h" |
| 59 #include "webkit/forms/form_field.h" | 59 #include "webkit/forms/form_field.h" |
| 60 #include "webkit/forms/password_form_dom_manager.h" |
| 60 | 61 |
| 61 using base::TimeTicks; | 62 using base::TimeTicks; |
| 62 using content::BrowserThread; | 63 using content::BrowserThread; |
| 63 using content::RenderViewHost; | 64 using content::RenderViewHost; |
| 64 using switches::kEnableAutofillFeedback; | 65 using switches::kEnableAutofillFeedback; |
| 65 using webkit::forms::FormData; | 66 using webkit::forms::FormData; |
| 66 using webkit::forms::FormDataPredictions; | 67 using webkit::forms::FormDataPredictions; |
| 67 using webkit::forms::FormField; | 68 using webkit::forms::FormField; |
| 68 | 69 |
| 69 namespace { | 70 namespace { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 kAutofillNegativeUploadRateDefaultValue, | 289 kAutofillNegativeUploadRateDefaultValue, |
| 289 PrefService::UNSYNCABLE_PREF); | 290 PrefService::UNSYNCABLE_PREF); |
| 290 } | 291 } |
| 291 | 292 |
| 292 void AutofillManager::DidNavigateMainFrame( | 293 void AutofillManager::DidNavigateMainFrame( |
| 293 const content::LoadCommittedDetails& details, | 294 const content::LoadCommittedDetails& details, |
| 294 const content::FrameNavigateParams& params) { | 295 const content::FrameNavigateParams& params) { |
| 295 Reset(); | 296 Reset(); |
| 296 } | 297 } |
| 297 | 298 |
| 299 bool AutofillManager::HasExternalDelegate() { |
| 300 return external_delegate_ != NULL; |
| 301 } |
| 302 |
| 298 bool AutofillManager::OnMessageReceived(const IPC::Message& message) { | 303 bool AutofillManager::OnMessageReceived(const IPC::Message& message) { |
| 299 bool handled = true; | 304 bool handled = true; |
| 300 IPC_BEGIN_MESSAGE_MAP(AutofillManager, message) | 305 IPC_BEGIN_MESSAGE_MAP(AutofillManager, message) |
| 301 IPC_MESSAGE_HANDLER(AutofillHostMsg_FormsSeen, OnFormsSeen) | 306 IPC_MESSAGE_HANDLER(AutofillHostMsg_FormsSeen, OnFormsSeen) |
| 302 IPC_MESSAGE_HANDLER(AutofillHostMsg_FormSubmitted, OnFormSubmitted) | 307 IPC_MESSAGE_HANDLER(AutofillHostMsg_FormSubmitted, OnFormSubmitted) |
| 303 IPC_MESSAGE_HANDLER(AutofillHostMsg_TextFieldDidChange, | 308 IPC_MESSAGE_HANDLER(AutofillHostMsg_TextFieldDidChange, |
| 304 OnTextFieldDidChange) | 309 OnTextFieldDidChange) |
| 305 IPC_MESSAGE_HANDLER(AutofillHostMsg_QueryFormFieldAutofill, | 310 IPC_MESSAGE_HANDLER(AutofillHostMsg_QueryFormFieldAutofill, |
| 306 OnQueryFormFieldAutofill) | 311 OnQueryFormFieldAutofill) |
| 307 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowAutofillDialog, | 312 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowAutofillDialog, |
| 308 OnShowAutofillDialog) | 313 OnShowAutofillDialog) |
| 309 IPC_MESSAGE_HANDLER(AutofillHostMsg_FillAutofillFormData, | 314 IPC_MESSAGE_HANDLER(AutofillHostMsg_FillAutofillFormData, |
| 310 OnFillAutofillFormData) | 315 OnFillAutofillFormData) |
| 311 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidPreviewAutofillFormData, | 316 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidPreviewAutofillFormData, |
| 312 OnDidPreviewAutofillFormData) | 317 OnDidPreviewAutofillFormData) |
| 313 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidFillAutofillFormData, | 318 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidFillAutofillFormData, |
| 314 OnDidFillAutofillFormData) | 319 OnDidFillAutofillFormData) |
| 315 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidShowAutofillSuggestions, | 320 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidShowAutofillSuggestions, |
| 316 OnDidShowAutofillSuggestions) | 321 OnDidShowAutofillSuggestions) |
| 317 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidEndTextFieldEditing, | 322 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidEndTextFieldEditing, |
| 318 OnDidEndTextFieldEditing) | 323 OnDidEndTextFieldEditing) |
| 319 IPC_MESSAGE_HANDLER(AutofillHostMsg_HideAutofillPopup, | 324 IPC_MESSAGE_HANDLER(AutofillHostMsg_HideAutofillPopup, |
| 320 OnHideAutofillPopup) | 325 OnHideAutofillPopup) |
| 326 IPC_MESSAGE_HANDLER(AutofillHostMsg_AddPasswordFormMapping, |
| 327 OnAddPasswordFormMapping) |
| 328 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordSuggestions, |
| 329 OnShowPasswordSuggestions) |
| 321 IPC_MESSAGE_UNHANDLED(handled = false) | 330 IPC_MESSAGE_UNHANDLED(handled = false) |
| 322 IPC_END_MESSAGE_MAP() | 331 IPC_END_MESSAGE_MAP() |
| 323 | 332 |
| 324 return handled; | 333 return handled; |
| 325 } | 334 } |
| 326 | 335 |
| 327 bool AutofillManager::OnFormSubmitted(const FormData& form, | 336 bool AutofillManager::OnFormSubmitted(const FormData& form, |
| 328 const TimeTicks& timestamp) { | 337 const TimeTicks& timestamp) { |
| 329 // Let AutoComplete know as well. | 338 // Let AutoComplete know as well. |
| 330 tab_contents_wrapper_->autocomplete_history_manager()->OnFormSubmitted(form); | 339 tab_contents_wrapper_->autocomplete_history_manager()->OnFormSubmitted(form); |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE); | 693 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE); |
| 685 } | 694 } |
| 686 } | 695 } |
| 687 } | 696 } |
| 688 | 697 |
| 689 void AutofillManager::OnHideAutofillPopup() { | 698 void AutofillManager::OnHideAutofillPopup() { |
| 690 if (external_delegate_) | 699 if (external_delegate_) |
| 691 external_delegate_->HideAutofillPopup(); | 700 external_delegate_->HideAutofillPopup(); |
| 692 } | 701 } |
| 693 | 702 |
| 703 void AutofillManager::OnAddPasswordFormMapping( |
| 704 const webkit::forms::FormField& form, |
| 705 const webkit::forms::PasswordFormFillData& fill_data) { |
| 706 if (external_delegate_) |
| 707 external_delegate_->AddPasswordFormMapping(form, fill_data); |
| 708 } |
| 709 |
| 710 void AutofillManager::OnShowPasswordSuggestions( |
| 711 const gfx::Rect& bounds, |
| 712 const std::vector<string16>& suggestions) { |
| 713 if (external_delegate_) { |
| 714 external_delegate_->SetBounds(bounds); |
| 715 external_delegate_->ShowPasswordSuggestions(suggestions); |
| 716 } |
| 717 } |
| 718 |
| 719 |
| 694 void AutofillManager::OnLoadedServerPredictions( | 720 void AutofillManager::OnLoadedServerPredictions( |
| 695 const std::string& response_xml) { | 721 const std::string& response_xml) { |
| 696 // Parse and store the server predictions. | 722 // Parse and store the server predictions. |
| 697 FormStructure::ParseQueryResponse(response_xml, | 723 FormStructure::ParseQueryResponse(response_xml, |
| 698 form_structures_.get(), | 724 form_structures_.get(), |
| 699 *metric_logger_); | 725 *metric_logger_); |
| 700 | 726 |
| 701 // If the corresponding flag is set, annotate forms with the predicted types. | 727 // If the corresponding flag is set, annotate forms with the predicted types. |
| 702 SendAutofillTypePredictions(form_structures_.get()); | 728 SendAutofillTypePredictions(form_structures_.get()); |
| 703 } | 729 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 void AutofillManager::Reset() { | 818 void AutofillManager::Reset() { |
| 793 form_structures_.reset(); | 819 form_structures_.reset(); |
| 794 has_logged_autofill_enabled_ = false; | 820 has_logged_autofill_enabled_ = false; |
| 795 has_logged_address_suggestions_count_ = false; | 821 has_logged_address_suggestions_count_ = false; |
| 796 did_show_suggestions_ = false; | 822 did_show_suggestions_ = false; |
| 797 user_did_type_ = false; | 823 user_did_type_ = false; |
| 798 user_did_autofill_ = false; | 824 user_did_autofill_ = false; |
| 799 user_did_edit_autofilled_field_ = false; | 825 user_did_edit_autofilled_field_ = false; |
| 800 forms_loaded_timestamp_ = TimeTicks(); | 826 forms_loaded_timestamp_ = TimeTicks(); |
| 801 initial_interaction_timestamp_ = TimeTicks(); | 827 initial_interaction_timestamp_ = TimeTicks(); |
| 828 |
| 829 if (external_delegate_) |
| 830 external_delegate_->Reset(); |
| 802 } | 831 } |
| 803 | 832 |
| 804 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents, | 833 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents, |
| 805 PersonalDataManager* personal_data) | 834 PersonalDataManager* personal_data) |
| 806 : content::WebContentsObserver(tab_contents->web_contents()), | 835 : content::WebContentsObserver(tab_contents->web_contents()), |
| 807 tab_contents_wrapper_(tab_contents), | 836 tab_contents_wrapper_(tab_contents), |
| 808 personal_data_(personal_data), | 837 personal_data_(personal_data), |
| 809 download_manager_(tab_contents->profile(), this), | 838 download_manager_(tab_contents->profile(), this), |
| 810 disable_download_manager_requests_(true), | 839 disable_download_manager_requests_(true), |
| 811 metric_logger_(new AutofillMetrics), | 840 metric_logger_(new AutofillMetrics), |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 *profile_guid = IDToGUID(profile_id); | 1330 *profile_guid = IDToGUID(profile_id); |
| 1302 } | 1331 } |
| 1303 | 1332 |
| 1304 void AutofillManager::UpdateInitialInteractionTimestamp( | 1333 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1305 const TimeTicks& interaction_timestamp) { | 1334 const TimeTicks& interaction_timestamp) { |
| 1306 if (initial_interaction_timestamp_.is_null() || | 1335 if (initial_interaction_timestamp_.is_null() || |
| 1307 interaction_timestamp < initial_interaction_timestamp_) { | 1336 interaction_timestamp < initial_interaction_timestamp_) { |
| 1308 initial_interaction_timestamp_ = interaction_timestamp; | 1337 initial_interaction_timestamp_ = interaction_timestamp; |
| 1309 } | 1338 } |
| 1310 } | 1339 } |
| OLD | NEW |