diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-20 02:04:41 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-20 02:04:41 +0000 |
commit | ddbf30172076500e7b5715201ad7f528f7b3a4d6 (patch) | |
tree | f0c468f70520cbda8ed6f73143a329bf944d68f7 /webkit/glue/webframeloaderclient_impl.cc | |
parent | ac82401483eb837c35ea54402cf10ad2393817c4 (diff) | |
download | chromium_src-ddbf30172076500e7b5715201ad7f528f7b3a4d6.zip chromium_src-ddbf30172076500e7b5715201ad7f528f7b3a4d6.tar.gz chromium_src-ddbf30172076500e7b5715201ad7f528f7b3a4d6.tar.bz2 |
Review URL: http://codereview.chromium.org/11306
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5747 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webframeloaderclient_impl.cc')
-rw-r--r-- | webkit/glue/webframeloaderclient_impl.cc | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index 5983854..f311ce1 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -44,6 +44,8 @@ MSVC_POP_WARNING(); #endif #include "webkit/glue/autofill_form.h" #include "webkit/glue/alt_404_page_resource_fetcher.h" +#include "webkit/glue/autocomplete_input_listener.h" +#include "webkit/glue/form_autocomplete_listener.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/password_form_dom_manager.h" #include "webkit/glue/plugins/plugin_list.h" @@ -326,10 +328,9 @@ void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader, void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() { WebViewImpl* webview = webframe_->webview_impl(); WebViewDelegate* d = webview->delegate(); - - // A frame may be reused. This call ensures we don't hold on to our password - // listeners and their associated HTMLInputElements. - webframe_->ClearPasswordListeners(); + // A frame may be reused. This call ensures a new AutoCompleteListener will + // be created for the newly created frame. + webframe_->ClearAutocompleteListener(); // The document has now been fully loaded. // Scan for password forms to be sent to the browser @@ -350,11 +351,28 @@ void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() { if (!form->autoComplete()) continue; + std::set<std::wstring> password_related_fields; scoped_ptr<PasswordForm> passwordFormPtr( PasswordFormDomManager::CreatePasswordForm(form)); - if (passwordFormPtr.get()) + if (passwordFormPtr.get()) { passwordForms.push_back(*passwordFormPtr); + + // Let's remember the names of password related fields so we do not + // autofill them with the regular form autofill. + + if (!passwordFormPtr->username_element.empty()) + password_related_fields.insert(passwordFormPtr->username_element); + DCHECK(!passwordFormPtr->password_element.empty()); + password_related_fields.insert(passwordFormPtr->password_element); + if (!passwordFormPtr->old_password_element.empty()) + password_related_fields.insert(passwordFormPtr->old_password_element); + } + + // Now let's register for any text input. + // TODO(jcampan): bug #3847 merge password and form autofill so we + // traverse the form elements only once. + RegisterAutofillListeners(form, password_related_fields); } } @@ -685,6 +703,40 @@ NavigationGesture WebFrameLoaderClient::NavigationGestureForLastLoad() { NavigationGestureAuto; } +void WebFrameLoaderClient::RegisterAutofillListeners( + WebCore::HTMLFormElement* form, + const std::set<std::wstring>& excluded_fields) { + + WebViewDelegate* webview_delegate = webframe_->webview_impl()->delegate(); + if (!webview_delegate) + return; + + for (size_t i = 0; i < form->formElements.size(); i++) { + WebCore::HTMLFormControlElement* form_element = form->formElements[i]; + if (!form_element->hasLocalName(WebCore::HTMLNames::inputTag)) + continue; + + WebCore::HTMLInputElement* input_element = + static_cast<WebCore::HTMLInputElement*>(form_element); + if (!input_element->isEnabled() || !input_element->isTextField() || + input_element->isPasswordField() || !input_element->autoComplete()) { + continue; + } + + std::wstring name = webkit_glue::StringToStdWString(input_element->name()); + if (name.empty() || excluded_fields.find(name) != excluded_fields.end()) + continue; + +#if !defined(OS_MACOSX) + // FIXME on Mac + webkit_glue::FormAutocompleteListener* listener = + new webkit_glue::FormAutocompleteListener(webview_delegate); + webframe_->GetAutocompleteListener()->AddInputListener(input_element, + listener); +#endif + } +} + void WebFrameLoaderClient::dispatchDidReceiveTitle(const String& title) { WebViewImpl* webview = webframe_->webview_impl(); WebViewDelegate* d = webview->delegate(); @@ -949,7 +1001,7 @@ void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> form_ref) { SearchableFormData* form_data = SearchableFormData::Create(form_ref->form()); WebDocumentLoaderImpl* loader = static_cast<WebDocumentLoaderImpl*>( - webframe_->frame()->loader()->provisionalDocumentLoader()); + webframe_->frame()->loader()->provisionalDocumentLoader()); // Don't free the SearchableFormData, the loader will do that. loader->set_searchable_form_data(form_data); |