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

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

Issue 265203002: Revert of [Autofill] Enable Autofill for dynamically created forms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/content/renderer/form_autofill_util.h" 9 #include "components/autofill/content/renderer/form_autofill_util.h"
10 #include "components/autofill/core/common/autofill_constants.h" 10 #include "components/autofill/core/common/autofill_constants.h"
11 #include "components/autofill/core/common/form_data.h" 11 #include "components/autofill/core/common/form_data.h"
12 #include "components/autofill/core/common/form_data_predictions.h" 12 #include "components/autofill/core/common/form_data_predictions.h"
13 #include "components/autofill/core/common/form_field_data.h" 13 #include "components/autofill/core/common/form_field_data.h"
14 #include "components/autofill/core/common/form_field_data_predictions.h" 14 #include "components/autofill/core/common/form_field_data_predictions.h"
15 #include "grit/component_strings.h" 15 #include "grit/component_strings.h"
16 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "third_party/WebKit/public/platform/WebVector.h" 17 #include "third_party/WebKit/public/platform/WebVector.h"
18 #include "third_party/WebKit/public/web/WebDocument.h" 18 #include "third_party/WebKit/public/web/WebDocument.h"
19 #include "third_party/WebKit/public/web/WebFormControlElement.h" 19 #include "third_party/WebKit/public/web/WebFormControlElement.h"
20 #include "third_party/WebKit/public/web/WebFormElement.h" 20 #include "third_party/WebKit/public/web/WebFormElement.h"
21 #include "third_party/WebKit/public/web/WebInputElement.h" 21 #include "third_party/WebKit/public/web/WebInputElement.h"
22 #include "third_party/WebKit/public/web/WebLocalFrame.h" 22 #include "third_party/WebKit/public/web/WebLocalFrame.h"
23 #include "third_party/WebKit/public/web/WebNodeList.h"
24 #include "third_party/WebKit/public/web/WebSelectElement.h" 23 #include "third_party/WebKit/public/web/WebSelectElement.h"
25 #include "third_party/WebKit/public/web/WebTextAreaElement.h" 24 #include "third_party/WebKit/public/web/WebTextAreaElement.h"
26 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
27 26
28 using blink::WebDocument; 27 using blink::WebDocument;
29 using blink::WebFormControlElement; 28 using blink::WebFormControlElement;
30 using blink::WebFormElement; 29 using blink::WebFormElement;
31 using blink::WebFrame; 30 using blink::WebFrame;
32 using blink::WebInputElement; 31 using blink::WebInputElement;
33 using blink::WebSelectElement; 32 using blink::WebSelectElement;
(...skipping 28 matching lines...) Expand all
62 states->erase(*it); 61 states->erase(*it);
63 } 62 }
64 } 63 }
65 64
66 FormCache::FormCache() { 65 FormCache::FormCache() {
67 } 66 }
68 67
69 FormCache::~FormCache() { 68 FormCache::~FormCache() {
70 } 69 }
71 70
72 void FormCache::ExtractNewForms(const WebFrame& frame, 71 void FormCache::ExtractForms(const WebFrame& frame,
73 std::vector<FormData>* forms) { 72 std::vector<FormData>* forms) {
73 ExtractFormsAndFormElements(frame, kRequiredAutofillFields, forms, NULL);
74 }
75
76 bool FormCache::ExtractFormsAndFormElements(
77 const WebFrame& frame,
78 size_t minimum_required_fields,
79 std::vector<FormData>* forms,
80 std::vector<WebFormElement>* web_form_elements) {
81 // Reset the cache for this frame.
82 ResetFrame(frame);
83
74 WebDocument document = frame.document(); 84 WebDocument document = frame.document();
75 if (document.isNull()) 85 if (document.isNull())
76 return; 86 return false;
77 87
78 web_documents_.insert(document); 88 web_documents_.insert(document);
79 89
80 WebVector<WebFormElement> web_forms; 90 WebVector<WebFormElement> web_forms;
81 document.forms(web_forms); 91 document.forms(web_forms);
82 92
83 size_t num_fields_seen = 0; 93 size_t num_fields_seen = 0;
94 bool has_skipped_forms = false;
84 for (size_t i = 0; i < web_forms.size(); ++i) { 95 for (size_t i = 0; i < web_forms.size(); ++i) {
85 WebFormElement form_element = web_forms[i]; 96 WebFormElement form_element = web_forms[i];
86 97
87 std::vector<WebFormControlElement> control_elements; 98 std::vector<WebFormControlElement> control_elements;
88 ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE, 99 ExtractAutofillableElements(form_element, autofill::REQUIRE_NONE,
89 &control_elements); 100 &control_elements);
90 101
91 size_t num_editable_elements = 0; 102 size_t num_editable_elements = 0;
92 for (size_t j = 0; j < control_elements.size(); ++j) { 103 for (size_t j = 0; j < control_elements.size(); ++j) {
93 WebFormControlElement element = control_elements[j]; 104 WebFormControlElement element = control_elements[j];
(...skipping 16 matching lines...) Expand all
110 std::make_pair(input_element, input_element.isChecked())); 121 std::make_pair(input_element, input_element.isChecked()));
111 } else { 122 } else {
112 ++num_editable_elements; 123 ++num_editable_elements;
113 } 124 }
114 } 125 }
115 } 126 }
116 127
117 // To avoid overly expensive computation, we impose a minimum number of 128 // To avoid overly expensive computation, we impose a minimum number of
118 // allowable fields. The corresponding maximum number of allowable fields 129 // allowable fields. The corresponding maximum number of allowable fields
119 // is imposed by WebFormElementToFormData(). 130 // is imposed by WebFormElementToFormData().
120 if (num_editable_elements < kRequiredAutofillFields && 131 if (num_editable_elements < minimum_required_fields &&
121 control_elements.size() > 0) { 132 control_elements.size() > 0) {
133 has_skipped_forms = true;
122 continue; 134 continue;
123 } 135 }
124 136
125 FormData form; 137 FormData form;
126 ExtractMask extract_mask = 138 ExtractMask extract_mask =
127 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); 139 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS);
128 140
129 if (!WebFormElementToFormData(form_element, WebFormControlElement(), 141 if (!WebFormElementToFormData(form_element, WebFormControlElement(),
130 REQUIRE_NONE, extract_mask, &form, NULL)) { 142 REQUIRE_NONE, extract_mask, &form, NULL)) {
131 continue; 143 continue;
132 } 144 }
133 145
134 num_fields_seen += form.fields.size(); 146 num_fields_seen += form.fields.size();
135 if (num_fields_seen > kMaxParseableFields) 147 if (num_fields_seen > kMaxParseableFields)
136 break; 148 break;
137 149
138 if (form.fields.size() >= kRequiredAutofillFields && 150 if (form.fields.size() >= minimum_required_fields) {
139 !parsed_forms_[&frame].count(form)) {
140 forms->push_back(form); 151 forms->push_back(form);
141 parsed_forms_[&frame].insert(form); 152 if (web_form_elements)
153 web_form_elements->push_back(form_element);
154 } else {
155 has_skipped_forms = true;
142 } 156 }
143 } 157 }
158
159 // Return true if there are any WebFormElements skipped, else false.
160 return has_skipped_forms;
144 } 161 }
145 162
146 void FormCache::ResetFrame(const WebFrame& frame) { 163 void FormCache::ResetFrame(const WebFrame& frame) {
147 std::vector<WebDocument> documents_to_delete; 164 std::vector<WebDocument> documents_to_delete;
148 for (std::set<WebDocument>::const_iterator it = web_documents_.begin(); 165 for (std::set<WebDocument>::const_iterator it = web_documents_.begin();
149 it != web_documents_.end(); ++it) { 166 it != web_documents_.end(); ++it) {
150 const WebFrame* document_frame = it->frame(); 167 const WebFrame* document_frame = it->frame();
151 if (!document_frame || document_frame == &frame) 168 if (!document_frame || document_frame == &frame)
152 documents_to_delete.push_back(*it); 169 documents_to_delete.push_back(*it);
153 } 170 }
154 171
155 for (std::vector<WebDocument>::const_iterator it = 172 for (std::vector<WebDocument>::const_iterator it =
156 documents_to_delete.begin(); 173 documents_to_delete.begin();
157 it != documents_to_delete.end(); ++it) { 174 it != documents_to_delete.end(); ++it) {
158 web_documents_.erase(*it); 175 web_documents_.erase(*it);
159 } 176 }
160 177
161 parsed_forms_[&frame].clear();
162 RemoveOldElements(frame, &initial_select_values_); 178 RemoveOldElements(frame, &initial_select_values_);
163 RemoveOldElements(frame, &initial_checked_state_); 179 RemoveOldElements(frame, &initial_checked_state_);
164 } 180 }
165 181
166 bool FormCache::ClearFormWithElement(const WebFormControlElement& element) { 182 bool FormCache::ClearFormWithElement(const WebFormControlElement& element) {
167 WebFormElement form_element = element.form(); 183 WebFormElement form_element = element.form();
168 if (form_element.isNull()) 184 if (form_element.isNull())
169 return false; 185 return false;
170 186
171 std::vector<WebFormControlElement> control_elements; 187 std::vector<WebFormControlElement> control_elements;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 element->setAttribute("placeholder", 296 element->setAttribute("placeholder",
281 WebString(base::UTF8ToUTF16(placeholder))); 297 WebString(base::UTF8ToUTF16(placeholder)));
282 } 298 }
283 element->setAttribute("title", WebString(title)); 299 element->setAttribute("title", WebString(title));
284 } 300 }
285 301
286 return true; 302 return true;
287 } 303 }
288 304
289 } // namespace autofill 305 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/form_cache.h ('k') | components/autofill/core/browser/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698