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.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CLIENT_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CLIENT_H_
10 #include "base/callback_forward.h"
11 #include "base/i18n/rtl.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/strings/string16.h"
14 #include "ui/base/window_open_disposition.h"
16 class IdentityProvider
;
19 class RenderFrameHost
;
32 class AutofillPopupDelegate
;
33 class AutofillWebDataService
;
34 class CardUnmaskDelegate
;
37 class PersonalDataManager
;
41 // A client interface that needs to be supplied to the Autofill component by the
44 // Each client instance is associated with a given context within which an
45 // AutofillManager is used (e.g. a single tab), so when we say "for the client"
46 // below, we mean "in the execution context the client is associated with" (e.g.
47 // for the tab the AutofillManager is attached to).
48 class AutofillClient
{
50 // Copy of blink::WebFormElement::AutocompleteResult.
51 enum RequestAutocompleteResult
{
52 AutocompleteResultSuccess
,
53 AutocompleteResultErrorDisabled
,
54 AutocompleteResultErrorCancel
,
55 AutocompleteResultErrorInvalid
,
58 enum GetRealPanResult
{
62 // Request failed; try again.
65 // Request failed; don't try again.
68 // Unable to connect to Wallet servers. Prompt user to check internet
73 typedef base::Callback
<void(RequestAutocompleteResult
,
74 const base::string16
&,
75 const FormStructure
*)> ResultCallback
;
77 typedef base::Callback
<void(const base::string16
& /* card number */,
79 int /* exp year */)> CreditCardScanCallback
;
81 virtual ~AutofillClient() {}
83 // Gets the PersonalDataManager instance associated with the client.
84 virtual PersonalDataManager
* GetPersonalDataManager() = 0;
86 // Gets the AutofillWebDataService instance associated with the client.
87 virtual scoped_refptr
<AutofillWebDataService
> GetDatabase() = 0;
89 // Gets the preferences associated with the client.
90 virtual PrefService
* GetPrefs() = 0;
92 // Gets the IdentityProvider associated with the client (for OAuth2).
93 virtual IdentityProvider
* GetIdentityProvider() = 0;
95 // Hides the associated request autocomplete dialog (if it exists).
96 virtual void HideRequestAutocompleteDialog() = 0;
98 // Causes the Autofill settings UI to be shown.
99 virtual void ShowAutofillSettings() = 0;
101 // A user has attempted to use a masked card. Prompt them for further
102 // information to proceed.
103 virtual void ShowUnmaskPrompt(const CreditCard
& card
,
104 base::WeakPtr
<CardUnmaskDelegate
> delegate
) = 0;
105 virtual void OnUnmaskVerificationResult(GetRealPanResult result
) = 0;
107 // Run |save_card_callback| if the credit card should be imported as personal
108 // data. |metric_logger| can be used to log user actions.
109 virtual void ConfirmSaveCreditCard(
110 const base::Closure
& save_card_callback
) = 0;
112 // Returns true if both the platform and the device support scanning credit
113 // cards. Should be called before ScanCreditCard().
114 virtual bool HasCreditCardScanFeature() = 0;
116 // Shows the user interface for scanning a credit card. Invokes the |callback|
117 // when a credit card is scanned successfully. Should be called only if
118 // HasCreditCardScanFeature() returns true.
119 virtual void ScanCreditCard(const CreditCardScanCallback
& callback
) = 0;
121 // Causes the dialog for request autocomplete feature to be shown.
122 virtual void ShowRequestAutocompleteDialog(
123 const FormData
& form
,
124 content::RenderFrameHost
* render_frame_host
,
125 const ResultCallback
& callback
) = 0;
127 // Shows an Autofill popup with the given |values|, |labels|, |icons|, and
128 // |identifiers| for the element at |element_bounds|. |delegate| will be
129 // notified of popup events.
130 virtual void ShowAutofillPopup(
131 const gfx::RectF
& element_bounds
,
132 base::i18n::TextDirection text_direction
,
133 const std::vector
<Suggestion
>& suggestions
,
134 base::WeakPtr
<AutofillPopupDelegate
> delegate
) = 0;
136 // Update the data list values shown by the Autofill popup, if visible.
137 virtual void UpdateAutofillPopupDataListValues(
138 const std::vector
<base::string16
>& values
,
139 const std::vector
<base::string16
>& labels
) = 0;
141 // Hide the Autofill popup if one is currently showing.
142 virtual void HideAutofillPopup() = 0;
144 // Whether the Autocomplete feature of Autofill should be enabled.
145 virtual bool IsAutocompleteEnabled() = 0;
147 // Pass the form structures to the password generation manager to detect
148 // account creation forms.
149 virtual void DetectAccountCreationForms(
150 content::RenderFrameHost
* rfh
,
151 const std::vector
<autofill::FormStructure
*>& forms
) = 0;
153 // Inform the client that the field has been filled.
154 virtual void DidFillOrPreviewField(
155 const base::string16
& autofilled_value
,
156 const base::string16
& profile_full_name
) = 0;
158 // Informs the client that a user gesture has been observed.
159 virtual void OnFirstUserGestureObserved() = 0;
161 // Opens |url| with the supplied |disposition|.
162 virtual void LinkClicked(const GURL
& url
,
163 WindowOpenDisposition disposition
) = 0;
166 } // namespace autofill
168 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CLIENT_H_