aw_autofill_client.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #ifndef ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_CLIENT_H_
  5. #define ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_CLIENT_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/android/jni_weak_ref.h"
  10. #include "base/compiler_specific.h"
  11. #include "base/memory/raw_ptr.h"
  12. #include "components/autofill/core/browser/autofill_client.h"
  13. #include "components/autofill/core/browser/payments/legal_message_line.h"
  14. #include "content/public/browser/web_contents_user_data.h"
  15. #include "ui/android/view_android.h"
  16. namespace autofill {
  17. class AutocompleteHistoryManager;
  18. class AutofillDriver;
  19. class AutofillPopupDelegate;
  20. class CardUnmaskDelegate;
  21. class CreditCard;
  22. class FormStructure;
  23. class PersonalDataManager;
  24. class StrikeDatabase;
  25. } // namespace autofill
  26. namespace content {
  27. class WebContents;
  28. }
  29. namespace gfx {
  30. class RectF;
  31. }
  32. namespace syncer {
  33. class SyncService;
  34. }
  35. class PersonalDataManager;
  36. class PrefService;
  37. namespace android_webview {
  38. // Manager delegate for the autofill functionality. Android webview
  39. // supports enabling autocomplete feature for each webview instance
  40. // (different than the browser which supports enabling/disabling for
  41. // a profile). Since there is only one pref service for a given browser
  42. // context, we cannot enable this feature via UserPrefs. Rather, we always
  43. // keep the feature enabled at the pref service, and control it via
  44. // the delegates.
  45. class AwAutofillClient : public autofill::AutofillClient,
  46. public content::WebContentsUserData<AwAutofillClient> {
  47. public:
  48. AwAutofillClient(const AwAutofillClient&) = delete;
  49. AwAutofillClient& operator=(const AwAutofillClient&) = delete;
  50. ~AwAutofillClient() override;
  51. void SetSaveFormData(bool enabled);
  52. bool GetSaveFormData();
  53. // AutofillClient:
  54. autofill::PersonalDataManager* GetPersonalDataManager() override;
  55. autofill::AutocompleteHistoryManager* GetAutocompleteHistoryManager()
  56. override;
  57. PrefService* GetPrefs() override;
  58. const PrefService* GetPrefs() const override;
  59. syncer::SyncService* GetSyncService() override;
  60. signin::IdentityManager* GetIdentityManager() override;
  61. autofill::FormDataImporter* GetFormDataImporter() override;
  62. autofill::payments::PaymentsClient* GetPaymentsClient() override;
  63. autofill::StrikeDatabase* GetStrikeDatabase() override;
  64. ukm::UkmRecorder* GetUkmRecorder() override;
  65. ukm::SourceId GetUkmSourceId() override;
  66. autofill::AddressNormalizer* GetAddressNormalizer() override;
  67. const GURL& GetLastCommittedURL() const override;
  68. security_state::SecurityLevel GetSecurityLevelForUmaHistograms() override;
  69. const translate::LanguageState* GetLanguageState() override;
  70. translate::TranslateDriver* GetTranslateDriver() override;
  71. void ShowAutofillSettings(bool show_credit_card_settings) override;
  72. void ShowUnmaskPrompt(
  73. const autofill::CreditCard& card,
  74. UnmaskCardReason reason,
  75. base::WeakPtr<autofill::CardUnmaskDelegate> delegate) override;
  76. void OnUnmaskVerificationResult(PaymentsRpcResult result) override;
  77. void ConfirmAccountNameFixFlow(
  78. base::OnceCallback<void(const std::u16string&)> callback) override;
  79. void ConfirmExpirationDateFixFlow(
  80. const autofill::CreditCard& card,
  81. base::OnceCallback<void(const std::u16string&, const std::u16string&)>
  82. callback) override;
  83. void ConfirmSaveCreditCardLocally(
  84. const autofill::CreditCard& card,
  85. SaveCreditCardOptions options,
  86. LocalSaveCardPromptCallback callback) override;
  87. void ConfirmSaveCreditCardToCloud(
  88. const autofill::CreditCard& card,
  89. const autofill::LegalMessageLines& legal_message_lines,
  90. SaveCreditCardOptions options,
  91. UploadSaveCardPromptCallback callback) override;
  92. void CreditCardUploadCompleted(bool card_saved) override;
  93. void ConfirmCreditCardFillAssist(const autofill::CreditCard& card,
  94. base::OnceClosure callback) override;
  95. void ConfirmSaveAddressProfile(
  96. const autofill::AutofillProfile& profile,
  97. const autofill::AutofillProfile* original_profile,
  98. SaveAddressProfilePromptOptions options,
  99. AddressProfileSavePromptCallback callback) override;
  100. bool HasCreditCardScanFeature() override;
  101. void ScanCreditCard(CreditCardScanCallback callback) override;
  102. bool IsTouchToFillCreditCardSupported() override;
  103. bool ShowTouchToFillCreditCard(
  104. base::WeakPtr<autofill::TouchToFillDelegate> delegate) override;
  105. void HideTouchToFillCreditCard() override;
  106. void ShowAutofillPopup(
  107. const autofill::AutofillClient::PopupOpenArgs& open_args,
  108. base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override;
  109. void UpdateAutofillPopupDataListValues(
  110. const std::vector<std::u16string>& values,
  111. const std::vector<std::u16string>& labels) override;
  112. base::span<const autofill::Suggestion> GetPopupSuggestions() const override;
  113. void PinPopupView() override;
  114. autofill::AutofillClient::PopupOpenArgs GetReopenPopupArgs() const override;
  115. void UpdatePopup(const std::vector<autofill::Suggestion>& suggestions,
  116. autofill::PopupType popup_type) override;
  117. void HideAutofillPopup(autofill::PopupHidingReason reason) override;
  118. bool IsAutocompleteEnabled() override;
  119. bool IsPasswordManagerEnabled() override;
  120. void PropagateAutofillPredictions(
  121. autofill::AutofillDriver* driver,
  122. const std::vector<autofill::FormStructure*>& forms) override;
  123. void DidFillOrPreviewField(const std::u16string& autofilled_value,
  124. const std::u16string& profile_full_name) override;
  125. bool IsContextSecure() const override;
  126. bool ShouldShowSigninPromo() override;
  127. bool AreServerCardsSupported() const override;
  128. void ExecuteCommand(int id) override;
  129. void OpenPromoCodeOfferDetailsURL(const GURL& url) override;
  130. // RiskDataLoader:
  131. void LoadRiskData(
  132. base::OnceCallback<void(const std::string&)> callback) override;
  133. void Dismissed(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
  134. void SuggestionSelected(JNIEnv* env,
  135. const base::android::JavaParamRef<jobject>& obj,
  136. jint position);
  137. private:
  138. explicit AwAutofillClient(content::WebContents* web_contents);
  139. friend class content::WebContentsUserData<AwAutofillClient>;
  140. void ShowAutofillPopupImpl(
  141. const gfx::RectF& element_bounds,
  142. bool is_rtl,
  143. const std::vector<autofill::Suggestion>& suggestions);
  144. content::WebContents& GetWebContents() const;
  145. bool save_form_data_ = false;
  146. JavaObjectWeakGlobalRef java_ref_;
  147. ui::ViewAndroid::ScopedAnchorView anchor_view_;
  148. // The current Autofill query values.
  149. std::vector<autofill::Suggestion> suggestions_;
  150. base::WeakPtr<autofill::AutofillPopupDelegate> delegate_;
  151. WEB_CONTENTS_USER_DATA_KEY_DECL();
  152. };
  153. } // namespace android_webview
  154. #endif // ANDROID_WEBVIEW_BROWSER_AW_AUTOFILL_CLIENT_H_