chrome_autofill_client.h revision 6d86b77056ed63eb6871182f42a9fd5f07550f90
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_ 6#define CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_ 7 8#include "base/callback.h" 9#include "base/compiler_specific.h" 10#include "base/i18n/rtl.h" 11#include "base/memory/weak_ptr.h" 12#include "components/autofill/core/browser/autofill_client.h" 13#include "content/public/browser/web_contents_observer.h" 14#include "content/public/browser/web_contents_user_data.h" 15 16namespace content { 17struct FrameNavigateParams; 18struct LoadCommittedDetails; 19class WebContents; 20} 21 22namespace autofill { 23 24class AutofillDialogController; 25class AutofillKeystoneBridgeWrapper; 26class AutofillPopupControllerImpl; 27struct FormData; 28 29// Chrome implementation of AutofillClient. 30class ChromeAutofillClient 31 : public AutofillClient, 32 public content::WebContentsUserData<ChromeAutofillClient>, 33 public content::WebContentsObserver { 34 public: 35 virtual ~ChromeAutofillClient(); 36 37 // Called when the tab corresponding to |this| instance is activated. 38 void TabActivated(); 39 40 // AutofillClient: 41 virtual PersonalDataManager* GetPersonalDataManager() OVERRIDE; 42 virtual scoped_refptr<AutofillWebDataService> GetDatabase() OVERRIDE; 43 virtual PrefService* GetPrefs() OVERRIDE; 44 virtual void HideRequestAutocompleteDialog() OVERRIDE; 45 virtual void ShowAutofillSettings() OVERRIDE; 46 virtual void ConfirmSaveCreditCard( 47 const AutofillMetrics& metric_logger, 48 const base::Closure& save_card_callback) OVERRIDE; 49 virtual void ShowRequestAutocompleteDialog( 50 const FormData& form, 51 const GURL& source_url, 52 const ResultCallback& callback) OVERRIDE; 53 virtual void ShowAutofillPopup( 54 const gfx::RectF& element_bounds, 55 base::i18n::TextDirection text_direction, 56 const std::vector<base::string16>& values, 57 const std::vector<base::string16>& labels, 58 const std::vector<base::string16>& icons, 59 const std::vector<int>& identifiers, 60 base::WeakPtr<AutofillPopupDelegate> delegate) OVERRIDE; 61 virtual void UpdateAutofillPopupDataListValues( 62 const std::vector<base::string16>& values, 63 const std::vector<base::string16>& labels) OVERRIDE; 64 virtual void HideAutofillPopup() OVERRIDE; 65 virtual bool IsAutocompleteEnabled() OVERRIDE; 66 virtual void DetectAccountCreationForms( 67 const std::vector<autofill::FormStructure*>& forms) OVERRIDE; 68 virtual void DidFillOrPreviewField( 69 const base::string16& autofilled_value, 70 const base::string16& profile_full_name) OVERRIDE; 71 72 // content::WebContentsObserver implementation. 73 virtual void WebContentsDestroyed() OVERRIDE; 74 75 // Exposed for testing. 76 AutofillDialogController* GetDialogControllerForTesting() { 77 return dialog_controller_.get(); 78 } 79 void SetDialogControllerForTesting( 80 const base::WeakPtr<AutofillDialogController>& dialog_controller) { 81 dialog_controller_ = dialog_controller; 82 } 83 84 private: 85#if defined(OS_MACOSX) && !defined(OS_IOS) 86 // Creates |bridge_wrapper_|, which is responsible for dealing with Keystone 87 // notifications. 88 void RegisterForKeystoneNotifications(); 89 90 // Deletes |bridge_wrapper_|. 91 void UnregisterFromKeystoneNotifications(); 92#endif // defined(OS_MACOSX) && !defined(OS_IOS) 93 94 explicit ChromeAutofillClient(content::WebContents* web_contents); 95 friend class content::WebContentsUserData<ChromeAutofillClient>; 96 97 content::WebContents* const web_contents_; 98 base::WeakPtr<AutofillDialogController> dialog_controller_; 99 base::WeakPtr<AutofillPopupControllerImpl> popup_controller_; 100 101#if defined(OS_MACOSX) && !defined(OS_IOS) 102 // Listens to Keystone notifications and passes relevant ones on to the 103 // PersonalDataManager. 104 // 105 // The class of this member must remain a forward declaration, even in the 106 // .cc implementation file, since the class is defined in a Mac-only 107 // implementation file. This means that the pointer cannot be wrapped in a 108 // scoped_ptr. 109 AutofillKeystoneBridgeWrapper* bridge_wrapper_; 110#endif // defined(OS_MACOSX) && !defined(OS_IOS) 111 112 DISALLOW_COPY_AND_ASSIGN(ChromeAutofillClient); 113}; 114 115} // namespace autofill 116 117#endif // CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_ 118