Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: components/autofill/content/renderer/autofill_agent.cc

Issue 2012763003: First pass at refactoring autofill_agent to eventually incorporate Synthetic Form logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing braces :{ Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/autofill/content/renderer/autofill_agent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, /*form_submitted=*/false);
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, /*form_submitted=*/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
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 form_submitted) {
302 FormData form_data;
303 if (!form_util::ExtractFormData(form, &form_data))
304 return;
305
306 FireHostSubmitEvents(form_data, form_submitted);
307 }
308
309 void AutofillAgent::FireHostSubmitEvents(const FormData& form_data,
310 bool form_submitted) {
311 // We remember when we have fired this IPC for this form in this frame load,
312 // because forms with a submit handler may fire both WillSendSubmitEvent
313 // and WillSubmitForm, and we don't want duplicate messages.
314 if (!submitted_forms_.count(form_data)) {
315 Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data,
316 base::TimeTicks::Now()));
317 submitted_forms_.insert(form_data);
318 }
319
320 if (form_submitted)
321 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data));
322 }
323
325 void AutofillAgent::Shutdown() { 324 void AutofillAgent::Shutdown() {
326 legacy_.Shutdown(); 325 legacy_.Shutdown();
327 weak_ptr_factory_.InvalidateWeakPtrs(); 326 weak_ptr_factory_.InvalidateWeakPtrs();
328 } 327 }
329 328
330 void AutofillAgent::FocusChangeComplete() { 329 void AutofillAgent::FocusChangeComplete() {
331 WebDocument doc = render_frame()->GetWebFrame()->document(); 330 WebDocument doc = render_frame()->GetWebFrame()->document();
332 WebElement focused_element; 331 WebElement focused_element;
333 if (!doc.isNull()) 332 if (!doc.isNull())
334 focused_element = doc.focusedElement(); 333 focused_element = doc.focusedElement();
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 const base::string16& username, 589 const base::string16& username,
591 const base::string16& password) { 590 const base::string16& password) {
592 bool handled = password_autofill_agent_->PreviewSuggestion( 591 bool handled = password_autofill_agent_->PreviewSuggestion(
593 element_, 592 element_,
594 username, 593 username,
595 password); 594 password);
596 DCHECK(handled); 595 DCHECK(handled);
597 } 596 }
598 597
599 void AutofillAgent::OnSamePageNavigationCompleted() { 598 void AutofillAgent::OnSamePageNavigationCompleted() {
600 if (last_interacted_form_.isNull()) 599 if (!last_interacted_form_.isNull()) {
601 return; 600 // Assume form submission only if the form is now gone, either invisible or
601 // removed from the DOM.
602 if (form_util::AreFormContentsVisible(last_interacted_form_))
603 return;
602 604
603 // Assume form submission only if the form is now gone, either invisible or 605 FireHostSubmitEvents(last_interacted_form_, /*form_submitted=*/true);
604 // removed from the DOM. 606 last_interacted_form_.reset();
605 if (form_util::AreFormContentsVisible(last_interacted_form_)) 607 }
606 return; 608 // TODO(tmartino): Else, try using Synthetic Form from form_cache.
607
608 // Could not find a visible form equal to our saved form, assume submission.
609 WillSendSubmitEvent(last_interacted_form_);
610 WillSubmitForm(last_interacted_form_);
611 last_interacted_form_.reset();
612 } 609 }
613 610
614 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, 611 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element,
615 const ShowSuggestionsOptions& options) { 612 const ShowSuggestionsOptions& options) {
616 if (!element.isEnabled() || element.isReadOnly()) 613 if (!element.isEnabled() || element.isReadOnly())
617 return; 614 return;
618 if (!element.suggestedValue().isEmpty()) 615 if (!element.suggestedValue().isEmpty())
619 return; 616 return;
620 617
621 const WebInputElement* input_element = toWebInputElement(&element); 618 const WebInputElement* input_element = toWebInputElement(&element);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { 796 void AutofillAgent::LegacyAutofillAgent::OnDestruct() {
800 // No-op. Don't delete |this|. 797 // No-op. Don't delete |this|.
801 } 798 }
802 799
803 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { 800 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() {
804 if (agent_) 801 if (agent_)
805 agent_->FocusChangeComplete(); 802 agent_->FocusChangeComplete();
806 } 803 }
807 804
808 } // namespace autofill 805 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/autofill_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698