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

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

Issue 1411363003: [Autofill] Always show available data when encountering autocomplete attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 1 month 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_cache.h" 5 #include "components/autofill/content/renderer/form_cache.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/content/renderer/form_autofill_util.h" 10 #include "components/autofill/content/renderer/form_autofill_util.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 std::string msg = std::string("autocomplete='") + deprecated[i] + 53 std::string msg = std::string("autocomplete='") + deprecated[i] +
54 "' is deprecated and will soon be ignored. See http://goo.gl/YjeSsW"; 54 "' is deprecated and will soon be ignored. See http://goo.gl/YjeSsW";
55 WebConsoleMessage console_message = WebConsoleMessage( 55 WebConsoleMessage console_message = WebConsoleMessage(
56 WebConsoleMessage::LevelWarning, 56 WebConsoleMessage::LevelWarning,
57 WebString(base::ASCIIToUTF16(msg))); 57 WebString(base::ASCIIToUTF16(msg)));
58 element.document().frame()->addMessageToConsole(console_message); 58 element.document().frame()->addMessageToConsole(console_message);
59 } 59 }
60 } 60 }
61 61
62 // To avoid overly expensive computation, we impose a minimum number of 62 // To avoid overly expensive computation, we impose a minimum number of
63 // allowable fields. The corresponding maximum number of allowable fields 63 // allowable fields. The corresponding maximum number of allowable fields
Evan Stade 2015/11/04 17:15:18 that minimum number is now one, so this comment ne
sebsg 2015/11/10 19:04:50 Done.
64 // is imposed by WebFormElementToFormData(). 64 // is imposed by WebFormElementToFormData().
Evan Stade 2015/11/04 17:15:18 I think this comment needs further updating becaus
sebsg 2015/11/10 19:04:50 As I read the code more I realized that num_editab
65 bool ShouldIgnoreForm(size_t num_editable_elements, 65 bool ShouldIgnoreForm(size_t num_editable_elements,
66 size_t num_control_elements) { 66 size_t num_control_elements) {
67 return (num_editable_elements < kRequiredAutofillFields && 67 return (!num_editable_elements && num_control_elements);
Evan Stade 2015/11/04 17:15:18 nit: remove excess parens
sebsg 2015/11/10 19:04:50 Done.
68 num_control_elements > 0);
Evan Stade 2015/11/04 17:15:18 prefer this way of checking against 0 rather than
sebsg 2015/11/10 19:04:50 Done.
69 } 68 }
70 69
71 } // namespace 70 } // namespace
72 71
73 FormCache::FormCache(const WebFrame& frame) : frame_(frame) { 72 FormCache::FormCache(const WebFrame& frame) : frame_(frame) {
74 } 73 }
75 74
76 FormCache::~FormCache() { 75 FormCache::~FormCache() {
77 } 76 }
78 77
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 FormData form; 109 FormData form;
111 if (!WebFormElementToFormData(form_element, WebFormControlElement(), 110 if (!WebFormElementToFormData(form_element, WebFormControlElement(),
112 extract_mask, &form, nullptr)) { 111 extract_mask, &form, nullptr)) {
113 continue; 112 continue;
114 } 113 }
115 114
116 num_fields_seen += form.fields.size(); 115 num_fields_seen += form.fields.size();
117 if (num_fields_seen > form_util::kMaxParseableFields) 116 if (num_fields_seen > form_util::kMaxParseableFields)
118 return forms; 117 return forms;
119 118
120 if (form.fields.size() >= kRequiredAutofillFields && 119 if (!ContainsKey(parsed_forms_, form) && IsFormInteresting(form)) {
121 !ContainsKey(parsed_forms_, form)) {
122 for (auto it = parsed_forms_.begin(); it != parsed_forms_.end(); ++it) { 120 for (auto it = parsed_forms_.begin(); it != parsed_forms_.end(); ++it) {
123 if (it->SameFormAs(form)) { 121 if (it->SameFormAs(form)) {
124 parsed_forms_.erase(it); 122 parsed_forms_.erase(it);
125 break; 123 break;
126 } 124 }
127 } 125 }
128 126
129 SaveInitialValues(control_elements); 127 SaveInitialValues(control_elements);
130 forms.push_back(form); 128 forms.push_back(form);
131 parsed_forms_.insert(form); 129 parsed_forms_.insert(form);
(...skipping 16 matching lines...) Expand all
148 if (!UnownedCheckoutFormElementsAndFieldSetsToFormData( 146 if (!UnownedCheckoutFormElementsAndFieldSetsToFormData(
149 fieldsets, control_elements, nullptr, document, extract_mask, 147 fieldsets, control_elements, nullptr, document, extract_mask,
150 &synthetic_form, nullptr)) { 148 &synthetic_form, nullptr)) {
151 return forms; 149 return forms;
152 } 150 }
153 151
154 num_fields_seen += synthetic_form.fields.size(); 152 num_fields_seen += synthetic_form.fields.size();
155 if (num_fields_seen > form_util::kMaxParseableFields) 153 if (num_fields_seen > form_util::kMaxParseableFields)
156 return forms; 154 return forms;
157 155
158 if (synthetic_form.fields.size() >= kRequiredAutofillFields && 156 if (!parsed_forms_.count(synthetic_form) &&
159 !parsed_forms_.count(synthetic_form)) { 157 IsFormInteresting(synthetic_form)) {
160 SaveInitialValues(control_elements); 158 SaveInitialValues(control_elements);
161 forms.push_back(synthetic_form); 159 forms.push_back(synthetic_form);
162 parsed_forms_.insert(synthetic_form); 160 parsed_forms_.insert(synthetic_form);
163 parsed_forms_.erase(synthetic_form_); 161 parsed_forms_.erase(synthetic_form_);
164 synthetic_form_ = synthetic_form; 162 synthetic_form_ = synthetic_form;
165 } 163 }
166 return forms; 164 return forms;
167 } 165 }
168 166
169 void FormCache::Reset() { 167 void FormCache::Reset() {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 base::UTF8ToUTF16(form.fields[i].server_type), 296 base::UTF8ToUTF16(form.fields[i].server_type),
299 base::UTF8ToUTF16(form.fields[i].heuristic_type), 297 base::UTF8ToUTF16(form.fields[i].heuristic_type),
300 base::UTF8ToUTF16(form.fields[i].signature), 298 base::UTF8ToUTF16(form.fields[i].signature),
301 base::UTF8ToUTF16(form.signature)); 299 base::UTF8ToUTF16(form.signature));
302 element.setAttribute("title", WebString(title)); 300 element.setAttribute("title", WebString(title));
303 } 301 }
304 302
305 return true; 303 return true;
306 } 304 }
307 305
306 // static
307 bool FormCache::IsFormInteresting(FormData form) {
308 if (form.fields.empty())
309 return false;
310
311 // If the form has at least one field with an autocomplete attribute,
312 // autocomplete suggestions will be shown.
Evan Stade 2015/11/04 17:15:18 this comment is misleading, we don't know if sugge
sebsg 2015/11/10 19:04:50 Done.
313 for (auto field : form.fields) {
314 if (!field.autocomplete_attribute.empty())
315 return true;
316 }
317
318 // If there are no autocomplete attributes, the form needs to have at least
319 // the required number of fields to be a candidate for autofill.
320 return form.fields.size() >= kRequiredAutofillFields;
321 }
322
308 size_t FormCache::ScanFormControlElements( 323 size_t FormCache::ScanFormControlElements(
309 const std::vector<WebFormControlElement>& control_elements, 324 const std::vector<WebFormControlElement>& control_elements,
310 bool log_deprecation_messages) { 325 bool log_deprecation_messages) {
311 size_t num_editable_elements = 0; 326 size_t num_editable_elements = 0;
312 for (size_t i = 0; i < control_elements.size(); ++i) { 327 for (size_t i = 0; i < control_elements.size(); ++i) {
313 const WebFormControlElement& element = control_elements[i]; 328 const WebFormControlElement& element = control_elements[i];
314 329
315 if (log_deprecation_messages) 330 if (log_deprecation_messages)
316 LogDeprecationMessages(element); 331 LogDeprecationMessages(element);
317 332
(...skipping 23 matching lines...) Expand all
341 const WebInputElement* input_element = toWebInputElement(&element); 356 const WebInputElement* input_element = toWebInputElement(&element);
342 if (form_util::IsCheckableElement(input_element)) { 357 if (form_util::IsCheckableElement(input_element)) {
343 initial_checked_state_.insert( 358 initial_checked_state_.insert(
344 std::make_pair(*input_element, input_element->isChecked())); 359 std::make_pair(*input_element, input_element->isChecked()));
345 } 360 }
346 } 361 }
347 } 362 }
348 } 363 }
349 364
350 } // namespace autofill 365 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698