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