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

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

Issue 2818033: AutoFill: Aggregate profile data. Remove the AutoFill InfoBar. (Closed)
Patch Set: Comment. Created 10 years, 5 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "chrome/browser/autofill/autofill_manager.h" 5 #include "chrome/browser/autofill/autofill_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
11 #include "chrome/browser/autofill/autofill_dialog.h" 11 #include "chrome/browser/autofill/autofill_dialog.h"
12 #include "chrome/browser/autofill/autofill_infobar_delegate.h"
13 #include "chrome/browser/autofill/form_structure.h" 12 #include "chrome/browser/autofill/form_structure.h"
14 #include "chrome/browser/pref_service.h" 13 #include "chrome/browser/pref_service.h"
15 #include "chrome/browser/profile.h" 14 #include "chrome/browser/profile.h"
16 #include "chrome/browser/renderer_host/render_view_host.h" 15 #include "chrome/browser/renderer_host/render_view_host.h"
17 #include "chrome/browser/tab_contents/tab_contents.h" 16 #include "chrome/browser/tab_contents/tab_contents.h"
18 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
20 #include "webkit/glue/form_data.h" 19 #include "webkit/glue/form_data.h"
21 #include "webkit/glue/form_field.h" 20 #include "webkit/glue/form_field.h"
22 21
(...skipping 17 matching lines...) Expand all
40 39
41 } // namespace 40 } // namespace
42 41
43 // TODO(jhawkins): Maybe this should be in a grd file? 42 // TODO(jhawkins): Maybe this should be in a grd file?
44 const char* kAutoFillLearnMoreUrl = 43 const char* kAutoFillLearnMoreUrl =
45 "http://www.google.com/support/chrome/bin/answer.py?answer=142893"; 44 "http://www.google.com/support/chrome/bin/answer.py?answer=142893";
46 45
47 AutoFillManager::AutoFillManager(TabContents* tab_contents) 46 AutoFillManager::AutoFillManager(TabContents* tab_contents)
48 : tab_contents_(tab_contents), 47 : tab_contents_(tab_contents),
49 personal_data_(NULL), 48 personal_data_(NULL),
50 download_manager_(tab_contents_->profile()), 49 download_manager_(tab_contents_->profile()) {
51 infobar_(NULL) {
52 DCHECK(tab_contents); 50 DCHECK(tab_contents);
53 51
54 // |personal_data_| is NULL when using TestTabContents. 52 // |personal_data_| is NULL when using TestTabContents.
55 personal_data_ = 53 personal_data_ =
56 tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager(); 54 tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager();
57 download_manager_.SetObserver(this); 55 download_manager_.SetObserver(this);
58 } 56 }
59 57
60 AutoFillManager::~AutoFillManager() { 58 AutoFillManager::~AutoFillManager() {
61 download_manager_.SetObserver(NULL); 59 download_manager_.SetObserver(NULL);
62 } 60 }
63 61
64 // static 62 // static
65 void AutoFillManager::RegisterBrowserPrefs(PrefService* prefs) { 63 void AutoFillManager::RegisterBrowserPrefs(PrefService* prefs) {
66 prefs->RegisterDictionaryPref(prefs::kAutoFillDialogPlacement); 64 prefs->RegisterDictionaryPref(prefs::kAutoFillDialogPlacement);
67 } 65 }
68 66
69 // static 67 // static
70 void AutoFillManager::RegisterUserPrefs(PrefService* prefs) { 68 void AutoFillManager::RegisterUserPrefs(PrefService* prefs) {
71 prefs->RegisterBooleanPref(prefs::kAutoFillInfoBarShown, false);
72 prefs->RegisterBooleanPref(prefs::kAutoFillEnabled, true); 69 prefs->RegisterBooleanPref(prefs::kAutoFillEnabled, true);
73 prefs->RegisterBooleanPref(prefs::kAutoFillAuxiliaryProfilesEnabled, true); 70 prefs->RegisterBooleanPref(prefs::kAutoFillAuxiliaryProfilesEnabled, true);
74 71
75 prefs->RegisterRealPref(prefs::kAutoFillPositiveUploadRate, 72 prefs->RegisterRealPref(prefs::kAutoFillPositiveUploadRate,
76 kAutoFillPositiveUploadRateDefaultValue); 73 kAutoFillPositiveUploadRateDefaultValue);
77 prefs->RegisterRealPref(prefs::kAutoFillNegativeUploadRate, 74 prefs->RegisterRealPref(prefs::kAutoFillNegativeUploadRate,
78 kAutoFillNegativeUploadRateDefaultValue); 75 kAutoFillNegativeUploadRateDefaultValue);
79 } 76 }
80 77
81 void AutoFillManager::FormSubmitted(const FormData& form) { 78 void AutoFillManager::FormSubmitted(const FormData& form) {
82 if (!IsAutoFillEnabled()) 79 if (!IsAutoFillEnabled())
83 return; 80 return;
84 81
85 if (tab_contents_->profile()->IsOffTheRecord()) 82 if (tab_contents_->profile()->IsOffTheRecord())
86 return; 83 return;
87 84
88 // Grab a copy of the form data. 85 // Grab a copy of the form data.
89 upload_form_structure_.reset(new FormStructure(form)); 86 upload_form_structure_.reset(new FormStructure(form));
90 87
91 if (!upload_form_structure_->IsAutoFillable()) 88 if (!upload_form_structure_->IsAutoFillable())
92 return; 89 return;
93 90
94 // Determine the possible field types and upload the form structure to the 91 // Determine the possible field types and upload the form structure to the
95 // PersonalDataManager. 92 // PersonalDataManager.
96 DeterminePossibleFieldTypes(upload_form_structure_.get()); 93 DeterminePossibleFieldTypes(upload_form_structure_.get());
97 HandleSubmit(); 94 HandleSubmit();
98
99 if (upload_form_structure_->HasAutoFillableValues()) {
100 PrefService* prefs = tab_contents_->profile()->GetPrefs();
101 bool infobar_shown = prefs->GetBoolean(prefs::kAutoFillInfoBarShown);
102 if (!infobar_shown) {
103 // Ask the user for permission to save form information.
104 infobar_.reset(new AutoFillInfoBarDelegate(tab_contents_, this));
105 }
106 }
107 } 95 }
108 96
109 void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) { 97 void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) {
110 if (!IsAutoFillEnabled()) 98 if (!IsAutoFillEnabled())
111 return; 99 return;
112 100
113 for (std::vector<FormData>::const_iterator iter = 101 for (std::vector<FormData>::const_iterator iter =
114 forms.begin(); 102 forms.begin();
115 iter != forms.end(); ++iter) { 103 iter != forms.end(); ++iter) {
116 FormStructure* form_structure = new FormStructure(*iter); 104 FormStructure* form_structure = new FormStructure(*iter);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 309 }
322 310
323 void AutoFillManager::ShowAutoFillDialog() { 311 void AutoFillManager::ShowAutoFillDialog() {
324 ::ShowAutoFillDialog(tab_contents_->GetContentNativeView(), 312 ::ShowAutoFillDialog(tab_contents_->GetContentNativeView(),
325 personal_data_, 313 personal_data_,
326 tab_contents_->profile()->GetOriginalProfile(), 314 tab_contents_->profile()->GetOriginalProfile(),
327 NULL, 315 NULL,
328 NULL); 316 NULL);
329 } 317 }
330 318
331 void AutoFillManager::OnInfoBarClosed() {
332 PrefService* prefs = tab_contents_->profile()->GetPrefs();
333 prefs->SetBoolean(prefs::kAutoFillEnabled, true);
334
335 // Save the imported form data as a profile.
336 personal_data_->SaveImportedFormData();
337 }
338
339 void AutoFillManager::OnInfoBarAccepted() {
340 PrefService* prefs = tab_contents_->profile()->GetPrefs();
341 prefs->SetBoolean(prefs::kAutoFillEnabled, true);
342
343 // This is the first time the user is interacting with AutoFill, so set the
344 // uploaded form structure as the initial profile and credit card in the
345 // AutoFillDialog.
346 AutoFillProfile* profile = NULL;
347 CreditCard* credit_card = NULL;
348 // TODO(dhollowa) Now that we aren't immediately saving the imported form
349 // data, we should store the profile and CC in the AFM instead of the PDM.
350 personal_data_->GetImportedFormData(&profile, &credit_card);
351 ::ShowAutoFillDialog(tab_contents_->GetContentNativeView(),
352 personal_data_,
353 tab_contents_->profile()->GetOriginalProfile(),
354 profile,
355 credit_card);
356 }
357
358 void AutoFillManager::OnInfoBarCancelled() {
359 PrefService* prefs = tab_contents_->profile()->GetPrefs();
360 prefs->SetBoolean(prefs::kAutoFillEnabled, false);
361 }
362
363 void AutoFillManager::Reset() { 319 void AutoFillManager::Reset() {
364 upload_form_structure_.reset(); 320 upload_form_structure_.reset();
365 form_structures_.reset(); 321 form_structures_.reset();
366 } 322 }
367 323
368 void AutoFillManager::OnLoadedAutoFillHeuristics( 324 void AutoFillManager::OnLoadedAutoFillHeuristics(
369 const std::string& heuristic_xml) { 325 const std::string& heuristic_xml) {
370 // TODO(jhawkins): Store |upload_required| in the AutoFillManager. 326 // TODO(jhawkins): Store |upload_required| in the AutoFillManager.
371 UploadRequired upload_required; 327 UploadRequired upload_required;
372 FormStructure::ParseQueryResponse(heuristic_xml, 328 FormStructure::ParseQueryResponse(heuristic_xml,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 AutoFillManager::AutoFillManager() 387 AutoFillManager::AutoFillManager()
432 : tab_contents_(NULL), 388 : tab_contents_(NULL),
433 personal_data_(NULL), 389 personal_data_(NULL),
434 download_manager_(NULL) { 390 download_manager_(NULL) {
435 } 391 }
436 392
437 AutoFillManager::AutoFillManager(TabContents* tab_contents, 393 AutoFillManager::AutoFillManager(TabContents* tab_contents,
438 PersonalDataManager* personal_data) 394 PersonalDataManager* personal_data)
439 : tab_contents_(tab_contents), 395 : tab_contents_(tab_contents),
440 personal_data_(personal_data), 396 personal_data_(personal_data),
441 download_manager_(NULL), // No download manager in tests. 397 download_manager_(NULL) {
442 infobar_(NULL) {
443 DCHECK(tab_contents); 398 DCHECK(tab_contents);
444 } 399 }
445 400
446 void AutoFillManager::GetProfileSuggestions(FormStructure* form, 401 void AutoFillManager::GetProfileSuggestions(FormStructure* form,
447 const FormField& field, 402 const FormField& field,
448 AutoFillType type, 403 AutoFillType type,
449 std::vector<string16>* values, 404 std::vector<string16>* values,
450 std::vector<string16>* labels) { 405 std::vector<string16>* labels) {
451 const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles(); 406 const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles();
452 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); 407 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 field->set_value(number); 569 field->set_value(number);
615 } else if (has_valid_suffix_and_prefix && 570 } else if (has_valid_suffix_and_prefix &&
616 field->size() == kAutoFillPhoneNumberSuffixCount) { 571 field->size() == kAutoFillPhoneNumberSuffixCount) {
617 number = number.substr(kAutoFillPhoneNumberSuffixOffset, 572 number = number.substr(kAutoFillPhoneNumberSuffixOffset,
618 kAutoFillPhoneNumberSuffixCount); 573 kAutoFillPhoneNumberSuffixCount);
619 field->set_value(number); 574 field->set_value(number);
620 } else { 575 } else {
621 field->set_value(number); 576 field->set_value(number);
622 } 577 }
623 } 578 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.h ('k') | chrome/browser/autofill/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698