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

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

Issue 541001: Add two AutoFill prefs. autofill.infobar_shown is true if the autofill infob... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 11 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
« no previous file with comments | « chrome/browser/autofill/autofill_manager.h ('k') | chrome/browser/browser_prefs.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/command_line.h" 9 #include "base/command_line.h"
10 #include "chrome/browser/autofill/autofill_infobar_delegate.h" 10 #include "chrome/browser/autofill/autofill_infobar_delegate.h"
11 #include "chrome/browser/autofill/form_structure.h" 11 #include "chrome/browser/autofill/form_structure.h"
12 #include "chrome/browser/autofill/personal_data_manager.h" 12 #include "chrome/browser/autofill/personal_data_manager.h"
13 #include "chrome/browser/profile.h" 13 #include "chrome/browser/profile.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 14 #include "chrome/browser/tab_contents/tab_contents.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h"
17 #include "chrome/common/pref_service.h"
16 #include "webkit/glue/form_field_values.h" 18 #include "webkit/glue/form_field_values.h"
17 19
18 AutoFillManager::AutoFillManager(TabContents* tab_contents) 20 AutoFillManager::AutoFillManager(TabContents* tab_contents)
19 : tab_contents_(tab_contents), 21 : tab_contents_(tab_contents),
20 infobar_(NULL) { 22 infobar_(NULL) {
21 personal_data_ = tab_contents_->profile()->GetPersonalDataManager(); 23 personal_data_ = tab_contents_->profile()->GetPersonalDataManager();
22 } 24 }
23 25
24 AutoFillManager::~AutoFillManager() { 26 AutoFillManager::~AutoFillManager() {
25 } 27 }
26 28
29 // static
30 void AutoFillManager::RegisterUserPrefs(PrefService* prefs) {
31 prefs->RegisterBooleanPref(prefs::kAutoFillInfoBarShown, false);
32 prefs->RegisterBooleanPref(prefs::kAutoFillEnabled, false);
33 }
34
27 void AutoFillManager::FormFieldValuesSubmitted( 35 void AutoFillManager::FormFieldValuesSubmitted(
28 const webkit_glue::FormFieldValues& form) { 36 const webkit_glue::FormFieldValues& form) {
29 // TODO(jhawkins): Remove this switch when AutoFill++ is fully implemented. 37 // TODO(jhawkins): Remove this switch when AutoFill++ is fully implemented.
30 if (!CommandLine::ForCurrentProcess()->HasSwitch( 38 if (!CommandLine::ForCurrentProcess()->HasSwitch(
31 switches::kEnableNewAutoFill)) 39 switches::kEnableNewAutoFill))
32 return; 40 return;
33 41
34 // Grab a copy of the form data. 42 // Grab a copy of the form data.
35 upload_form_structure_.reset(new FormStructure(form)); 43 upload_form_structure_.reset(new FormStructure(form));
36 44
37 if (!upload_form_structure_->IsAutoFillable()) 45 if (!upload_form_structure_->IsAutoFillable())
38 return; 46 return;
39 47
40 // Determine the possible field types. 48 // Determine the possible field types.
41 DeterminePossibleFieldTypes(upload_form_structure_.get()); 49 DeterminePossibleFieldTypes(upload_form_structure_.get());
42 50
43 if (!personal_data_->ImportFormData(form_structures_, this)) 51 PrefService* prefs = tab_contents_->profile()->GetPrefs();
44 return; 52 bool autofill_enabled = prefs->GetBoolean(prefs::kAutoFillEnabled);
45 53 bool infobar_shown = prefs->GetBoolean(prefs::kAutoFillInfoBarShown);
46 // Ask the user for permission to save form information. 54 if (!infobar_shown) {
47 infobar_.reset(new AutoFillInfoBarDelegate(tab_contents_, this)); 55 // Ask the user for permission to save form information.
56 infobar_.reset(new AutoFillInfoBarDelegate(tab_contents_, this));
57 } else if (autofill_enabled) {
58 HandleSubmit();
59 }
48 } 60 }
49 61
50 void AutoFillManager::DeterminePossibleFieldTypes( 62 void AutoFillManager::DeterminePossibleFieldTypes(
51 FormStructure* form_structure) { 63 FormStructure* form_structure) {
52 // TODO(jhawkins): Update field text. 64 // TODO(jhawkins): Update field text.
53 65
54 form_structure->GetHeuristicAutoFillTypes(); 66 form_structure->GetHeuristicAutoFillTypes();
55 67
56 for (size_t i = 0; i < form_structure->field_count(); i++) { 68 for (size_t i = 0; i < form_structure->field_count(); i++) {
57 const AutoFillField* field = form_structure->field(i); 69 const AutoFillField* field = form_structure->field(i);
58 FieldTypeSet field_types; 70 FieldTypeSet field_types;
59 personal_data_->GetPossibleFieldTypes(field->value(), &field_types); 71 personal_data_->GetPossibleFieldTypes(field->value(), &field_types);
60 form_structure->set_possible_types(i, field_types); 72 form_structure->set_possible_types(i, field_types);
61 } 73 }
62 } 74 }
63 75
76 void AutoFillManager::HandleSubmit() {
77 // If there wasn't enough data to import then we don't want to send an upload
78 // to the server.
79 if (!personal_data_->ImportFormData(form_structures_, this))
80 return;
81
82 UploadFormData();
83 }
84
85 void AutoFillManager::OnInfoBarAccepted() {
86 PrefService* prefs = tab_contents_->profile()->GetPrefs();
87 prefs->SetBoolean(prefs::kAutoFillEnabled, true);
88
89 // TODO(jhawkins): AutoFillDialog
90
91 HandleSubmit();
92 }
93
64 void AutoFillManager::SaveFormData() { 94 void AutoFillManager::SaveFormData() {
65 UploadFormData();
66
67 // TODO(jhawkins): Save the form data to the web database. 95 // TODO(jhawkins): Save the form data to the web database.
68 } 96 }
69 97
70 void AutoFillManager::UploadFormData() { 98 void AutoFillManager::UploadFormData() {
71 std::string xml; 99 std::string xml;
72 bool ok = upload_form_structure_->EncodeUploadRequest(false, &xml); 100 bool ok = upload_form_structure_->EncodeUploadRequest(false, &xml);
73 DCHECK(ok); 101 DCHECK(ok);
74 102
75 // TODO(jhawkins): Initiate the upload request thread. 103 // TODO(jhawkins): Initiate the upload request thread.
76 } 104 }
77 105
78 void AutoFillManager::Reset() { 106 void AutoFillManager::Reset() {
79 upload_form_structure_.reset(); 107 upload_form_structure_.reset();
80 } 108 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.h ('k') | chrome/browser/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698