// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_CLIENT_H_ #define ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_CLIENT_H_ #include #include #include #include "base/android/jni_weak_ref.h" #include "base/compiler_specific.h" #include "base/memory/raw_ptr.h" #include "components/autofill/core/browser/autofill_client.h" #include "components/autofill/core/browser/payments/legal_message_line.h" #include "content/public/browser/web_contents_user_data.h" #include "ui/android/view_android.h" namespace autofill { class AutocompleteHistoryManager; class AutofillDriver; class AutofillPopupDelegate; class CardUnmaskDelegate; class CreditCard; class FormStructure; class PersonalDataManager; class StrikeDatabase; } // namespace autofill namespace content { class WebContents; } namespace gfx { class RectF; } namespace syncer { class SyncService; } class PersonalDataManager; class PrefService; namespace android_webview { // Manager delegate for the autofill functionality. Android webview // supports enabling autocomplete feature for each webview instance // (different than the browser which supports enabling/disabling for // a profile). Since there is only one pref service for a given browser // context, we cannot enable this feature via UserPrefs. Rather, we always // keep the feature enabled at the pref service, and control it via // the delegates. class AwAutofillClient : public autofill::AutofillClient, public content::WebContentsUserData { public: AwAutofillClient(const AwAutofillClient&) = delete; AwAutofillClient& operator=(const AwAutofillClient&) = delete; ~AwAutofillClient() override; void SetSaveFormData(bool enabled); bool GetSaveFormData(); // AutofillClient: autofill::PersonalDataManager* GetPersonalDataManager() override; autofill::AutocompleteHistoryManager* GetAutocompleteHistoryManager() override; PrefService* GetPrefs() override; const PrefService* GetPrefs() const override; syncer::SyncService* GetSyncService() override; signin::IdentityManager* GetIdentityManager() override; autofill::FormDataImporter* GetFormDataImporter() override; autofill::payments::PaymentsClient* GetPaymentsClient() override; autofill::StrikeDatabase* GetStrikeDatabase() override; ukm::UkmRecorder* GetUkmRecorder() override; ukm::SourceId GetUkmSourceId() override; autofill::AddressNormalizer* GetAddressNormalizer() override; const GURL& GetLastCommittedURL() const override; security_state::SecurityLevel GetSecurityLevelForUmaHistograms() override; const translate::LanguageState* GetLanguageState() override; translate::TranslateDriver* GetTranslateDriver() override; void ShowAutofillSettings(bool show_credit_card_settings) override; void ShowUnmaskPrompt( const autofill::CreditCard& card, UnmaskCardReason reason, base::WeakPtr delegate) override; void OnUnmaskVerificationResult(PaymentsRpcResult result) override; void ConfirmAccountNameFixFlow( base::OnceCallback callback) override; void ConfirmExpirationDateFixFlow( const autofill::CreditCard& card, base::OnceCallback callback) override; void ConfirmSaveCreditCardLocally( const autofill::CreditCard& card, SaveCreditCardOptions options, LocalSaveCardPromptCallback callback) override; void ConfirmSaveCreditCardToCloud( const autofill::CreditCard& card, const autofill::LegalMessageLines& legal_message_lines, SaveCreditCardOptions options, UploadSaveCardPromptCallback callback) override; void CreditCardUploadCompleted(bool card_saved) override; void ConfirmCreditCardFillAssist(const autofill::CreditCard& card, base::OnceClosure callback) override; void ConfirmSaveAddressProfile( const autofill::AutofillProfile& profile, const autofill::AutofillProfile* original_profile, SaveAddressProfilePromptOptions options, AddressProfileSavePromptCallback callback) override; bool HasCreditCardScanFeature() override; void ScanCreditCard(CreditCardScanCallback callback) override; bool IsTouchToFillCreditCardSupported() override; bool ShowTouchToFillCreditCard( base::WeakPtr delegate) override; void HideTouchToFillCreditCard() override; void ShowAutofillPopup( const autofill::AutofillClient::PopupOpenArgs& open_args, base::WeakPtr delegate) override; void UpdateAutofillPopupDataListValues( const std::vector& values, const std::vector& labels) override; base::span GetPopupSuggestions() const override; void PinPopupView() override; autofill::AutofillClient::PopupOpenArgs GetReopenPopupArgs() const override; void UpdatePopup(const std::vector& suggestions, autofill::PopupType popup_type) override; void HideAutofillPopup(autofill::PopupHidingReason reason) override; bool IsAutocompleteEnabled() override; bool IsPasswordManagerEnabled() override; void PropagateAutofillPredictions( autofill::AutofillDriver* driver, const std::vector& forms) override; void DidFillOrPreviewField(const std::u16string& autofilled_value, const std::u16string& profile_full_name) override; bool IsContextSecure() const override; bool ShouldShowSigninPromo() override; bool AreServerCardsSupported() const override; void ExecuteCommand(int id) override; void OpenPromoCodeOfferDetailsURL(const GURL& url) override; // RiskDataLoader: void LoadRiskData( base::OnceCallback callback) override; void Dismissed(JNIEnv* env, const base::android::JavaParamRef& obj); void SuggestionSelected(JNIEnv* env, const base::android::JavaParamRef& obj, jint position); private: explicit AwAutofillClient(content::WebContents* web_contents); friend class content::WebContentsUserData; void ShowAutofillPopupImpl( const gfx::RectF& element_bounds, bool is_rtl, const std::vector& suggestions); content::WebContents& GetWebContents() const; bool save_form_data_ = false; JavaObjectWeakGlobalRef java_ref_; ui::ViewAndroid::ScopedAnchorView anchor_view_; // The current Autofill query values. std::vector suggestions_; base::WeakPtr delegate_; WEB_CONTENTS_USER_DATA_KEY_DECL(); }; } // namespace android_webview #endif // ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_CLIENT_H_