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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "components/autofill/content/common/autofill_messages.h" | 14 #include "components/autofill/content/common/autofill_messages.h" |
15 #include "components/autofill/content/renderer/form_autofill_util.h" | 15 #include "components/autofill/content/renderer/form_autofill_util.h" |
16 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 16 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
17 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" | 17 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" |
18 #include "components/autofill/core/common/autofill_constants.h" | 18 #include "components/autofill/core/common/autofill_constants.h" |
19 #include "components/autofill/core/common/autofill_switches.h" | 19 #include "components/autofill/core/common/autofill_switches.h" |
| 20 #include "components/autofill/core/common/autofill_util.h" |
20 #include "components/autofill/core/common/form_field_data.h" | 21 #include "components/autofill/core/common/form_field_data.h" |
21 #include "components/autofill/core/common/password_form.h" | 22 #include "components/autofill/core/common/password_form.h" |
22 #include "components/autofill/core/common/password_form_fill_data.h" | 23 #include "components/autofill/core/common/password_form_fill_data.h" |
23 #include "content/public/renderer/document_state.h" | 24 #include "content/public/renderer/document_state.h" |
24 #include "content/public/renderer/navigation_state.h" | 25 #include "content/public/renderer/navigation_state.h" |
25 #include "content/public/renderer/render_frame.h" | 26 #include "content/public/renderer/render_frame.h" |
26 #include "content/public/renderer/render_view.h" | 27 #include "content/public/renderer/render_view.h" |
27 #include "third_party/WebKit/public/platform/WebVector.h" | 28 #include "third_party/WebKit/public/platform/WebVector.h" |
28 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 29 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
29 #include "third_party/WebKit/public/web/WebDocument.h" | 30 #include "third_party/WebKit/public/web/WebDocument.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 230 |
230 bool IsElementEditable(const blink::WebInputElement& element) { | 231 bool IsElementEditable(const blink::WebInputElement& element) { |
231 return element.isEnabled() && !element.isReadOnly(); | 232 return element.isEnabled() && !element.isReadOnly(); |
232 } | 233 } |
233 | 234 |
234 bool DoUsernamesMatch(const base::string16& username1, | 235 bool DoUsernamesMatch(const base::string16& username1, |
235 const base::string16& username2, | 236 const base::string16& username2, |
236 bool exact_match) { | 237 bool exact_match) { |
237 if (exact_match) | 238 if (exact_match) |
238 return username1 == username2; | 239 return username1 == username2; |
239 return StartsWith(username1, username2, true); | 240 return IsFeatureSubstringMatchEnabled() |
| 241 ? IsContentsPrefixOfSuggestionToken(username1, username2, true) |
| 242 : StartsWith(username1, username2, true); |
240 } | 243 } |
241 | 244 |
242 // Returns |true| if the given element is editable. Otherwise, returns |false|. | 245 // Returns |true| if the given element is editable. Otherwise, returns |false|. |
243 bool IsElementAutocompletable(const blink::WebInputElement& element) { | 246 bool IsElementAutocompletable(const blink::WebInputElement& element) { |
244 return IsElementEditable(element); | 247 return IsElementEditable(element); |
245 } | 248 } |
246 | 249 |
247 // Returns true if the password specified in |form| is a default value. | 250 // Returns true if the password specified in |form| is a default value. |
248 bool PasswordValueIsDefault(const base::string16& password_element, | 251 bool PasswordValueIsDefault(const base::string16& password_element, |
249 const base::string16& password_value, | 252 const base::string16& password_value, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 // fields. | 422 // fields. |
420 | 423 |
421 // Input matches the username, fill in required values. | 424 // Input matches the username, fill in required values. |
422 if (!username_element->isNull() && | 425 if (!username_element->isNull() && |
423 IsElementAutocompletable(*username_element)) { | 426 IsElementAutocompletable(*username_element)) { |
424 username_element->setValue(username, true); | 427 username_element->setValue(username, true); |
425 nonscript_modified_values[*username_element] = username; | 428 nonscript_modified_values[*username_element] = username; |
426 username_element->setAutofilled(true); | 429 username_element->setAutofilled(true); |
427 | 430 |
428 if (set_selection) { | 431 if (set_selection) { |
429 username_element->setSelectionRange(current_username.length(), | 432 if (IsFeatureSubstringMatchEnabled()) { |
430 username.length()); | 433 size_t start = 0; |
| 434 size_t end = 0; |
| 435 if (base::string16::npos != |
| 436 ComputeRange(username, current_username, &start, &end)) { |
| 437 username_element->setSelectionRange(start, end); |
| 438 } |
| 439 } else { |
| 440 username_element->setSelectionRange(current_username.length(), |
| 441 username.length()); |
| 442 } |
431 } | 443 } |
432 } else if (current_username != username) { | 444 } else if (current_username != username) { |
433 // If the username can't be filled and it doesn't match a saved password | 445 // If the username can't be filled and it doesn't match a saved password |
434 // as is, don't autofill a password. | 446 // as is, don't autofill a password. |
435 return other_possible_username_selected; | 447 return other_possible_username_selected; |
436 } | 448 } |
437 | 449 |
438 // Wait to fill in the password until a user gesture occurs. This is to make | 450 // Wait to fill in the password until a user gesture occurs. This is to make |
439 // sure that we do not fill in the DOM with a password until we believe the | 451 // sure that we do not fill in the DOM with a password until we believe the |
440 // user is intentionally interacting with the page. | 452 // user is intentionally interacting with the page. |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 const blink::WebString& password) { | 769 const blink::WebString& password) { |
758 blink::WebInputElement username_element; | 770 blink::WebInputElement username_element; |
759 PasswordInfo* password_info; | 771 PasswordInfo* password_info; |
760 | 772 |
761 if (!FindLoginInfo(node, &username_element, &password_info) || | 773 if (!FindLoginInfo(node, &username_element, &password_info) || |
762 !IsElementAutocompletable(username_element) || | 774 !IsElementAutocompletable(username_element) || |
763 !IsElementAutocompletable(password_info->password_field)) { | 775 !IsElementAutocompletable(password_info->password_field)) { |
764 return false; | 776 return false; |
765 } | 777 } |
766 | 778 |
| 779 base::string16 current_username = username_element.value(); |
| 780 base::string16 suggested_username = username; |
767 was_username_autofilled_ = username_element.isAutofilled(); | 781 was_username_autofilled_ = username_element.isAutofilled(); |
768 username_selection_start_ = username_element.selectionStart(); | 782 username_selection_start_ = username_element.selectionStart(); |
769 username_element.setSuggestedValue(username); | 783 username_element.setSuggestedValue(username); |
770 username_element.setAutofilled(true); | 784 username_element.setAutofilled(true); |
771 username_element.setSelectionRange( | 785 |
772 username_selection_start_, | 786 if (IsFeatureSubstringMatchEnabled()) { |
773 username_element.suggestedValue().length()); | 787 size_t start = 0; |
| 788 size_t end = 0; |
| 789 if (base::string16::npos != |
| 790 ComputeRange(suggested_username, current_username, &start, &end)) { |
| 791 username_element.setSelectionRange(start, end); |
| 792 was_username_autofilled_ = start; |
| 793 } |
| 794 } else { |
| 795 username_element.setSelectionRange( |
| 796 username_selection_start_, username_element.suggestedValue().length()); |
| 797 } |
774 | 798 |
775 was_password_autofilled_ = password_info->password_field.isAutofilled(); | 799 was_password_autofilled_ = password_info->password_field.isAutofilled(); |
776 password_info->password_field.setSuggestedValue(password); | 800 password_info->password_field.setSuggestedValue(password); |
777 password_info->password_field.setAutofilled(true); | 801 password_info->password_field.setAutofilled(true); |
778 | 802 |
779 return true; | 803 return true; |
780 } | 804 } |
781 | 805 |
782 bool PasswordAutofillAgent::DidClearAutofillSelection( | 806 bool PasswordAutofillAgent::DidClearAutofillSelection( |
783 const blink::WebNode& node) { | 807 const blink::WebNode& node) { |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { | 1457 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { |
1434 agent_->DidStopLoading(); | 1458 agent_->DidStopLoading(); |
1435 } | 1459 } |
1436 | 1460 |
1437 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: | 1461 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: |
1438 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { | 1462 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { |
1439 agent_->LegacyDidStartProvisionalLoad(navigated_frame); | 1463 agent_->LegacyDidStartProvisionalLoad(navigated_frame); |
1440 } | 1464 } |
1441 | 1465 |
1442 } // namespace autofill | 1466 } // namespace autofill |
OLD | NEW |