summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 02:03:07 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 02:03:07 +0000
commit8f6e658a45d2b3b8ac488eca254507e541aaaef6 (patch)
treeaf1fab7b7b09b0b77d86223ece5013d25ae291f5
parentc8b1a3b503dfe2c2be7db6430638a0db2a22c184 (diff)
downloadchromium_src-8f6e658a45d2b3b8ac488eca254507e541aaaef6.zip
chromium_src-8f6e658a45d2b3b8ac488eca254507e541aaaef6.tar.gz
chromium_src-8f6e658a45d2b3b8ac488eca254507e541aaaef6.tar.bz2
AutoFill: Initiate AutoFill for all fields, not just the name field.
Fix a case issue when matching names. BUG=40299 TEST=none Review URL: http://codereview.chromium.org/1575023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44043 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/autofill_manager.cc129
-rw-r--r--chrome/browser/autofill/autofill_manager.h2
-rw-r--r--chrome/browser/autofill/contact_info.cc3
-rw-r--r--chrome/browser/renderer_host/render_view_host.h4
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h4
-rw-r--r--chrome/renderer/render_view.cc8
-rw-r--r--chrome/renderer/render_view.h6
7 files changed, 67 insertions, 89 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 880ef3c..16cca32 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -128,7 +128,7 @@ bool AutoFillManager::GetAutoFillSuggestions(int query_id,
if (profiles.empty() && credit_cards.empty())
return false;
- AutoFillFieldType type = UNKNOWN_TYPE;
+ AutoFillField* form_field = NULL;
for (std::vector<FormStructure*>::iterator form = form_structures_.begin();
form != form_structures_.end(); ++form) {
for (std::vector<AutoFillField*>::const_iterator iter = (*form)->begin();
@@ -138,93 +138,62 @@ bool AutoFillManager::GetAutoFillSuggestions(int query_id,
if (!*iter)
break;
- AutoFillField* form_field = *iter;
- if (*form_field != field)
- continue;
-
- if (form_field->possible_types().find(CREDIT_CARD_NAME) !=
- form_field->possible_types().end() ||
- form_field->heuristic_type() == CREDIT_CARD_NAME) {
- type = CREDIT_CARD_NAME;
- break;
- }
-
- if (form_field->possible_types().find(CREDIT_CARD_NUMBER) !=
- form_field->possible_types().end() ||
- form_field->heuristic_type() == CREDIT_CARD_NUMBER) {
- type = CREDIT_CARD_NUMBER;
- break;
- }
-
- if (form_field->possible_types().find(NAME_FIRST) !=
- form_field->possible_types().end() ||
- form_field->heuristic_type() == NAME_FIRST) {
- type = NAME_FIRST;
- break;
- }
-
- if (form_field->possible_types().find(NAME_FULL) !=
- form_field->possible_types().end() ||
- form_field->heuristic_type() == NAME_FULL) {
- type = NAME_FULL;
+ if ((**iter) == field) {
+ form_field = *iter;
break;
}
}
}
- if (type == UNKNOWN_TYPE)
+ if (form_field == NULL)
return false;
- std::vector<string16> names;
+ std::vector<string16> values;
std::vector<string16> labels;
- // Check for credit card suggestions.
- if (type == CREDIT_CARD_NAME || type == CREDIT_CARD_NUMBER) {
- for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin();
- iter != credit_cards.end(); ++iter) {
- // TODO(jhawkins): What if GetFieldText(...).length() == 0?
- if (StartsWith((*iter)->GetFieldText(AutoFillType(type)),
- field.value(), false)) {
- string16 name;
- if (type == CREDIT_CARD_NUMBER) {
- name = (*iter)->ObfuscatedNumber();
- } else {
- name = (*iter)->GetFieldText(AutoFillType(type));
- }
- string16 label = (*iter)->Label();
+ for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin();
+ iter != profiles.end(); ++iter) {
+ if (StartsWith((*iter)->GetFieldText(AutoFillType(form_field->type())),
+ field.value(), false)) {
+ string16 value = (*iter)->GetFieldText(AutoFillType(form_field->type()));
+ string16 label = (*iter)->Label();
- names.push_back(name);
- labels.push_back(label);
- }
+ values.push_back(value);
+ labels.push_back(label);
}
- } else if (type == NAME_FIRST || type == NAME_FULL) {
- for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin();
- iter != profiles.end(); ++iter) {
- // TODO(jhawkins): What if GetFieldText(...).length() == 0?
- if (StartsWith((*iter)->GetFieldText(AutoFillType(type)),
- field.value(), false)) {
- string16 name = (*iter)->GetFieldText(AutoFillType(type));
- string16 label = (*iter)->Label();
-
- names.push_back(name);
- labels.push_back(label);
+ }
+
+ for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin();
+ iter != credit_cards.end(); ++iter) {
+ // TODO(jhawkins): What if GetFieldText(...).length() == 0?
+ if (StartsWith((*iter)->GetFieldText(AutoFillType(form_field->type())),
+ field.value(), false)) {
+ string16 value;
+ if (form_field->type() == CREDIT_CARD_NUMBER) {
+ value = (*iter)->ObfuscatedNumber();
+ } else {
+ value = (*iter)->GetFieldText(AutoFillType(form_field->type()));
}
+ string16 label = (*iter)->Label();
+
+ values.push_back(value);
+ labels.push_back(label);
}
}
// No suggestions.
- if (names.empty())
+ if (values.empty())
return false;
// TODO(jhawkins): If the default profile is in this list, set it as the
// default suggestion index.
- host->AutoFillSuggestionsReturned(query_id, names, labels, -1);
+ host->AutoFillSuggestionsReturned(query_id, values, labels, -1);
return true;
}
bool AutoFillManager::FillAutoFillFormData(int query_id,
const FormData& form,
- const string16& name,
+ const string16& value,
const string16& label) {
if (!IsAutoFillEnabled())
return false;
@@ -245,12 +214,15 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
if ((*iter)->Label() != label)
continue;
- if ((*iter)->GetFieldText(AutoFillType(NAME_FIRST)) != name &&
- (*iter)->GetFieldText(AutoFillType(NAME_FULL)) != name)
- continue;
-
- profile = *iter;
- break;
+ FieldTypeSet field_types;
+ (*iter)->GetPossibleFieldTypes(value, &field_types);
+ for (FieldTypeSet::const_iterator type = field_types.begin();
+ type != field_types.end(); ++type) {
+ if ((*iter)->GetFieldText(AutoFillType(*type)) == value) {
+ profile = *iter;
+ break;
+ }
+ }
}
// Only look for credit card info if we're not filling profile.
@@ -261,12 +233,15 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
if ((*iter)->Label() != label)
continue;
- if ((*iter)->GetFieldText(AutoFillType(CREDIT_CARD_NAME)) != name &&
- (*iter)->ObfuscatedNumber() != name)
- continue;
-
- credit_card = *iter;
- break;
+ FieldTypeSet field_types;
+ (*iter)->GetPossibleFieldTypes(value, &field_types);
+ for (FieldTypeSet::const_iterator type = field_types.begin();
+ type != field_types.end(); ++type) {
+ if ((*iter)->GetFieldText(AutoFillType(*type)) == value) {
+ credit_card = *iter;
+ break;
+ }
+ }
}
} else {
// If we're filling a profile we can attempt to use the default credit card
@@ -290,10 +265,12 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
for (size_t i = 0; i < form_structure->field_count(); ++i) {
const AutoFillField* field = form_structure->field(i);
+ // TODO(jhawkins): We should have the same number of fields in both
+ // |form_structure| and |result|, so this loop should be unnecessary.
for (size_t j = 0; j < result.fields.size(); ++j) {
if (field->name() == result.fields[j].name() &&
field->label() == result.fields[j].label()) {
- AutoFillType autofill_type(field->heuristic_type());
+ AutoFillType autofill_type(field->type());
if (credit_card &&
autofill_type.group() == AutoFillType::CREDIT_CARD) {
result.fields[j].set_value(
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index 4f455b9..4683483 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -54,7 +54,7 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
const webkit_glue::FormField& field);
virtual bool FillAutoFillFormData(int query_id,
const webkit_glue::FormData& form,
- const string16& name,
+ const string16& value,
const string16& label);
// AutoFillDialogObserver implementation:
diff --git a/chrome/browser/autofill/contact_info.cc b/chrome/browser/autofill/contact_info.cc
index bf547b8..8d4a08f 100644
--- a/chrome/browser/autofill/contact_info.cc
+++ b/chrome/browser/autofill/contact_info.cc
@@ -323,7 +323,8 @@ bool ContactInfo::IsWordInName(const string16& word,
const NameTokens& name_tokens) const {
NameTokens::const_iterator iter;
for (iter = name_tokens.begin(); iter != name_tokens.end(); ++iter) {
- if (word == *iter)
+ // |*iter| is already lower-cased.
+ if (StringToLowerASCII(word) == *iter)
return true;
}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index 1a24783..3492603 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -389,7 +389,7 @@ class RenderViewHost : public RenderWidgetHost {
// Called by the AutoFillManager when the list of suggestions is ready.
void AutoFillSuggestionsReturned(
int query_id,
- const std::vector<string16>& names,
+ const std::vector<string16>& values,
const std::vector<string16>& labels,
int default_suggestion_index);
@@ -602,7 +602,7 @@ class RenderViewHost : public RenderWidgetHost {
const string16& value);
void OnFillAutoFillFormData(int query_id,
const webkit_glue::FormData& form,
- const string16& name,
+ const string16& value,
const string16& label);
void OnShowDesktopNotification(const GURL& source_origin,
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index 829ee9e..5ae58e4 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -416,11 +416,11 @@ class RenderViewHostDelegate {
int query_id, const webkit_glue::FormField& field) = 0;
// Called to fill the FormData object with AutoFill profile information that
- // matches the |name|, |label| key. Returns true to indicate that
+ // matches the |value|, |label| key. Returns true to indicate that
// RenderViewHost::AutoFillFormDataFilled has been called.
virtual bool FillAutoFillFormData(int query_id,
const webkit_glue::FormData& form,
- const string16& name,
+ const string16& value,
const string16& label) = 0;
};
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index c1025ab37..eb80dd6 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1438,12 +1438,12 @@ void RenderView::AddGURLSearchProvider(const GURL& osd_url, bool autodetected) {
void RenderView::OnAutoFillSuggestionsReturned(
int query_id,
- const std::vector<string16>& names,
+ const std::vector<string16>& values,
const std::vector<string16>& labels,
int default_suggestion_index) {
if (webview() && query_id == autofill_query_id_) {
webview()->applyAutoFillSuggestions(
- autofill_query_node_, names, labels, default_suggestion_index);
+ autofill_query_node_, values, labels, default_suggestion_index);
}
autofill_query_node_.reset();
}
@@ -1983,7 +1983,7 @@ void RenderView::removeAutofillSuggestions(const WebString& name,
void RenderView::didAcceptAutoFillSuggestion(
const WebKit::WebNode& node,
- const WebKit::WebString& name,
+ const WebKit::WebString& value,
const WebKit::WebString& label) {
static int query_counter = 0;
autofill_query_id_ = query_counter++;
@@ -1995,7 +1995,7 @@ void RenderView::didAcceptAutoFillSuggestion(
return;
Send(new ViewHostMsg_FillAutoFillFormData(
- routing_id_, autofill_query_id_, form, name, label));
+ routing_id_, autofill_query_id_, form, value, label));
}
// WebKit::WebWidgetClient ----------------------------------------------------
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 97cc7ea..3ef8732 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -273,7 +273,7 @@ class RenderView : public RenderWidget,
const WebKit::WebString& name, const WebKit::WebString& value);
virtual void didAcceptAutoFillSuggestion(
const WebKit::WebNode& node,
- const WebKit::WebString& name,
+ const WebKit::WebString& value,
const WebKit::WebString& label);
virtual WebKit::WebNotificationPresenter* GetNotificationPresenter() {
@@ -738,11 +738,11 @@ class RenderView : public RenderWidget,
// Notification about ui theme changes.
void OnThemeChanged();
- // Notification that we have received AutoFill suggestions. |names| and
+ // Notification that we have received AutoFill suggestions. |values| and
// |labels| correspond with each other and should be the same size.
void OnAutoFillSuggestionsReturned(
int query_id,
- const std::vector<string16>& names,
+ const std::vector<string16>& values,
const std::vector<string16>& labels,
int default_suggestions_index);