Chromium Code Reviews| Index: chrome/renderer/autofill/autofill_agent.cc |
| diff --git a/chrome/renderer/autofill/autofill_agent.cc b/chrome/renderer/autofill/autofill_agent.cc |
| index 73baa1f81f024d11d04684b8c84081f43594cf48..6b2021ac9530c5102abf4ce1c5d1b6e25a222083 100644 |
| --- a/chrome/renderer/autofill/autofill_agent.cc |
| +++ b/chrome/renderer/autofill/autofill_agent.cc |
| @@ -7,6 +7,8 @@ |
| #include "base/bind.h" |
| #include "base/message_loop.h" |
| #include "base/time.h" |
| +#include "base/string_util.h" |
| +#include "base/string_split.h" |
|
Ilya Sherman
2012/05/15 21:12:39
nit: These should precede the time.h include.
keishi
2012/05/16 11:44:07
Done.
|
| #include "base/utf_string_conversions.h" |
| #include "chrome/common/autofill_messages.h" |
| #include "chrome/common/chrome_constants.h" |
| @@ -59,9 +61,17 @@ void AppendDataListSuggestions(const WebKit::WebInputElement& element, |
| if (options.isNull()) |
| return; |
| + string16 prefix = element.editingValue(); |
| + if (element.isMultiple() && |
| + element.formControlType() == WebString::fromUTF8("email")) { |
| + std::vector<string16> parts; |
| + base::SplitStringDontTrim(prefix, ',', &parts); |
| + if (parts.size() > 0) |
| + TrimWhitespace(parts[parts.size() - 1], TRIM_LEADING, &prefix); |
| + } |
| for (WebOptionElement option = options.firstItem().to<WebOptionElement>(); |
| - !option.isNull(); option = options.nextItem().to<WebOptionElement>()) { |
| - if (!StartsWith(option.value(), element.value(), false)) |
| + !option.isNull(); option = options.nextItem().to<WebOptionElement>()) { |
| + if (!StartsWith(option.value(), prefix, false) || option.value() == prefix) |
|
Ilya Sherman
2012/05/15 21:12:39
nit: Do you really need the "option.value() == pre
keishi
2012/05/16 11:44:07
This removes suggestions that completely matches t
Ilya Sherman
2012/05/16 18:05:31
Ah, I see, that makes sense. Thanks.
|
| continue; |
| values->push_back(option.value()); |
| @@ -209,11 +219,37 @@ void AutofillAgent::didAcceptAutofillSuggestion(const WebNode& node, |
| break; |
| case WebAutofillClient::MenuItemIDAutocompleteEntry: |
| case WebAutofillClient::MenuItemIDPasswordEntry: |
| - case WebAutofillClient::MenuItemIDDataListEntry: |
| - // User selected an Autocomplete or password or datalist entry, so we |
| - // fill directly. |
| + // User selected an Autocomplete or password entry, so we fill directly. |
| SetNodeText(value, &element_); |
| break; |
| + case WebAutofillClient::MenuItemIDDataListEntry: { |
| + string16 new_value = value; |
| + // If this element takes multiple values then replace the last part with |
| + // the suggestion. |
| + if (element_.isMultiple() && |
| + element_.formControlType() == WebString::fromUTF8("email")) { |
| + std::vector<string16> parts; |
| + |
| + base::SplitStringDontTrim(element_.editingValue(), ',', &parts); |
| + if (parts.size() == 0) |
| + parts.push_back(string16()); |
| + |
| + string16 last_part = parts.back(); |
| + // We want to keep just the leading whitespace. |
| + for (size_t i = 0; i < last_part.size(); ++i) { |
| + if (!IsWhitespace(last_part[i])) { |
| + last_part = last_part.substr(0, i); |
| + break; |
| + } |
| + } |
| + last_part.append(value); |
| + parts[parts.size() - 1] = last_part; |
| + |
| + new_value = JoinString(parts, ','); |
| + } |
| + SetNodeText(new_value, &element_); |
| + break; |
| + } |
|
Ilya Sherman
2012/05/15 21:12:39
nit: Please decompose this block to a helper metho
keishi
2012/05/16 11:44:07
Done.
|
| default: |
| // A positive item_id is a unique id for an autofill (vs. autocomplete) |
| // suggestion. |
| @@ -502,7 +538,7 @@ void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
| // Don't attempt to autofill with values that are too large or if filling |
| // criteria are not met. |
| - WebString value = element.value(); |
| + WebString value = element.editingValue(); |
| if (value.length() > kMaximumTextSizeForAutofill || |
| (!autofill_on_empty_values && value.isEmpty()) || |
| (requires_caret_at_end && |
| @@ -586,7 +622,11 @@ void AutofillAgent::SetNodeText(const string16& value, |
| string16 substring = value; |
| substring = substring.substr(0, node->maxLength()); |
| - node->setValue(substring, true); |
| + WebKit::WebView* web_view = render_view()->GetWebView(); |
| + if (!web_view || !web_view->focusedFrame()) |
| + return; |
|
Ilya Sherman
2012/05/15 21:12:39
nit: Is this code still needed? If so, please add
keishi
2012/05/16 11:44:07
Done.
|
| + |
| + node->setEditingValue(substring); |
| } |
| } // namespace autofill |