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.
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/i18n/rtl.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "components/autofill/core/browser/autofill_client.h"
16 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl.h"
17 #include "components/ui/zoom/zoom_observer.h"
18 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/browser/web_contents_user_data.h"
22 struct FrameNavigateParams
;
23 struct LoadCommittedDetails
;
29 class AutofillDialogController
;
30 class AutofillKeystoneBridgeWrapper
;
31 class AutofillPopupControllerImpl
;
32 class CreditCardScannerController
;
35 // Chrome implementation of AutofillClient.
36 class ChromeAutofillClient
37 : public AutofillClient
,
38 public content::WebContentsUserData
<ChromeAutofillClient
>,
39 public content::WebContentsObserver
,
40 public ui_zoom::ZoomObserver
{
42 ~ChromeAutofillClient() override
;
44 // Called when the tab corresponding to |this| instance is activated.
48 PersonalDataManager
* GetPersonalDataManager() override
;
49 scoped_refptr
<AutofillWebDataService
> GetDatabase() override
;
50 PrefService
* GetPrefs() override
;
51 IdentityProvider
* GetIdentityProvider() override
;
52 rappor::RapporService
* GetRapporService() override
;
53 void HideRequestAutocompleteDialog() override
;
54 void ShowAutofillSettings() override
;
55 void ShowUnmaskPrompt(const CreditCard
& card
,
56 base::WeakPtr
<CardUnmaskDelegate
> delegate
) override
;
57 void OnUnmaskVerificationResult(GetRealPanResult result
) override
;
58 void ConfirmSaveCreditCard(const base::Closure
& save_card_callback
) override
;
59 bool HasCreditCardScanFeature() override
;
60 void ScanCreditCard(const CreditCardScanCallback
& callback
) override
;
61 void ShowRequestAutocompleteDialog(
63 content::RenderFrameHost
* render_frame_host
,
64 const ResultCallback
& callback
) override
;
65 void ShowAutofillPopup(
66 const gfx::RectF
& element_bounds
,
67 base::i18n::TextDirection text_direction
,
68 const std::vector
<autofill::Suggestion
>& suggestions
,
69 base::WeakPtr
<AutofillPopupDelegate
> delegate
) override
;
70 void UpdateAutofillPopupDataListValues(
71 const std::vector
<base::string16
>& values
,
72 const std::vector
<base::string16
>& labels
) override
;
73 void HideAutofillPopup() override
;
74 bool IsAutocompleteEnabled() override
;
75 void PropagateAutofillPredictions(
76 content::RenderFrameHost
* rfh
,
77 const std::vector
<autofill::FormStructure
*>& forms
) override
;
78 void DidFillOrPreviewField(const base::string16
& autofilled_value
,
79 const base::string16
& profile_full_name
) override
;
80 void OnFirstUserGestureObserved() override
;
81 void LinkClicked(const GURL
& url
, WindowOpenDisposition disposition
) override
;
83 // content::WebContentsObserver implementation.
84 void RenderFrameDeleted(content::RenderFrameHost
* rfh
) override
;
85 void DidNavigateAnyFrame(
86 content::RenderFrameHost
* render_frame_host
,
87 const content::LoadCommittedDetails
& details
,
88 const content::FrameNavigateParams
& params
) override
;
89 void MainFrameWasResized(bool width_changed
) override
;
90 void WebContentsDestroyed() override
;
92 // ZoomObserver implementation.
94 const ui_zoom::ZoomController::ZoomChangedEventData
& data
) override
;
96 // Exposed for testing.
97 AutofillDialogController
* GetDialogControllerForTesting() {
98 return dialog_controller_
.get();
100 void SetDialogControllerForTesting(
101 const base::WeakPtr
<AutofillDialogController
>& dialog_controller
) {
102 dialog_controller_
= dialog_controller
;
106 #if defined(OS_MACOSX) && !defined(OS_IOS)
107 // Creates |bridge_wrapper_|, which is responsible for dealing with Keystone
109 void RegisterForKeystoneNotifications();
111 // Deletes |bridge_wrapper_|.
112 void UnregisterFromKeystoneNotifications();
113 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
115 explicit ChromeAutofillClient(content::WebContents
* web_contents
);
116 friend class content::WebContentsUserData
<ChromeAutofillClient
>;
118 base::WeakPtr
<AutofillDialogController
> dialog_controller_
;
119 base::WeakPtr
<AutofillPopupControllerImpl
> popup_controller_
;
120 CardUnmaskPromptControllerImpl unmask_controller_
;
122 #if defined(OS_MACOSX) && !defined(OS_IOS)
123 // Listens to Keystone notifications and passes relevant ones on to the
124 // PersonalDataManager.
126 // The class of this member must remain a forward declaration, even in the
127 // .cc implementation file, since the class is defined in a Mac-only
128 // implementation file. This means that the pointer cannot be wrapped in a
130 AutofillKeystoneBridgeWrapper
* bridge_wrapper_
;
131 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
133 // The last render frame that called requestAutocomplete.
134 content::RenderFrameHost
* last_rfh_to_rac_
;
136 // The identity provider, used for Wallet integration.
137 scoped_ptr
<IdentityProvider
> identity_provider_
;
139 DISALLOW_COPY_AND_ASSIGN(ChromeAutofillClient
);
142 } // namespace autofill
144 #endif // CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_