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 ANDROID_WEBVIEW_NATIVE_AW_AUTOFILL_CLIENT_H_
6 #define ANDROID_WEBVIEW_NATIVE_AW_AUTOFILL_CLIENT_H_
11 #include "base/android/jni_weak_ref.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/prefs/pref_registry_simple.h"
15 #include "base/prefs/pref_service_factory.h"
16 #include "components/autofill/core/browser/autofill_client.h"
17 #include "content/public/browser/web_contents_user_data.h"
20 class AutofillMetrics
;
21 class AutofillPopupDelegate
;
22 class CardUnmaskDelegate
;
25 class PasswordGenerator
;
26 class PersonalDataManager
;
38 class PersonalDataManager
;
41 namespace android_webview
{
43 // Manager delegate for the autofill functionality. Android webview
44 // supports enabling autocomplete feature for each webview instance
45 // (different than the browser which supports enabling/disabling for
46 // a profile). Since there is only one pref service for a given browser
47 // context, we cannot enable this feature via UserPrefs. Rather, we always
48 // keep the feature enabled at the pref service, and control it via
50 class AwAutofillClient
: public autofill::AutofillClient
,
51 public content::WebContentsUserData
<AwAutofillClient
> {
53 virtual ~AwAutofillClient();
55 void SetSaveFormData(bool enabled
);
56 bool GetSaveFormData();
59 virtual autofill::PersonalDataManager
* GetPersonalDataManager() override
;
60 virtual scoped_refptr
<autofill::AutofillWebDataService
> GetDatabase()
62 virtual PrefService
* GetPrefs() override
;
63 IdentityProvider
* GetIdentityProvider() override
;
64 virtual void HideRequestAutocompleteDialog() override
;
65 virtual void ShowAutofillSettings() override
;
66 virtual void ShowUnmaskPrompt(
67 const autofill::CreditCard
& card
,
68 base::WeakPtr
<autofill::CardUnmaskDelegate
> delegate
) override
;
69 virtual void OnUnmaskVerificationResult(bool success
) override
;
70 virtual void ConfirmSaveCreditCard(
71 const base::Closure
& save_card_callback
) override
;
72 virtual bool HasCreditCardScanFeature() override
;
73 virtual void ScanCreditCard(const CreditCardScanCallback
& callback
) override
;
74 virtual void ShowRequestAutocompleteDialog(
75 const autofill::FormData
& form
,
76 content::RenderFrameHost
* rfh
,
77 const ResultCallback
& callback
) override
;
78 virtual void ShowAutofillPopup(
79 const gfx::RectF
& element_bounds
,
80 base::i18n::TextDirection text_direction
,
81 const std::vector
<autofill::Suggestion
>& suggestions
,
82 base::WeakPtr
<autofill::AutofillPopupDelegate
> delegate
) override
;
83 virtual void UpdateAutofillPopupDataListValues(
84 const std::vector
<base::string16
>& values
,
85 const std::vector
<base::string16
>& labels
) override
;
86 virtual void HideAutofillPopup() override
;
87 virtual bool IsAutocompleteEnabled() override
;
88 virtual void DetectAccountCreationForms(
89 content::RenderFrameHost
* rfh
,
90 const std::vector
<autofill::FormStructure
*>& forms
) override
;
91 virtual void DidFillOrPreviewField(
92 const base::string16
& autofilled_value
,
93 const base::string16
& profile_full_name
) override
;
94 virtual void OnFirstUserGestureObserved() override
;
95 virtual void LinkClicked(const GURL
& url
,
96 WindowOpenDisposition disposition
) override
;
98 void SuggestionSelected(JNIEnv
* env
, jobject obj
, jint position
);
101 AwAutofillClient(content::WebContents
* web_contents
);
102 friend class content::WebContentsUserData
<AwAutofillClient
>;
104 void ShowAutofillPopupImpl(
105 const gfx::RectF
& element_bounds
,
107 const std::vector
<autofill::Suggestion
>& suggestions
);
109 // The web_contents associated with this delegate.
110 content::WebContents
* web_contents_
;
111 bool save_form_data_
;
112 JavaObjectWeakGlobalRef java_ref_
;
114 // The current Autofill query values.
115 std::vector
<autofill::Suggestion
> suggestions_
;
116 base::WeakPtr
<autofill::AutofillPopupDelegate
> delegate_
;
118 DISALLOW_COPY_AND_ASSIGN(AwAutofillClient
);
121 bool RegisterAwAutofillClient(JNIEnv
* env
);
123 } // namespace android_webview
125 #endif // ANDROID_WEBVIEW_NATIVE_AW_AUTOFILL_CLIENT_H_