Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / autofill / core / browser / autofill_client.h
blob11700dc6515f5c515d5b8eda7bccc00662c0302a
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_
8 #include <vector>
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"
15 #include "url/gurl.h"
17 class IdentityProvider;
19 namespace content {
20 class RenderFrameHost;
23 namespace gfx {
24 class Rect;
25 class RectF;
28 namespace rappor {
29 class RapporService;
32 class GURL;
33 class PrefService;
35 namespace autofill {
37 class AutofillPopupDelegate;
38 class AutofillWebDataService;
39 class CardUnmaskDelegate;
40 class CreditCard;
41 class FormStructure;
42 class PersonalDataManager;
43 struct FormData;
44 struct Suggestion;
46 // A client interface that needs to be supplied to the Autofill component by the
47 // embedder.
49 // Each client instance is associated with a given context within which an
50 // AutofillManager is used (e.g. a single tab), so when we say "for the client"
51 // below, we mean "in the execution context the client is associated with" (e.g.
52 // for the tab the AutofillManager is attached to).
53 class AutofillClient {
54 public:
55 // Copy of blink::WebFormElement::AutocompleteResult.
56 enum RequestAutocompleteResult {
57 AutocompleteResultSuccess,
58 AutocompleteResultErrorDisabled,
59 AutocompleteResultErrorCancel,
60 AutocompleteResultErrorInvalid,
63 enum GetRealPanResult {
64 // Empty result. Used for initializing variables and should generally
65 // not be returned nor passed as arguments unless explicitly allowed by
66 // the API.
67 NONE,
69 // Request succeeded.
70 SUCCESS,
72 // Request failed; try again.
73 TRY_AGAIN_FAILURE,
75 // Request failed; don't try again.
76 PERMANENT_FAILURE,
78 // Unable to connect to Wallet servers. Prompt user to check internet
79 // connection.
80 NETWORK_ERROR,
83 typedef base::Callback<void(RequestAutocompleteResult,
84 const base::string16&,
85 const FormStructure*)> ResultCallback;
87 typedef base::Callback<void(const base::string16& /* card number */,
88 int /* exp month */,
89 int /* exp year */)> CreditCardScanCallback;
91 virtual ~AutofillClient() {}
93 // Gets the PersonalDataManager instance associated with the client.
94 virtual PersonalDataManager* GetPersonalDataManager() = 0;
96 // Gets the AutofillWebDataService instance associated with the client.
97 virtual scoped_refptr<AutofillWebDataService> GetDatabase() = 0;
99 // Gets the preferences associated with the client.
100 virtual PrefService* GetPrefs() = 0;
102 // Gets the IdentityProvider associated with the client (for OAuth2).
103 virtual IdentityProvider* GetIdentityProvider() = 0;
105 // Gets the RapporService associated with the client (for metrics).
106 virtual rappor::RapporService* GetRapporService() = 0;
108 // Hides the associated request autocomplete dialog (if it exists).
109 virtual void HideRequestAutocompleteDialog() = 0;
111 // Causes the Autofill settings UI to be shown.
112 virtual void ShowAutofillSettings() = 0;
114 // A user has attempted to use a masked card. Prompt them for further
115 // information to proceed.
116 virtual void ShowUnmaskPrompt(const CreditCard& card,
117 base::WeakPtr<CardUnmaskDelegate> delegate) = 0;
118 virtual void OnUnmaskVerificationResult(GetRealPanResult result) = 0;
120 // Run |save_card_callback| if the credit card should be imported as personal
121 // data. |metric_logger| can be used to log user actions.
122 virtual void ConfirmSaveCreditCard(
123 const base::Closure& save_card_callback) = 0;
125 // Returns true if both the platform and the device support scanning credit
126 // cards. Should be called before ScanCreditCard().
127 virtual bool HasCreditCardScanFeature() = 0;
129 // Shows the user interface for scanning a credit card. Invokes the |callback|
130 // when a credit card is scanned successfully. Should be called only if
131 // HasCreditCardScanFeature() returns true.
132 virtual void ScanCreditCard(const CreditCardScanCallback& callback) = 0;
134 // Causes the dialog for request autocomplete feature to be shown.
135 virtual void ShowRequestAutocompleteDialog(
136 const FormData& form,
137 content::RenderFrameHost* render_frame_host,
138 const ResultCallback& callback) = 0;
140 // Shows an Autofill popup with the given |values|, |labels|, |icons|, and
141 // |identifiers| for the element at |element_bounds|. |delegate| will be
142 // notified of popup events.
143 virtual void ShowAutofillPopup(
144 const gfx::RectF& element_bounds,
145 base::i18n::TextDirection text_direction,
146 const std::vector<Suggestion>& suggestions,
147 base::WeakPtr<AutofillPopupDelegate> delegate) = 0;
149 // Update the data list values shown by the Autofill popup, if visible.
150 virtual void UpdateAutofillPopupDataListValues(
151 const std::vector<base::string16>& values,
152 const std::vector<base::string16>& labels) = 0;
154 // Hide the Autofill popup if one is currently showing.
155 virtual void HideAutofillPopup() = 0;
157 // Whether the Autocomplete feature of Autofill should be enabled.
158 virtual bool IsAutocompleteEnabled() = 0;
160 // Pass the form structures to the password manager to choose correct username
161 // and to the password generation manager to detect account creation forms.
162 virtual void PropagateAutofillPredictions(
163 content::RenderFrameHost* rfh,
164 const std::vector<autofill::FormStructure*>& forms) = 0;
166 // Inform the client that the field has been filled.
167 virtual void DidFillOrPreviewField(
168 const base::string16& autofilled_value,
169 const base::string16& profile_full_name) = 0;
171 // Informs the client that a user gesture has been observed.
172 virtual void OnFirstUserGestureObserved() = 0;
174 // Opens |url| with the supplied |disposition|.
175 virtual void LinkClicked(const GURL& url,
176 WindowOpenDisposition disposition) = 0;
178 // If the context is secure.
179 virtual bool IsContextSecure(const GURL& form_origin) = 0;
182 } // namespace autofill
184 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CLIENT_H_