Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 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" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 16 | #include "components/autofill/core/browser/autocheckout_bubble_state.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 17 | #include "components/autofill/core/browser/autofill_manager_delegate.h" |
| 18 | #include "content/public/browser/web_contents_user_data.h" |
| 19 | |
| 20 | namespace autofill { |
| 21 | class AutofillMetrics; |
| 22 | class AutofillPopupDelegate; |
| 23 | class CreditCard; |
| 24 | class FormStructure; |
| 25 | class PasswordGenerator; |
| 26 | class PersonalDataManager; |
| 27 | struct FormData; |
| 28 | namespace autocheckout { |
| 29 | class WhitelistManager; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | namespace content { |
| 34 | class WebContents; |
| 35 | } |
| 36 | |
| 37 | namespace gfx { |
| 38 | class RectF; |
| 39 | } |
| 40 | |
| 41 | class PersonalDataManager; |
| 42 | class PrefService; |
| 43 | |
| 44 | namespace android_webview { |
| 45 | |
| 46 | // Manager delegate for the autofill functionality. Android webview |
| 47 | // supports enabling autocomplete feature for each webview instance |
| 48 | // (different than the browser which supports enabling/disabling for |
| 49 | // a profile). Since there is only one pref service for a given browser |
| 50 | // context, we cannot enable this feature via UserPrefs. Rather, we always |
| 51 | // keep the feature enabled at the pref service, and control it via |
| 52 | // the delegates. |
| 53 | class AwAutofillManagerDelegate |
| 54 | : public autofill::AutofillManagerDelegate, |
| 55 | public content::WebContentsUserData<AwAutofillManagerDelegate> { |
| 56 | |
| 57 | public: |
| 58 | virtual ~AwAutofillManagerDelegate(); |
| 59 | |
| 60 | void SetSaveFormData(bool enabled); |
| 61 | bool GetSaveFormData(); |
| 62 | |
| 63 | // AutofillManagerDelegate implementation. |
| 64 | virtual autofill::PersonalDataManager* GetPersonalDataManager() OVERRIDE; |
| 65 | virtual PrefService* GetPrefs() OVERRIDE; |
| 66 | virtual autofill::autocheckout::WhitelistManager* |
| 67 | GetAutocheckoutWhitelistManager() const OVERRIDE; |
| 68 | virtual void HideRequestAutocompleteDialog() OVERRIDE; |
| 69 | virtual void OnAutocheckoutError() OVERRIDE; |
| 70 | virtual void OnAutocheckoutSuccess() OVERRIDE; |
| 71 | virtual void ShowAutofillSettings() OVERRIDE; |
| 72 | virtual void ConfirmSaveCreditCard( |
| 73 | const autofill::AutofillMetrics& metric_logger, |
| 74 | const autofill::CreditCard& credit_card, |
| 75 | const base::Closure& save_card_callback) OVERRIDE; |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 76 | virtual bool ShowAutocheckoutBubble( |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 77 | const gfx::RectF& bounds, |
| 78 | bool is_google_user, |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 79 | const base::Callback<void( |
| 80 | autofill::AutocheckoutBubbleState)>& callback) OVERRIDE; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 81 | virtual void HideAutocheckoutBubble() OVERRIDE; |
| 82 | virtual void ShowRequestAutocompleteDialog( |
| 83 | const autofill::FormData& form, |
| 84 | const GURL& source_url, |
| 85 | autofill::DialogType dialog_type, |
| 86 | const base::Callback<void(const autofill::FormStructure*, |
| 87 | const std::string&)>& callback) OVERRIDE; |
| 88 | virtual void ShowAutofillPopup( |
| 89 | const gfx::RectF& element_bounds, |
| 90 | base::i18n::TextDirection text_direction, |
| 91 | const std::vector<string16>& values, |
| 92 | const std::vector<string16>& labels, |
| 93 | const std::vector<string16>& icons, |
| 94 | const std::vector<int>& identifiers, |
| 95 | base::WeakPtr<autofill::AutofillPopupDelegate> delegate) OVERRIDE; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 96 | virtual void UpdateAutofillPopupDataListValues( |
| 97 | const std::vector<base::string16>& values, |
| 98 | const std::vector<base::string16>& labels) OVERRIDE; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 99 | virtual void HideAutofillPopup() OVERRIDE; |
| 100 | virtual bool IsAutocompleteEnabled() OVERRIDE; |
| 101 | virtual void AddAutocheckoutStep(autofill::AutocheckoutStepType step_type) |
| 102 | OVERRIDE; |
| 103 | virtual void UpdateAutocheckoutStep( |
| 104 | autofill::AutocheckoutStepType step_type, |
| 105 | autofill::AutocheckoutStepStatus step_status) OVERRIDE; |
| 106 | |
| 107 | void SuggestionSelected(JNIEnv* env, |
| 108 | jobject obj, |
| 109 | jint position); |
| 110 | private: |
| 111 | AwAutofillManagerDelegate(content::WebContents* web_contents); |
| 112 | friend class content::WebContentsUserData<AwAutofillManagerDelegate>; |
| 113 | |
| 114 | void ShowAutofillPopupImpl(const gfx::RectF& element_bounds, |
| 115 | const std::vector<string16>& values, |
| 116 | const std::vector<string16>& labels, |
| 117 | const std::vector<int>& identifiers); |
| 118 | |
| 119 | // The web_contents associated with this delegate. |
| 120 | content::WebContents* web_contents_; |
| 121 | bool save_form_data_; |
| 122 | JavaObjectWeakGlobalRef java_ref_; |
| 123 | |
| 124 | // The current Autofill query values. |
| 125 | std::vector<string16> values_; |
| 126 | std::vector<int> identifiers_; |
| 127 | base::WeakPtr<autofill::AutofillPopupDelegate> delegate_; |
| 128 | |
| 129 | DISALLOW_COPY_AND_ASSIGN(AwAutofillManagerDelegate); |
| 130 | }; |
| 131 | |
| 132 | bool RegisterAwAutofillManagerDelegate(JNIEnv* env); |
| 133 | |
| 134 | } // namespace android_webview |
| 135 | |
| 136 | #endif // ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_MANAGER_DELEGATE_H_ |