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