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

Side by Side Diff: components/autofill/content/renderer/form_autofill_util.cc

Issue 1365203002: Make WebNode::to<Type>() (and toConst) casts contain type asserts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add BLINK_IMPLEMENTATION guard. Created 5 years, 2 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/content/renderer/form_autofill_util.h" 5 #include "components/autofill/content/renderer/form_autofill_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 // label.firstChild().nodeValue() of the label element. 920 // label.firstChild().nodeValue() of the label element.
921 void MatchLabelsAndFields( 921 void MatchLabelsAndFields(
922 const WebElementCollection& labels, 922 const WebElementCollection& labels,
923 std::map<WebFormControlElement, FormFieldData*>* element_map) { 923 std::map<WebFormControlElement, FormFieldData*>* element_map) {
924 CR_DEFINE_STATIC_LOCAL(WebString, kFor, ("for")); 924 CR_DEFINE_STATIC_LOCAL(WebString, kFor, ("for"));
925 CR_DEFINE_STATIC_LOCAL(WebString, kHidden, ("hidden")); 925 CR_DEFINE_STATIC_LOCAL(WebString, kHidden, ("hidden"));
926 926
927 for (WebElement item = labels.firstItem(); !item.isNull(); 927 for (WebElement item = labels.firstItem(); !item.isNull();
928 item = labels.nextItem()) { 928 item = labels.nextItem()) {
929 WebLabelElement label = item.to<WebLabelElement>(); 929 WebLabelElement label = item.to<WebLabelElement>();
930 WebFormControlElement field_element = 930 WebElement control = label.correspondingControl();
931 label.correspondingControl().to<WebFormControlElement>();
932 FormFieldData* field_data = nullptr; 931 FormFieldData* field_data = nullptr;
933 932
934 if (field_element.isNull()) { 933 if (control.isNull()) {
935 // Sometimes site authors will incorrectly specify the corresponding 934 // Sometimes site authors will incorrectly specify the corresponding
936 // field element's name rather than its id, so we compensate here. 935 // field element's name rather than its id, so we compensate here.
937 base::string16 element_name = label.getAttribute(kFor); 936 base::string16 element_name = label.getAttribute(kFor);
938 if (element_name.empty()) 937 if (element_name.empty())
939 continue; 938 continue;
940 // Look through the list for elements with this name. There can actually 939 // Look through the list for elements with this name. There can actually
941 // be more than one. In this case, the label may not be particularly 940 // be more than one. In this case, the label may not be particularly
942 // useful, so just discard it. 941 // useful, so just discard it.
943 for (const auto& iter : *element_map) { 942 for (const auto& iter : *element_map) {
944 if (iter.second->name == element_name) { 943 if (iter.second->name == element_name) {
945 if (field_data) { 944 if (field_data) {
946 field_data = nullptr; 945 field_data = nullptr;
947 break; 946 break;
948 } else { 947 } else {
949 field_data = iter.second; 948 field_data = iter.second;
950 } 949 }
951 } 950 }
952 } 951 }
953 } else if (!field_element.isFormControlElement() || 952 } else if (control.isFormControlElement()) {
954 field_element.formControlType() == kHidden) { 953 WebFormControlElement form_control = control.to<WebFormControlElement>();
955 continue; 954 if (form_control.formControlType() == kHidden)
956 } else { 955 continue;
957 // Typical case: look up |field_data| in |element_map|. 956 // Typical case: look up |field_data| in |element_map|.
958 auto iter = element_map->find(field_element); 957 auto iter = element_map->find(form_control);
959 if (iter == element_map->end()) 958 if (iter == element_map->end())
960 continue; 959 continue;
961 field_data = iter->second; 960 field_data = iter->second;
962 } 961 }
963 962
964 if (!field_data) 963 if (!field_data)
965 continue; 964 continue;
966 965
967 base::string16 label_text = FindChildText(label); 966 base::string16 label_text = FindChildText(label);
968 967
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 size_t offset = GetTextSelectionStart(suggestion, user_input, false); 1530 size_t offset = GetTextSelectionStart(suggestion, user_input, false);
1532 // Zero selection start is for password manager, which can show usernames 1531 // Zero selection start is for password manager, which can show usernames
1533 // that do not begin with the user input value. 1532 // that do not begin with the user input value.
1534 selection_start = (offset == base::string16::npos) ? 0 : offset; 1533 selection_start = (offset == base::string16::npos) ? 0 : offset;
1535 } 1534 }
1536 1535
1537 input_element->setSelectionRange(selection_start, suggestion.length()); 1536 input_element->setSelectionRange(selection_start, suggestion.length());
1538 } 1537 }
1539 1538
1540 } // namespace autofill 1539 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/form_autofill_browsertest.cc ('k') | third_party/WebKit/Source/web/AssertMatchingEnums.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698