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

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

Issue 11000016: Move forms/ out of webkit/. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Response to review Created 8 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 27 matching lines...) Expand all
38 class ProfileSyncService; 38 class ProfileSyncService;
39 class TabContents; 39 class TabContents;
40 40
41 struct ViewHostMsg_FrameNavigate_Params; 41 struct ViewHostMsg_FrameNavigate_Params;
42 42
43 namespace autofill { 43 namespace autofill {
44 class AutofillManagerDelegate; 44 class AutofillManagerDelegate;
45 class PasswordGenerator; 45 class PasswordGenerator;
46 } 46 }
47 47
48 namespace chrome {
49 struct FormData;
50 struct FormField;
51 struct PasswordFormFillData;
52 }
53
48 namespace content { 54 namespace content {
49 class RenderViewHost; 55 class RenderViewHost;
56 struct PasswordForm;
50 } 57 }
51 58
52 namespace gfx { 59 namespace gfx {
53 class Rect; 60 class Rect;
54 } 61 }
55 62
56 namespace IPC { 63 namespace IPC {
57 class Message; 64 class Message;
58 } 65 }
59 66
60 namespace webkit {
61 namespace forms {
62 struct FormData;
63 struct FormField;
64 struct PasswordForm;
65 struct PasswordFormFillData;
66 }
67 }
68
69 // Manages saving and restoring the user's personal information entered into web 67 // Manages saving and restoring the user's personal information entered into web
70 // forms. 68 // forms.
71 class AutofillManager : public content::NotificationObserver, 69 class AutofillManager : public content::NotificationObserver,
72 public content::WebContentsObserver, 70 public content::WebContentsObserver,
73 public AutofillDownloadManager::Observer, 71 public AutofillDownloadManager::Observer,
74 public ProfileSyncServiceObserver, 72 public ProfileSyncServiceObserver,
75 public base::RefCounted<AutofillManager> { 73 public base::RefCounted<AutofillManager> {
76 public: 74 public:
77 // Lifetime of |client| and |tab_contents| must exceed lifetime of 75 // Lifetime of |client| and |tab_contents| must exceed lifetime of
78 // AutofillManager. 76 // AutofillManager.
79 explicit AutofillManager(autofill::AutofillManagerDelegate* delegate, 77 explicit AutofillManager(autofill::AutofillManagerDelegate* delegate,
80 TabContents* tab_contents); 78 TabContents* tab_contents);
81 79
82 // Registers our Enable/Disable Autofill pref. 80 // Registers our Enable/Disable Autofill pref.
83 static void RegisterUserPrefs(PrefServiceBase* prefs); 81 static void RegisterUserPrefs(PrefServiceBase* prefs);
84 82
85 // Set our external delegate. 83 // Set our external delegate.
86 // TODO(jrg): consider passing delegate into the ctor. That won't 84 // TODO(jrg): consider passing delegate into the ctor. That won't
87 // work if the delegate has a pointer to the AutofillManager, but 85 // work if the delegate has a pointer to the AutofillManager, but
88 // future directions may not need such a pointer. 86 // future directions may not need such a pointer.
89 void SetExternalDelegate(AutofillExternalDelegate* delegate) { 87 void SetExternalDelegate(AutofillExternalDelegate* delegate) {
90 external_delegate_ = delegate; 88 external_delegate_ = delegate;
91 } 89 }
92 90
93 // Used to say if this class has an external delegate that it is using. 91 // Used to say if this class has an external delegate that it is using.
94 bool HasExternalDelegate(); 92 bool HasExternalDelegate();
95 93
96 // Called from our external delegate so they cannot be private. 94 // Called from our external delegate so they cannot be private.
97 virtual void OnFillAutofillFormData(int query_id, 95 virtual void OnFillAutofillFormData(int query_id,
98 const webkit::forms::FormData& form, 96 const chrome::FormData& form,
99 const webkit::forms::FormField& field, 97 const chrome::FormField& field,
100 int unique_id); 98 int unique_id);
101 void OnDidShowAutofillSuggestions(bool is_new_popup); 99 void OnDidShowAutofillSuggestions(bool is_new_popup);
102 void OnDidFillAutofillFormData(const base::TimeTicks& timestamp); 100 void OnDidFillAutofillFormData(const base::TimeTicks& timestamp);
103 void OnShowAutofillDialog(); 101 void OnShowAutofillDialog();
104 void OnDidPreviewAutofillFormData(); 102 void OnDidPreviewAutofillFormData();
105 void OnShowPasswordGenerationPopup(const gfx::Rect& bounds, 103 void OnShowPasswordGenerationPopup(const gfx::Rect& bounds,
106 int max_length, 104 int max_length,
107 const webkit::forms::PasswordForm& form); 105 const content::PasswordForm& form);
108 106
109 // Remove the credit card or Autofill profile that matches |unique_id| 107 // Remove the credit card or Autofill profile that matches |unique_id|
110 // from the database. 108 // from the database.
111 void RemoveAutofillProfileOrCreditCard(int unique_id); 109 void RemoveAutofillProfileOrCreditCard(int unique_id);
112 110
113 protected: 111 protected:
114 // Only test code should subclass AutofillManager. 112 // Only test code should subclass AutofillManager.
115 friend class base::RefCounted<AutofillManager>; 113 friend class base::RefCounted<AutofillManager>;
116 virtual ~AutofillManager(); 114 virtual ~AutofillManager();
117 115
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 ScopedVector<FormStructure>* form_structures() { return &form_structures_; } 162 ScopedVector<FormStructure>* form_structures() { return &form_structures_; }
165 163
166 // Exposed for testing. 164 // Exposed for testing.
167 AutofillExternalDelegate* external_delegate() { 165 AutofillExternalDelegate* external_delegate() {
168 return external_delegate_; 166 return external_delegate_;
169 } 167 }
170 168
171 // Processes the submitted |form|, saving any new Autofill data and uploading 169 // Processes the submitted |form|, saving any new Autofill data and uploading
172 // the possible field types for the submitted fields to the crowdsouring 170 // the possible field types for the submitted fields to the crowdsouring
173 // server. Returns false if this form is not relevant for Autofill. 171 // server. Returns false if this form is not relevant for Autofill.
174 bool OnFormSubmitted(const webkit::forms::FormData& form, 172 bool OnFormSubmitted(const chrome::FormData& form,
175 const base::TimeTicks& timestamp); 173 const base::TimeTicks& timestamp);
176 174
177 private: 175 private:
178 // content::WebContentsObserver: 176 // content::WebContentsObserver:
179 virtual void RenderViewCreated(content::RenderViewHost* host) OVERRIDE; 177 virtual void RenderViewCreated(content::RenderViewHost* host) OVERRIDE;
180 virtual void DidNavigateMainFrame( 178 virtual void DidNavigateMainFrame(
181 const content::LoadCommittedDetails& details, 179 const content::LoadCommittedDetails& details,
182 const content::FrameNavigateParams& params) OVERRIDE; 180 const content::FrameNavigateParams& params) OVERRIDE;
183 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 181 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
184 182
(...skipping 12 matching lines...) Expand all
197 const content::NotificationSource& source, 195 const content::NotificationSource& source,
198 const content::NotificationDetails& details) OVERRIDE; 196 const content::NotificationDetails& details) OVERRIDE;
199 197
200 // Determines what the current state of password generation is, and if it has 198 // Determines what the current state of password generation is, and if it has
201 // changed from |password_generation_enabled_|. If it has changed or if 199 // changed from |password_generation_enabled_|. If it has changed or if
202 // |new_renderer| is true, it notifies the renderer of this change via 200 // |new_renderer| is true, it notifies the renderer of this change via
203 // SendPasswordGenerationStateToRenderer. 201 // SendPasswordGenerationStateToRenderer.
204 void UpdatePasswordGenerationState(content::RenderViewHost* host, 202 void UpdatePasswordGenerationState(content::RenderViewHost* host,
205 bool new_renderer); 203 bool new_renderer);
206 204
207 void OnFormsSeen(const std::vector<webkit::forms::FormData>& forms, 205 void OnFormsSeen(const std::vector<chrome::FormData>& forms,
208 const base::TimeTicks& timestamp); 206 const base::TimeTicks& timestamp);
209 void OnTextFieldDidChange(const webkit::forms::FormData& form, 207 void OnTextFieldDidChange(const chrome::FormData& form,
210 const webkit::forms::FormField& field, 208 const chrome::FormField& field,
211 const base::TimeTicks& timestamp); 209 const base::TimeTicks& timestamp);
212 210
213 // The |bounding_box| is a window relative value. 211 // The |bounding_box| is a window relative value.
214 void OnQueryFormFieldAutofill(int query_id, 212 void OnQueryFormFieldAutofill(int query_id,
215 const webkit::forms::FormData& form, 213 const chrome::FormData& form,
216 const webkit::forms::FormField& field, 214 const chrome::FormField& field,
217 const gfx::Rect& bounding_box, 215 const gfx::Rect& bounding_box,
218 bool display_warning); 216 bool display_warning);
219 void OnDidEndTextFieldEditing(); 217 void OnDidEndTextFieldEditing();
220 void OnHideAutofillPopup(); 218 void OnHideAutofillPopup();
221 void OnAddPasswordFormMapping( 219 void OnAddPasswordFormMapping(
222 const webkit::forms::FormField& form, 220 const chrome::FormField& form,
223 const webkit::forms::PasswordFormFillData& fill_data); 221 const chrome::PasswordFormFillData& fill_data);
224 void OnShowPasswordSuggestions(const webkit::forms::FormField& field, 222 void OnShowPasswordSuggestions(const chrome::FormField& field,
225 const gfx::Rect& bounds, 223 const gfx::Rect& bounds,
226 const std::vector<string16>& suggestions); 224 const std::vector<string16>& suggestions);
227 void OnSetDataList(const std::vector<string16>& values, 225 void OnSetDataList(const std::vector<string16>& values,
228 const std::vector<string16>& labels, 226 const std::vector<string16>& labels,
229 const std::vector<string16>& icons, 227 const std::vector<string16>& icons,
230 const std::vector<int>& unique_ids); 228 const std::vector<int>& unique_ids);
231 229
232 // Fills |host| with the RenderViewHost for this tab. 230 // Fills |host| with the RenderViewHost for this tab.
233 // Returns false if Autofill is disabled or if the host is unavailable. 231 // Returns false if Autofill is disabled or if the host is unavailable.
234 bool GetHost(const std::vector<AutofillProfile*>& profiles, 232 bool GetHost(const std::vector<AutofillProfile*>& profiles,
235 const std::vector<CreditCard*>& credit_cards, 233 const std::vector<CreditCard*>& credit_cards,
236 content::RenderViewHost** host) const WARN_UNUSED_RESULT; 234 content::RenderViewHost** host) const WARN_UNUSED_RESULT;
237 235
238 // Unpacks |unique_id| and fills |profile| or |credit_card| with the 236 // Unpacks |unique_id| and fills |profile| or |credit_card| with the
239 // appropriate data source. Returns false if the unpacked id cannot be found. 237 // appropriate data source. Returns false if the unpacked id cannot be found.
240 bool GetProfileOrCreditCard(int unique_id, 238 bool GetProfileOrCreditCard(int unique_id,
241 const std::vector<AutofillProfile*>& profiles, 239 const std::vector<AutofillProfile*>& profiles,
242 const std::vector<CreditCard*>& credit_cards, 240 const std::vector<CreditCard*>& credit_cards,
243 const AutofillProfile** profile, 241 const AutofillProfile** profile,
244 const CreditCard** credit_card, 242 const CreditCard** credit_card,
245 size_t* variant) const WARN_UNUSED_RESULT; 243 size_t* variant) const WARN_UNUSED_RESULT;
246 244
247 // Fills |form_structure| cached element corresponding to |form|. 245 // Fills |form_structure| cached element corresponding to |form|.
248 // Returns false if the cached element was not found. 246 // Returns false if the cached element was not found.
249 bool FindCachedForm(const webkit::forms::FormData& form, 247 bool FindCachedForm(const chrome::FormData& form,
250 FormStructure** form_structure) const WARN_UNUSED_RESULT; 248 FormStructure** form_structure) const WARN_UNUSED_RESULT;
251 249
252 // Fills |form_structure| and |autofill_field| with the cached elements 250 // Fills |form_structure| and |autofill_field| with the cached elements
253 // corresponding to |form| and |field|. This might have the side-effect of 251 // corresponding to |form| and |field|. This might have the side-effect of
254 // updating the cache. Returns false if the |form| is not autofillable, or if 252 // updating the cache. Returns false if the |form| is not autofillable, or if
255 // it is not already present in the cache and the cache is full. 253 // it is not already present in the cache and the cache is full.
256 bool GetCachedFormAndField(const webkit::forms::FormData& form, 254 bool GetCachedFormAndField(const chrome::FormData& form,
257 const webkit::forms::FormField& field, 255 const chrome::FormField& field,
258 FormStructure** form_structure, 256 FormStructure** form_structure,
259 AutofillField** autofill_field) WARN_UNUSED_RESULT; 257 AutofillField** autofill_field) WARN_UNUSED_RESULT;
260 258
261 // Re-parses |live_form| and adds the result to |form_structures_|. 259 // Re-parses |live_form| and adds the result to |form_structures_|.
262 // |cached_form| should be a pointer to the existing version of the form, or 260 // |cached_form| should be a pointer to the existing version of the form, or
263 // NULL if no cached version exists. The updated form is then written into 261 // NULL if no cached version exists. The updated form is then written into
264 // |updated_form|. Returns false if the cache could not be updated. 262 // |updated_form|. Returns false if the cache could not be updated.
265 bool UpdateCachedForm(const webkit::forms::FormData& live_form, 263 bool UpdateCachedForm(const chrome::FormData& live_form,
266 const FormStructure* cached_form, 264 const FormStructure* cached_form,
267 FormStructure** updated_form) WARN_UNUSED_RESULT; 265 FormStructure** updated_form) WARN_UNUSED_RESULT;
268 266
269 // Returns a list of values from the stored profiles that match |type| and the 267 // Returns a list of values from the stored profiles that match |type| and the
270 // value of |field| and returns the labels of the matching profiles. |labels| 268 // value of |field| and returns the labels of the matching profiles. |labels|
271 // is filled with the Profile label. 269 // is filled with the Profile label.
272 void GetProfileSuggestions(FormStructure* form, 270 void GetProfileSuggestions(FormStructure* form,
273 const webkit::forms::FormField& field, 271 const chrome::FormField& field,
274 AutofillFieldType type, 272 AutofillFieldType type,
275 std::vector<string16>* values, 273 std::vector<string16>* values,
276 std::vector<string16>* labels, 274 std::vector<string16>* labels,
277 std::vector<string16>* icons, 275 std::vector<string16>* icons,
278 std::vector<int>* unique_ids) const; 276 std::vector<int>* unique_ids) const;
279 277
280 // Returns a list of values from the stored credit cards that match |type| and 278 // Returns a list of values from the stored credit cards that match |type| and
281 // the value of |field| and returns the labels of the matching credit cards. 279 // the value of |field| and returns the labels of the matching credit cards.
282 void GetCreditCardSuggestions(FormStructure* form, 280 void GetCreditCardSuggestions(FormStructure* form,
283 const webkit::forms::FormField& field, 281 const chrome::FormField& field,
284 AutofillFieldType type, 282 AutofillFieldType type,
285 std::vector<string16>* values, 283 std::vector<string16>* values,
286 std::vector<string16>* labels, 284 std::vector<string16>* labels,
287 std::vector<string16>* icons, 285 std::vector<string16>* icons,
288 std::vector<int>* unique_ids) const; 286 std::vector<int>* unique_ids) const;
289 287
290 // Set |field|'s value based on |type| and contents of the |credit_card|. 288 // Set |field|'s value based on |type| and contents of the |credit_card|.
291 void FillCreditCardFormField(const CreditCard& credit_card, 289 void FillCreditCardFormField(const CreditCard& credit_card,
292 AutofillFieldType type, 290 AutofillFieldType type,
293 webkit::forms::FormField* field); 291 chrome::FormField* field);
294 292
295 // Set |field|'s value based on |cached_field|'s type and contents of the 293 // Set |field|'s value based on |cached_field|'s type and contents of the
296 // |profile|. The |variant| parameter specifies which value in a multi-valued 294 // |profile|. The |variant| parameter specifies which value in a multi-valued
297 // profile. 295 // profile.
298 void FillFormField(const AutofillProfile& profile, 296 void FillFormField(const AutofillProfile& profile,
299 const AutofillField& cached_field, 297 const AutofillField& cached_field,
300 size_t variant, 298 size_t variant,
301 webkit::forms::FormField* field); 299 chrome::FormField* field);
302 300
303 // Set |field|'s value for phone number based on contents of the |profile|. 301 // Set |field|'s value for phone number based on contents of the |profile|.
304 // The |cached_field| specifies the type of the phone and whether this is a 302 // The |cached_field| specifies the type of the phone and whether this is a
305 // phone prefix or suffix. The |variant| parameter specifies which value in a 303 // phone prefix or suffix. The |variant| parameter specifies which value in a
306 // multi-valued profile. 304 // multi-valued profile.
307 void FillPhoneNumberField(const AutofillProfile& profile, 305 void FillPhoneNumberField(const AutofillProfile& profile,
308 const AutofillField& cached_field, 306 const AutofillField& cached_field,
309 size_t variant, 307 size_t variant,
310 webkit::forms::FormField* field); 308 chrome::FormField* field);
311 309
312 // Parses the forms using heuristic matching and querying the Autofill server. 310 // Parses the forms using heuristic matching and querying the Autofill server.
313 void ParseForms(const std::vector<webkit::forms::FormData>& forms); 311 void ParseForms(const std::vector<chrome::FormData>& forms);
314 312
315 // Imports the form data, submitted by the user, into |personal_data_|. 313 // Imports the form data, submitted by the user, into |personal_data_|.
316 void ImportFormData(const FormStructure& submitted_form); 314 void ImportFormData(const FormStructure& submitted_form);
317 315
318 // If |initial_interaction_timestamp_| is unset or is set to a later time than 316 // If |initial_interaction_timestamp_| is unset or is set to a later time than
319 // |interaction_timestamp|, updates the cached timestamp. The latter check is 317 // |interaction_timestamp|, updates the cached timestamp. The latter check is
320 // needed because IPC messages can arrive out of order. 318 // needed because IPC messages can arrive out of order.
321 void UpdateInitialInteractionTimestamp( 319 void UpdateInitialInteractionTimestamp(
322 const base::TimeTicks& interaction_timestamp); 320 const base::TimeTicks& interaction_timestamp);
323 321
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 TestTabContentsWithExternalDelegate); 408 TestTabContentsWithExternalDelegate);
411 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, 409 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest,
412 UserHappinessFormLoadAndSubmission); 410 UserHappinessFormLoadAndSubmission);
413 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction); 411 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, UserHappinessFormInteraction);
414 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FormFillDuration); 412 FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, FormFillDuration);
415 413
416 DISALLOW_COPY_AND_ASSIGN(AutofillManager); 414 DISALLOW_COPY_AND_ASSIGN(AutofillManager);
417 }; 415 };
418 416
419 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_ 417 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698