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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 ignore_text_changes_ = ignore; | 311 ignore_text_changes_ = ignore; |
312 } | 312 } |
313 | 313 |
314 void AutofillAgent::FormControlElementClicked( | 314 void AutofillAgent::FormControlElementClicked( |
315 const WebFormControlElement& element, | 315 const WebFormControlElement& element, |
316 bool was_focused) { | 316 bool was_focused) { |
317 const WebInputElement* input_element = toWebInputElement(&element); | 317 const WebInputElement* input_element = toWebInputElement(&element); |
318 if (!input_element && !IsTextAreaElement(element)) | 318 if (!input_element && !IsTextAreaElement(element)) |
319 return; | 319 return; |
320 | 320 |
321 if (was_focused) | 321 bool show_full_suggestion_list = element.isAutofilled() || was_focused; |
322 ShowSuggestions(element, true, false, true, false); | 322 bool show_password_suggestions_only = !was_focused; |
| 323 ShowSuggestions(element, |
| 324 true, |
| 325 false, |
| 326 true, |
| 327 false, |
| 328 show_full_suggestion_list, |
| 329 show_password_suggestions_only); |
323 } | 330 } |
324 | 331 |
325 void AutofillAgent::FormControlElementLostFocus() { | 332 void AutofillAgent::FormControlElementLostFocus() { |
326 HidePopup(); | 333 HidePopup(); |
327 } | 334 } |
328 | 335 |
329 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { | 336 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { |
330 password_autofill_agent_->TextFieldDidEndEditing(element); | 337 password_autofill_agent_->TextFieldDidEndEditing(element); |
331 has_shown_autofill_popup_for_current_edit_ = false; | 338 has_shown_autofill_popup_for_current_edit_ = false; |
332 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); | 339 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 is_popup_possibly_visible_ = true; | 375 is_popup_possibly_visible_ = true; |
369 return; | 376 return; |
370 } | 377 } |
371 | 378 |
372 if (password_autofill_agent_->TextDidChangeInTextField(*input_element)) { | 379 if (password_autofill_agent_->TextDidChangeInTextField(*input_element)) { |
373 element_ = element; | 380 element_ = element; |
374 return; | 381 return; |
375 } | 382 } |
376 } | 383 } |
377 | 384 |
378 ShowSuggestions(element, false, true, false, false); | 385 ShowSuggestions(element, false, true, false, false, false, false); |
379 | 386 |
380 FormData form; | 387 FormData form; |
381 FormFieldData field; | 388 FormFieldData field; |
382 if (FindFormAndFieldForFormControlElement(element, | 389 if (FindFormAndFieldForFormControlElement(element, |
383 &form, | 390 &form, |
384 &field, | 391 &field, |
385 REQUIRE_NONE)) { | 392 REQUIRE_NONE)) { |
386 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, | 393 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, |
387 base::TimeTicks::Now())); | 394 base::TimeTicks::Now())); |
388 } | 395 } |
389 } | 396 } |
390 | 397 |
391 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, | 398 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, |
392 const WebKeyboardEvent& event) { | 399 const WebKeyboardEvent& event) { |
393 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { | 400 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { |
394 element_ = element; | 401 element_ = element; |
395 return; | 402 return; |
396 } | 403 } |
397 | 404 |
398 if (event.windowsKeyCode == ui::VKEY_DOWN || | 405 if (event.windowsKeyCode == ui::VKEY_DOWN || |
399 event.windowsKeyCode == ui::VKEY_UP) | 406 event.windowsKeyCode == ui::VKEY_UP) |
400 ShowSuggestions(element, true, true, true, false); | 407 ShowSuggestions(element, true, true, true, false, false, false); |
401 } | 408 } |
402 | 409 |
403 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { | 410 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { |
404 ShowSuggestions(element, true, false, false, true); | 411 ShowSuggestions(element, true, false, false, true, false, false); |
405 } | 412 } |
406 | 413 |
407 void AutofillAgent::firstUserGestureObserved() { | 414 void AutofillAgent::firstUserGestureObserved() { |
408 password_autofill_agent_->FirstUserGestureObserved(); | 415 password_autofill_agent_->FirstUserGestureObserved(); |
409 } | 416 } |
410 | 417 |
411 void AutofillAgent::AcceptDataListSuggestion( | 418 void AutofillAgent::AcceptDataListSuggestion( |
412 const base::string16& suggested_value) { | 419 const base::string16& suggested_value) { |
413 WebInputElement* input_element = toWebInputElement(&element_); | 420 WebInputElement* input_element = toWebInputElement(&element_); |
414 DCHECK(input_element); | 421 DCHECK(input_element); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 console_message); | 553 console_message); |
547 } | 554 } |
548 | 555 |
549 in_flight_request_form_.reset(); | 556 in_flight_request_form_.reset(); |
550 } | 557 } |
551 | 558 |
552 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, | 559 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, |
553 bool autofill_on_empty_values, | 560 bool autofill_on_empty_values, |
554 bool requires_caret_at_end, | 561 bool requires_caret_at_end, |
555 bool display_warning_if_disabled, | 562 bool display_warning_if_disabled, |
556 bool datalist_only) { | 563 bool datalist_only, |
| 564 bool show_full_suggestion_list, |
| 565 bool show_password_suggestions_only) { |
557 if (!element.isEnabled() || element.isReadOnly()) | 566 if (!element.isEnabled() || element.isReadOnly()) |
558 return; | 567 return; |
| 568 if (!datalist_only && !element.suggestedValue().isEmpty()) |
| 569 return; |
559 | 570 |
560 const WebInputElement* input_element = toWebInputElement(&element); | 571 const WebInputElement* input_element = toWebInputElement(&element); |
561 if (input_element) { | 572 if (input_element) { |
562 if (!input_element->isTextField() || input_element->isPasswordField()) | 573 if (!input_element->isTextField() || input_element->isPasswordField()) |
563 return; | 574 return; |
564 if (!datalist_only && !input_element->suggestedValue().isEmpty()) | 575 if (!datalist_only && !input_element->suggestedValue().isEmpty()) |
565 return; | 576 return; |
566 } else { | 577 } else { |
567 DCHECK(IsTextAreaElement(element)); | 578 DCHECK(IsTextAreaElement(element)); |
568 if (!element.toConst<WebTextAreaElement>().suggestedValue().isEmpty()) | 579 if (!element.toConst<WebTextAreaElement>().suggestedValue().isEmpty()) |
569 return; | 580 return; |
570 } | 581 } |
571 | 582 |
572 // Don't attempt to autofill with values that are too large or if filling | 583 // Don't attempt to autofill with values that are too large or if filling |
573 // criteria are not met. | 584 // criteria are not met. |
574 WebString value = element.editingValue(); | 585 WebString value = element.editingValue(); |
575 if (!datalist_only && | 586 if (!datalist_only && |
576 (value.length() > kMaxDataLength || | 587 (value.length() > kMaxDataLength || |
577 (!autofill_on_empty_values && value.isEmpty()) || | 588 (!autofill_on_empty_values && value.isEmpty()) || |
578 (requires_caret_at_end && | 589 (requires_caret_at_end && |
579 (element.selectionStart() != element.selectionEnd() || | 590 (element.selectionStart() != element.selectionEnd() || |
580 element.selectionEnd() != static_cast<int>(value.length()))))) { | 591 element.selectionEnd() != static_cast<int>(value.length()))))) { |
581 // Any popup currently showing is obsolete. | 592 // Any popup currently showing is obsolete. |
582 HidePopup(); | 593 HidePopup(); |
583 return; | 594 return; |
584 } | 595 } |
585 | 596 |
586 element_ = element; | 597 element_ = element; |
587 if (input_element && | 598 if (IsAutofillableInputElement(input_element) && |
588 password_autofill_agent_->ShowSuggestions(*input_element)) { | 599 (password_autofill_agent_->ShowSuggestions(*input_element, |
| 600 show_full_suggestion_list) || |
| 601 show_password_suggestions_only)) { |
589 is_popup_possibly_visible_ = true; | 602 is_popup_possibly_visible_ = true; |
590 return; | 603 return; |
591 } | 604 } |
592 | 605 |
593 // If autocomplete is disabled at the field level, ensure that the native | 606 // If autocomplete is disabled at the field level, ensure that the native |
594 // UI won't try to show a warning, since that may conflict with a custom | 607 // UI won't try to show a warning, since that may conflict with a custom |
595 // popup. Note that we cannot use the WebKit method element.autoComplete() | 608 // popup. Note that we cannot use the WebKit method element.autoComplete() |
596 // as it does not allow us to distinguish the case where autocomplete is | 609 // as it does not allow us to distinguish the case where autocomplete is |
597 // disabled for *both* the element and for the form. | 610 // disabled for *both* the element and for the form. |
598 const base::string16 autocomplete_attribute = | 611 const base::string16 autocomplete_attribute = |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 // parsed form. | 734 // parsed form. |
722 if (frame && !frame->parent() && !frame->isLoading()) { | 735 if (frame && !frame->parent() && !frame->isLoading()) { |
723 ProcessForms(*frame); | 736 ProcessForms(*frame); |
724 password_autofill_agent_->OnDynamicFormsSeen(frame); | 737 password_autofill_agent_->OnDynamicFormsSeen(frame); |
725 return; | 738 return; |
726 } | 739 } |
727 } | 740 } |
728 } | 741 } |
729 | 742 |
730 } // namespace autofill | 743 } // namespace autofill |
OLD | NEW |