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

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

Issue 1106313002: Revert of Limit form-less Autofilling to pages that look like checkout pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "components/autofill/core/common/autofill_data_validation.h" 16 #include "components/autofill/core/common/autofill_data_validation.h"
17 #include "components/autofill/core/common/autofill_regexes.h"
18 #include "components/autofill/core/common/autofill_switches.h" 17 #include "components/autofill/core/common/autofill_switches.h"
19 #include "components/autofill/core/common/form_data.h" 18 #include "components/autofill/core/common/form_data.h"
20 #include "components/autofill/core/common/form_field_data.h" 19 #include "components/autofill/core/common/form_field_data.h"
21 #include "third_party/WebKit/public/platform/WebString.h" 20 #include "third_party/WebKit/public/platform/WebString.h"
22 #include "third_party/WebKit/public/platform/WebVector.h" 21 #include "third_party/WebKit/public/platform/WebVector.h"
23 #include "third_party/WebKit/public/web/WebDocument.h" 22 #include "third_party/WebKit/public/web/WebDocument.h"
24 #include "third_party/WebKit/public/web/WebElement.h" 23 #include "third_party/WebKit/public/web/WebElement.h"
25 #include "third_party/WebKit/public/web/WebElementCollection.h" 24 #include "third_party/WebKit/public/web/WebElementCollection.h"
26 #include "third_party/WebKit/public/web/WebFormControlElement.h" 25 #include "third_party/WebKit/public/web/WebFormControlElement.h"
27 #include "third_party/WebKit/public/web/WebFormElement.h" 26 #include "third_party/WebKit/public/web/WebFormElement.h"
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 FormFieldData* field) { 1154 FormFieldData* field) {
1156 DCHECK(field); 1155 DCHECK(field);
1157 DCHECK(!element.isNull()); 1156 DCHECK(!element.isNull());
1158 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete")); 1157 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete"));
1159 CR_DEFINE_STATIC_LOCAL(WebString, kRole, ("role")); 1158 CR_DEFINE_STATIC_LOCAL(WebString, kRole, ("role"));
1160 1159
1161 // The label is not officially part of a WebFormControlElement; however, the 1160 // The label is not officially part of a WebFormControlElement; however, the
1162 // labels for all form control elements are scraped from the DOM and set in 1161 // labels for all form control elements are scraped from the DOM and set in
1163 // WebFormElementToFormData. 1162 // WebFormElementToFormData.
1164 field->name = element.nameForAutofill(); 1163 field->name = element.nameForAutofill();
1165 field->form_control_type = element.formControlType().utf8(); 1164 field->form_control_type = base::UTF16ToUTF8(element.formControlType());
1166 field->autocomplete_attribute = element.getAttribute(kAutocomplete).utf8(); 1165 field->autocomplete_attribute =
1166 base::UTF16ToUTF8(element.getAttribute(kAutocomplete));
1167 if (field->autocomplete_attribute.size() > kMaxDataLength) { 1167 if (field->autocomplete_attribute.size() > kMaxDataLength) {
1168 // Discard overly long attribute values to avoid DOS-ing the browser 1168 // Discard overly long attribute values to avoid DOS-ing the browser
1169 // process. However, send over a default string to indicate that the 1169 // process. However, send over a default string to indicate that the
1170 // attribute was present. 1170 // attribute was present.
1171 field->autocomplete_attribute = "x-max-data-length-exceeded"; 1171 field->autocomplete_attribute = "x-max-data-length-exceeded";
1172 } 1172 }
1173 if (LowerCaseEqualsASCII(element.getAttribute(kRole), "presentation")) 1173 if (LowerCaseEqualsASCII(element.getAttribute(kRole), "presentation"))
1174 field->role = FormFieldData::ROLE_ATTRIBUTE_PRESENTATION; 1174 field->role = FormFieldData::ROLE_ATTRIBUTE_PRESENTATION;
1175 1175
1176 if (!IsAutofillableElement(element)) 1176 if (!IsAutofillableElement(element))
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 fieldsets->push_back(element); 1279 fieldsets->push_back(element);
1280 } 1280 }
1281 } 1281 }
1282 return ExtractAutofillableElementsFromSet(unowned_fieldset_children); 1282 return ExtractAutofillableElementsFromSet(unowned_fieldset_children);
1283 } 1283 }
1284 1284
1285 bool UnownedFormElementsAndFieldSetsToFormData( 1285 bool UnownedFormElementsAndFieldSetsToFormData(
1286 const std::vector<blink::WebElement>& fieldsets, 1286 const std::vector<blink::WebElement>& fieldsets,
1287 const std::vector<blink::WebFormControlElement>& control_elements, 1287 const std::vector<blink::WebFormControlElement>& control_elements,
1288 const blink::WebFormControlElement* element, 1288 const blink::WebFormControlElement* element,
1289 const blink::WebDocument& document, 1289 const GURL& origin,
1290 ExtractMask extract_mask, 1290 ExtractMask extract_mask,
1291 FormData* form, 1291 FormData* form,
1292 FormFieldData* field) { 1292 FormFieldData* field) {
1293 // Only attempt formless Autofill on checkout flows. This avoids the many 1293 form->origin = origin;
1294 // false positives found on the non-checkout web. See http://crbug.com/462375
1295 // For now this early abort only applies to English-language pages, because
1296 // the regex is not translated. Note that an empty "lang" attribute counts as
1297 // English. A potential problem is that this only checks document.title(), but
1298 // should actually check the main frame's title. Thus it may make bad
1299 // decisions for iframes.
1300 WebElement html_element = document.documentElement();
1301 std::string lang;
1302 if (!html_element.isNull())
1303 lang = html_element.getAttribute("lang").utf8();
1304 if ((lang.empty() || StartsWithASCII(lang, "en", false)) &&
1305 !MatchesPattern(document.title(),
1306 base::UTF8ToUTF16("payment|checkout|address|delivery|shipping"))) {
1307 return false;
1308 }
1309
1310 form->origin = document.url();
1311 form->user_submitted = false; 1294 form->user_submitted = false;
1312 form->is_form_tag = false; 1295 form->is_form_tag = false;
1313 1296
1314 return FormOrFieldsetsToFormData(nullptr, element, fieldsets, 1297 return FormOrFieldsetsToFormData(nullptr, element, fieldsets,
1315 control_elements, extract_mask, form, field); 1298 control_elements, extract_mask, form, field);
1316 } 1299 }
1317 1300
1318 bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element, 1301 bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element,
1319 FormData* form, 1302 FormData* form,
1320 FormFieldData* field) { 1303 FormFieldData* field) {
1321 if (!IsAutofillableElement(element)) 1304 if (!IsAutofillableElement(element))
1322 return false; 1305 return false;
1323 1306
1324 ExtractMask extract_mask = 1307 ExtractMask extract_mask =
1325 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); 1308 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS);
1326 const WebFormElement form_element = element.form(); 1309 const WebFormElement form_element = element.form();
1327 if (form_element.isNull()) { 1310 if (form_element.isNull()) {
1328 // No associated form, try the synthetic form for unowned form elements. 1311 // No associated form, try the synthetic form for unowned form elements.
1329 WebDocument document = element.document(); 1312 WebDocument document = element.document();
1330 std::vector<WebElement> fieldsets; 1313 std::vector<WebElement> fieldsets;
1331 std::vector<WebFormControlElement> control_elements = 1314 std::vector<WebFormControlElement> control_elements =
1332 GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets); 1315 GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets);
1333 return UnownedFormElementsAndFieldSetsToFormData( 1316 return UnownedFormElementsAndFieldSetsToFormData(
1334 fieldsets, control_elements, &element, document, extract_mask, 1317 fieldsets, control_elements, &element, document.url(), extract_mask,
1335 form, field); 1318 form, field);
1336 } 1319 }
1337 1320
1338 return WebFormElementToFormData(form_element, 1321 return WebFormElementToFormData(form_element,
1339 element, 1322 element,
1340 extract_mask, 1323 extract_mask,
1341 form, 1324 form,
1342 field); 1325 field);
1343 } 1326 }
1344 1327
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 1498
1516 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) { 1499 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) {
1517 gfx::Rect bounding_box(element->boundsInViewportSpace()); 1500 gfx::Rect bounding_box(element->boundsInViewportSpace());
1518 return gfx::RectF(bounding_box.x() * scale, 1501 return gfx::RectF(bounding_box.x() * scale,
1519 bounding_box.y() * scale, 1502 bounding_box.y() * scale,
1520 bounding_box.width() * scale, 1503 bounding_box.width() * scale,
1521 bounding_box.height() * scale); 1504 bounding_box.height() * scale);
1522 } 1505 }
1523 1506
1524 } // namespace autofill 1507 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/form_autofill_util.h ('k') | components/autofill/content/renderer/form_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698