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"
25 class AutofillMetrics;
26 class AutofillPopupDelegate;
27 class AutofillWebDataService;
30 class PersonalDataManager;
33 // A client interface that needs to be supplied to the Autofill component by the
36 // Each client instance is associated with a given context within which an
37 // AutofillManager is used (e.g. a single tab), so when we say "for the client"
38 // below, we mean "in the execution context the client is associated with" (e.g.
39 // for the tab the AutofillManager is attached to).
40 class AutofillClient {
42 // Copy of blink::WebFormElement::AutocompleteResult.
43 enum RequestAutocompleteResult {
44 AutocompleteResultSuccess,
45 AutocompleteResultErrorDisabled,
46 AutocompleteResultErrorCancel,
47 AutocompleteResultErrorInvalid,
50 typedef base::Callback<void(RequestAutocompleteResult,
51 const base::string16&,
52 const FormStructure*)> ResultCallback;
54 virtual ~AutofillClient() {}
56 // Gets the PersonalDataManager instance associated with the client.
57 virtual PersonalDataManager* GetPersonalDataManager() = 0;
59 // Gets the AutofillWebDataService instance associated with the client.
60 virtual scoped_refptr<AutofillWebDataService> GetDatabase() = 0;
62 // Gets the preferences associated with the client.
63 virtual PrefService* GetPrefs() = 0;
65 // Hides the associated request autocomplete dialog (if it exists).
66 virtual void HideRequestAutocompleteDialog() = 0;
68 // Causes the Autofill settings UI to be shown.
69 virtual void ShowAutofillSettings() = 0;
71 // Run |save_card_callback| if the credit card should be imported as personal
72 // data. |metric_logger| can be used to log user actions.
73 virtual void ConfirmSaveCreditCard(
74 const AutofillMetrics& metric_logger,
75 const base::Closure& save_card_callback) = 0;
77 // Causes the dialog for request autocomplete feature to be shown.
78 virtual void ShowRequestAutocompleteDialog(
80 const GURL& source_url,
81 const ResultCallback& callback) = 0;
83 // Shows an Autofill popup with the given |values|, |labels|, |icons|, and
84 // |identifiers| for the element at |element_bounds|. |delegate| will be
85 // notified of popup events.
86 virtual void ShowAutofillPopup(
87 const gfx::RectF& element_bounds,
88 base::i18n::TextDirection text_direction,
89 const std::vector<base::string16>& values,
90 const std::vector<base::string16>& labels,
91 const std::vector<base::string16>& icons,
92 const std::vector<int>& identifiers,
93 base::WeakPtr<AutofillPopupDelegate> delegate) = 0;
95 // Update the data list values shown by the Autofill popup, if visible.
96 virtual void UpdateAutofillPopupDataListValues(
97 const std::vector<base::string16>& values,
98 const std::vector<base::string16>& labels) = 0;
100 // Hide the Autofill popup if one is currently showing.
101 virtual void HideAutofillPopup() = 0;
103 // Whether the Autocomplete feature of Autofill should be enabled.
104 virtual bool IsAutocompleteEnabled() = 0;
106 // Pass the form structures to the password generation manager to detect
107 // account creation forms.
108 virtual void DetectAccountCreationForms(
109 const std::vector<autofill::FormStructure*>& forms) = 0;
111 // Inform the client that the field has been filled.
112 virtual void DidFillOrPreviewField(
113 const base::string16& autofilled_value,
114 const base::string16& profile_full_name) = 0;
117 } // namespace autofill
119 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_CLIENT_H_