summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 21:35:37 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 21:35:37 +0000
commitd2cdea035ffb94dad5eb559e3960ab4164b4db0c (patch)
tree273b9b50a8006c382db8afa0b21ccd2d231793d8 /chrome
parent284f766950396abce8f0672c2ccde6b45de25578 (diff)
downloadchromium_src-d2cdea035ffb94dad5eb559e3960ab4164b4db0c.zip
chromium_src-d2cdea035ffb94dad5eb559e3960ab4164b4db0c.tar.gz
chromium_src-d2cdea035ffb94dad5eb559e3960ab4164b4db0c.tar.bz2
AutoFill: Only query the AutoFill server if we've parsed any of the forms.
BUG=none TEST=none Review URL: http://codereview.chromium.org/2880022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51899 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autofill/autofill_manager.cc32
-rw-r--r--chrome/browser/autofill/autofill_manager.h6
-rw-r--r--chrome/browser/autofill/form_structure.cc27
-rw-r--r--chrome/browser/autofill/form_structure.h3
4 files changed, 48 insertions, 20 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index aec30ee..0c778f0 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -122,14 +122,12 @@ void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) {
if (!IsAutoFillEnabled())
return;
- for (std::vector<FormData>::const_iterator iter =
- forms.begin();
- iter != forms.end(); ++iter) {
- FormStructure* form_structure = new FormStructure(*iter);
- DeterminePossibleFieldTypes(form_structure);
- form_structures_.push_back(form_structure);
- }
- download_manager_.StartQueryRequest(form_structures_);
+ // No profiles or credit cards, no need to parse the forms.
+ if (personal_data_->profiles().empty() &&
+ personal_data_->credit_cards().empty())
+ return;
+
+ ParseForms(forms);
}
bool AutoFillManager::GetAutoFillSuggestions(int query_id,
@@ -604,3 +602,21 @@ void AutoFillManager::FillPhoneNumberField(const AutoFillProfile* profile,
field->set_value(number);
}
}
+
+void AutoFillManager::ParseForms(
+ const std::vector<webkit_glue::FormData>& forms) {
+ for (std::vector<FormData>::const_iterator iter =
+ forms.begin();
+ iter != forms.end(); ++iter) {
+ FormStructure* form_structure = new FormStructure(*iter);
+ if (!form_structure->ShouldBeParsed())
+ continue;
+
+ DeterminePossibleFieldTypes(form_structure);
+ form_structures_.push_back(form_structure);
+ }
+
+ // If none of the forms were parsed, no use querying the server.
+ if (!form_structures_.empty())
+ download_manager_.StartQueryRequest(form_structures_);
+}
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index f4fdb44..3804848 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -45,8 +45,7 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
// RenderViewHostDelegate::AutoFill implementation:
virtual void FormSubmitted(const webkit_glue::FormData& form);
- virtual void FormsSeen(
- const std::vector<webkit_glue::FormData>& forms);
+ virtual void FormsSeen(const std::vector<webkit_glue::FormData>& forms);
virtual bool GetAutoFillSuggestions(int query_id,
bool form_autofilled,
const webkit_glue::FormField& field);
@@ -134,6 +133,9 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
void FillPhoneNumberField(const AutoFillProfile* profile,
webkit_glue::FormField* field);
+ // Parses the forms using heuristic matching and querying the AutoFill server.
+ void ParseForms(const std::vector<webkit_glue::FormData>& forms);
+
// The TabContents hosting this AutoFillManager.
// Weak reference.
// May not be NULL.
diff --git a/chrome/browser/autofill/form_structure.cc b/chrome/browser/autofill/form_structure.cc
index 1a6a973..dd12d37 100644
--- a/chrome/browser/autofill/form_structure.cc
+++ b/chrome/browser/autofill/form_structure.cc
@@ -223,16 +223,7 @@ bool FormStructure::IsAutoFillable() const {
if (autofill_count() < kRequiredFillableFields)
return false;
- // Rule out http(s)://*/search?...
- // e.g. http://www.google.com/search?q=...
- // http://search.yahoo.com/search?p=...
- if (target_url_.path() == "/search")
- return false;
-
- if (method_ == GET)
- return false;
-
- return true;
+ return ShouldBeParsed();
}
bool FormStructure::HasAutoFillableValues() const {
@@ -299,6 +290,22 @@ void FormStructure::UpdateAutoFillCount() {
}
}
+bool FormStructure::ShouldBeParsed() const {
+ if (field_count() < kRequiredFillableFields)
+ return false;
+
+ // Rule out http(s)://*/search?...
+ // e.g. http://www.google.com/search?q=...
+ // http://search.yahoo.com/search?p=...
+ if (target_url_.path() == "/search")
+ return false;
+
+ if (method_ == GET)
+ return false;
+
+ return true;
+}
+
void FormStructure::set_possible_types(int index, const FieldTypeSet& types) {
int num_fields = static_cast<int>(field_count());
DCHECK(index >= 0 && index < num_fields);
diff --git a/chrome/browser/autofill/form_structure.h b/chrome/browser/autofill/form_structure.h
index 6537bd4..1ba357b 100644
--- a/chrome/browser/autofill/form_structure.h
+++ b/chrome/browser/autofill/form_structure.h
@@ -80,6 +80,9 @@ class FormStructure {
// heuristically.
void UpdateAutoFillCount();
+ // Returns true if this form matches the structural requirements for AutoFill.
+ bool ShouldBeParsed() const;
+
// Sets the possible types for the field at |index|.
void set_possible_types(int index, const FieldTypeSet& types);