Chromium Code Reviews| 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 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 return true; | 180 return true; |
| 179 } | 181 } |
| 180 return false; | 182 return false; |
| 181 } | 183 } |
| 182 | 184 |
| 183 } // namespace | 185 } // namespace |
| 184 | 186 |
| 185 // static | 187 // static |
| 186 void AutofillManager::CreateForWebContentsAndDelegate( | 188 void AutofillManager::CreateForWebContentsAndDelegate( |
| 187 content::WebContents* contents, | 189 content::WebContents* contents, |
| 190 AutofillDriver* driver, | |
| 188 autofill::AutofillManagerDelegate* delegate, | 191 autofill::AutofillManagerDelegate* delegate, |
| 189 const std::string& app_locale, | 192 const std::string& app_locale, |
| 190 AutofillDownloadManagerState enable_download_manager) { | 193 AutofillDownloadManagerState enable_download_manager) { |
| 191 if (FromWebContents(contents)) | 194 if (FromWebContents(contents)) |
| 192 return; | 195 return; |
| 193 | 196 |
| 194 contents->SetUserData( | 197 contents->SetUserData( |
| 195 kAutofillManagerWebContentsUserDataKey, | 198 kAutofillManagerWebContentsUserDataKey, |
| 196 new AutofillManager( | 199 new AutofillManager( |
| 197 contents, delegate, app_locale, enable_download_manager)); | 200 driver, delegate, app_locale, enable_download_manager)); |
| 198 | 201 |
| 199 // Trigger the lazy creation of AutocheckoutWhitelistManagerService, and | 202 // Trigger the lazy creation of AutocheckoutWhitelistManagerService, and |
| 200 // schedule a fetch of the Autocheckout whitelist file if it's not already | 203 // 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 | 204 // 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. | 205 // the user navigates to a form on which Autocheckout should be enabled. |
| 203 delegate->GetAutocheckoutWhitelistManager(); | 206 delegate->GetAutocheckoutWhitelistManager(); |
|
Ilya Sherman
2013/06/14 02:44:37
Where does this happen now?
blundell
2013/06/14 09:54:08
Great catch, thanks. Moved to AutofillDriverImpl::
| |
| 204 } | 207 } |
| 205 | 208 |
| 206 // static | 209 // static |
| 207 AutofillManager* AutofillManager::FromWebContents( | 210 AutofillManager* AutofillManager::FromWebContents( |
| 208 content::WebContents* contents) { | 211 content::WebContents* contents) { |
| 209 return static_cast<AutofillManager*>( | 212 return static_cast<AutofillManager*>( |
| 210 contents->GetUserData(kAutofillManagerWebContentsUserDataKey)); | 213 contents->GetUserData(kAutofillManagerWebContentsUserDataKey)); |
| 211 } | 214 } |
| 212 | 215 |
| 213 AutofillManager::AutofillManager( | 216 AutofillManager::AutofillManager( |
| 214 content::WebContents* web_contents, | 217 AutofillDriver* driver, |
| 215 autofill::AutofillManagerDelegate* delegate, | 218 autofill::AutofillManagerDelegate* delegate, |
| 216 const std::string& app_locale, | 219 const std::string& app_locale, |
| 217 AutofillDownloadManagerState enable_download_manager) | 220 AutofillDownloadManagerState enable_download_manager) |
| 218 : content::WebContentsObserver(web_contents), | 221 : driver_(driver), |
| 219 manager_delegate_(delegate), | 222 manager_delegate_(delegate), |
| 220 app_locale_(app_locale), | 223 app_locale_(app_locale), |
| 221 personal_data_(delegate->GetPersonalDataManager()), | 224 personal_data_(delegate->GetPersonalDataManager()), |
| 222 autocomplete_history_manager_(web_contents), | 225 autocomplete_history_manager_(driver), |
| 223 autocheckout_manager_(this), | 226 autocheckout_manager_(this), |
| 224 metric_logger_(new AutofillMetrics), | 227 metric_logger_(new AutofillMetrics), |
| 225 has_logged_autofill_enabled_(false), | 228 has_logged_autofill_enabled_(false), |
| 226 has_logged_address_suggestions_count_(false), | 229 has_logged_address_suggestions_count_(false), |
| 227 did_show_suggestions_(false), | 230 did_show_suggestions_(false), |
| 228 user_did_type_(false), | 231 user_did_type_(false), |
| 229 user_did_autofill_(false), | 232 user_did_autofill_(false), |
| 230 user_did_edit_autofilled_field_(false), | 233 user_did_edit_autofilled_field_(false), |
| 231 external_delegate_(NULL), | 234 external_delegate_(NULL), |
| 232 test_delegate_(NULL), | 235 test_delegate_(NULL), |
| 233 weak_ptr_factory_(this) { | 236 weak_ptr_factory_(this) { |
| 234 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { | 237 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { |
| 235 download_manager_.reset( | 238 download_manager_.reset( |
| 236 new AutofillDownloadManager(web_contents->GetBrowserContext(), this)); | 239 new AutofillDownloadManager( |
| 240 driver->GetWebContents()->GetBrowserContext(), this)); | |
| 237 } | 241 } |
| 238 } | 242 } |
| 239 | 243 |
| 240 AutofillManager::~AutofillManager() {} | 244 AutofillManager::~AutofillManager() {} |
| 241 | 245 |
| 242 // static | 246 // static |
| 243 void AutofillManager::RegisterUserPrefs( | 247 void AutofillManager::RegisterUserPrefs( |
| 244 user_prefs::PrefRegistrySyncable* registry) { | 248 user_prefs::PrefRegistrySyncable* registry) { |
| 245 registry->RegisterBooleanPref( | 249 registry->RegisterBooleanPref( |
| 246 prefs::kAutofillEnabled, | 250 prefs::kAutofillEnabled, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordSuggestions, | 318 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordSuggestions, |
| 315 OnShowPasswordSuggestions) | 319 OnShowPasswordSuggestions) |
| 316 IPC_MESSAGE_HANDLER(AutofillHostMsg_SetDataList, | 320 IPC_MESSAGE_HANDLER(AutofillHostMsg_SetDataList, |
| 317 OnSetDataList) | 321 OnSetDataList) |
| 318 IPC_MESSAGE_HANDLER(AutofillHostMsg_RequestAutocomplete, | 322 IPC_MESSAGE_HANDLER(AutofillHostMsg_RequestAutocomplete, |
| 319 OnRequestAutocomplete) | 323 OnRequestAutocomplete) |
| 320 IPC_MESSAGE_HANDLER(AutofillHostMsg_ClickFailed, | 324 IPC_MESSAGE_HANDLER(AutofillHostMsg_ClickFailed, |
| 321 OnClickFailed) | 325 OnClickFailed) |
| 322 IPC_MESSAGE_HANDLER(AutofillHostMsg_MaybeShowAutocheckoutBubble, | 326 IPC_MESSAGE_HANDLER(AutofillHostMsg_MaybeShowAutocheckoutBubble, |
| 323 OnMaybeShowAutocheckoutBubble) | 327 OnMaybeShowAutocheckoutBubble) |
| 328 IPC_MESSAGE_HANDLER(AutofillHostMsg_RemoveAutocompleteEntry, | |
| 329 RemoveAutocompleteEntry) | |
| 324 IPC_MESSAGE_UNHANDLED(handled = false) | 330 IPC_MESSAGE_UNHANDLED(handled = false) |
| 325 IPC_END_MESSAGE_MAP() | 331 IPC_END_MESSAGE_MAP() |
| 326 | 332 |
| 327 return handled; | 333 return handled; |
| 328 } | 334 } |
| 329 | 335 |
| 330 bool AutofillManager::OnFormSubmitted(const FormData& form, | 336 bool AutofillManager::OnFormSubmitted(const FormData& form, |
| 331 const TimeTicks& timestamp) { | 337 const TimeTicks& timestamp) { |
| 332 // Let AutoComplete know as well. | 338 // Let AutoComplete know as well. |
| 333 autocomplete_history_manager_.OnFormSubmitted(form); | 339 autocomplete_history_manager_.OnFormSubmitted(form); |
| 334 | 340 |
| 335 if (!IsAutofillEnabled()) | 341 if (!IsAutofillEnabled()) |
| 336 return false; | 342 return false; |
| 337 | 343 |
| 338 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) | 344 if (driver_->GetWebContents()->GetBrowserContext()->IsOffTheRecord()) |
| 339 return false; | 345 return false; |
| 340 | 346 |
| 341 // Don't save data that was submitted through JavaScript. | 347 // Don't save data that was submitted through JavaScript. |
| 342 if (!form.user_submitted) | 348 if (!form.user_submitted) |
| 343 return false; | 349 return false; |
| 344 | 350 |
| 345 // Grab a copy of the form data. | 351 // Grab a copy of the form data. |
| 346 scoped_ptr<FormStructure> submitted_form( | 352 scoped_ptr<FormStructure> submitted_form( |
| 347 new FormStructure(form, GetAutocheckoutURLPrefix())); | 353 new FormStructure(form, GetAutocheckoutURLPrefix())); |
| 348 | 354 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 | 413 |
| 408 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, | 414 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, |
| 409 const TimeTicks& timestamp, | 415 const TimeTicks& timestamp, |
| 410 autofill::FormsSeenState state) { | 416 autofill::FormsSeenState state) { |
| 411 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; | 417 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; |
| 412 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN; | 418 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN; |
| 413 // If new forms were added via AJAX or DHML, treat as new page. | 419 // If new forms were added via AJAX or DHML, treat as new page. |
| 414 if (is_post_document_load) | 420 if (is_post_document_load) |
| 415 Reset(); | 421 Reset(); |
| 416 | 422 |
| 417 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 423 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); |
| 418 if (!host) | 424 if (!host) |
| 419 return; | 425 return; |
| 420 | 426 |
| 421 if (!GetAutocheckoutURLPrefix().empty()) { | 427 if (!GetAutocheckoutURLPrefix().empty()) { |
| 422 // If whitelisted URL, fetch all the forms. | 428 // If whitelisted URL, fetch all the forms. |
| 423 if (has_more_forms) | 429 if (has_more_forms) |
| 424 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID())); | 430 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID())); |
| 425 if (!is_post_document_load) { | 431 if (!is_post_document_load) { |
| 426 host->Send( | 432 host->Send( |
| 427 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); | 433 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 | 721 |
| 716 personal_data_->RemoveByGUID(data_model->guid()); | 722 personal_data_->RemoveByGUID(data_model->guid()); |
| 717 } | 723 } |
| 718 | 724 |
| 719 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, | 725 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, |
| 720 const base::string16& value) { | 726 const base::string16& value) { |
| 721 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value); | 727 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value); |
| 722 } | 728 } |
| 723 | 729 |
| 724 content::WebContents* AutofillManager::GetWebContents() const { | 730 content::WebContents* AutofillManager::GetWebContents() const { |
| 725 return web_contents(); | 731 return driver_->GetWebContents(); |
| 726 } | 732 } |
| 727 | 733 |
| 728 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { | 734 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { |
| 729 return form_structures_.get(); | 735 return form_structures_.get(); |
| 730 } | 736 } |
| 731 | 737 |
| 732 void AutofillManager::ShowRequestAutocompleteDialog( | 738 void AutofillManager::ShowRequestAutocompleteDialog( |
| 733 const FormData& form, | 739 const FormData& form, |
| 734 const GURL& source_url, | 740 const GURL& source_url, |
| 735 autofill::DialogType dialog_type, | 741 autofill::DialogType dialog_type, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 787 | 793 |
| 788 base::Callback<void(const FormStructure*, const std::string&)> callback = | 794 base::Callback<void(const FormStructure*, const std::string&)> callback = |
| 789 base::Bind(&AutofillManager::ReturnAutocompleteData, | 795 base::Bind(&AutofillManager::ReturnAutocompleteData, |
| 790 weak_ptr_factory_.GetWeakPtr()); | 796 weak_ptr_factory_.GetWeakPtr()); |
| 791 ShowRequestAutocompleteDialog( | 797 ShowRequestAutocompleteDialog( |
| 792 form, frame_url, autofill::DIALOG_TYPE_REQUEST_AUTOCOMPLETE, callback); | 798 form, frame_url, autofill::DIALOG_TYPE_REQUEST_AUTOCOMPLETE, callback); |
| 793 } | 799 } |
| 794 | 800 |
| 795 void AutofillManager::ReturnAutocompleteResult( | 801 void AutofillManager::ReturnAutocompleteResult( |
| 796 WebFormElement::AutocompleteResult result, const FormData& form_data) { | 802 WebFormElement::AutocompleteResult result, const FormData& form_data) { |
| 797 // web_contents() will be NULL when the interactive autocomplete is closed due | 803 // driver_->GetWebContents() will be NULL when the interactive autocomplete |
| 798 // to a tab or browser window closing. | 804 // is closed due to a tab or browser window closing. |
| 799 if (!web_contents()) | 805 if (!driver_->GetWebContents()) |
| 800 return; | 806 return; |
| 801 | 807 |
| 802 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 808 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); |
| 803 if (!host) | 809 if (!host) |
| 804 return; | 810 return; |
| 805 | 811 |
| 806 host->Send(new AutofillMsg_RequestAutocompleteResult(host->GetRoutingID(), | 812 host->Send(new AutofillMsg_RequestAutocompleteResult(host->GetRoutingID(), |
| 807 result, | 813 result, |
| 808 form_data)); | 814 form_data)); |
| 809 } | 815 } |
| 810 | 816 |
| 811 void AutofillManager::ReturnAutocompleteData( | 817 void AutofillManager::ReturnAutocompleteData( |
| 812 const FormStructure* result, | 818 const FormStructure* result, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 825 scoped_ptr<autofill::AutocheckoutPageMetaData> page_meta_data( | 831 scoped_ptr<autofill::AutocheckoutPageMetaData> page_meta_data( |
| 826 new autofill::AutocheckoutPageMetaData()); | 832 new autofill::AutocheckoutPageMetaData()); |
| 827 | 833 |
| 828 // Parse and store the server predictions. | 834 // Parse and store the server predictions. |
| 829 FormStructure::ParseQueryResponse(response_xml, | 835 FormStructure::ParseQueryResponse(response_xml, |
| 830 form_structures_.get(), | 836 form_structures_.get(), |
| 831 page_meta_data.get(), | 837 page_meta_data.get(), |
| 832 *metric_logger_); | 838 *metric_logger_); |
| 833 | 839 |
| 834 if (page_meta_data->IsInAutofillableFlow()) { | 840 if (page_meta_data->IsInAutofillableFlow()) { |
| 835 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 841 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); |
| 836 if (host) | 842 if (host) |
| 837 host->Send(new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); | 843 host->Send(new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); |
| 838 } | 844 } |
| 839 | 845 |
| 840 // TODO(ahutter): Remove this once Autocheckout is implemented on other | 846 // TODO(ahutter): Remove this once Autocheckout is implemented on other |
| 841 // platforms. See http://crbug.com/173416. | 847 // platforms. See http://crbug.com/173416. |
| 842 #if defined(TOOLKIT_VIEWS) | 848 #if defined(TOOLKIT_VIEWS) |
| 843 if (!GetAutocheckoutURLPrefix().empty()) | 849 if (!GetAutocheckoutURLPrefix().empty()) |
| 844 autocheckout_manager_.OnLoadedPageMetaData(page_meta_data.Pass()); | 850 autocheckout_manager_.OnLoadedPageMetaData(page_meta_data.Pass()); |
| 845 #endif // #if defined(TOOLKIT_VIEWS) | 851 #endif // #if defined(TOOLKIT_VIEWS) |
| 846 | 852 |
| 847 // If the corresponding flag is set, annotate forms with the predicted types. | 853 // If the corresponding flag is set, annotate forms with the predicted types. |
| 848 SendAutofillTypePredictions(form_structures_.get()); | 854 SendAutofillTypePredictions(form_structures_.get()); |
| 849 } | 855 } |
| 850 | 856 |
| 851 void AutofillManager::OnDidEndTextFieldEditing() { | 857 void AutofillManager::OnDidEndTextFieldEditing() { |
| 852 if (external_delegate_) | 858 if (external_delegate_) |
| 853 external_delegate_->DidEndTextFieldEditing(); | 859 external_delegate_->DidEndTextFieldEditing(); |
| 854 } | 860 } |
| 855 | 861 |
| 856 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { | 862 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { |
| 857 autocheckout_manager_.OnClickFailed(status); | 863 autocheckout_manager_.OnClickFailed(status); |
| 858 } | 864 } |
| 859 | 865 |
| 860 std::string AutofillManager::GetAutocheckoutURLPrefix() const { | 866 std::string AutofillManager::GetAutocheckoutURLPrefix() const { |
| 861 if (!web_contents()) | 867 if (!driver_->GetWebContents()) |
| 862 return std::string(); | 868 return std::string(); |
| 863 | 869 |
| 864 autofill::autocheckout::WhitelistManager* whitelist_manager = | 870 autofill::autocheckout::WhitelistManager* whitelist_manager = |
| 865 manager_delegate_->GetAutocheckoutWhitelistManager(); | 871 manager_delegate_->GetAutocheckoutWhitelistManager(); |
| 866 | 872 |
| 867 return whitelist_manager->GetMatchedURLPrefix(web_contents()->GetURL()); | 873 return whitelist_manager->GetMatchedURLPrefix( |
| 874 driver_->GetWebContents()->GetURL()); | |
| 868 } | 875 } |
| 869 | 876 |
| 870 bool AutofillManager::IsAutofillEnabled() const { | 877 bool AutofillManager::IsAutofillEnabled() const { |
| 871 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 878 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
| 872 } | 879 } |
| 873 | 880 |
| 874 void AutofillManager::SendAutofillTypePredictions( | 881 void AutofillManager::SendAutofillTypePredictions( |
| 875 const std::vector<FormStructure*>& forms) const { | 882 const std::vector<FormStructure*>& forms) const { |
| 876 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 883 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 877 switches::kShowAutofillTypePredictions)) | 884 switches::kShowAutofillTypePredictions)) |
| 878 return; | 885 return; |
| 879 | 886 |
| 880 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 887 RenderViewHost* host = driver_->GetWebContents()->GetRenderViewHost(); |
| 881 if (!host) | 888 if (!host) |
| 882 return; | 889 return; |
| 883 | 890 |
| 884 std::vector<FormDataPredictions> type_predictions; | 891 std::vector<FormDataPredictions> type_predictions; |
| 885 FormStructure::GetFieldTypePredictions(forms, &type_predictions); | 892 FormStructure::GetFieldTypePredictions(forms, &type_predictions); |
| 886 host->Send( | 893 host->Send( |
| 887 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), | 894 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), |
| 888 type_predictions)); | 895 type_predictions)); |
| 889 } | 896 } |
| 890 | 897 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 975 user_did_type_ = false; | 982 user_did_type_ = false; |
| 976 user_did_autofill_ = false; | 983 user_did_autofill_ = false; |
| 977 user_did_edit_autofilled_field_ = false; | 984 user_did_edit_autofilled_field_ = false; |
| 978 forms_loaded_timestamp_ = TimeTicks(); | 985 forms_loaded_timestamp_ = TimeTicks(); |
| 979 initial_interaction_timestamp_ = TimeTicks(); | 986 initial_interaction_timestamp_ = TimeTicks(); |
| 980 | 987 |
| 981 if (external_delegate_) | 988 if (external_delegate_) |
| 982 external_delegate_->Reset(); | 989 external_delegate_->Reset(); |
| 983 } | 990 } |
| 984 | 991 |
| 985 AutofillManager::AutofillManager(content::WebContents* web_contents, | 992 AutofillManager::AutofillManager(AutofillDriver* driver, |
| 986 autofill::AutofillManagerDelegate* delegate, | 993 autofill::AutofillManagerDelegate* delegate, |
| 987 PersonalDataManager* personal_data) | 994 PersonalDataManager* personal_data) |
| 988 : content::WebContentsObserver(web_contents), | 995 : driver_(driver), |
| 989 manager_delegate_(delegate), | 996 manager_delegate_(delegate), |
| 990 app_locale_("en-US"), | 997 app_locale_("en-US"), |
| 991 personal_data_(personal_data), | 998 personal_data_(personal_data), |
| 992 autocomplete_history_manager_(web_contents), | 999 autocomplete_history_manager_(driver), |
| 993 autocheckout_manager_(this), | 1000 autocheckout_manager_(this), |
| 994 metric_logger_(new AutofillMetrics), | 1001 metric_logger_(new AutofillMetrics), |
| 995 has_logged_autofill_enabled_(false), | 1002 has_logged_autofill_enabled_(false), |
| 996 has_logged_address_suggestions_count_(false), | 1003 has_logged_address_suggestions_count_(false), |
| 997 did_show_suggestions_(false), | 1004 did_show_suggestions_(false), |
| 998 user_did_type_(false), | 1005 user_did_type_(false), |
| 999 user_did_autofill_(false), | 1006 user_did_autofill_(false), |
| 1000 user_did_edit_autofilled_field_(false), | 1007 user_did_edit_autofilled_field_(false), |
| 1001 external_delegate_(NULL), | 1008 external_delegate_(NULL), |
| 1002 test_delegate_(NULL), | 1009 test_delegate_(NULL), |
| 1003 weak_ptr_factory_(this) { | 1010 weak_ptr_factory_(this) { |
| 1004 DCHECK(web_contents); | 1011 DCHECK(driver_); |
| 1012 DCHECK(driver_->GetWebContents()); | |
| 1005 DCHECK(manager_delegate_); | 1013 DCHECK(manager_delegate_); |
| 1006 } | 1014 } |
| 1007 | 1015 |
| 1008 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { | 1016 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { |
| 1009 metric_logger_.reset(metric_logger); | 1017 metric_logger_.reset(metric_logger); |
| 1010 } | 1018 } |
| 1011 | 1019 |
| 1012 bool AutofillManager::GetHost(RenderViewHost** host) const { | 1020 bool AutofillManager::GetHost(RenderViewHost** host) const { |
| 1013 if (!IsAutofillEnabled()) | 1021 if (!IsAutofillEnabled()) |
| 1014 return false; | 1022 return false; |
| 1015 | 1023 |
| 1016 // No autofill data to return if the profiles are empty. | 1024 // No autofill data to return if the profiles are empty. |
| 1017 if (personal_data_->GetProfiles().empty() && | 1025 if (personal_data_->GetProfiles().empty() && |
| 1018 personal_data_->GetCreditCards().empty()) { | 1026 personal_data_->GetCreditCards().empty()) { |
| 1019 return false; | 1027 return false; |
| 1020 } | 1028 } |
| 1021 | 1029 |
| 1022 *host = web_contents()->GetRenderViewHost(); | 1030 *host = driver_->GetWebContents()->GetRenderViewHost(); |
| 1023 if (!*host) | 1031 if (!*host) |
| 1024 return false; | 1032 return false; |
| 1025 | 1033 |
| 1026 return true; | 1034 return true; |
| 1027 } | 1035 } |
| 1028 | 1036 |
| 1029 bool AutofillManager::GetProfileOrCreditCard( | 1037 bool AutofillManager::GetProfileOrCreditCard( |
| 1030 int unique_id, | 1038 int unique_id, |
| 1031 const AutofillDataModel** data_model, | 1039 const AutofillDataModel** data_model, |
| 1032 size_t* variant) const { | 1040 size_t* variant) const { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 | 1324 |
| 1317 void AutofillManager::UpdateInitialInteractionTimestamp( | 1325 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1318 const TimeTicks& interaction_timestamp) { | 1326 const TimeTicks& interaction_timestamp) { |
| 1319 if (initial_interaction_timestamp_.is_null() || | 1327 if (initial_interaction_timestamp_.is_null() || |
| 1320 interaction_timestamp < initial_interaction_timestamp_) { | 1328 interaction_timestamp < initial_interaction_timestamp_) { |
| 1321 initial_interaction_timestamp_ = interaction_timestamp; | 1329 initial_interaction_timestamp_ = interaction_timestamp; |
| 1322 } | 1330 } |
| 1323 } | 1331 } |
| 1324 | 1332 |
| 1325 } // namespace autofill | 1333 } // namespace autofill |
| OLD | NEW |