Index: components/autofill/content/renderer/password_autofill_agent.cc |
diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc |
index 357ab1e8eca3ca228c39e42d00296a617b46bb5b..e9afd03ca8788b3ef759580caa9611e1f723cb99 100644 |
--- a/components/autofill/content/renderer/password_autofill_agent.cc |
+++ b/components/autofill/content/renderer/password_autofill_agent.cc |
@@ -17,6 +17,7 @@ |
#include "components/autofill/content/renderer/renderer_save_password_progress_logger.h" |
#include "components/autofill/core/common/autofill_constants.h" |
#include "components/autofill/core/common/autofill_switches.h" |
+#include "components/autofill/core/common/autofill_util.h" |
#include "components/autofill/core/common/form_field_data.h" |
#include "components/autofill/core/common/password_form.h" |
#include "components/autofill/core/common/password_form_fill_data.h" |
@@ -236,7 +237,10 @@ bool DoUsernamesMatch(const base::string16& username1, |
bool exact_match) { |
if (exact_match) |
return username1 == username2; |
- return StartsWith(username1, username2, true); |
+ return IsFeatureSubstringMatchEnabled() |
+ ? IsContentsPrefixOfSuggestionToken(username1, username2, |
+ CASE_SENSITIVE) |
+ : StartsWith(username1, username2, true); |
} |
// Returns |true| if the given element is editable. Otherwise, returns |false|. |
@@ -426,8 +430,17 @@ bool FillUserNameAndPassword( |
username_element->setAutofilled(true); |
if (set_selection) { |
- username_element->setSelectionRange(current_username.length(), |
- username.length()); |
+ if (IsFeatureSubstringMatchEnabled()) { |
+ size_t start = 0; |
+ size_t end = 0; |
+ if (base::string16::npos != |
+ ComputeRange(username, current_username, &start, &end)) { |
+ username_element->setSelectionRange(start, end); |
+ } |
+ } else { |
+ username_element->setSelectionRange(current_username.length(), |
+ username.length()); |
+ } |
} |
} else if (current_username != username) { |
// If the username can't be filled and it doesn't match a saved password |
@@ -764,13 +777,25 @@ bool PasswordAutofillAgent::PreviewSuggestion( |
return false; |
} |
+ base::string16 current_username = username_element.value(); |
+ base::string16 suggested_username = username; |
was_username_autofilled_ = username_element.isAutofilled(); |
username_selection_start_ = username_element.selectionStart(); |
username_element.setSuggestedValue(username); |
username_element.setAutofilled(true); |
- username_element.setSelectionRange( |
- username_selection_start_, |
- username_element.suggestedValue().length()); |
+ |
+ if (IsFeatureSubstringMatchEnabled()) { |
+ size_t start = 0; |
+ size_t end = 0; |
+ if (base::string16::npos != |
+ ComputeRange(suggested_username, current_username, &start, &end)) { |
+ username_element.setSelectionRange(start, end); |
+ was_username_autofilled_ = start; |
+ } |
+ } else { |
+ username_element.setSelectionRange( |
+ username_selection_start_, username_element.suggestedValue().length()); |
+ } |
was_password_autofilled_ = password_info->password_field.isAutofilled(); |
password_info->password_field.setSuggestedValue(password); |
@@ -1335,7 +1360,8 @@ void PasswordAutofillAgent::PerformInlineAutocomplete( |
#if !defined(OS_ANDROID) |
// Fill the user and password field with the most relevant match. Android |
// only fills in the fields after the user clicks on the suggestion popup. |
- if (FillUserNameAndPassword( |
+ if (!IsFeatureSubstringMatchEnabled() && |
vabr (Chromium)
2015/03/27 10:13:34
I still do not understand why do we switch off inl
Pritam Nikam
2015/03/27 14:57:42
With autocomplete on, user experience for token ma
|
+ FillUserNameAndPassword( |
&username, |
&password, |
fill_data, |