Chromium Code Reviews| Index: components/autofill/content/renderer/autofill_agent.cc |
| diff --git a/components/autofill/content/renderer/autofill_agent.cc b/components/autofill/content/renderer/autofill_agent.cc |
| index 8ee04e6429f6a4c908d2d6e295ed8056e5a7a9e2..ee6380f3e6d31cee6d9a15e709b2f62b87fa1def 100644 |
| --- a/components/autofill/content/renderer/autofill_agent.cc |
| +++ b/components/autofill/content/renderer/autofill_agent.cc |
| @@ -248,36 +248,11 @@ void AutofillAgent::DidFinishDocumentLoad() { |
| } |
| void AutofillAgent::WillSendSubmitEvent(const WebFormElement& form) { |
| - FormData form_data; |
| - if (!form_util::ExtractFormData(form, &form_data)) |
| - return; |
| - |
| - // The WillSendSubmitEvent function is called when there is a submit handler |
| - // on the form, such as in the case of (but not restricted to) |
| - // JavaScript-submitted forms. Sends a WillSubmitForm message to the browser |
| - // and remembers for which form it did that in the current frame load, so that |
| - // no additional message is sent if AutofillAgent::WillSubmitForm() is called |
| - // (which is itself not guaranteed if the submit event is prevented by |
| - // JavaScript). |
| - if (!submitted_forms_.count(form_data)) { |
| - Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data, |
| - base::TimeTicks::Now())); |
| - submitted_forms_.insert(form_data); |
| - } |
| + FireHostSubmitEvents(form, /*form_submitted=*/false); |
| } |
| void AutofillAgent::WillSubmitForm(const WebFormElement& form) { |
| - FormData form_data; |
| - if (!form_util::ExtractFormData(form, &form_data)) |
| - return; |
| - |
| - // If WillSubmitForm message had not been sent for this form, send it. |
| - if (!submitted_forms_.count(form_data)) { |
| - Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data, |
| - base::TimeTicks::Now())); |
| - } |
| - |
| - Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data)); |
| + FireHostSubmitEvents(form, /*form_submitted=*/true); |
| } |
| void AutofillAgent::DidChangeScrollOffset() { |
| @@ -322,6 +297,31 @@ void AutofillAgent::OnDestruct() { |
| base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| } |
| +void AutofillAgent::FireHostSubmitEvents(const WebFormElement& form, |
| + bool form_submitted) { |
| + FormData form_data; |
| + if (!form_util::ExtractFormData(form, &form_data)) { |
|
Mathieu
2016/05/25 20:02:58
nit: unnecessary {}
|
| + return; |
| + } |
| + FireHostSubmitEvents(form_data, form_submitted); |
| +} |
| + |
| +void AutofillAgent::FireHostSubmitEvents(const FormData& form_data, |
| + bool form_submitted) { |
| + // We remember when we have fired this IPC for this form in this frame load, |
| + // because forms with a submit handler may fire both WillSendSubmitEvent |
| + // and WillSubmitForm, and we don't want duplicate messages. |
| + if (!submitted_forms_.count(form_data)) { |
| + Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data, |
| + base::TimeTicks::Now())); |
| + submitted_forms_.insert(form_data); |
| + } |
| + |
| + if (form_submitted) { |
|
Mathieu
2016/05/25 20:02:59
nit: unnecessary {}
|
| + Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data)); |
| + } |
| +} |
| + |
| void AutofillAgent::Shutdown() { |
| legacy_.Shutdown(); |
| weak_ptr_factory_.InvalidateWeakPtrs(); |
| @@ -597,18 +597,16 @@ void AutofillAgent::OnPreviewPasswordSuggestion( |
| } |
| void AutofillAgent::OnSamePageNavigationCompleted() { |
| - if (last_interacted_form_.isNull()) |
| - return; |
| - |
| - // Assume form submission only if the form is now gone, either invisible or |
| - // removed from the DOM. |
| - if (form_util::AreFormContentsVisible(last_interacted_form_)) |
| - return; |
| - |
| - // Could not find a visible form equal to our saved form, assume submission. |
| - WillSendSubmitEvent(last_interacted_form_); |
| - WillSubmitForm(last_interacted_form_); |
| - last_interacted_form_.reset(); |
| + if (!last_interacted_form_.isNull()) { |
| + // Assume form submission only if the form is now gone, either invisible or |
| + // removed from the DOM. |
| + if (form_util::AreFormContentsVisible(last_interacted_form_)) { |
|
Mathieu
2016/05/25 20:02:59
nit: remove {}
|
| + return; |
| + } |
| + FireHostSubmitEvents(last_interacted_form_, /*form_submitted=*/true); |
| + last_interacted_form_.reset(); |
| + } |
| + // TODO(tmartino): Else, try using Synthetic Form from form_cache. |
| } |
| void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, |