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 "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> |
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/browser/autocheckout/whitelist_manager.h" | 23 #include "components/autofill/browser/autocheckout/whitelist_manager.h" |
24 #include "components/autofill/browser/autocheckout_manager.h" | 24 #include "components/autofill/browser/autocheckout_manager.h" |
25 #include "components/autofill/browser/autocomplete_history_manager.h" | 25 #include "components/autofill/browser/autocomplete_history_manager.h" |
26 #include "components/autofill/browser/autofill_data_model.h" | 26 #include "components/autofill/browser/autofill_data_model.h" |
| 27 #include "components/autofill/browser/autofill_driver.h" |
27 #include "components/autofill/browser/autofill_external_delegate.h" | 28 #include "components/autofill/browser/autofill_external_delegate.h" |
28 #include "components/autofill/browser/autofill_field.h" | 29 #include "components/autofill/browser/autofill_field.h" |
29 #include "components/autofill/browser/autofill_manager_delegate.h" | 30 #include "components/autofill/browser/autofill_manager_delegate.h" |
30 #include "components/autofill/browser/autofill_manager_test_delegate.h" | 31 #include "components/autofill/browser/autofill_manager_test_delegate.h" |
31 #include "components/autofill/browser/autofill_metrics.h" | 32 #include "components/autofill/browser/autofill_metrics.h" |
32 #include "components/autofill/browser/autofill_profile.h" | 33 #include "components/autofill/browser/autofill_profile.h" |
33 #include "components/autofill/browser/autofill_type.h" | 34 #include "components/autofill/browser/autofill_type.h" |
34 #include "components/autofill/browser/credit_card.h" | 35 #include "components/autofill/browser/credit_card.h" |
35 #include "components/autofill/browser/form_structure.h" | 36 #include "components/autofill/browser/form_structure.h" |
36 #include "components/autofill/browser/personal_data_manager.h" | 37 #include "components/autofill/browser/personal_data_manager.h" |
37 #include "components/autofill/browser/phone_number.h" | 38 #include "components/autofill/browser/phone_number.h" |
38 #include "components/autofill/browser/phone_number_i18n.h" | 39 #include "components/autofill/browser/phone_number_i18n.h" |
39 #include "components/autofill/common/autofill_messages.h" | 40 #include "components/autofill/common/autofill_messages.h" |
40 #include "components/autofill/common/autofill_pref_names.h" | 41 #include "components/autofill/common/autofill_pref_names.h" |
41 #include "components/autofill/common/autofill_switches.h" | 42 #include "components/autofill/common/autofill_switches.h" |
42 #include "components/autofill/common/form_data.h" | 43 #include "components/autofill/common/form_data.h" |
43 #include "components/autofill/common/form_data_predictions.h" | 44 #include "components/autofill/common/form_data_predictions.h" |
44 #include "components/autofill/common/form_field_data.h" | 45 #include "components/autofill/common/form_field_data.h" |
45 #include "components/autofill/common/password_form_fill_data.h" | 46 #include "components/autofill/common/password_form_fill_data.h" |
46 #include "components/user_prefs/pref_registry_syncable.h" | 47 #include "components/user_prefs/pref_registry_syncable.h" |
47 #include "content/public/browser/browser_context.h" | 48 #include "content/public/browser/browser_context.h" |
48 #include "content/public/browser/browser_thread.h" | 49 #include "content/public/browser/browser_thread.h" |
49 #include "content/public/browser/navigation_details.h" | 50 #include "content/public/browser/navigation_details.h" |
50 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
51 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
52 #include "content/public/browser/web_contents_view.h" | 53 #include "content/public/browser/web_contents_view.h" |
| 54 #include "content/public/common/frame_navigate_params.h" |
53 #include "content/public/common/url_constants.h" | 55 #include "content/public/common/url_constants.h" |
54 #include "googleurl/src/gurl.h" | 56 #include "googleurl/src/gurl.h" |
55 #include "grit/component_resources.h" | 57 #include "grit/component_resources.h" |
56 #include "ipc/ipc_message_macros.h" | 58 #include "ipc/ipc_message_macros.h" |
57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 59 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
58 #include "ui/base/l10n/l10n_util.h" | 60 #include "ui/base/l10n/l10n_util.h" |
59 #include "ui/gfx/rect.h" | 61 #include "ui/gfx/rect.h" |
60 | 62 |
61 namespace autofill { | 63 namespace autofill { |
62 | 64 |
63 typedef PersonalDataManager::GUIDPair GUIDPair; | 65 typedef PersonalDataManager::GUIDPair GUIDPair; |
64 | 66 |
65 using base::TimeTicks; | 67 using base::TimeTicks; |
66 using content::BrowserThread; | 68 using content::BrowserThread; |
67 using content::RenderViewHost; | 69 using content::RenderViewHost; |
68 using WebKit::WebFormElement; | 70 using WebKit::WebFormElement; |
69 | 71 |
70 namespace { | 72 namespace { |
71 | 73 |
72 const char* kAutofillManagerWebContentsUserDataKey = "web_contents_autofill"; | |
73 | |
74 // We only send a fraction of the forms to upload server. | 74 // We only send a fraction of the forms to upload server. |
75 // The rate for positive/negative matches potentially could be different. | 75 // The rate for positive/negative matches potentially could be different. |
76 const double kAutofillPositiveUploadRateDefaultValue = 0.20; | 76 const double kAutofillPositiveUploadRateDefaultValue = 0.20; |
77 const double kAutofillNegativeUploadRateDefaultValue = 0.20; | 77 const double kAutofillNegativeUploadRateDefaultValue = 0.20; |
78 | 78 |
79 const size_t kMaxRecentFormSignaturesToRemember = 3; | 79 const size_t kMaxRecentFormSignaturesToRemember = 3; |
80 | 80 |
81 // Set a conservative upper bound on the number of forms we are willing to | 81 // Set a conservative upper bound on the number of forms we are willing to |
82 // cache, simply to prevent unbounded memory consumption. | 82 // cache, simply to prevent unbounded memory consumption. |
83 const size_t kMaxFormCacheSize = 100; | 83 const size_t kMaxFormCacheSize = 100; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 bool HasServerSpecifiedFieldTypes(const FormStructure& form_structure) { | 175 bool HasServerSpecifiedFieldTypes(const FormStructure& form_structure) { |
176 for (size_t i = 0; i < form_structure.field_count(); ++i) { | 176 for (size_t i = 0; i < form_structure.field_count(); ++i) { |
177 if (form_structure.field(i)->server_type() != NO_SERVER_DATA) | 177 if (form_structure.field(i)->server_type() != NO_SERVER_DATA) |
178 return true; | 178 return true; |
179 } | 179 } |
180 return false; | 180 return false; |
181 } | 181 } |
182 | 182 |
183 } // namespace | 183 } // namespace |
184 | 184 |
185 // static | |
186 void AutofillManager::CreateForWebContentsAndDelegate( | |
187 content::WebContents* contents, | |
188 autofill::AutofillManagerDelegate* delegate, | |
189 const std::string& app_locale, | |
190 AutofillDownloadManagerState enable_download_manager) { | |
191 if (FromWebContents(contents)) | |
192 return; | |
193 | |
194 contents->SetUserData( | |
195 kAutofillManagerWebContentsUserDataKey, | |
196 new AutofillManager( | |
197 contents, delegate, app_locale, enable_download_manager)); | |
198 | |
199 // Trigger the lazy creation of AutocheckoutWhitelistManagerService, and | |
200 // schedule a fetch of the Autocheckout whitelist file if it's not already | |
201 // loaded. This helps ensure that the whitelist will be available by the time | |
202 // the user navigates to a form on which Autocheckout should be enabled. | |
203 delegate->GetAutocheckoutWhitelistManager(); | |
204 } | |
205 | |
206 // static | |
207 AutofillManager* AutofillManager::FromWebContents( | |
208 content::WebContents* contents) { | |
209 return static_cast<AutofillManager*>( | |
210 contents->GetUserData(kAutofillManagerWebContentsUserDataKey)); | |
211 } | |
212 | |
213 AutofillManager::AutofillManager( | 185 AutofillManager::AutofillManager( |
214 content::WebContents* web_contents, | 186 AutofillDriver* driver, |
215 autofill::AutofillManagerDelegate* delegate, | 187 autofill::AutofillManagerDelegate* delegate, |
216 const std::string& app_locale, | 188 const std::string& app_locale, |
217 AutofillDownloadManagerState enable_download_manager) | 189 AutofillDownloadManagerState enable_download_manager) |
218 : content::WebContentsObserver(web_contents), | 190 : driver_(driver), |
219 manager_delegate_(delegate), | 191 manager_delegate_(delegate), |
220 app_locale_(app_locale), | 192 app_locale_(app_locale), |
221 personal_data_(delegate->GetPersonalDataManager()), | 193 personal_data_(delegate->GetPersonalDataManager()), |
222 autocomplete_history_manager_(web_contents), | 194 autocomplete_history_manager_(driver), |
223 autocheckout_manager_(this), | 195 autocheckout_manager_(this), |
224 metric_logger_(new AutofillMetrics), | 196 metric_logger_(new AutofillMetrics), |
225 has_logged_autofill_enabled_(false), | 197 has_logged_autofill_enabled_(false), |
226 has_logged_address_suggestions_count_(false), | 198 has_logged_address_suggestions_count_(false), |
227 did_show_suggestions_(false), | 199 did_show_suggestions_(false), |
228 user_did_type_(false), | 200 user_did_type_(false), |
229 user_did_autofill_(false), | 201 user_did_autofill_(false), |
230 user_did_edit_autofilled_field_(false), | 202 user_did_edit_autofilled_field_(false), |
231 external_delegate_(NULL), | 203 external_delegate_(NULL), |
232 test_delegate_(NULL), | 204 test_delegate_(NULL), |
233 weak_ptr_factory_(this) { | 205 weak_ptr_factory_(this) { |
234 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { | 206 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { |
235 download_manager_.reset( | 207 download_manager_.reset( |
236 new AutofillDownloadManager(web_contents->GetBrowserContext(), this)); | 208 new AutofillDownloadManager( |
| 209 driver->GetWebContents()->GetBrowserContext(), this)); |
237 } | 210 } |
238 } | 211 } |
239 | 212 |
240 AutofillManager::~AutofillManager() {} | 213 AutofillManager::~AutofillManager() {} |
241 | 214 |
242 // static | 215 // static |
243 void AutofillManager::RegisterUserPrefs( | 216 void AutofillManager::RegisterUserPrefs( |
244 user_prefs::PrefRegistrySyncable* registry) { | 217 user_prefs::PrefRegistrySyncable* registry) { |
245 registry->RegisterBooleanPref( | 218 registry->RegisterBooleanPref( |
246 prefs::kAutofillEnabled, | 219 prefs::kAutofillEnabled, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordSuggestions, | 287 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordSuggestions, |
315 OnShowPasswordSuggestions) | 288 OnShowPasswordSuggestions) |
316 IPC_MESSAGE_HANDLER(AutofillHostMsg_SetDataList, | 289 IPC_MESSAGE_HANDLER(AutofillHostMsg_SetDataList, |
317 OnSetDataList) | 290 OnSetDataList) |
318 IPC_MESSAGE_HANDLER(AutofillHostMsg_RequestAutocomplete, | 291 IPC_MESSAGE_HANDLER(AutofillHostMsg_RequestAutocomplete, |
319 OnRequestAutocomplete) | 292 OnRequestAutocomplete) |
320 IPC_MESSAGE_HANDLER(AutofillHostMsg_ClickFailed, | 293 IPC_MESSAGE_HANDLER(AutofillHostMsg_ClickFailed, |
321 OnClickFailed) | 294 OnClickFailed) |
322 IPC_MESSAGE_HANDLER(AutofillHostMsg_MaybeShowAutocheckoutBubble, | 295 IPC_MESSAGE_HANDLER(AutofillHostMsg_MaybeShowAutocheckoutBubble, |
323 OnMaybeShowAutocheckoutBubble) | 296 OnMaybeShowAutocheckoutBubble) |
| 297 IPC_MESSAGE_HANDLER(AutofillHostMsg_RemoveAutocompleteEntry, |
| 298 RemoveAutocompleteEntry) |
324 IPC_MESSAGE_UNHANDLED(handled = false) | 299 IPC_MESSAGE_UNHANDLED(handled = false) |
325 IPC_END_MESSAGE_MAP() | 300 IPC_END_MESSAGE_MAP() |
326 | 301 |
327 return handled; | 302 return handled; |
328 } | 303 } |
329 | 304 |
330 bool AutofillManager::OnFormSubmitted(const FormData& form, | 305 bool AutofillManager::OnFormSubmitted(const FormData& form, |
331 const TimeTicks& timestamp) { | 306 const TimeTicks& timestamp) { |
332 // Let AutoComplete know as well. | 307 // Let AutoComplete know as well. |
333 autocomplete_history_manager_.OnFormSubmitted(form); | 308 autocomplete_history_manager_.OnFormSubmitted(form); |
334 | 309 |
335 if (!IsAutofillEnabled()) | 310 if (!IsAutofillEnabled()) |
336 return false; | 311 return false; |
337 | 312 |
338 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) | 313 if (driver_->GetWebContents()->GetBrowserContext()->IsOffTheRecord()) |
339 return false; | 314 return false; |
340 | 315 |
341 // Don't save data that was submitted through JavaScript. | 316 // Don't save data that was submitted through JavaScript. |
342 if (!form.user_submitted) | 317 if (!form.user_submitted) |
343 return false; | 318 return false; |
344 | 319 |
345 // Grab a copy of the form data. | 320 // Grab a copy of the form data. |
346 scoped_ptr<FormStructure> submitted_form( | 321 scoped_ptr<FormStructure> submitted_form( |
347 new FormStructure(form, GetAutocheckoutURLPrefix())); | 322 new FormStructure(form, GetAutocheckoutURLPrefix())); |
348 | 323 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 382 |
408 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, | 383 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, |
409 const TimeTicks& timestamp, | 384 const TimeTicks& timestamp, |
410 autofill::FormsSeenState state) { | 385 autofill::FormsSeenState state) { |
411 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; | 386 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; |
412 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN; | 387 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN; |
413 // If new forms were added via AJAX or DHML, treat as new page. | 388 // If new forms were added via AJAX or DHML, treat as new page. |
414 if (is_post_document_load) | 389 if (is_post_document_load) |
415 Reset(); | 390 Reset(); |
416 | 391 |
417 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 392 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); |
418 if (!host) | 393 if (!host) |
419 return; | 394 return; |
420 | 395 |
421 if (!GetAutocheckoutURLPrefix().empty()) { | 396 if (!GetAutocheckoutURLPrefix().empty()) { |
422 // If whitelisted URL, fetch all the forms. | 397 // If whitelisted URL, fetch all the forms. |
423 if (has_more_forms) | 398 if (has_more_forms) |
424 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID())); | 399 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID())); |
425 if (!is_post_document_load) { | 400 if (!is_post_document_load) { |
426 host->Send( | 401 host->Send( |
427 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); | 402 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 | 690 |
716 personal_data_->RemoveByGUID(data_model->guid()); | 691 personal_data_->RemoveByGUID(data_model->guid()); |
717 } | 692 } |
718 | 693 |
719 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, | 694 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, |
720 const base::string16& value) { | 695 const base::string16& value) { |
721 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value); | 696 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value); |
722 } | 697 } |
723 | 698 |
724 content::WebContents* AutofillManager::GetWebContents() const { | 699 content::WebContents* AutofillManager::GetWebContents() const { |
725 return web_contents(); | 700 return driver_->GetWebContents(); |
726 } | 701 } |
727 | 702 |
728 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { | 703 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { |
729 return form_structures_.get(); | 704 return form_structures_.get(); |
730 } | 705 } |
731 | 706 |
732 void AutofillManager::ShowRequestAutocompleteDialog( | 707 void AutofillManager::ShowRequestAutocompleteDialog( |
733 const FormData& form, | 708 const FormData& form, |
734 const GURL& source_url, | 709 const GURL& source_url, |
735 autofill::DialogType dialog_type, | 710 autofill::DialogType dialog_type, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 | 762 |
788 base::Callback<void(const FormStructure*, const std::string&)> callback = | 763 base::Callback<void(const FormStructure*, const std::string&)> callback = |
789 base::Bind(&AutofillManager::ReturnAutocompleteData, | 764 base::Bind(&AutofillManager::ReturnAutocompleteData, |
790 weak_ptr_factory_.GetWeakPtr()); | 765 weak_ptr_factory_.GetWeakPtr()); |
791 ShowRequestAutocompleteDialog( | 766 ShowRequestAutocompleteDialog( |
792 form, frame_url, autofill::DIALOG_TYPE_REQUEST_AUTOCOMPLETE, callback); | 767 form, frame_url, autofill::DIALOG_TYPE_REQUEST_AUTOCOMPLETE, callback); |
793 } | 768 } |
794 | 769 |
795 void AutofillManager::ReturnAutocompleteResult( | 770 void AutofillManager::ReturnAutocompleteResult( |
796 WebFormElement::AutocompleteResult result, const FormData& form_data) { | 771 WebFormElement::AutocompleteResult result, const FormData& form_data) { |
797 // web_contents() will be NULL when the interactive autocomplete is closed due | 772 // driver_->GetWebContents() will be NULL when the interactive autocomplete |
798 // to a tab or browser window closing. | 773 // is closed due to a tab or browser window closing. |
799 if (!web_contents()) | 774 if (!driver_->GetWebContents()) |
800 return; | 775 return; |
801 | 776 |
802 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 777 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); |
803 if (!host) | 778 if (!host) |
804 return; | 779 return; |
805 | 780 |
806 host->Send(new AutofillMsg_RequestAutocompleteResult(host->GetRoutingID(), | 781 host->Send(new AutofillMsg_RequestAutocompleteResult(host->GetRoutingID(), |
807 result, | 782 result, |
808 form_data)); | 783 form_data)); |
809 } | 784 } |
810 | 785 |
811 void AutofillManager::ReturnAutocompleteData( | 786 void AutofillManager::ReturnAutocompleteData( |
812 const FormStructure* result, | 787 const FormStructure* result, |
(...skipping 12 matching lines...) Expand all Loading... |
825 scoped_ptr<autofill::AutocheckoutPageMetaData> page_meta_data( | 800 scoped_ptr<autofill::AutocheckoutPageMetaData> page_meta_data( |
826 new autofill::AutocheckoutPageMetaData()); | 801 new autofill::AutocheckoutPageMetaData()); |
827 | 802 |
828 // Parse and store the server predictions. | 803 // Parse and store the server predictions. |
829 FormStructure::ParseQueryResponse(response_xml, | 804 FormStructure::ParseQueryResponse(response_xml, |
830 form_structures_.get(), | 805 form_structures_.get(), |
831 page_meta_data.get(), | 806 page_meta_data.get(), |
832 *metric_logger_); | 807 *metric_logger_); |
833 | 808 |
834 if (page_meta_data->IsInAutofillableFlow()) { | 809 if (page_meta_data->IsInAutofillableFlow()) { |
835 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 810 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); |
836 if (host) | 811 if (host) |
837 host->Send(new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); | 812 host->Send(new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); |
838 } | 813 } |
839 | 814 |
840 // TODO(ahutter): Remove this once Autocheckout is implemented on other | 815 // TODO(ahutter): Remove this once Autocheckout is implemented on other |
841 // platforms. See http://crbug.com/173416. | 816 // platforms. See http://crbug.com/173416. |
842 #if defined(TOOLKIT_VIEWS) | 817 #if defined(TOOLKIT_VIEWS) |
843 if (!GetAutocheckoutURLPrefix().empty()) | 818 if (!GetAutocheckoutURLPrefix().empty()) |
844 autocheckout_manager_.OnLoadedPageMetaData(page_meta_data.Pass()); | 819 autocheckout_manager_.OnLoadedPageMetaData(page_meta_data.Pass()); |
845 #endif // #if defined(TOOLKIT_VIEWS) | 820 #endif // #if defined(TOOLKIT_VIEWS) |
846 | 821 |
847 // If the corresponding flag is set, annotate forms with the predicted types. | 822 // If the corresponding flag is set, annotate forms with the predicted types. |
848 SendAutofillTypePredictions(form_structures_.get()); | 823 SendAutofillTypePredictions(form_structures_.get()); |
849 } | 824 } |
850 | 825 |
851 void AutofillManager::OnDidEndTextFieldEditing() { | 826 void AutofillManager::OnDidEndTextFieldEditing() { |
852 if (external_delegate_) | 827 if (external_delegate_) |
853 external_delegate_->DidEndTextFieldEditing(); | 828 external_delegate_->DidEndTextFieldEditing(); |
854 } | 829 } |
855 | 830 |
856 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { | 831 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { |
857 autocheckout_manager_.OnClickFailed(status); | 832 autocheckout_manager_.OnClickFailed(status); |
858 } | 833 } |
859 | 834 |
860 std::string AutofillManager::GetAutocheckoutURLPrefix() const { | 835 std::string AutofillManager::GetAutocheckoutURLPrefix() const { |
861 if (!web_contents()) | 836 if (!driver_->GetWebContents()) |
862 return std::string(); | 837 return std::string(); |
863 | 838 |
864 autofill::autocheckout::WhitelistManager* whitelist_manager = | 839 autofill::autocheckout::WhitelistManager* whitelist_manager = |
865 manager_delegate_->GetAutocheckoutWhitelistManager(); | 840 manager_delegate_->GetAutocheckoutWhitelistManager(); |
866 | 841 |
867 return whitelist_manager->GetMatchedURLPrefix(web_contents()->GetURL()); | 842 return whitelist_manager->GetMatchedURLPrefix( |
| 843 driver_->GetWebContents()->GetURL()); |
868 } | 844 } |
869 | 845 |
870 bool AutofillManager::IsAutofillEnabled() const { | 846 bool AutofillManager::IsAutofillEnabled() const { |
871 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 847 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
872 } | 848 } |
873 | 849 |
874 void AutofillManager::SendAutofillTypePredictions( | 850 void AutofillManager::SendAutofillTypePredictions( |
875 const std::vector<FormStructure*>& forms) const { | 851 const std::vector<FormStructure*>& forms) const { |
876 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 852 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
877 switches::kShowAutofillTypePredictions)) | 853 switches::kShowAutofillTypePredictions)) |
878 return; | 854 return; |
879 | 855 |
880 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 856 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); |
881 if (!host) | 857 if (!host) |
882 return; | 858 return; |
883 | 859 |
884 std::vector<FormDataPredictions> type_predictions; | 860 std::vector<FormDataPredictions> type_predictions; |
885 FormStructure::GetFieldTypePredictions(forms, &type_predictions); | 861 FormStructure::GetFieldTypePredictions(forms, &type_predictions); |
886 host->Send( | 862 host->Send( |
887 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), | 863 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), |
888 type_predictions)); | 864 type_predictions)); |
889 } | 865 } |
890 | 866 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 user_did_type_ = false; | 951 user_did_type_ = false; |
976 user_did_autofill_ = false; | 952 user_did_autofill_ = false; |
977 user_did_edit_autofilled_field_ = false; | 953 user_did_edit_autofilled_field_ = false; |
978 forms_loaded_timestamp_ = TimeTicks(); | 954 forms_loaded_timestamp_ = TimeTicks(); |
979 initial_interaction_timestamp_ = TimeTicks(); | 955 initial_interaction_timestamp_ = TimeTicks(); |
980 | 956 |
981 if (external_delegate_) | 957 if (external_delegate_) |
982 external_delegate_->Reset(); | 958 external_delegate_->Reset(); |
983 } | 959 } |
984 | 960 |
985 AutofillManager::AutofillManager(content::WebContents* web_contents, | 961 AutofillManager::AutofillManager(AutofillDriver* driver, |
986 autofill::AutofillManagerDelegate* delegate, | 962 autofill::AutofillManagerDelegate* delegate, |
987 PersonalDataManager* personal_data) | 963 PersonalDataManager* personal_data) |
988 : content::WebContentsObserver(web_contents), | 964 : driver_(driver), |
989 manager_delegate_(delegate), | 965 manager_delegate_(delegate), |
990 app_locale_("en-US"), | 966 app_locale_("en-US"), |
991 personal_data_(personal_data), | 967 personal_data_(personal_data), |
992 autocomplete_history_manager_(web_contents), | 968 autocomplete_history_manager_(driver), |
993 autocheckout_manager_(this), | 969 autocheckout_manager_(this), |
994 metric_logger_(new AutofillMetrics), | 970 metric_logger_(new AutofillMetrics), |
995 has_logged_autofill_enabled_(false), | 971 has_logged_autofill_enabled_(false), |
996 has_logged_address_suggestions_count_(false), | 972 has_logged_address_suggestions_count_(false), |
997 did_show_suggestions_(false), | 973 did_show_suggestions_(false), |
998 user_did_type_(false), | 974 user_did_type_(false), |
999 user_did_autofill_(false), | 975 user_did_autofill_(false), |
1000 user_did_edit_autofilled_field_(false), | 976 user_did_edit_autofilled_field_(false), |
1001 external_delegate_(NULL), | 977 external_delegate_(NULL), |
1002 test_delegate_(NULL), | 978 test_delegate_(NULL), |
1003 weak_ptr_factory_(this) { | 979 weak_ptr_factory_(this) { |
1004 DCHECK(web_contents); | 980 DCHECK(driver_); |
| 981 DCHECK(driver_->GetWebContents()); |
1005 DCHECK(manager_delegate_); | 982 DCHECK(manager_delegate_); |
1006 } | 983 } |
1007 | 984 |
1008 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { | 985 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { |
1009 metric_logger_.reset(metric_logger); | 986 metric_logger_.reset(metric_logger); |
1010 } | 987 } |
1011 | 988 |
1012 bool AutofillManager::GetHost(RenderViewHost** host) const { | 989 bool AutofillManager::GetHost(RenderViewHost** host) const { |
1013 if (!IsAutofillEnabled()) | 990 if (!IsAutofillEnabled()) |
1014 return false; | 991 return false; |
1015 | 992 |
1016 // No autofill data to return if the profiles are empty. | 993 // No autofill data to return if the profiles are empty. |
1017 if (personal_data_->GetProfiles().empty() && | 994 if (personal_data_->GetProfiles().empty() && |
1018 personal_data_->GetCreditCards().empty()) { | 995 personal_data_->GetCreditCards().empty()) { |
1019 return false; | 996 return false; |
1020 } | 997 } |
1021 | 998 |
1022 *host = web_contents()->GetRenderViewHost(); | 999 *host = driver_->GetWebContents()->GetRenderViewHost(); |
1023 if (!*host) | 1000 if (!*host) |
1024 return false; | 1001 return false; |
1025 | 1002 |
1026 return true; | 1003 return true; |
1027 } | 1004 } |
1028 | 1005 |
1029 bool AutofillManager::GetProfileOrCreditCard( | 1006 bool AutofillManager::GetProfileOrCreditCard( |
1030 int unique_id, | 1007 int unique_id, |
1031 const AutofillDataModel** data_model, | 1008 const AutofillDataModel** data_model, |
1032 size_t* variant) const { | 1009 size_t* variant) const { |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 | 1293 |
1317 void AutofillManager::UpdateInitialInteractionTimestamp( | 1294 void AutofillManager::UpdateInitialInteractionTimestamp( |
1318 const TimeTicks& interaction_timestamp) { | 1295 const TimeTicks& interaction_timestamp) { |
1319 if (initial_interaction_timestamp_.is_null() || | 1296 if (initial_interaction_timestamp_.is_null() || |
1320 interaction_timestamp < initial_interaction_timestamp_) { | 1297 interaction_timestamp < initial_interaction_timestamp_) { |
1321 initial_interaction_timestamp_ = interaction_timestamp; | 1298 initial_interaction_timestamp_ = interaction_timestamp; |
1322 } | 1299 } |
1323 } | 1300 } |
1324 | 1301 |
1325 } // namespace autofill | 1302 } // namespace autofill |
OLD | NEW |