| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/renderer/autofill/form_cache.h" | 5 #include "chrome/renderer/autofill/form_cache.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/renderer/autofill/form_autofill_util.h" | 9 #include "chrome/renderer/autofill/form_autofill_util.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 using webkit::forms::FormDataPredictions; | 34 using webkit::forms::FormDataPredictions; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // The number of fields required by Autofill. Ideally we could send the forms | 38 // The number of fields required by Autofill. Ideally we could send the forms |
| 39 // to Autofill no matter how many fields are in the forms; however, finding the | 39 // to Autofill no matter how many fields are in the forms; however, finding the |
| 40 // label for each field is a costly operation and we can't spare the cycles if | 40 // label for each field is a costly operation and we can't spare the cycles if |
| 41 // it's not necessary. | 41 // it's not necessary. |
| 42 const size_t kRequiredAutofillFields = 3; | 42 const size_t kRequiredAutofillFields = 3; |
| 43 | 43 |
| 44 // The maximum number of form fields we are willing to parse, due to | |
| 45 // computational costs. Several examples of forms with lots of fields that are | |
| 46 // not relevant to Autofill: (1) the Netflix queue; (2) the Amazon wishlist; | |
| 47 // (3) router configuration pages; and (4) other configuration pages, e.g. for | |
| 48 // Google code project settings. | |
| 49 const size_t kMaxParseableFields = 100; | |
| 50 | |
| 51 } // namespace | 44 } // namespace |
| 52 | 45 |
| 53 namespace autofill { | 46 namespace autofill { |
| 54 | 47 |
| 55 FormCache::FormCache() { | 48 FormCache::FormCache() { |
| 56 } | 49 } |
| 57 | 50 |
| 58 FormCache::~FormCache() { | 51 FormCache::~FormCache() { |
| 59 } | 52 } |
| 60 | 53 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 85 // Save original values of <select> elements so we can restore them | 78 // Save original values of <select> elements so we can restore them |
| 86 // when |ClearFormWithNode()| is invoked. | 79 // when |ClearFormWithNode()| is invoked. |
| 87 if (IsSelectElement(element)) { | 80 if (IsSelectElement(element)) { |
| 88 const WebSelectElement select_element = | 81 const WebSelectElement select_element = |
| 89 element.toConst<WebSelectElement>(); | 82 element.toConst<WebSelectElement>(); |
| 90 initial_select_values_.insert(std::make_pair(select_element, | 83 initial_select_values_.insert(std::make_pair(select_element, |
| 91 select_element.value())); | 84 select_element.value())); |
| 92 } | 85 } |
| 93 } | 86 } |
| 94 | 87 |
| 95 // To avoid overly expensive computation, we impose both a minimum and a | 88 // To avoid overly expensive computation, we impose a minimum number of |
| 96 // maximum number of allowable fields. | 89 // allowable fields. The corresponding maximum number of allowable fields |
| 97 if (control_elements.size() < kRequiredAutofillFields || | 90 // is imposed by WebFormElementToFormData(). |
| 98 control_elements.size() > kMaxParseableFields) | 91 if (control_elements.size() < kRequiredAutofillFields) |
| 99 continue; | 92 continue; |
| 100 | 93 |
| 101 FormData form; | 94 FormData form; |
| 102 WebFormElementToFormData(form_element, WebFormControlElement(), | 95 if (!WebFormElementToFormData(form_element, WebFormControlElement(), |
| 103 REQUIRE_NONE, EXTRACT_VALUE, &form, NULL); | 96 REQUIRE_NONE, EXTRACT_VALUE, &form, NULL)) { |
| 97 continue; |
| 98 } |
| 104 | 99 |
| 105 num_fields_seen += form.fields.size(); | 100 num_fields_seen += form.fields.size(); |
| 106 if (num_fields_seen > kMaxParseableFields) | 101 if (num_fields_seen > kMaxParseableFields) |
| 107 break; | 102 break; |
| 108 | 103 |
| 109 if (form.fields.size() >= kRequiredAutofillFields) | 104 if (form.fields.size() >= kRequiredAutofillFields) |
| 110 forms->push_back(form); | 105 forms->push_back(form); |
| 111 } | 106 } |
| 112 } | 107 } |
| 113 | 108 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 UTF8ToUTF16(form.experiment_id)); | 246 UTF8ToUTF16(form.experiment_id)); |
| 252 if (!element->hasAttribute("placeholder")) | 247 if (!element->hasAttribute("placeholder")) |
| 253 element->setAttribute("placeholder", WebString(UTF8ToUTF16(placeholder))); | 248 element->setAttribute("placeholder", WebString(UTF8ToUTF16(placeholder))); |
| 254 element->setAttribute("title", WebString(title)); | 249 element->setAttribute("title", WebString(title)); |
| 255 } | 250 } |
| 256 | 251 |
| 257 return true; | 252 return true; |
| 258 } | 253 } |
| 259 | 254 |
| 260 } // namespace autofill | 255 } // namespace autofill |
| OLD | NEW |