blob: 374c105fd5dce8fd96a5d973e1e59953fcba6259 [file] [log] [blame]
Ben Murdocheb525c52013-07-10 11:40:50 +01001// 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.
4
5#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_DELEGATE_H_
6#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_DELEGATE_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#include "components/autofill/content/browser/autocheckout_steps.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010015#include "components/autofill/core/browser/autocheckout_bubble_state.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010016
17namespace content {
18struct PasswordForm;
Ben Murdocheb525c52013-07-10 11:40:50 +010019}
20
21namespace gfx {
22class Rect;
23class RectF;
24}
25
26class GURL;
27class InfoBarService;
28class PrefService;
29
30namespace autofill {
31
32class AutofillMetrics;
33class AutofillPopupDelegate;
34class CreditCard;
35class FormStructure;
36class PasswordGenerator;
37class PersonalDataManager;
38struct FormData;
39
40namespace autocheckout {
41class WhitelistManager;
42}
43
44enum DialogType {
45 // Autofill dialog for the Autocheckout feature.
46 DIALOG_TYPE_AUTOCHECKOUT,
47 // Autofill dialog for the requestAutocomplete feature.
48 DIALOG_TYPE_REQUEST_AUTOCOMPLETE,
49};
50
51// A delegate interface that needs to be supplied to AutofillManager
52// by the embedder.
53//
54// Each delegate instance is associated with a given context within
55// which an AutofillManager is used (e.g. a single tab), so when we
56// say "for the delegate" below, we mean "in the execution context the
57// delegate is associated with" (e.g. for the tab the AutofillManager is
58// attached to).
59class AutofillManagerDelegate {
60 public:
61 virtual ~AutofillManagerDelegate() {}
62
63 // Gets the PersonalDataManager instance associated with the delegate.
64 virtual PersonalDataManager* GetPersonalDataManager() = 0;
65
66 // Gets the preferences associated with the delegate.
67 virtual PrefService* GetPrefs() = 0;
68
69 // Gets the autocheckout::WhitelistManager instance associated with the
70 // delegate.
71 virtual autocheckout::WhitelistManager*
72 GetAutocheckoutWhitelistManager() const = 0;
73
74 // Hides the associated request autocomplete dialog (if it exists).
75 virtual void HideRequestAutocompleteDialog() = 0;
76
77 // Causes an error explaining that Autocheckout has failed to be displayed to
78 // the user.
79 virtual void OnAutocheckoutError() = 0;
80
81 // Called when an Autocheckout flow has succeeded. Causes a notification
82 // explaining that they must confirm their purchase to be displayed to the
83 // user.
84 virtual void OnAutocheckoutSuccess() = 0;
85
86 // Causes the Autofill settings UI to be shown.
87 virtual void ShowAutofillSettings() = 0;
88
89 // Run |save_card_callback| if the credit card should be imported as personal
90 // data. |metric_logger| can be used to log user actions.
91 virtual void ConfirmSaveCreditCard(
92 const AutofillMetrics& metric_logger,
93 const CreditCard& credit_card,
94 const base::Closure& save_card_callback) = 0;
95
96 // Causes the Autocheckout bubble UI to be displayed. |bounding_box| is the
97 // anchor for the bubble. |is_google_user| is whether or not the user is
98 // logged into or has been logged into accounts.google.com. |callback| is run
Ben Murdochbb1529c2013-08-08 10:24:53 +010099 // if the bubble is accepted. The returned boolean informs the caller whether
100 // or not the bubble is successfully shown.
101 virtual bool ShowAutocheckoutBubble(
Ben Murdocheb525c52013-07-10 11:40:50 +0100102 const gfx::RectF& bounding_box,
103 bool is_google_user,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100104 const base::Callback<void(AutocheckoutBubbleState)>& callback) = 0;
Ben Murdocheb525c52013-07-10 11:40:50 +0100105
106 // Causes the dialog for request autocomplete feature to be shown.
107 virtual void ShowRequestAutocompleteDialog(
108 const FormData& form,
109 const GURL& source_url,
110 DialogType dialog_type,
111 const base::Callback<void(const FormStructure*,
112 const std::string&)>& callback) = 0;
113
114 // Hide the Autocheckout bubble if one is currently showing.
115 virtual void HideAutocheckoutBubble() = 0;
116
117 // Shows an Autofill popup with the given |values|, |labels|, |icons|, and
118 // |identifiers| for the element at |element_bounds|. |delegate| will be
119 // notified of popup events.
120 virtual void ShowAutofillPopup(
121 const gfx::RectF& element_bounds,
122 base::i18n::TextDirection text_direction,
123 const std::vector<base::string16>& values,
124 const std::vector<base::string16>& labels,
125 const std::vector<base::string16>& icons,
126 const std::vector<int>& identifiers,
127 base::WeakPtr<AutofillPopupDelegate> delegate) = 0;
128
Ben Murdochca12bfa2013-07-23 11:17:05 +0100129 // Update the data list values shown by the Autofill popup, if visible.
130 virtual void UpdateAutofillPopupDataListValues(
131 const std::vector<base::string16>& values,
132 const std::vector<base::string16>& labels) = 0;
133
Ben Murdocheb525c52013-07-10 11:40:50 +0100134 // Hide the Autofill popup if one is currently showing.
135 virtual void HideAutofillPopup() = 0;
136
137 // Whether the Autocomplete feature of Autofill should be enabled.
138 virtual bool IsAutocompleteEnabled() = 0;
139
140 // Update progress of the Autocheckout flow as displayed to the user.
141 virtual void AddAutocheckoutStep(AutocheckoutStepType step_type) = 0;
142 virtual void UpdateAutocheckoutStep(
143 AutocheckoutStepType step_type,
144 AutocheckoutStepStatus step_status) = 0;
145};
146
147} // namespace autofill
148
149#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_MANAGER_DELEGATE_H_