| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/form_manager.h" | 5 #include "chrome/renderer/form_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" |
| 8 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 9 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" | 11 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" |
| 11 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
| 13 | 14 |
| 14 using WebKit::WebFormElement; | 15 using WebKit::WebFormElement; |
| 15 using WebKit::WebFrame; | 16 using WebKit::WebFrame; |
| 16 using WebKit::WebInputElement; | 17 using WebKit::WebInputElement; |
| 17 using WebKit::WebNode; | 18 using WebKit::WebNode; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 35 // Form loop. | 36 // Form loop. |
| 36 for (size_t i = 0; i < web_forms.size(); ++i) { | 37 for (size_t i = 0; i < web_forms.size(); ++i) { |
| 37 FormElement* form_elements = new FormElement; | 38 FormElement* form_elements = new FormElement; |
| 38 form_elements->form_element = web_forms[i]; | 39 form_elements->form_element = web_forms[i]; |
| 39 | 40 |
| 40 // Form elements loop. | 41 // Form elements loop. |
| 41 WebVector<WebInputElement> input_elements; | 42 WebVector<WebInputElement> input_elements; |
| 42 form_elements->form_element.getInputElements(input_elements); | 43 form_elements->form_element.getInputElements(input_elements); |
| 43 for (size_t j = 0; j < input_elements.size(); ++j) { | 44 for (size_t j = 0; j < input_elements.size(); ++j) { |
| 44 WebInputElement element = input_elements[j]; | 45 WebInputElement element = input_elements[j]; |
| 45 form_elements->input_elements[element.nameForAutofill()] = element; | 46 // TODO(jhawkins): Remove this check when we have labels. |
| 47 if (!element.nameForAutofill().isEmpty()) |
| 48 form_elements->input_elements[element.nameForAutofill()] = element; |
| 46 } | 49 } |
| 47 | 50 |
| 48 form_elements_map_[frame].push_back(form_elements); | 51 form_elements_map_[frame].push_back(form_elements); |
| 49 } | 52 } |
| 50 } | 53 } |
| 51 | 54 |
| 52 void FormManager::GetForms(std::vector<FormData>* forms, | 55 void FormManager::GetForms(std::vector<FormData>* forms, |
| 53 RequirementsMask requirements) { | 56 RequirementsMask requirements) { |
| 54 // Frame loop. | 57 // Frame loop. |
| 55 for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin(); | 58 for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 if (!form_element) | 116 if (!form_element) |
| 114 return false; | 117 return false; |
| 115 | 118 |
| 116 DCHECK(form_element->input_elements.size() == form.elements.size()); | 119 DCHECK(form_element->input_elements.size() == form.elements.size()); |
| 117 DCHECK(form.elements.size() == form.values.size()); | 120 DCHECK(form.elements.size() == form.values.size()); |
| 118 | 121 |
| 119 size_t i = 0; | 122 size_t i = 0; |
| 120 for (FormInputElementMap::iterator iter = | 123 for (FormInputElementMap::iterator iter = |
| 121 form_element->input_elements.begin(); | 124 form_element->input_elements.begin(); |
| 122 iter != form_element->input_elements.end(); ++iter, ++i) { | 125 iter != form_element->input_elements.end(); ++iter, ++i) { |
| 123 DCHECK(iter->second.nameForAutofill() == form.elements[i]); | 126 DCHECK_EQ(form.elements[i], iter->second.nameForAutofill()); |
| 124 | 127 |
| 125 iter->second.setValue(form.values[i]); | 128 iter->second.setValue(form.values[i]); |
| 126 iter->second.setAutofilled(true); | 129 iter->second.setAutofilled(true); |
| 127 } | 130 } |
| 128 | 131 |
| 129 return true; | 132 return true; |
| 130 } | 133 } |
| 131 | 134 |
| 132 void FormManager::Reset() { | 135 void FormManager::Reset() { |
| 133 for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin(); | 136 for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 form->elements.push_back(input_element.nameForAutofill()); | 178 form->elements.push_back(input_element.nameForAutofill()); |
| 176 form->values.push_back(input_element.value()); | 179 form->values.push_back(input_element.value()); |
| 177 | 180 |
| 178 // TODO(jhawkins): It's possible for a form to have more than one submit | 181 // TODO(jhawkins): It's possible for a form to have more than one submit |
| 179 // input element. The FormData structure probably doesn't need to keep | 182 // input element. The FormData structure probably doesn't need to keep |
| 180 // track of the name of any submit button. | 183 // track of the name of any submit button. |
| 181 if (input_element.inputType() == WebInputElement::Submit) | 184 if (input_element.inputType() == WebInputElement::Submit) |
| 182 form->submit = input_element.nameForAutofill(); | 185 form->submit = input_element.nameForAutofill(); |
| 183 } | 186 } |
| 184 } | 187 } |
| OLD | NEW |