| OLD | NEW |
| 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 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 // Only text input, textarea and select elements can be previewed. | 1088 // Only text input, textarea and select elements can be previewed. |
| 1089 WebInputElement* input_element = toWebInputElement(&control_element); | 1089 WebInputElement* input_element = toWebInputElement(&control_element); |
| 1090 if (!IsTextInput(input_element) && | 1090 if (!IsTextInput(input_element) && |
| 1091 !IsMonthInput(input_element) && | 1091 !IsMonthInput(input_element) && |
| 1092 !IsTextAreaElement(control_element) && | 1092 !IsTextAreaElement(control_element) && |
| 1093 !IsSelectElement(control_element)) | 1093 !IsSelectElement(control_element)) |
| 1094 continue; | 1094 continue; |
| 1095 | 1095 |
| 1096 // If the element is not auto-filled, we did not preview it, | 1096 // If the element is not auto-filled, we did not preview it, |
| 1097 // so there is nothing to reset. | 1097 // so there is nothing to reset. |
| 1098 if(!control_element.isAutofilled()) | 1098 if (!control_element.isAutofilled()) |
| 1099 continue; | 1099 continue; |
| 1100 | 1100 |
| 1101 if ((IsTextInput(input_element) || | 1101 if ((IsTextInput(input_element) || |
| 1102 IsMonthInput(input_element) || | 1102 IsMonthInput(input_element) || |
| 1103 IsTextAreaElement(control_element) || | 1103 IsTextAreaElement(control_element) || |
| 1104 IsSelectElement(control_element)) && | 1104 IsSelectElement(control_element)) && |
| 1105 control_element.suggestedValue().isEmpty()) | 1105 control_element.suggestedValue().isEmpty()) |
| 1106 continue; | 1106 continue; |
| 1107 | 1107 |
| 1108 // Clear the suggested value. For the initiating node, also restore the | 1108 // Clear the suggested value. For the initiating node, also restore the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1123 } | 1123 } |
| 1124 } else if (IsSelectElement(control_element)) { | 1124 } else if (IsSelectElement(control_element)) { |
| 1125 control_element.setSuggestedValue(WebString()); | 1125 control_element.setSuggestedValue(WebString()); |
| 1126 control_element.setAutofilled(false); | 1126 control_element.setAutofilled(false); |
| 1127 } | 1127 } |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 return true; | 1130 return true; |
| 1131 } | 1131 } |
| 1132 | 1132 |
| 1133 bool FormWithElementIsAutofilled(const WebInputElement& element) { | |
| 1134 WebFormElement form_element = element.form(); | |
| 1135 if (form_element.isNull()) | |
| 1136 return false; | |
| 1137 | |
| 1138 std::vector<WebFormControlElement> control_elements; | |
| 1139 ExtractAutofillableElements( | |
| 1140 form_element, ExtractionRequirements(), &control_elements); | |
| 1141 for (size_t i = 0; i < control_elements.size(); ++i) { | |
| 1142 WebInputElement* input_element = toWebInputElement(&control_elements[i]); | |
| 1143 if (!IsAutofillableInputElement(input_element)) | |
| 1144 continue; | |
| 1145 | |
| 1146 if (input_element->isAutofilled()) | |
| 1147 return true; | |
| 1148 } | |
| 1149 | |
| 1150 return false; | |
| 1151 } | |
| 1152 | |
| 1153 bool IsWebpageEmpty(const blink::WebFrame* frame) { | 1133 bool IsWebpageEmpty(const blink::WebFrame* frame) { |
| 1154 blink::WebDocument document = frame->document(); | 1134 blink::WebDocument document = frame->document(); |
| 1155 | 1135 |
| 1156 return IsWebElementEmpty(document.head()) && | 1136 return IsWebElementEmpty(document.head()) && |
| 1157 IsWebElementEmpty(document.body()); | 1137 IsWebElementEmpty(document.body()); |
| 1158 } | 1138 } |
| 1159 | 1139 |
| 1160 bool IsWebElementEmpty(const blink::WebElement& element) { | 1140 bool IsWebElementEmpty(const blink::WebElement& element) { |
| 1161 // This array contains all tags which can be present in an empty page. | 1141 // This array contains all tags which can be present in an empty page. |
| 1162 const char* const kAllowedValue[] = { | 1142 const char* const kAllowedValue[] = { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 | 1183 |
| 1204 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { | 1184 gfx::RectF GetScaledBoundingBox(float scale, WebFormControlElement* element) { |
| 1205 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1185 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
| 1206 return gfx::RectF(bounding_box.x() * scale, | 1186 return gfx::RectF(bounding_box.x() * scale, |
| 1207 bounding_box.y() * scale, | 1187 bounding_box.y() * scale, |
| 1208 bounding_box.width() * scale, | 1188 bounding_box.width() * scale, |
| 1209 bounding_box.height() * scale); | 1189 bounding_box.height() * scale); |
| 1210 } | 1190 } |
| 1211 | 1191 |
| 1212 } // namespace autofill | 1192 } // namespace autofill |
| OLD | NEW |