- add sources.
[platform/framework/web/crosswalk.git] / src / android_webview / native / aw_autofill_manager_delegate.h
1 // Copyright 2013 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 ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_MANAGER_DELEGATE_H_
6 #define ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_MANAGER_DELEGATE_H_
7
8 #include <jni.h>
9 #include <vector>
10
11 #include "base/android/jni_helper.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_builder.h"
16 #include "components/autofill/core/browser/autofill_manager_delegate.h"
17 #include "content/public/browser/web_contents_user_data.h"
18
19 namespace autofill {
20 class AutofillMetrics;
21 class AutofillPopupDelegate;
22 class CreditCard;
23 class FormStructure;
24 class PasswordGenerator;
25 class PersonalDataManager;
26 struct FormData;
27 }
28
29 namespace content {
30 class WebContents;
31 }
32
33 namespace gfx {
34 class RectF;
35 }
36
37 class PersonalDataManager;
38 class PrefService;
39
40 namespace android_webview {
41
42 // Manager delegate for the autofill functionality. Android webview
43 // supports enabling autocomplete feature for each webview instance
44 // (different than the browser which supports enabling/disabling for
45 // a profile). Since there is only one pref service for a given browser
46 // context, we cannot enable this feature via UserPrefs. Rather, we always
47 // keep the feature enabled at the pref service, and control it via
48 // the delegates.
49 class AwAutofillManagerDelegate
50     : public autofill::AutofillManagerDelegate,
51       public content::WebContentsUserData<AwAutofillManagerDelegate> {
52
53  public:
54   virtual ~AwAutofillManagerDelegate();
55
56   void SetSaveFormData(bool enabled);
57   bool GetSaveFormData();
58
59   // AutofillManagerDelegate implementation.
60   virtual autofill::PersonalDataManager* GetPersonalDataManager() OVERRIDE;
61   virtual PrefService* GetPrefs() OVERRIDE;
62   virtual void HideRequestAutocompleteDialog() OVERRIDE;
63   virtual void ShowAutofillSettings() OVERRIDE;
64   virtual void ConfirmSaveCreditCard(
65       const autofill::AutofillMetrics& metric_logger,
66       const autofill::CreditCard& credit_card,
67       const base::Closure& save_card_callback) OVERRIDE;
68   virtual void ShowRequestAutocompleteDialog(
69       const autofill::FormData& form,
70       const GURL& source_url,
71       const base::Callback<void(const autofill::FormStructure*)>& callback)
72       OVERRIDE;
73   virtual void ShowAutofillPopup(
74       const gfx::RectF& element_bounds,
75       base::i18n::TextDirection text_direction,
76       const std::vector<string16>& values,
77       const std::vector<string16>& labels,
78       const std::vector<string16>& icons,
79       const std::vector<int>& identifiers,
80       base::WeakPtr<autofill::AutofillPopupDelegate> delegate) OVERRIDE;
81   virtual void UpdateAutofillPopupDataListValues(
82       const std::vector<base::string16>& values,
83       const std::vector<base::string16>& labels) OVERRIDE;
84   virtual void HideAutofillPopup() OVERRIDE;
85   virtual bool IsAutocompleteEnabled() OVERRIDE;
86   virtual void DetectAccountCreationForms(
87       const std::vector<autofill::FormStructure*>& forms) OVERRIDE;
88
89   void SuggestionSelected(JNIEnv* env,
90                           jobject obj,
91                           jint position);
92  private:
93   AwAutofillManagerDelegate(content::WebContents* web_contents);
94   friend class content::WebContentsUserData<AwAutofillManagerDelegate>;
95
96   void ShowAutofillPopupImpl(const gfx::RectF& element_bounds,
97                              const std::vector<string16>& values,
98                              const std::vector<string16>& labels,
99                              const std::vector<int>& identifiers);
100
101   // The web_contents associated with this delegate.
102   content::WebContents* web_contents_;
103   bool save_form_data_;
104   JavaObjectWeakGlobalRef java_ref_;
105
106   // The current Autofill query values.
107   std::vector<string16> values_;
108   std::vector<int> identifiers_;
109   base::WeakPtr<autofill::AutofillPopupDelegate> delegate_;
110
111   DISALLOW_COPY_AND_ASSIGN(AwAutofillManagerDelegate);
112 };
113
114 bool RegisterAwAutofillManagerDelegate(JNIEnv* env);
115
116 }  // namespace android_webview
117
118 #endif // ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_MANAGER_DELEGATE_H_