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. 4 5#ifndef ANDROID_WEBVIEW_NATIVE_AW_AUTOFILL_CLIENT_H_ 6#define ANDROID_WEBVIEW_NATIVE_AW_AUTOFILL_CLIENT_H_ 7 8#include <jni.h> 9#include <vector> 10 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" 18 19namespace autofill { 20class AutofillMetrics; 21class AutofillPopupDelegate; 22class CreditCard; 23class FormStructure; 24class PasswordGenerator; 25class PersonalDataManager; 26struct FormData; 27} 28 29namespace content { 30class WebContents; 31} 32 33namespace gfx { 34class RectF; 35} 36 37class PersonalDataManager; 38class PrefService; 39 40namespace 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. 49class AwAutofillClient : public autofill::AutofillClient, 50 public content::WebContentsUserData<AwAutofillClient> { 51 public: 52 virtual ~AwAutofillClient(); 53 54 void SetSaveFormData(bool enabled); 55 bool GetSaveFormData(); 56 57 // AutofillClient: 58 virtual autofill::PersonalDataManager* GetPersonalDataManager() OVERRIDE; 59 virtual scoped_refptr<autofill::AutofillWebDataService> GetDatabase() 60 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 base::Closure& save_card_callback) OVERRIDE; 67 virtual void ShowRequestAutocompleteDialog( 68 const autofill::FormData& form, 69 const GURL& source_url, 70 const ResultCallback& callback) OVERRIDE; 71 virtual void ShowAutofillPopup( 72 const gfx::RectF& element_bounds, 73 base::i18n::TextDirection text_direction, 74 const std::vector<base::string16>& values, 75 const std::vector<base::string16>& labels, 76 const std::vector<base::string16>& icons, 77 const std::vector<int>& identifiers, 78 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) OVERRIDE; 79 virtual void UpdateAutofillPopupDataListValues( 80 const std::vector<base::string16>& values, 81 const std::vector<base::string16>& labels) OVERRIDE; 82 virtual void HideAutofillPopup() OVERRIDE; 83 virtual bool IsAutocompleteEnabled() OVERRIDE; 84 virtual void DetectAccountCreationForms( 85 const std::vector<autofill::FormStructure*>& forms) OVERRIDE; 86 virtual void DidFillOrPreviewField( 87 const base::string16& autofilled_value, 88 const base::string16& profile_full_name) OVERRIDE; 89 90 void SuggestionSelected(JNIEnv* env, jobject obj, jint position); 91 92 private: 93 AwAutofillClient(content::WebContents* web_contents); 94 friend class content::WebContentsUserData<AwAutofillClient>; 95 96 void ShowAutofillPopupImpl(const gfx::RectF& element_bounds, 97 bool is_rtl, 98 const std::vector<base::string16>& values, 99 const std::vector<base::string16>& labels, 100 const std::vector<int>& identifiers); 101 102 // The web_contents associated with this delegate. 103 content::WebContents* web_contents_; 104 bool save_form_data_; 105 JavaObjectWeakGlobalRef java_ref_; 106 107 // The current Autofill query values. 108 std::vector<base::string16> values_; 109 std::vector<int> identifiers_; 110 base::WeakPtr<autofill::AutofillPopupDelegate> delegate_; 111 112 DISALLOW_COPY_AND_ASSIGN(AwAutofillClient); 113}; 114 115bool RegisterAwAutofillClient(JNIEnv* env); 116 117} // namespace android_webview 118 119#endif // ANDROID_WEBVIEW_NATIVE_AW_AUTOFILL_CLIENT_H_ 120