| Index: chrome/renderer/autofill_helper.cc
|
| diff --git a/chrome/renderer/autofill_helper.cc b/chrome/renderer/autofill_helper.cc
|
| index 2832f0dbaa83f61e744f2dc04047f1f6b1bc579d..7725658ff1c4581c531991d7cc692ec417fd8789 100644
|
| --- a/chrome/renderer/autofill_helper.cc
|
| +++ b/chrome/renderer/autofill_helper.cc
|
| @@ -54,10 +54,12 @@ AutoFillHelper::AutoFillHelper(RenderView* render_view)
|
| suggestions_options_index_(-1) {
|
| }
|
|
|
| -void AutoFillHelper::QueryAutoFillSuggestions(const WebNode& node) {
|
| +void AutoFillHelper::QueryAutoFillSuggestions(const WebNode& node,
|
| + bool autofill_disabled) {
|
| static int query_counter = 0;
|
| autofill_query_id_ = query_counter++;
|
| autofill_query_node_ = node;
|
| + autofill_disabled_ = autofill_disabled;
|
|
|
| const WebFormControlElement& element = node.toConst<WebFormControlElement>();
|
| webkit_glue::FormField field;
|
| @@ -108,6 +110,22 @@ void AutoFillHelper::SuggestionsReceived(int query_id,
|
| std::vector<int> ids(unique_ids);
|
| int separator_index = -1;
|
|
|
| + if (autofill_disabled_) {
|
| + // If autofill is disabled and we had suggestions, show a warning instead.
|
| + v.assign(1,
|
| + l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
|
| + l.assign(1, string16());
|
| + i.assign(1, string16());
|
| + ids.assign(1, -1);
|
| + } else if (ids[0] < 0 && ids.size() > 1) {
|
| + // If we received a warning instead of suggestions from autofill but regular
|
| + // suggestions from autocomplete, don't show the autofill warning.
|
| + v.erase(v.begin());
|
| + l.erase(l.begin());
|
| + i.erase(i.begin());
|
| + ids.erase(ids.begin());
|
| + }
|
| +
|
| // The form has been auto-filled, so give the user the chance to clear the
|
| // form. Append the 'Clear form' menu item.
|
| if (form_manager_.FormWithNodeIsAutoFilled(autofill_query_node_)) {
|
| @@ -116,14 +134,14 @@ void AutoFillHelper::SuggestionsReceived(int query_id,
|
| i.push_back(string16());
|
| ids.push_back(0);
|
| suggestions_clear_index_ = v.size() - 1;
|
| - separator_index = values.size();
|
| + separator_index = v.size() - 1;
|
| }
|
|
|
| // Only include "AutoFill Options" special menu item if we have AutoFill
|
| // items, identified by |unique_ids| having at least one valid value.
|
| bool show_options = false;
|
| for (size_t i = 0; i < ids.size(); ++i) {
|
| - if (ids[i] != 0) {
|
| + if (ids[i] > 0) {
|
| show_options = true;
|
| break;
|
| }
|
| @@ -226,33 +244,29 @@ void AutoFillHelper::FrameDetached(WebFrame* frame) {
|
| }
|
|
|
| void AutoFillHelper::TextDidChangeInTextField(const WebInputElement& element) {
|
| - ShowSuggestions(element, false, true);
|
| + ShowSuggestions(element, false, true, false);
|
| }
|
|
|
| bool AutoFillHelper::InputElementClicked(const WebInputElement& element,
|
| bool was_focused,
|
| bool is_focused) {
|
| if (was_focused)
|
| - ShowSuggestions(element, true, false);
|
| + ShowSuggestions(element, true, false, true);
|
| return false;
|
| }
|
|
|
| -
|
| -void AutoFillHelper::ShowSuggestions(
|
| - const WebInputElement& const_element,
|
| - bool autofill_on_empty_values,
|
| - bool requires_caret_at_end) {
|
| - // We need to call non-const methods.
|
| - WebInputElement element(const_element);
|
| - if (!element.isEnabledFormControl() ||
|
| - !element.isText() ||
|
| - element.isPasswordField() ||
|
| - !element.autoComplete() || element.isReadOnly()) {
|
| +void AutoFillHelper::ShowSuggestions(const WebInputElement& element,
|
| + bool autofill_on_empty_values,
|
| + bool requires_caret_at_end,
|
| + bool display_warning_if_disabled) {
|
| + bool autofill_disabled = !element.isEnabledFormControl() ||
|
| + !element.isText() || element.isPasswordField() ||
|
| + !element.autoComplete() || element.isReadOnly();
|
| + if (autofill_disabled && !display_warning_if_disabled)
|
| return;
|
| - }
|
|
|
| - WebString name = element.nameForAutofill();
|
| - if (name.isEmpty()) // If the field has no name, then we won't have values.
|
| + // If the field has no name, then we won't have values.
|
| + if (element.nameForAutofill().isEmpty())
|
| return;
|
|
|
| // Don't attempt to autofill with values that are too large.
|
| @@ -265,11 +279,10 @@ void AutoFillHelper::ShowSuggestions(
|
|
|
| if (requires_caret_at_end &&
|
| (element.selectionStart() != element.selectionEnd() ||
|
| - element.selectionEnd() != static_cast<int>(value.length()))) {
|
| + element.selectionEnd() != static_cast<int>(value.length())))
|
| return;
|
| - }
|
|
|
| - QueryAutoFillSuggestions(element);
|
| + QueryAutoFillSuggestions(element, autofill_disabled);
|
| }
|
|
|
| void AutoFillHelper::QueryAutoFillFormData(const WebNode& node,
|
|
|