Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/content/renderer/autofill_agent.h" | 5 #include "components/autofill/content/renderer/autofill_agent.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 | 10 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 submitted_forms_.clear(); | 241 submitted_forms_.clear(); |
| 242 last_interacted_form_.reset(); | 242 last_interacted_form_.reset(); |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 void AutofillAgent::DidFinishDocumentLoad() { | 246 void AutofillAgent::DidFinishDocumentLoad() { |
| 247 ProcessForms(); | 247 ProcessForms(); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void AutofillAgent::WillSendSubmitEvent(const WebFormElement& form) { | 250 void AutofillAgent::WillSendSubmitEvent(const WebFormElement& form) { |
| 251 FormData form_data; | 251 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.
| |
| 252 if (!form_util::ExtractFormData(form, &form_data)) | |
| 253 return; | |
| 254 | |
| 255 // The WillSendSubmitEvent function is called when there is a submit handler | |
| 256 // on the form, such as in the case of (but not restricted to) | |
| 257 // JavaScript-submitted forms. Sends a WillSubmitForm message to the browser | |
| 258 // and remembers for which form it did that in the current frame load, so that | |
| 259 // no additional message is sent if AutofillAgent::WillSubmitForm() is called | |
| 260 // (which is itself not guaranteed if the submit event is prevented by | |
| 261 // JavaScript). | |
| 262 if (!submitted_forms_.count(form_data)) { | |
| 263 Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data, | |
| 264 base::TimeTicks::Now())); | |
| 265 submitted_forms_.insert(form_data); | |
| 266 } | |
| 267 } | 252 } |
| 268 | 253 |
| 269 void AutofillAgent::WillSubmitForm(const WebFormElement& form) { | 254 void AutofillAgent::WillSubmitForm(const WebFormElement& form) { |
| 270 FormData form_data; | 255 FireHostSubmitEvents(form, true, true); |
| 271 if (!form_util::ExtractFormData(form, &form_data)) | |
| 272 return; | |
| 273 | |
| 274 // If WillSubmitForm message had not been sent for this form, send it. | |
| 275 if (!submitted_forms_.count(form_data)) { | |
| 276 Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data, | |
| 277 base::TimeTicks::Now())); | |
| 278 } | |
| 279 | |
| 280 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data)); | |
| 281 } | 256 } |
| 282 | 257 |
| 283 void AutofillAgent::DidChangeScrollOffset() { | 258 void AutofillAgent::DidChangeScrollOffset() { |
| 284 if (IsKeyboardAccessoryEnabled()) | 259 if (IsKeyboardAccessoryEnabled()) |
| 285 return; | 260 return; |
| 286 | 261 |
| 287 HidePopup(); | 262 HidePopup(); |
| 288 } | 263 } |
| 289 | 264 |
| 290 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { | 265 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 315 return; | 290 return; |
| 316 | 291 |
| 317 element_ = *element; | 292 element_ = *element; |
| 318 } | 293 } |
| 319 | 294 |
| 320 void AutofillAgent::OnDestruct() { | 295 void AutofillAgent::OnDestruct() { |
| 321 Shutdown(); | 296 Shutdown(); |
| 322 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 297 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 323 } | 298 } |
| 324 | 299 |
| 300 void AutofillAgent::FireHostSubmitEvents(const WebFormElement& form, | |
| 301 bool willSubmitForm, | |
| 302 bool formSubmitted) { | |
| 303 FormData form_data; | |
| 304 if (!form_util::ExtractFormData(form, &form_data)) { | |
| 305 return; | |
| 306 } | |
| 307 FireHostSubmitEvents(form_data, willSubmitForm, formSubmitted); | |
| 308 } | |
| 309 | |
| 310 void AutofillAgent::FireHostSubmitEvents(const FormData& form_data, | |
| 311 bool willSubmitForm, | |
| 312 bool formSubmitted) { | |
| 313 // We remember when we have fired this IPC for this form in this frame load, | |
| 314 // because forms with a submit handler may fire both WillSendSubmitEvent | |
| 315 // and WillSubmitForm, and we don't want duplicate messages. | |
| 316 if (willSubmitForm && !submitted_forms_.count(form_data)) { | |
| 317 Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data, | |
| 318 base::TimeTicks::Now())); | |
| 319 submitted_forms_.insert(form_data); | |
| 320 } | |
| 321 | |
| 322 if (formSubmitted) { | |
| 323 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data)); | |
| 324 } | |
| 325 } | |
| 326 | |
| 325 void AutofillAgent::Shutdown() { | 327 void AutofillAgent::Shutdown() { |
| 326 legacy_.Shutdown(); | 328 legacy_.Shutdown(); |
| 327 weak_ptr_factory_.InvalidateWeakPtrs(); | 329 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 328 } | 330 } |
| 329 | 331 |
| 330 void AutofillAgent::FocusChangeComplete() { | 332 void AutofillAgent::FocusChangeComplete() { |
| 331 WebDocument doc = render_frame()->GetWebFrame()->document(); | 333 WebDocument doc = render_frame()->GetWebFrame()->document(); |
| 332 WebElement focused_element; | 334 WebElement focused_element; |
| 333 if (!doc.isNull()) | 335 if (!doc.isNull()) |
| 334 focused_element = doc.focusedElement(); | 336 focused_element = doc.focusedElement(); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 const base::string16& username, | 592 const base::string16& username, |
| 591 const base::string16& password) { | 593 const base::string16& password) { |
| 592 bool handled = password_autofill_agent_->PreviewSuggestion( | 594 bool handled = password_autofill_agent_->PreviewSuggestion( |
| 593 element_, | 595 element_, |
| 594 username, | 596 username, |
| 595 password); | 597 password); |
| 596 DCHECK(handled); | 598 DCHECK(handled); |
| 597 } | 599 } |
| 598 | 600 |
| 599 void AutofillAgent::OnSamePageNavigationCompleted() { | 601 void AutofillAgent::OnSamePageNavigationCompleted() { |
| 600 if (last_interacted_form_.isNull()) | 602 if (last_interacted_form_.isNull()) { |
| 603 // TODO(tmartino): Try using Synthetic Form from form_cache. | |
| 601 return; | 604 return; |
| 602 | 605 } 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.
| |
| 603 // Assume form submission only if the form is now gone, either invisible or | 606 // Assume form submission only if the form is now gone, either invisible or |
| 604 // removed from the DOM. | 607 // removed from the DOM. |
| 605 if (form_util::AreFormContentsVisible(last_interacted_form_)) | 608 if (form_util::AreFormContentsVisible(last_interacted_form_)) { |
| 606 return; | 609 return; |
| 607 | 610 } |
| 608 // Could not find a visible form equal to our saved form, assume submission. | 611 FireHostSubmitEvents(last_interacted_form_, true, true); |
| 609 WillSendSubmitEvent(last_interacted_form_); | 612 last_interacted_form_.reset(); |
| 610 WillSubmitForm(last_interacted_form_); | 613 } |
| 611 last_interacted_form_.reset(); | |
| 612 } | 614 } |
| 613 | 615 |
| 614 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, | 616 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, |
| 615 const ShowSuggestionsOptions& options) { | 617 const ShowSuggestionsOptions& options) { |
| 616 if (!element.isEnabled() || element.isReadOnly()) | 618 if (!element.isEnabled() || element.isReadOnly()) |
| 617 return; | 619 return; |
| 618 if (!element.suggestedValue().isEmpty()) | 620 if (!element.suggestedValue().isEmpty()) |
| 619 return; | 621 return; |
| 620 | 622 |
| 621 const WebInputElement* input_element = toWebInputElement(&element); | 623 const WebInputElement* input_element = toWebInputElement(&element); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { | 801 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 800 // No-op. Don't delete |this|. | 802 // No-op. Don't delete |this|. |
| 801 } | 803 } |
| 802 | 804 |
| 803 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { | 805 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { |
| 804 if (agent_) | 806 if (agent_) |
| 805 agent_->FocusChangeComplete(); | 807 agent_->FocusChangeComplete(); |
| 806 } | 808 } |
| 807 | 809 |
| 808 } // namespace autofill | 810 } // namespace autofill |
| OLD | NEW |