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

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

Issue 7044032: Heuristics for grabber-google.com.out (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/renderer/autofill/form_manager_browsertest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/form_manager.h" 5 #include "chrome/renderer/autofill/form_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 71
72 bool IsOptionElement(const WebElement& element) { 72 bool IsOptionElement(const WebElement& element) {
73 return element.hasTagName("option"); 73 return element.hasTagName("option");
74 } 74 }
75 75
76 bool IsScriptElement(const WebElement& element) { 76 bool IsScriptElement(const WebElement& element) {
77 return element.hasTagName("script"); 77 return element.hasTagName("script");
78 } 78 }
79 79
80 bool IsNoScriptElement(const WebElement& element) {
81 return element.hasTagName("noscript");
82 }
83
80 bool IsAutofillableElement(const WebFormControlElement& element) { 84 bool IsAutofillableElement(const WebFormControlElement& element) {
81 const WebInputElement* input_element = toWebInputElement(&element); 85 const WebInputElement* input_element = toWebInputElement(&element);
82 return IsTextInput(input_element) || IsSelectElement(element); 86 return IsTextInput(input_element) || IsSelectElement(element);
83 } 87 }
84 88
85 // This is a helper function for the FindChildText() function (see below). 89 // This is a helper function for the FindChildText() function (see below).
86 // Search depth is limited with the |depth| parameter. 90 // Search depth is limited with the |depth| parameter.
87 string16 FindChildTextInner(const WebNode& node, int depth) { 91 string16 FindChildTextInner(const WebNode& node, int depth) {
88 string16 element_text; 92 string16 element_text;
89 if (depth <= 0 || node.isNull()) 93 if (depth <= 0 || node.isNull())
90 return element_text; 94 return element_text;
91 95
92 if (node.nodeType() != WebNode::ElementNode && 96 if (node.nodeType() != WebNode::ElementNode &&
93 node.nodeType() != WebNode::TextNode) 97 node.nodeType() != WebNode::TextNode)
94 return element_text; 98 return element_text;
95 99
96 // If |node| is WebElement and that has <option> or <script>, ignore the text. 100 // If |node| is WebElement and that has <option> or <script>, ignore the text.
97 // Because this function is only used to infer label and those tags should be 101 // Because this function is only used to infer label and those tags should be
98 // excluded. 102 // excluded.
99 if (node.isElementNode()) { 103 if (node.isElementNode()) {
100 const WebElement element = node.toConst<WebElement>(); 104 const WebElement element = node.toConst<WebElement>();
101 if (IsOptionElement(element) || IsScriptElement(element)) 105 if (IsOptionElement(element) ||
106 IsScriptElement(element) ||
107 IsNoScriptElement(element)) {
102 return element_text; 108 return element_text;
109 }
103 } 110 }
104 111
105 string16 node_text = node.nodeValue(); 112 string16 node_text = node.nodeValue();
106 TrimWhitespace(node_text, TRIM_ALL, &node_text); 113 TrimWhitespace(node_text, TRIM_ALL, &node_text);
107 if (!node_text.empty()) 114 if (!node_text.empty())
108 element_text = node_text; 115 element_text = node_text;
109 116
110 string16 child_text = FindChildTextInner(node.firstChild(), depth-1); 117 string16 child_text = FindChildTextInner(node.firstChild(), depth-1);
111 if (!child_text.empty()) 118 if (!child_text.empty())
112 element_text = element_text + child_text; 119 element_text = element_text + child_text;
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 data->value.substr(0, input_element->maxLength())); 963 data->value.substr(0, input_element->maxLength()));
957 input_element->setAutofilled(true); 964 input_element->setAutofilled(true);
958 if (is_initiating_node) { 965 if (is_initiating_node) {
959 // Select the part of the text that the user didn't type. 966 // Select the part of the text that the user didn't type.
960 input_element->setSelectionRange(input_element->value().length(), 967 input_element->setSelectionRange(input_element->value().length(),
961 input_element->suggestedValue().length()); 968 input_element->suggestedValue().length());
962 } 969 }
963 } 970 }
964 971
965 } // namespace autofill 972 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/autofill/form_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698