From 8d0f15cbef041e318ddf691c1e2cc711c14a160e Mon Sep 17 00:00:00 2001
From: "petersont@google.com"
 <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Tue, 11 Nov 2008 01:01:09 +0000
Subject: Review URL: http://codereview.chromium.org/10005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5151 0039d316-1c4b-4281-b951-d872f2087c98
---
 webkit/build/glue/glue.vcproj            |  4 +++
 webkit/glue/autofill_form.cc             |  2 +-
 webkit/glue/autofill_form.h              |  1 +
 webkit/glue/webframeloaderclient_impl.cc | 49 +++++++++++++++++++++-----------
 4 files changed, 39 insertions(+), 17 deletions(-)

(limited to 'webkit')

diff --git a/webkit/build/glue/glue.vcproj b/webkit/build/glue/glue.vcproj
index 6af0a12..602dbf4 100644
--- a/webkit/build/glue/glue.vcproj
+++ b/webkit/build/glue/glue.vcproj
@@ -125,6 +125,10 @@
 			Name="API"
 			>
 			<File
+				RelativePath="..\..\glue\autofill_form.cc"
+				>
+			</File>
+			<File
 				RelativePath="..\..\glue\autofill_form.h"
 				>
 			</File>
diff --git a/webkit/glue/autofill_form.cc b/webkit/glue/autofill_form.cc
index 98c25bf..bb5f1da 100644
--- a/webkit/glue/autofill_form.cc
+++ b/webkit/glue/autofill_form.cc
@@ -63,4 +63,4 @@ AutofillForm* AutofillForm::CreateAutofillForm(
   }
 
   return result;
-}
\ No newline at end of file
+}
diff --git a/webkit/glue/autofill_form.h b/webkit/glue/autofill_form.h
index 2433e67..91a530cb 100644
--- a/webkit/glue/autofill_form.h
+++ b/webkit/glue/autofill_form.h
@@ -8,6 +8,7 @@
 #include <string>
 #include <vector>
 
+#include "base/time.h"
 #include "webkit/glue/autofill_form.h"
 
 namespace WebCore {
diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc
index c35cf9d..362ea58 100644
--- a/webkit/glue/webframeloaderclient_impl.cc
+++ b/webkit/glue/webframeloaderclient_impl.cc
@@ -42,6 +42,7 @@ MSVC_POP_WARNING();
 #if defined(OS_WIN)
 #include "webkit/activex_shim/activex_shared.h"
 #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"
@@ -330,7 +331,8 @@ void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() {
   PassRefPtr<WebCore::HTMLCollection> forms =
       webframe_->frame()->document()->forms();
 
-  std::vector<PasswordForm> actions;
+  std::vector<PasswordForm> passwordForms;
+
   unsigned int form_count = forms->length();
   for (unsigned int i = 0; i < form_count; ++i) {
     // Strange but true, sometimes item can be NULL.
@@ -344,18 +346,21 @@ void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() {
         continue;
 
       std::set<std::wstring> password_related_fields;
-      scoped_ptr<PasswordForm> data(
+      scoped_ptr<PasswordForm> passwordFormPtr(
           PasswordFormDomManager::CreatePasswordForm(form));
-      if (data.get()) {
-        actions.push_back(*data);
+
+      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 (!data->username_element.empty())
-          password_related_fields.insert(data->username_element);
-        DCHECK(!data->password_element.empty());
-        password_related_fields.insert(data->password_element);
-        if (!data->old_password_element.empty())
-          password_related_fields.insert(data->old_password_element);
+
+        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.
@@ -365,8 +370,8 @@ void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() {
     }
   }
 
-  if (d && (actions.size() > 0))
-    d->OnPasswordFormsSeen(webview, actions);
+  if (d && (passwordForms.size() > 0))
+    d->OnPasswordFormsSeen(webview, passwordForms);
   if (d)
     d->DidFinishDocumentLoadForFrame(webview, webframe_);
 }
@@ -717,15 +722,14 @@ void WebFrameLoaderClient::RegisterAutofillListeners(
     if (excluded_fields.find(name) != excluded_fields.end())
       continue;
 
-/* Disabling this temporarily to investigate perf regressions
+/* Disabling this temporarily to investigate perf regressions.
 #if !defined(OS_MACOSX)
     // FIXME on Mac
     webkit_glue::FormAutocompleteListener* listener =
         new webkit_glue::FormAutocompleteListener(webview_delegate,
                                                   input_element);
     webkit_glue::AttachForInlineAutocomplete(input_element, listener);
-#endif
-    */
+#endif*/
   }
 }
 
@@ -990,7 +994,7 @@ void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError&)
 }
 
 void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function,
-                                                  PassRefPtr<FormState> form_ref) {
+    PassRefPtr<FormState> form_ref) {
   SearchableFormData* form_data = SearchableFormData::Create(form_ref->form());
   WebDocumentLoaderImpl* loader = static_cast<WebDocumentLoaderImpl*>(
     webframe_->frame()->loader()->provisionalDocumentLoader());
@@ -1002,6 +1006,19 @@ void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function,
   // Don't free the PasswordFormData, the loader will do that.
   loader->set_password_form_data(pass_data);
 
+  WebViewImpl* webview = webframe_->webview_impl();
+  WebViewDelegate* d = webview->delegate();
+
+  // Unless autocomplete=off, record what the user put in it for future
+  // autofilling.
+  if (form_ref->form()->autoComplete()) {
+    scoped_ptr<AutofillForm> autofill_form(
+        AutofillForm::CreateAutofillForm(form_ref->form()));
+    if (autofill_form.get()) {
+      d->OnAutofillFormSubmitted(webview, *autofill_form);
+    }
+  }
+
   loader->set_form_submit(true);
 
   (webframe_->frame()->loader()->*function)(PolicyUse);
-- 
cgit v1.1