Chromium Code Reviews| 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_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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 64 // is imposed by WebFormElementToFormData(). | 64 // is imposed by WebFormElementToFormData(). |
| 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 < 1 && num_control_elements > 0); |
|
Mathieu
2015/10/20 21:03:10
!num_editable_elements && num_control_elements
sebsg
2015/10/21 18:20:50
Done.
| |
| 68 num_control_elements > 0); | |
| 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 Loading... | |
| 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 (form.fields.size() >= 1 && !ContainsKey(parsed_forms_, form)) { |
|
Mathieu
2015/10/20 21:03:10
!form.fields.empty()
same with change below
sebsg
2015/10/21 18:20:50
Done.
| |
| 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 Loading... | |
| 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 (synthetic_form.fields.size() >= 1 && |
| 159 !parsed_forms_.count(synthetic_form)) { | 157 !parsed_forms_.count(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 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 const WebInputElement* input_element = toWebInputElement(&element); | 341 const WebInputElement* input_element = toWebInputElement(&element); |
| 344 if (form_util::IsCheckableElement(input_element)) { | 342 if (form_util::IsCheckableElement(input_element)) { |
| 345 initial_checked_state_.insert( | 343 initial_checked_state_.insert( |
| 346 std::make_pair(*input_element, input_element->isChecked())); | 344 std::make_pair(*input_element, input_element->isChecked())); |
| 347 } | 345 } |
| 348 } | 346 } |
| 349 } | 347 } |
| 350 } | 348 } |
| 351 | 349 |
| 352 } // namespace autofill | 350 } // namespace autofill |
| OLD | NEW |