| 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/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 SetElementAutofilled(&username, false); | 242 SetElementAutofilled(&username, false); |
| 243 if (password.isAutofilled()) { | 243 if (password.isAutofilled()) { |
| 244 password.setValue(base::string16()); | 244 password.setValue(base::string16()); |
| 245 SetElementAutofilled(&password, false); | 245 SetElementAutofilled(&password, false); |
| 246 } | 246 } |
| 247 | 247 |
| 248 // If wait_for_username is true we will fill when the username loses focus. | 248 // If wait_for_username is true we will fill when the username loses focus. |
| 249 if (iter->second.fill_data.wait_for_username) | 249 if (iter->second.fill_data.wait_for_username) |
| 250 return false; | 250 return false; |
| 251 | 251 |
| 252 if (!IsElementEditable(element) || | 252 if (!IsElementEditable(element) || !element.isText()) { |
| 253 !element.isText() || | |
| 254 !element.autoComplete()) { | |
| 255 return false; | 253 return false; |
| 256 } | 254 } |
| 257 | 255 |
| 258 // Don't inline autocomplete if the user is deleting, that would be confusing. | 256 // Don't inline autocomplete if the user is deleting, that would be confusing. |
| 259 // But refresh the popup. Note, since this is ours, return true to signal | 257 // But refresh the popup. Note, since this is ours, return true to signal |
| 260 // no further processing is required. | 258 // no further processing is required. |
| 261 if (iter->second.backspace_pressed_last) { | 259 if (iter->second.backspace_pressed_last) { |
| 262 ShowSuggestionPopup(iter->second.fill_data, username); | 260 ShowSuggestionPopup(iter->second.fill_data, username); |
| 263 return true; | 261 return true; |
| 264 } | 262 } |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 | 630 |
| 633 void PasswordAutofillAgent::FillFormOnPasswordRecieved( | 631 void PasswordAutofillAgent::FillFormOnPasswordRecieved( |
| 634 const PasswordFormFillData& fill_data, | 632 const PasswordFormFillData& fill_data, |
| 635 blink::WebInputElement username_element, | 633 blink::WebInputElement username_element, |
| 636 blink::WebInputElement password_element) { | 634 blink::WebInputElement password_element) { |
| 637 // Do not fill if the password field is in an iframe. | 635 // Do not fill if the password field is in an iframe. |
| 638 DCHECK(password_element.document().frame()); | 636 DCHECK(password_element.document().frame()); |
| 639 if (password_element.document().frame()->parent()) | 637 if (password_element.document().frame()->parent()) |
| 640 return; | 638 return; |
| 641 | 639 |
| 642 if (!username_element.form().autoComplete()) | |
| 643 return; | |
| 644 | |
| 645 // If we can't modify the password, don't try to set the username | 640 // If we can't modify the password, don't try to set the username |
| 646 if (!IsElementEditable(password_element) || !password_element.autoComplete()) | 641 if (!IsElementEditable(password_element)) |
| 647 return; | 642 return; |
| 648 | 643 |
| 649 // Try to set the username to the preferred name, but only if the field | 644 // Try to set the username to the preferred name, but only if the field |
| 650 // can be set and isn't prefilled. | 645 // can be set and isn't prefilled. |
| 651 if (IsElementEditable(username_element) && | 646 if (IsElementEditable(username_element) && |
| 652 username_element.autoComplete() && | |
| 653 username_element.value().isEmpty()) { | 647 username_element.value().isEmpty()) { |
| 654 // TODO(tkent): Check maxlength and pattern. | 648 // TODO(tkent): Check maxlength and pattern. |
| 655 username_element.setValue(fill_data.basic_data.fields[0].value); | 649 username_element.setValue(fill_data.basic_data.fields[0].value); |
| 656 } | 650 } |
| 657 | 651 |
| 658 // Fill if we have an exact match for the username. Note that this sets | 652 // Fill if we have an exact match for the username. Note that this sets |
| 659 // username to autofilled. | 653 // username to autofilled. |
| 660 FillUserNameAndPassword(&username_element, &password_element, fill_data, | 654 FillUserNameAndPassword(&username_element, &password_element, fill_data, |
| 661 true /* exact_username_match */, | 655 true /* exact_username_match */, |
| 662 false /* set_selection */); | 656 false /* set_selection */); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 } | 704 } |
| 711 } | 705 } |
| 712 } | 706 } |
| 713 if (password.empty()) | 707 if (password.empty()) |
| 714 return false; // No match was found. | 708 return false; // No match was found. |
| 715 | 709 |
| 716 // TODO(tkent): Check maxlength and pattern for both username and password | 710 // TODO(tkent): Check maxlength and pattern for both username and password |
| 717 // fields. | 711 // fields. |
| 718 | 712 |
| 719 // Don't fill username if password can't be set. | 713 // Don't fill username if password can't be set. |
| 720 if (!IsElementEditable(*password_element) || | 714 if (!IsElementEditable(*password_element)) |
| 721 !password_element->autoComplete()) { | |
| 722 return false; | 715 return false; |
| 723 } | |
| 724 | 716 |
| 725 // Input matches the username, fill in required values. | 717 // Input matches the username, fill in required values. |
| 726 if (IsElementEditable(*username_element) && | 718 if (IsElementEditable(*username_element)) { |
| 727 username_element->autoComplete()) { | |
| 728 username_element->setValue(username); | 719 username_element->setValue(username); |
| 729 SetElementAutofilled(username_element, true); | 720 SetElementAutofilled(username_element, true); |
| 730 | 721 |
| 731 if (set_selection) { | 722 if (set_selection) { |
| 732 username_element->setSelectionRange(current_username.length(), | 723 username_element->setSelectionRange(current_username.length(), |
| 733 username.length()); | 724 username.length()); |
| 734 } | 725 } |
| 735 } else if (current_username != username) { | 726 } else if (current_username != username) { |
| 736 // If the username can't be filled and it doesn't match a saved password | 727 // If the username can't be filled and it doesn't match a saved password |
| 737 // as is, don't autofill a password. | 728 // as is, don't autofill a password. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 } | 824 } |
| 834 | 825 |
| 835 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | 826 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| 836 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) | 827 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) |
| 837 : agent_(agent) {} | 828 : agent_(agent) {} |
| 838 | 829 |
| 839 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | 830 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| 840 ~AutofillWebUserGestureHandler() {} | 831 ~AutofillWebUserGestureHandler() {} |
| 841 | 832 |
| 842 } // namespace autofill | 833 } // namespace autofill |
| OLD | NEW |