diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-18 17:51:53 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-18 17:51:53 +0000 |
commit | fedaf2e8932a982d65490955a9d59bace9798b62 (patch) | |
tree | bc95b60f2aeadc4bac41dbe093802dcf02925703 /webkit | |
parent | 7777d9633bed51e5458ca2ec4b0df1f73d809bfb (diff) | |
download | chromium_src-fedaf2e8932a982d65490955a9d59bace9798b62.zip chromium_src-fedaf2e8932a982d65490955a9d59bace9798b62.tar.gz chromium_src-fedaf2e8932a982d65490955a9d59bace9798b62.tar.bz2 |
Autocomplete now uses the input field id when no name is available to perform autocomplete.
This matches FF behavior.
BUG=6310
TEST=See bug.
Review URL: http://codereview.chromium.org/48033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11987 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/autofill_form.cc | 26 | ||||
-rw-r--r-- | webkit/glue/autofill_form.h | 7 | ||||
-rw-r--r-- | webkit/glue/editor_client_impl.cc | 7 |
3 files changed, 31 insertions, 9 deletions
diff --git a/webkit/glue/autofill_form.cc b/webkit/glue/autofill_form.cc index ee38b05..182aab6 100644 --- a/webkit/glue/autofill_form.cc +++ b/webkit/glue/autofill_form.cc @@ -64,15 +64,29 @@ AutofillForm* AutofillForm::CreateAutofillForm( if (value.length() == 0) continue; - std::wstring name = webkit_glue::StringToStdWString(input_element->name()); - // Test that the name is not blank. - std::wstring trimmed_name; - TrimWhitespace(name, TRIM_LEADING, &trimmed_name); - if (trimmed_name.length() == 0) - continue; + std::wstring name = GetNameForInputElement(input_element); + if (name.length() == 0) + continue; // If we have no name, there is nothing to store. result->elements.push_back(AutofillForm::Element(name, value)); } return result; } + +// static +std::wstring AutofillForm::GetNameForInputElement(WebCore::HTMLInputElement* + element) { + std::wstring name = webkit_glue::StringToStdWString(element->name()); + std::wstring trimmed_name; + TrimWhitespace(name, TRIM_LEADING, &trimmed_name); + if (trimmed_name.length() > 0) + return trimmed_name; + + name = webkit_glue::StringToStdWString(element->id()); + TrimWhitespace(name, TRIM_LEADING, &trimmed_name); + if (trimmed_name.length() > 0) + return trimmed_name; + + return std::wstring(); +} diff --git a/webkit/glue/autofill_form.h b/webkit/glue/autofill_form.h index 6a300a7..8375e75 100644 --- a/webkit/glue/autofill_form.h +++ b/webkit/glue/autofill_form.h @@ -9,6 +9,7 @@ #include <vector> namespace WebCore { + class HTMLInputElement; class HTMLFormElement; } @@ -30,6 +31,12 @@ class AutofillForm { static AutofillForm* CreateAutofillForm(WebCore::HTMLFormElement* form); + // Returns the name that should be used for the specified |element| when + // storing autofill data. This is either the field name or its id, an empty + // string if it has no name and no id. + static std::wstring GetNameForInputElement(WebCore::HTMLInputElement* + element); + // A vector of all the input fields in the form. std::vector<Element> elements; }; diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc index a3b245c..b4ba417 100644 --- a/webkit/glue/editor_client_impl.cc +++ b/webkit/glue/editor_client_impl.cc @@ -31,6 +31,7 @@ MSVC_POP_WARNING(); #undef LOG #include "base/message_loop.h" #include "base/string_util.h" +#include "webkit/glue/autofill_form.h" #include "webkit/glue/editor_client_impl.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/webkit_glue.h" @@ -688,7 +689,7 @@ void EditorClientImpl::Autofill(WebCore::HTMLInputElement* input_element, return; } - std::wstring name = webkit_glue::StringToStdWString(input_element->name()); + std::wstring name = AutofillForm::GetNameForInputElement(input_element); if (name.empty()) // If the field has no name, then we won't have values. return; @@ -736,8 +737,8 @@ void EditorClientImpl::DoAutofill(WebCore::HTMLInputElement* input_element, } // Then trigger form autofill. - std::wstring name = webkit_glue::StringToStdWString(input_element-> - name().string()); + std::wstring name = AutofillForm::GetNameForInputElement(input_element); + DCHECK_GT(static_cast<int>(name.length()), 0); web_view_->delegate()->QueryFormFieldAutofill(name, value, reinterpret_cast<int64>(input_element)); } |