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

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

Issue 2009823003: Do not trigger layout in PasswordAutofillAgent::DidFinishDocumentLoad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // Filters non-focusable elements with the exception of select elements, which 64 // Filters non-focusable elements with the exception of select elements, which
65 // are sometimes made non-focusable because they are present for accessibility 65 // are sometimes made non-focusable because they are present for accessibility
66 // while a prettier, non-<select> dropdown is shown. We still want to autofill 66 // while a prettier, non-<select> dropdown is shown. We still want to autofill
67 // the non-focusable <select>. 67 // the non-focusable <select>.
68 FILTER_NON_FOCUSABLE_ELEMENTS = 1 << 2, 68 FILTER_NON_FOCUSABLE_ELEMENTS = 1 << 2,
69 FILTER_ALL_NON_EDITABLE_ELEMENTS = FILTER_DISABLED_ELEMENTS | 69 FILTER_ALL_NON_EDITABLE_ELEMENTS = FILTER_DISABLED_ELEMENTS |
70 FILTER_READONLY_ELEMENTS | 70 FILTER_READONLY_ELEMENTS |
71 FILTER_NON_FOCUSABLE_ELEMENTS, 71 FILTER_NON_FOCUSABLE_ELEMENTS,
72 }; 72 };
73 73
74 // If true, operations causing layout computation should be avoided. Set by
75 // ScopedLayoutPreventer.
76 bool g_prevent_layout = false;
77
74 void TruncateString(base::string16* str, size_t max_length) { 78 void TruncateString(base::string16* str, size_t max_length) {
75 if (str->length() > max_length) 79 if (str->length() > max_length)
76 str->resize(max_length); 80 str->resize(max_length);
77 } 81 }
78 82
79 bool IsOptionElement(const WebElement& element) { 83 bool IsOptionElement(const WebElement& element) {
80 CR_DEFINE_STATIC_LOCAL(WebString, kOption, ("option")); 84 CR_DEFINE_STATIC_LOCAL(WebString, kOption, ("option"));
81 return element.hasHTMLTagName(kOption); 85 return element.hasHTMLTagName(kOption);
82 } 86 }
83 87
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 // input field's "value" or "placeholder" attribute, is skipped. 819 // input field's "value" or "placeholder" attribute, is skipped.
816 (IsAutofillableInputElement(input_element) || 820 (IsAutofillableInputElement(input_element) ||
817 IsTextAreaElement(*element)) && 821 IsTextAreaElement(*element)) &&
818 !element->value().isEmpty() && 822 !element->value().isEmpty() &&
819 (!element->hasAttribute(kValue) || 823 (!element->hasAttribute(kValue) ||
820 element->getAttribute(kValue) != element->value()) && 824 element->getAttribute(kValue) != element->value()) &&
821 (!element->hasAttribute(kPlaceholder) || 825 (!element->hasAttribute(kPlaceholder) ||
822 element->getAttribute(kPlaceholder) != element->value())) 826 element->getAttribute(kPlaceholder) != element->value()))
823 continue; 827 continue;
824 828
829 DCHECK(!g_prevent_layout || !(filters & FILTER_NON_FOCUSABLE_ELEMENTS))
830 << "The callsite of this code wanted to both prevent layout and check "
831 "isFocusable. Pick one.";
825 if (((filters & FILTER_DISABLED_ELEMENTS) && !element->isEnabled()) || 832 if (((filters & FILTER_DISABLED_ELEMENTS) && !element->isEnabled()) ||
826 ((filters & FILTER_READONLY_ELEMENTS) && element->isReadOnly()) || 833 ((filters & FILTER_READONLY_ELEMENTS) && element->isReadOnly()) ||
827 // See description for FILTER_NON_FOCUSABLE_ELEMENTS. 834 // See description for FILTER_NON_FOCUSABLE_ELEMENTS.
828 ((filters & FILTER_NON_FOCUSABLE_ELEMENTS) && !element->isFocusable() && 835 ((filters & FILTER_NON_FOCUSABLE_ELEMENTS) && !element->isFocusable() &&
829 !IsSelectElement(*element))) 836 !IsSelectElement(*element)))
830 continue; 837 continue;
831 838
832 callback(data.fields[i], is_initiating_element, element); 839 callback(data.fields[i], is_initiating_element, element);
833 } 840 }
834 } 841 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 GURL::Replacements rep; 1172 GURL::Replacements rep;
1166 rep.ClearUsername(); 1173 rep.ClearUsername();
1167 rep.ClearPassword(); 1174 rep.ClearPassword();
1168 rep.ClearQuery(); 1175 rep.ClearQuery();
1169 rep.ClearRef(); 1176 rep.ClearRef();
1170 return gurl.ReplaceComponents(rep); 1177 return gurl.ReplaceComponents(rep);
1171 } 1178 }
1172 1179
1173 } // namespace 1180 } // namespace
1174 1181
1182 ScopedLayoutPreventer::ScopedLayoutPreventer() {
1183 DCHECK(!g_prevent_layout) << "Is any other instance of ScopedLayoutPreventer "
1184 "alive in the same process?";
1185 g_prevent_layout = true;
1186 }
1187
1188 ScopedLayoutPreventer::~ScopedLayoutPreventer() {
1189 DCHECK(g_prevent_layout) << "Is any other instance of ScopedLayoutPreventer "
1190 "alive in the same process?";
1191 g_prevent_layout = false;
1192 }
1193
1175 bool ExtractFormData(const WebFormElement& form_element, FormData* data) { 1194 bool ExtractFormData(const WebFormElement& form_element, FormData* data) {
1176 return WebFormElementToFormData( 1195 return WebFormElementToFormData(
1177 form_element, WebFormControlElement(), 1196 form_element, WebFormControlElement(),
1178 static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE | 1197 static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE |
1179 form_util::EXTRACT_OPTION_TEXT | 1198 form_util::EXTRACT_OPTION_TEXT |
1180 form_util::EXTRACT_OPTIONS), 1199 form_util::EXTRACT_OPTIONS),
1181 data, NULL); 1200 data, NULL);
1182 } 1201 }
1183 1202
1184 bool IsFormVisible(blink::WebFrame* frame, 1203 bool IsFormVisible(blink::WebFrame* frame,
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 field->placeholder = element.getAttribute(kPlaceholder); 1386 field->placeholder = element.getAttribute(kPlaceholder);
1368 1387
1369 if (!IsAutofillableElement(element)) 1388 if (!IsAutofillableElement(element))
1370 return; 1389 return;
1371 1390
1372 const WebInputElement* input_element = toWebInputElement(&element); 1391 const WebInputElement* input_element = toWebInputElement(&element);
1373 if (IsAutofillableInputElement(input_element) || 1392 if (IsAutofillableInputElement(input_element) ||
1374 IsTextAreaElement(element) || 1393 IsTextAreaElement(element) ||
1375 IsSelectElement(element)) { 1394 IsSelectElement(element)) {
1376 field->is_autofilled = element.isAutofilled(); 1395 field->is_autofilled = element.isAutofilled();
1377 field->is_focusable = element.isFocusable(); 1396 if (!g_prevent_layout)
1397 field->is_focusable = element.isFocusable();
1378 field->should_autocomplete = element.autoComplete(); 1398 field->should_autocomplete = element.autoComplete();
1379 field->text_direction = element.directionForFormData() == 1399 field->text_direction = element.directionForFormData() ==
1380 "rtl" ? base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT; 1400 "rtl" ? base::i18n::RIGHT_TO_LEFT : base::i18n::LEFT_TO_RIGHT;
1381 } 1401 }
1382 1402
1383 if (IsAutofillableInputElement(input_element)) { 1403 if (IsAutofillableInputElement(input_element)) {
1384 if (IsTextInput(input_element)) 1404 if (IsTextInput(input_element))
1385 field->max_length = input_element->maxLength(); 1405 field->max_length = input_element->maxLength();
1386 1406
1387 field->is_checkable = IsCheckableElement(input_element); 1407 field->is_checkable = IsCheckableElement(input_element);
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 // Zero selection start is for password manager, which can show usernames 1786 // Zero selection start is for password manager, which can show usernames
1767 // that do not begin with the user input value. 1787 // that do not begin with the user input value.
1768 selection_start = (offset == base::string16::npos) ? 0 : offset; 1788 selection_start = (offset == base::string16::npos) ? 0 : offset;
1769 } 1789 }
1770 1790
1771 input_element->setSelectionRange(selection_start, suggestion.length()); 1791 input_element->setSelectionRange(selection_start, suggestion.length());
1772 } 1792 }
1773 1793
1774 } // namespace form_util 1794 } // namespace form_util
1775 } // namespace autofill 1795 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698