Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: chrome/renderer/autofill/autofill_agent.cc

Issue 11364066: [Autofill] Show a warning if the form disables Autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar comment Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/renderer/autofill/autofill_agent.h" 5 #include "chrome/renderer/autofill/autofill_agent.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/string_split.h" 10 #include "base/string_split.h"
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // Any popup currently showing is obsolete. 593 // Any popup currently showing is obsolete.
594 WebKit::WebView* web_view = render_view()->GetWebView(); 594 WebKit::WebView* web_view = render_view()->GetWebView();
595 if (web_view) 595 if (web_view)
596 web_view->hidePopups(); 596 web_view->hidePopups();
597 597
598 return; 598 return;
599 } 599 }
600 600
601 element_ = element; 601 element_ = element;
602 602
603 // If autocomplete is disabled at the form level, then we might want to show 603 // If autocomplete is disabled at the form level, then we might want to show a
604 // a warning in place of suggestions. However, if autocomplete is disabled 604 // warning in place of suggestions. However, if autocomplete is disabled
605 // specifically for this field, we never want to show a warning. Otherwise, 605 // specifically for this field, we never want to show a warning. Otherwise,
606 // we might interfere with custom popups (e.g. search suggestions) used by 606 // we might interfere with custom popups (e.g. search suggestions) used by the
607 // the website. Also, if the field has no name, then we won't have values. 607 // website. Note that we cannot use the WebKit method element.autoComplete()
608 const WebFormElement form = element.form(); 608 // as it does not allow us to distinguish the case where autocomplete is
609 if ((!element.autoComplete() && (form.isNull() || form.autoComplete())) || 609 // disabled for *both* the element and for the form.
610 // Also, if the field has no name, then we won't have values.
611 if (element.getAttribute("autocomplete") == ASCIIToUTF16("off") ||
Dan Beam 2012/11/03 03:56:21 does this need to be lowercased?
Ilya Sherman 2012/11/06 02:14:43 Good call -- done.
610 element.nameForAutofill().isEmpty()) { 612 element.nameForAutofill().isEmpty()) {
611 CombineDataListEntriesAndShow(element, std::vector<string16>(), 613 CombineDataListEntriesAndShow(element, std::vector<string16>(),
612 std::vector<string16>(), 614 std::vector<string16>(),
613 std::vector<string16>(), 615 std::vector<string16>(),
614 std::vector<int>(), false); 616 std::vector<int>(), false);
615 return; 617 return;
616 } 618 }
617 619
618 QueryAutofillSuggestions(element, display_warning_if_disabled); 620 QueryAutofillSuggestions(element, display_warning_if_disabled);
619 } 621 }
620 622
621 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, 623 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element,
622 bool display_warning_if_disabled) { 624 bool display_warning_if_disabled) {
623 static int query_counter = 0; 625 static int query_counter = 0;
624 autofill_query_id_ = query_counter++; 626 autofill_query_id_ = query_counter++;
625 display_warning_if_disabled_ = display_warning_if_disabled; 627 display_warning_if_disabled_ = display_warning_if_disabled;
626 628
629 // If autocomplete is disabled at the form level, we want to see if there
630 // would have been any suggestions were it enabled, so that we can show a
631 // warning. Otherwise, we want to ignore fields that disable autocomplete, so
632 // that the suggestions list does not include suggestions for these form
633 // fields -- see comment 1 on http://crbug.com/69914
634 RequirementsMask requirements = REQUIRE_AUTOCOMPLETE;
635 const WebFormElement form_element = element.form();
636 if (!form_element.isNull() && !form_element.autoComplete())
637 requirements = REQUIRE_NONE;
638
627 FormData form; 639 FormData form;
628 FormFieldData field; 640 FormFieldData field;
629 if (!FindFormAndFieldForInputElement(element, &form, &field, 641 if (!FindFormAndFieldForInputElement(element, &form, &field, requirements)) {
630 REQUIRE_AUTOCOMPLETE)) {
631 // If we didn't find the cached form, at least let autocomplete have a shot 642 // If we didn't find the cached form, at least let autocomplete have a shot
632 // at providing suggestions. 643 // at providing suggestions.
633 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); 644 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field);
634 } 645 }
635 646
636 gfx::Rect bounding_box(element_.boundsInViewportSpace()); 647 gfx::Rect bounding_box(element_.boundsInViewportSpace());
637 648
638 // Find the datalist values and send them to the browser process. 649 // Find the datalist values and send them to the browser process.
639 std::vector<string16> data_list_values; 650 std::vector<string16> data_list_values;
640 std::vector<string16> data_list_labels; 651 std::vector<string16> data_list_labels;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 void AutofillAgent::SetNodeText(const string16& value, 699 void AutofillAgent::SetNodeText(const string16& value,
689 WebKit::WebInputElement* node) { 700 WebKit::WebInputElement* node) {
690 did_set_node_text_ = true; 701 did_set_node_text_ = true;
691 string16 substring = value; 702 string16 substring = value;
692 substring = substring.substr(0, node->maxLength()); 703 substring = substring.substr(0, node->maxLength());
693 704
694 node->setEditingValue(substring); 705 node->setEditingValue(substring);
695 } 706 }
696 707
697 } // namespace autofill 708 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698