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..2261252d7f3c63929b2ec4edf278ddf6013fbc15 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, true, false); |
|
Mathieu
2016/05/25 17:48:55
nit: FireHostSubmitEvents(form, /* form_submitted=
tmartino
2016/05/25 18:39:42
Agreed, done.
|
| } |
| 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, true, true); |
| } |
| void AutofillAgent::DidChangeScrollOffset() { |
| @@ -322,6 +297,33 @@ void AutofillAgent::OnDestruct() { |
| base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| } |
| +void AutofillAgent::FireHostSubmitEvents(const WebFormElement& form, |
| + bool willSubmitForm, |
| + bool formSubmitted) { |
| + FormData form_data; |
| + if (!form_util::ExtractFormData(form, &form_data)) { |
| + return; |
| + } |
| + FireHostSubmitEvents(form_data, willSubmitForm, formSubmitted); |
| +} |
| + |
| +void AutofillAgent::FireHostSubmitEvents(const FormData& form_data, |
| + bool willSubmitForm, |
| + bool formSubmitted) { |
| + // 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 (willSubmitForm && !submitted_forms_.count(form_data)) { |
| + Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data, |
| + base::TimeTicks::Now())); |
| + submitted_forms_.insert(form_data); |
| + } |
| + |
| + if (formSubmitted) { |
| + Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data)); |
| + } |
| +} |
| + |
| void AutofillAgent::Shutdown() { |
| legacy_.Shutdown(); |
| weak_ptr_factory_.InvalidateWeakPtrs(); |
| @@ -597,18 +599,18 @@ void AutofillAgent::OnPreviewPasswordSuggestion( |
| } |
| void AutofillAgent::OnSamePageNavigationCompleted() { |
| - if (last_interacted_form_.isNull()) |
| + if (last_interacted_form_.isNull()) { |
| + // TODO(tmartino): Try using Synthetic Form from form_cache. |
| 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(); |
| + } else { |
|
Mathieu
2016/05/25 17:48:55
nit: don't need an else if you return in the above
tmartino
2016/05/25 18:39:42
Done.
|
| + // 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; |
| + } |
| + FireHostSubmitEvents(last_interacted_form_, true, true); |
| + last_interacted_form_.reset(); |
| + } |
| } |
| void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, |