| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
| 52 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
| 53 #include "googleurl/src/gurl.h" | 53 #include "googleurl/src/gurl.h" |
| 54 #include "grit/generated_resources.h" | 54 #include "grit/generated_resources.h" |
| 55 #include "ipc/ipc_message_macros.h" | 55 #include "ipc/ipc_message_macros.h" |
| 56 #include "ui/base/l10n/l10n_util.h" | 56 #include "ui/base/l10n/l10n_util.h" |
| 57 #include "ui/gfx/rect.h" | 57 #include "ui/gfx/rect.h" |
| 58 #include "webkit/forms/form_data.h" | 58 #include "webkit/forms/form_data.h" |
| 59 #include "webkit/forms/form_data_predictions.h" | 59 #include "webkit/forms/form_data_predictions.h" |
| 60 #include "webkit/forms/form_field.h" | 60 #include "webkit/forms/form_field.h" |
| 61 #include "webkit/forms/password_form_dom_manager.h" |
| 61 | 62 |
| 62 using base::TimeTicks; | 63 using base::TimeTicks; |
| 63 using content::BrowserThread; | 64 using content::BrowserThread; |
| 64 using content::RenderViewHost; | 65 using content::RenderViewHost; |
| 65 using switches::kEnableAutofillFeedback; | 66 using switches::kEnableAutofillFeedback; |
| 66 using webkit::forms::FormData; | 67 using webkit::forms::FormData; |
| 67 using webkit::forms::FormDataPredictions; | 68 using webkit::forms::FormDataPredictions; |
| 68 using webkit::forms::FormField; | 69 using webkit::forms::FormField; |
| 69 | 70 |
| 70 namespace { | 71 namespace { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 kAutofillNegativeUploadRateDefaultValue, | 214 kAutofillNegativeUploadRateDefaultValue, |
| 214 PrefService::UNSYNCABLE_PREF); | 215 PrefService::UNSYNCABLE_PREF); |
| 215 } | 216 } |
| 216 | 217 |
| 217 void AutofillManager::DidNavigateMainFrame( | 218 void AutofillManager::DidNavigateMainFrame( |
| 218 const content::LoadCommittedDetails& details, | 219 const content::LoadCommittedDetails& details, |
| 219 const content::FrameNavigateParams& params) { | 220 const content::FrameNavigateParams& params) { |
| 220 Reset(); | 221 Reset(); |
| 221 } | 222 } |
| 222 | 223 |
| 224 bool AutofillManager::HasExternalDelegate() { |
| 225 return external_delegate_ != NULL; |
| 226 } |
| 227 |
| 223 bool AutofillManager::OnMessageReceived(const IPC::Message& message) { | 228 bool AutofillManager::OnMessageReceived(const IPC::Message& message) { |
| 224 bool handled = true; | 229 bool handled = true; |
| 225 IPC_BEGIN_MESSAGE_MAP(AutofillManager, message) | 230 IPC_BEGIN_MESSAGE_MAP(AutofillManager, message) |
| 226 IPC_MESSAGE_HANDLER(AutofillHostMsg_FormsSeen, OnFormsSeen) | 231 IPC_MESSAGE_HANDLER(AutofillHostMsg_FormsSeen, OnFormsSeen) |
| 227 IPC_MESSAGE_HANDLER(AutofillHostMsg_FormSubmitted, OnFormSubmitted) | 232 IPC_MESSAGE_HANDLER(AutofillHostMsg_FormSubmitted, OnFormSubmitted) |
| 228 IPC_MESSAGE_HANDLER(AutofillHostMsg_TextFieldDidChange, | 233 IPC_MESSAGE_HANDLER(AutofillHostMsg_TextFieldDidChange, |
| 229 OnTextFieldDidChange) | 234 OnTextFieldDidChange) |
| 230 IPC_MESSAGE_HANDLER(AutofillHostMsg_QueryFormFieldAutofill, | 235 IPC_MESSAGE_HANDLER(AutofillHostMsg_QueryFormFieldAutofill, |
| 231 OnQueryFormFieldAutofill) | 236 OnQueryFormFieldAutofill) |
| 232 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowAutofillDialog, | 237 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowAutofillDialog, |
| 233 OnShowAutofillDialog) | 238 OnShowAutofillDialog) |
| 234 IPC_MESSAGE_HANDLER(AutofillHostMsg_FillAutofillFormData, | 239 IPC_MESSAGE_HANDLER(AutofillHostMsg_FillAutofillFormData, |
| 235 OnFillAutofillFormData) | 240 OnFillAutofillFormData) |
| 236 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidPreviewAutofillFormData, | 241 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidPreviewAutofillFormData, |
| 237 OnDidPreviewAutofillFormData) | 242 OnDidPreviewAutofillFormData) |
| 238 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidFillAutofillFormData, | 243 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidFillAutofillFormData, |
| 239 OnDidFillAutofillFormData) | 244 OnDidFillAutofillFormData) |
| 240 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidShowAutofillSuggestions, | 245 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidShowAutofillSuggestions, |
| 241 OnDidShowAutofillSuggestions) | 246 OnDidShowAutofillSuggestions) |
| 242 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidEndTextFieldEditing, | 247 IPC_MESSAGE_HANDLER(AutofillHostMsg_DidEndTextFieldEditing, |
| 243 OnDidEndTextFieldEditing) | 248 OnDidEndTextFieldEditing) |
| 244 IPC_MESSAGE_HANDLER(AutofillHostMsg_HideAutofillPopup, | 249 IPC_MESSAGE_HANDLER(AutofillHostMsg_HideAutofillPopup, |
| 245 OnHideAutofillPopup) | 250 OnHideAutofillPopup) |
| 246 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, | 251 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordGenerationPopup, |
| 247 OnShowPasswordGenerationPopup) | 252 OnShowPasswordGenerationPopup) |
| 253 IPC_MESSAGE_HANDLER(AutofillHostMsg_AddPasswordFormMapping, |
| 254 OnAddPasswordFormMapping) |
| 255 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordSuggestions, |
| 256 OnShowPasswordSuggestions) |
| 248 IPC_MESSAGE_UNHANDLED(handled = false) | 257 IPC_MESSAGE_UNHANDLED(handled = false) |
| 249 IPC_END_MESSAGE_MAP() | 258 IPC_END_MESSAGE_MAP() |
| 250 | 259 |
| 251 return handled; | 260 return handled; |
| 252 } | 261 } |
| 253 | 262 |
| 254 bool AutofillManager::OnFormSubmitted(const FormData& form, | 263 bool AutofillManager::OnFormSubmitted(const FormData& form, |
| 255 const TimeTicks& timestamp) { | 264 const TimeTicks& timestamp) { |
| 256 // Let AutoComplete know as well. | 265 // Let AutoComplete know as well. |
| 257 tab_contents_wrapper_->autocomplete_history_manager()->OnFormSubmitted(form); | 266 tab_contents_wrapper_->autocomplete_history_manager()->OnFormSubmitted(form); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 void AutofillManager::OnShowPasswordGenerationPopup(const gfx::Rect& bounds) { | 634 void AutofillManager::OnShowPasswordGenerationPopup(const gfx::Rect& bounds) { |
| 626 #if defined(OS_ANDROID) | 635 #if defined(OS_ANDROID) |
| 627 NOTIMPLEMENTED(); | 636 NOTIMPLEMENTED(); |
| 628 #else | 637 #else |
| 629 Browser* browser = BrowserList::GetLastActiveWithProfile( | 638 Browser* browser = BrowserList::GetLastActiveWithProfile( |
| 630 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); | 639 Profile::FromBrowserContext(web_contents()->GetBrowserContext())); |
| 631 browser->window()->ShowPasswordGenerationBubble(bounds); | 640 browser->window()->ShowPasswordGenerationBubble(bounds); |
| 632 #endif // #if defined(OS_ANDROID) | 641 #endif // #if defined(OS_ANDROID) |
| 633 } | 642 } |
| 634 | 643 |
| 644 void AutofillManager::OnAddPasswordFormMapping( |
| 645 const webkit::forms::FormField& form, |
| 646 const webkit::forms::PasswordFormFillData& fill_data) { |
| 647 if (external_delegate_) |
| 648 external_delegate_->AddPasswordFormMapping(form, fill_data); |
| 649 } |
| 650 |
| 651 void AutofillManager::OnShowPasswordSuggestions( |
| 652 const webkit::forms::FormField& field, |
| 653 const gfx::Rect& bounds, |
| 654 const std::vector<string16>& suggestions) { |
| 655 if (external_delegate_) |
| 656 external_delegate_->OnShowPasswordSuggestions(suggestions, field, bounds); |
| 657 } |
| 658 |
| 635 void AutofillManager::OnLoadedServerPredictions( | 659 void AutofillManager::OnLoadedServerPredictions( |
| 636 const std::string& response_xml) { | 660 const std::string& response_xml) { |
| 637 // Parse and store the server predictions. | 661 // Parse and store the server predictions. |
| 638 FormStructure::ParseQueryResponse(response_xml, | 662 FormStructure::ParseQueryResponse(response_xml, |
| 639 form_structures_.get(), | 663 form_structures_.get(), |
| 640 *metric_logger_); | 664 *metric_logger_); |
| 641 | 665 |
| 642 // If the corresponding flag is set, annotate forms with the predicted types. | 666 // If the corresponding flag is set, annotate forms with the predicted types. |
| 643 SendAutofillTypePredictions(form_structures_.get()); | 667 SendAutofillTypePredictions(form_structures_.get()); |
| 644 } | 668 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 void AutofillManager::Reset() { | 757 void AutofillManager::Reset() { |
| 734 form_structures_.reset(); | 758 form_structures_.reset(); |
| 735 has_logged_autofill_enabled_ = false; | 759 has_logged_autofill_enabled_ = false; |
| 736 has_logged_address_suggestions_count_ = false; | 760 has_logged_address_suggestions_count_ = false; |
| 737 did_show_suggestions_ = false; | 761 did_show_suggestions_ = false; |
| 738 user_did_type_ = false; | 762 user_did_type_ = false; |
| 739 user_did_autofill_ = false; | 763 user_did_autofill_ = false; |
| 740 user_did_edit_autofilled_field_ = false; | 764 user_did_edit_autofilled_field_ = false; |
| 741 forms_loaded_timestamp_ = TimeTicks(); | 765 forms_loaded_timestamp_ = TimeTicks(); |
| 742 initial_interaction_timestamp_ = TimeTicks(); | 766 initial_interaction_timestamp_ = TimeTicks(); |
| 767 |
| 768 if (external_delegate_) |
| 769 external_delegate_->Reset(); |
| 743 } | 770 } |
| 744 | 771 |
| 745 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents, | 772 AutofillManager::AutofillManager(TabContentsWrapper* tab_contents, |
| 746 PersonalDataManager* personal_data) | 773 PersonalDataManager* personal_data) |
| 747 : content::WebContentsObserver(tab_contents->web_contents()), | 774 : content::WebContentsObserver(tab_contents->web_contents()), |
| 748 tab_contents_wrapper_(tab_contents), | 775 tab_contents_wrapper_(tab_contents), |
| 749 personal_data_(personal_data), | 776 personal_data_(personal_data), |
| 750 download_manager_(tab_contents->profile(), this), | 777 download_manager_(tab_contents->profile(), this), |
| 751 disable_download_manager_requests_(true), | 778 disable_download_manager_requests_(true), |
| 752 metric_logger_(new AutofillMetrics), | 779 metric_logger_(new AutofillMetrics), |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 *profile_guid = IDToGUID(profile_id); | 1269 *profile_guid = IDToGUID(profile_id); |
| 1243 } | 1270 } |
| 1244 | 1271 |
| 1245 void AutofillManager::UpdateInitialInteractionTimestamp( | 1272 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1246 const TimeTicks& interaction_timestamp) { | 1273 const TimeTicks& interaction_timestamp) { |
| 1247 if (initial_interaction_timestamp_.is_null() || | 1274 if (initial_interaction_timestamp_.is_null() || |
| 1248 interaction_timestamp < initial_interaction_timestamp_) { | 1275 interaction_timestamp < initial_interaction_timestamp_) { |
| 1249 initial_interaction_timestamp_ = interaction_timestamp; | 1276 initial_interaction_timestamp_ = interaction_timestamp; |
| 1250 } | 1277 } |
| 1251 } | 1278 } |
| OLD | NEW |