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

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

Issue 1119004: Integration with Toolbar autofill servers.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « chrome/browser/autofill/autofill_manager.h ('k') | chrome/browser/autofill/form_structure.h » ('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) 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/command_line.h" 9 #include "base/command_line.h"
10 #include "chrome/browser/autofill/autofill_dialog.h" 10 #include "chrome/browser/autofill/autofill_dialog.h"
11 #include "chrome/browser/autofill/autofill_infobar_delegate.h" 11 #include "chrome/browser/autofill/autofill_infobar_delegate.h"
12 #include "chrome/browser/autofill/autofill_xml_parser.h"
12 #include "chrome/browser/autofill/form_structure.h" 13 #include "chrome/browser/autofill/form_structure.h"
13 #include "chrome/browser/pref_service.h" 14 #include "chrome/browser/pref_service.h"
14 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
15 #include "chrome/browser/renderer_host/render_view_host.h" 16 #include "chrome/browser/renderer_host/render_view_host.h"
16 #include "chrome/browser/tab_contents/tab_contents.h" 17 #include "chrome/browser/tab_contents/tab_contents.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "webkit/glue/form_data.h" 20 #include "webkit/glue/form_data.h"
20 #include "webkit/glue/form_field.h" 21 #include "webkit/glue/form_field.h"
21 #include "webkit/glue/form_field_values.h" 22 #include "webkit/glue/form_field_values.h"
22 23
23 AutoFillManager::AutoFillManager(TabContents* tab_contents) 24 AutoFillManager::AutoFillManager(TabContents* tab_contents)
24 : tab_contents_(tab_contents), 25 : tab_contents_(tab_contents),
25 personal_data_(NULL), 26 personal_data_(NULL),
26 infobar_(NULL) { 27 infobar_(NULL) {
27 DCHECK(tab_contents); 28 DCHECK(tab_contents);
28 29
29 personal_data_ = 30 personal_data_ =
30 tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager(); 31 tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager();
31 DCHECK(personal_data_); 32 DCHECK(personal_data_);
33 download_manager_.SetObserver(this);
32 } 34 }
33 35
34 AutoFillManager::~AutoFillManager() { 36 AutoFillManager::~AutoFillManager() {
35 // This is NULL in the MockAutoFillManager. 37 // This is NULL in the MockAutoFillManager.
36 if (personal_data_) 38 if (personal_data_)
37 personal_data_->RemoveObserver(this); 39 personal_data_->RemoveObserver(this);
40 download_manager_.SetObserver(NULL);
38 } 41 }
39 42
40 // static 43 // static
41 void AutoFillManager::RegisterBrowserPrefs(PrefService* prefs) { 44 void AutoFillManager::RegisterBrowserPrefs(PrefService* prefs) {
42 prefs->RegisterDictionaryPref(prefs::kAutoFillDialogPlacement); 45 prefs->RegisterDictionaryPref(prefs::kAutoFillDialogPlacement);
43 } 46 }
44 47
45 // static 48 // static
46 void AutoFillManager::RegisterUserPrefs(PrefService* prefs) { 49 void AutoFillManager::RegisterUserPrefs(PrefService* prefs) {
47 prefs->RegisterBooleanPref(prefs::kAutoFillInfoBarShown, false); 50 prefs->RegisterBooleanPref(prefs::kAutoFillInfoBarShown, false);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const std::vector<webkit_glue::FormFieldValues>& forms) { 83 const std::vector<webkit_glue::FormFieldValues>& forms) {
81 if (!IsAutoFillEnabled()) 84 if (!IsAutoFillEnabled())
82 return; 85 return;
83 86
84 for (std::vector<webkit_glue::FormFieldValues>::const_iterator iter = 87 for (std::vector<webkit_glue::FormFieldValues>::const_iterator iter =
85 forms.begin(); 88 forms.begin();
86 iter != forms.end(); ++iter) { 89 iter != forms.end(); ++iter) {
87 FormStructure* form_structure = new FormStructure(*iter); 90 FormStructure* form_structure = new FormStructure(*iter);
88 DeterminePossibleFieldTypes(form_structure); 91 DeterminePossibleFieldTypes(form_structure);
89 form_structures_.push_back(form_structure); 92 form_structures_.push_back(form_structure);
93 std::string request_xml;
94 if (form_structure->IsAutoFillable() &&
95 form_structure->EncodeUploadRequest(true, true, &request_xml)) {
96 download_manager_.StartRequest(request_xml,
97 form_structure->FormSignature(),
98 true,
99 false);
100 }
90 } 101 }
91 } 102 }
92 103
93 bool AutoFillManager::GetAutoFillSuggestions( 104 bool AutoFillManager::GetAutoFillSuggestions(
94 int query_id, const webkit_glue::FormField& field) { 105 int query_id, const webkit_glue::FormField& field) {
95 if (!IsAutoFillEnabled()) 106 if (!IsAutoFillEnabled())
96 return false; 107 return false;
97 108
98 RenderViewHost* host = tab_contents_->render_view_host(); 109 RenderViewHost* host = tab_contents_->render_view_host();
99 if (!host) 110 if (!host)
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 void AutoFillManager::OnInfoBarCancelled() { 286 void AutoFillManager::OnInfoBarCancelled() {
276 PrefService* prefs = tab_contents_->profile()->GetPrefs(); 287 PrefService* prefs = tab_contents_->profile()->GetPrefs();
277 prefs->SetBoolean(prefs::kAutoFillEnabled, false); 288 prefs->SetBoolean(prefs::kAutoFillEnabled, false);
278 } 289 }
279 290
280 void AutoFillManager::Reset() { 291 void AutoFillManager::Reset() {
281 upload_form_structure_.reset(); 292 upload_form_structure_.reset();
282 form_structures_.reset(); 293 form_structures_.reset();
283 } 294 }
284 295
296 void AutoFillManager::OnLoadedAutoFillHeuristics(
297 const std::string& form_signature,
298 const std::string& heuristic_xml) {
299 for (ScopedVector<FormStructure>::iterator it = form_structures_.begin();
300 it != form_structures_.end();
301 ++it) {
302 if ((*it)->FormSignature() == form_signature) {
303 // Create a vector of AutoFillFieldTypes,
304 // to assign the parsed field types to.
305 std::vector<AutoFillFieldType> field_types;
306 UploadRequired upload_required = USE_UPLOAD_RATES;
307
308 // Create a parser.
309 AutoFillQueryXmlParser parse_handler(&field_types, &upload_required);
310 buzz::XmlParser parser(&parse_handler);
311 parser.Parse(heuristic_xml.c_str(), heuristic_xml.length(), true);
312 if (parse_handler.succeeded()) {
313 DCHECK(field_types.size() == (*it)->field_count());
314 if (field_types.size() == (*it)->field_count()) {
315 for (size_t i = 0; i < (*it)->field_count(); ++i) {
316 if (field_types[i] != NO_SERVER_DATA &&
317 field_types[i] != UNKNOWN_TYPE) {
318 FieldTypeSet types = (*it)->field(i)->possible_types();
319 types.insert(field_types[i]);
320 (*it)->set_possible_types(i, types);
321 }
322 }
323 }
324 return;
325 }
326 }
327 }
328 }
329
330 void AutoFillManager::OnUploadedAutoFillHeuristics(
331 const std::string& form_signature) {
332 }
333
334 void AutoFillManager::OnHeuristicsRequestError(
335 const std::string& form_signature, int http_error) {
336 }
337
285 void AutoFillManager::DeterminePossibleFieldTypes( 338 void AutoFillManager::DeterminePossibleFieldTypes(
286 FormStructure* form_structure) { 339 FormStructure* form_structure) {
287 // TODO(jhawkins): Update field text. 340 // TODO(jhawkins): Update field text.
288 341
289 form_structure->GetHeuristicAutoFillTypes(); 342 form_structure->GetHeuristicAutoFillTypes();
290 343
291 for (size_t i = 0; i < form_structure->field_count(); i++) { 344 for (size_t i = 0; i < form_structure->field_count(); i++) {
292 const AutoFillField* field = form_structure->field(i); 345 const AutoFillField* field = form_structure->field(i);
293 FieldTypeSet field_types; 346 FieldTypeSet field_types;
294 personal_data_->GetPossibleFieldTypes(field->value(), &field_types); 347 personal_data_->GetPossibleFieldTypes(field->value(), &field_types);
295 form_structure->set_possible_types(i, field_types); 348 form_structure->set_possible_types(i, field_types);
296 } 349 }
297 } 350 }
298 351
299 void AutoFillManager::HandleSubmit() { 352 void AutoFillManager::HandleSubmit() {
300 // If there wasn't enough data to import then we don't want to send an upload 353 // If there wasn't enough data to import then we don't want to send an upload
301 // to the server. 354 // to the server.
302 if (!personal_data_->ImportFormData(form_structures_.get(), this)) 355 if (!personal_data_->ImportFormData(form_structures_.get(), this))
303 return; 356 return;
304 357
305 UploadFormData(); 358 UploadFormData();
306 } 359 }
307 360
308 void AutoFillManager::UploadFormData() { 361 void AutoFillManager::UploadFormData() {
309 std::string xml; 362 std::string xml;
310 bool ok = upload_form_structure_->EncodeUploadRequest(false, &xml); 363 bool ok = upload_form_structure_->EncodeUploadRequest(false, false, &xml);
311 DCHECK(ok); 364 DCHECK(ok);
312 365
313 // TODO(jhawkins): Initiate the upload request thread. 366 // TODO(georgey): enable upload request when we make sure that our data is in
367 // line with toolbar data:
368 // download_manager_.StartRequest(xml,
369 // upload_form_structure_->FormSignature(),
370 // false,
371 // form_is_autofilled);
314 } 372 }
315 373
316 bool AutoFillManager::IsAutoFillEnabled() { 374 bool AutoFillManager::IsAutoFillEnabled() {
317 PrefService* prefs = tab_contents_->profile()->GetPrefs(); 375 PrefService* prefs = tab_contents_->profile()->GetPrefs();
318 376
319 // Migrate obsolete AutoFill pref. 377 // Migrate obsolete AutoFill pref.
320 if (prefs->HasPrefPath(prefs::kFormAutofillEnabled)) { 378 if (prefs->HasPrefPath(prefs::kFormAutofillEnabled)) {
321 bool enabled = prefs->GetBoolean(prefs::kFormAutofillEnabled); 379 bool enabled = prefs->GetBoolean(prefs::kFormAutofillEnabled);
322 prefs->ClearPref(prefs::kFormAutofillEnabled); 380 prefs->ClearPref(prefs::kFormAutofillEnabled);
323 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled); 381 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled);
324 return enabled; 382 return enabled;
325 } 383 }
326 384
327 return prefs->GetBoolean(prefs::kAutoFillEnabled); 385 return prefs->GetBoolean(prefs::kAutoFillEnabled);
328 } 386 }
329 387
330 AutoFillManager::AutoFillManager() 388 AutoFillManager::AutoFillManager()
331 : tab_contents_(NULL), 389 : tab_contents_(NULL),
332 personal_data_(NULL) { 390 personal_data_(NULL) {
333 } 391 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.h ('k') | chrome/browser/autofill/form_structure.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698