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

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

Powered by Google App Engine
This is Rietveld 408576698