diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-16 06:19:56 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-16 06:19:56 +0000 |
commit | 1866d061a07ad56c082f439d5f50301944be4170 (patch) | |
tree | 2983cc377e5fe79f41f93fa7354258bee17ec07d /chrome/renderer/autofill_helper.cc | |
parent | e41c1da3c9b54efaa715b86aeec81a50ee86bfd4 (diff) | |
download | chromium_src-1866d061a07ad56c082f439d5f50301944be4170.zip chromium_src-1866d061a07ad56c082f439d5f50301944be4170.tar.gz chromium_src-1866d061a07ad56c082f439d5f50301944be4170.tar.bz2 |
Display a warning when autofill is disabled for a website.
This depends on a WebKit change being tracked at https://bugs.webkit.org/show_bug.cgi?id=49291
BUG=58509
TEST=unit_tests --gtest_filter=AutoFillManagerTest.*:AutoFillHelperTest.*
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=66214
Review URL: http://codereview.chromium.org/4591001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66237 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/autofill_helper.cc')
-rw-r--r-- | chrome/renderer/autofill_helper.cc | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/chrome/renderer/autofill_helper.cc b/chrome/renderer/autofill_helper.cc index 2832f0d..7725658 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, |