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/autocheckout_bubble_state.h" 17#include "components/autofill/core/browser/autofill_manager_delegate.h" 18#include "content/public/browser/web_contents_user_data.h" 19 20namespace autofill { 21class AutofillMetrics; 22class AutofillPopupDelegate; 23class CreditCard; 24class FormStructure; 25class PasswordGenerator; 26class PersonalDataManager; 27struct FormData; 28namespace autocheckout { 29class WhitelistManager; 30} 31} 32 33namespace content { 34class WebContents; 35} 36 37namespace gfx { 38class RectF; 39} 40 41class PersonalDataManager; 42class PrefService; 43 44namespace 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. 53class 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; 76 virtual bool ShowAutocheckoutBubble( 77 const gfx::RectF& bounds, 78 bool is_google_user, 79 const base::Callback<void( 80 autofill::AutocheckoutBubbleState)>& callback) OVERRIDE; 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; 96 virtual void UpdateAutofillPopupDataListValues( 97 const std::vector<base::string16>& values, 98 const std::vector<base::string16>& labels) OVERRIDE; 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 132bool RegisterAwAutofillManagerDelegate(JNIEnv* env); 133 134} // namespace android_webview 135 136#endif // ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_MANAGER_DELEGATE_H_ 137