Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate.h

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix long lines Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 CHROME_BROWSER_AUTOFILL_AUTOFILL_EXTERNAL_DELEGATE_H_
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_EXTERNAL_DELEGATE_H_
7
8 #include <vector>
9
10 #include "base/compiler_specific.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/string16.h"
13 #include "chrome/browser/autofill/autofill_popup_delegate.h"
14 #include "chrome/browser/autofill/password_autofill_manager.h"
15 #include "components/autofill/common/form_data.h"
16 #include "components/autofill/common/form_field_data.h"
17 #include "components/autofill/common/password_form_fill_data.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/web_contents_user_data.h"
21 #include "ui/gfx/rect.h"
22
23 class AutofillManager;
24
25 namespace gfx {
26 class Rect;
27 }
28
29 namespace content {
30 class WebContents;
31 }
32
33 // TODO(csharp): A lot of the logic in this class is copied from autofillagent.
34 // Once Autofill is moved out of WebKit this class should be the only home for
35 // this logic. See http://crbug.com/51644
36
37 // Delegate for in-browser Autocomplete and Autofill display and selection.
38 class AutofillExternalDelegate
39 : public content::WebContentsUserData<AutofillExternalDelegate>,
40 public content::NotificationObserver,
41 public AutofillPopupDelegate {
42 public:
43 // Creates an AutofillExternalDelegate and attaches it to the specified
44 // contents; the second argument is an AutofillManager managing Autofill for
45 // that WebContents.
46 static void CreateForWebContentsAndManager(content::WebContents* web_contents,
47 AutofillManager* autofill_manager);
48
49 // AutofillPopupDelegate implementation.
50 virtual void OnPopupShown(content::KeyboardListener* listener) OVERRIDE;
51 virtual void OnPopupHidden(content::KeyboardListener* listener) OVERRIDE;
52 virtual void DidSelectSuggestion(int identifier) OVERRIDE;
53 virtual void DidAcceptSuggestion(const string16& value,
54 int identifier) OVERRIDE;
55 virtual void RemoveSuggestion(const string16& value, int identifier) OVERRIDE;
56 virtual void ClearPreviewedForm() OVERRIDE;
57
58 // Records and associates a query_id with web form data. Called
59 // when the renderer posts an Autofill query to the browser. |bounds|
60 // is window relative. |display_warning_if_disabled| tells us if we should
61 // display warnings (such as autofill is disabled, but had suggestions).
62 // We might not want to display the warning if a website has disabled
63 // Autocomplete because they have their own popup, and showing our popup
64 // on to of theirs would be a poor user experience.
65 virtual void OnQuery(int query_id,
66 const FormData& form,
67 const FormFieldData& field,
68 const gfx::RectF& element_bounds,
69 bool display_warning_if_disabled);
70
71 // Records query results and correctly formats them before sending them off
72 // to be displayed. Called when an Autofill query result is available.
73 virtual void OnSuggestionsReturned(
74 int query_id,
75 const std::vector<string16>& autofill_values,
76 const std::vector<string16>& autofill_labels,
77 const std::vector<string16>& autofill_icons,
78 const std::vector<int>& autofill_unique_ids);
79
80 // Show password suggestions in the popup.
81 void OnShowPasswordSuggestions(const std::vector<string16>& suggestions,
82 const FormFieldData& field,
83 const gfx::RectF& bounds);
84
85 // Set the data list value associated with the current field.
86 void SetCurrentDataListValues(const std::vector<string16>& autofill_values,
87 const std::vector<string16>& autofill_labels,
88 const std::vector<string16>& autofill_icons,
89 const std::vector<int>& autofill_unique_ids);
90
91 // Inform the delegate that the text field editing has ended. This is
92 // used to help record the metrics of when a new popup is shown.
93 void DidEndTextFieldEditing();
94
95 // Returns the delegate to its starting state by removing any page specific
96 // values or settings.
97 void Reset();
98
99 // Inform the Password Manager of a filled form.
100 void AddPasswordFormMapping(
101 const FormFieldData& form,
102 const PasswordFormFillData& fill_data);
103
104 protected:
105 friend class content::WebContentsUserData<AutofillExternalDelegate>;
106 AutofillExternalDelegate(content::WebContents* web_contents,
107 AutofillManager* autofill_manager);
108 virtual ~AutofillExternalDelegate();
109
110 content::WebContents* web_contents() { return web_contents_; }
111
112 private:
113 // Fills the form with the Autofill data corresponding to |unique_id|.
114 // If |is_preview| is true then this is just a preview to show the user what
115 // would be selected and if |is_preview| is false then the user has selected
116 // this data.
117 void FillAutofillFormData(int unique_id, bool is_preview);
118
119 // Handle applying any Autofill warnings to the Autofill popup.
120 void ApplyAutofillWarnings(std::vector<string16>* autofill_values,
121 std::vector<string16>* autofill_labels,
122 std::vector<string16>* autofill_icons,
123 std::vector<int>* autofill_unique_ids);
124
125 // Handle applying any Autofill option listings to the Autofill popup.
126 // This function should only get called when there is at least one
127 // multi-field suggestion in the list of suggestions.
128 void ApplyAutofillOptions(std::vector<string16>* autofill_values,
129 std::vector<string16>* autofill_labels,
130 std::vector<string16>* autofill_icons,
131 std::vector<int>* autofill_unique_ids);
132
133 // Insert the data list values at the start of the given list, including
134 // any required separators.
135 void InsertDataListValues(std::vector<string16>* autofill_values,
136 std::vector<string16>* autofill_labels,
137 std::vector<string16>* autofill_icons,
138 std::vector<int>* autofill_unique_ids);
139
140 // content::NotificationObserver method override.
141 virtual void Observe(int type,
142 const content::NotificationSource& source,
143 const content::NotificationDetails& details) OVERRIDE;
144
145 // The web_contents associated with this delegate.
146 content::WebContents* web_contents_; // weak; owns me.
147 AutofillManager* autofill_manager_; // weak.
148
149 // Password Autofill manager, handles all password-related Autofilling.
150 PasswordAutofillManager password_autofill_manager_;
151
152 // The ID of the last request sent for form field Autofill. Used to ignore
153 // out of date responses.
154 int autofill_query_id_;
155
156 // A scoped container for notification registries.
157 content::NotificationRegistrar registrar_;
158
159 // The current form and field selected by Autofill.
160 FormData autofill_query_form_;
161 FormFieldData autofill_query_field_;
162
163 // The bounds of the form field that user is interacting with.
164 gfx::RectF element_bounds_;
165
166 // Should we display a warning if Autofill is disabled?
167 bool display_warning_if_disabled_;
168
169 // Does the popup include any Autofill profile or credit card suggestions?
170 bool has_autofill_suggestion_;
171
172 // Have we already shown Autofill suggestions for the field the user is
173 // currently editing? Used to keep track of state for metrics logging.
174 bool has_shown_autofill_popup_for_current_edit_;
175
176 // The RenderViewHost that this object has been registered with as a
177 // keyboard listener.
178 content::RenderViewHost* registered_keyboard_listener_with_;
179
180 // The current data list values.
181 std::vector<string16> data_list_values_;
182 std::vector<string16> data_list_labels_;
183 std::vector<string16> data_list_icons_;
184 std::vector<int> data_list_unique_ids_;
185
186 DISALLOW_COPY_AND_ASSIGN(AutofillExternalDelegate);
187 };
188
189 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_EXTERNAL_DELEGATE_H_
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_download_url_unittest.cc ('k') | chrome/browser/autofill/autofill_external_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698