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
;
82 bool IsContextSecure(const GURL
& form_origin
) override
;
84 // content::WebContentsObserver implementation.
85 void RenderFrameDeleted(content::RenderFrameHost
* rfh
) override
;
86 void DidNavigateAnyFrame(
87 content::RenderFrameHost
* render_frame_host
,
88 const content::LoadCommittedDetails
& details
,
89 const content::FrameNavigateParams
& params
) override
;
90 void MainFrameWasResized(bool width_changed
) override
;
91 void WebContentsDestroyed() override
;
93 // ZoomObserver implementation.
95 const ui_zoom::ZoomController::ZoomChangedEventData
& data
) override
;
97 // Exposed for testing.
98 AutofillDialogController
* GetDialogControllerForTesting() {
99 return dialog_controller_
.get();
101 void SetDialogControllerForTesting(
102 const base::WeakPtr
<AutofillDialogController
>& dialog_controller
) {
103 dialog_controller_
= dialog_controller
;
107 #if defined(OS_MACOSX) && !defined(OS_IOS)
108 // Creates |bridge_wrapper_|, which is responsible for dealing with Keystone
110 void RegisterForKeystoneNotifications();
112 // Deletes |bridge_wrapper_|.
113 void UnregisterFromKeystoneNotifications();
114 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
116 explicit ChromeAutofillClient(content::WebContents
* web_contents
);
117 friend class content::WebContentsUserData
<ChromeAutofillClient
>;
119 base::WeakPtr
<AutofillDialogController
> dialog_controller_
;
120 base::WeakPtr
<AutofillPopupControllerImpl
> popup_controller_
;
121 CardUnmaskPromptControllerImpl unmask_controller_
;
123 #if defined(OS_MACOSX) && !defined(OS_IOS)
124 // Listens to Keystone notifications and passes relevant ones on to the
125 // PersonalDataManager.
127 // The class of this member must remain a forward declaration, even in the
128 // .cc implementation file, since the class is defined in a Mac-only
129 // implementation file. This means that the pointer cannot be wrapped in a
131 AutofillKeystoneBridgeWrapper
* bridge_wrapper_
;
132 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
134 // The last render frame that called requestAutocomplete.
135 content::RenderFrameHost
* last_rfh_to_rac_
;
137 // The identity provider, used for Wallet integration.
138 scoped_ptr
<IdentityProvider
> identity_provider_
;
140 DISALLOW_COPY_AND_ASSIGN(ChromeAutofillClient
);
143 } // namespace autofill
145 #endif // CHROME_BROWSER_UI_AUTOFILL_CHROME_AUTOFILL_CLIENT_H_