OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "config.h" | 5 #include "config.h" |
6 | 6 |
| 7 #include "Document.h" |
7 #include "Frame.h" | 8 #include "Frame.h" |
8 #include "HTMLFormElement.h" | 9 #include "HTMLFormElement.h" |
9 #include "HTMLInputElement.h" | 10 #include "HTMLInputElement.h" |
10 #include "HTMLNames.h" | 11 #include "HTMLNames.h" |
11 #undef LOG | 12 #undef LOG |
12 | 13 |
13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/string16.h" | 16 #include "base/string16.h" |
16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
17 #include "webkit/api/public/WebForm.h" | 18 #include "webkit/api/public/WebForm.h" |
18 #include "webkit/glue/form_field_values.h" | 19 #include "webkit/glue/form_field_values.h" |
19 // Can include from api/src because this file will eventually be there too. | 20 // Can include from api/src because this file will eventually be there too. |
20 #include "webkit/api/src/DOMUtilitiesPrivate.h" | 21 #include "webkit/api/src/DOMUtilitiesPrivate.h" |
21 #include "webkit/glue/glue_util.h" | 22 #include "webkit/glue/glue_util.h" |
22 | 23 |
23 using WebKit::WebForm; | 24 using WebKit::WebForm; |
24 | 25 |
25 namespace webkit_glue { | 26 namespace webkit_glue { |
26 | 27 |
27 FormFieldValues* FormFieldValues::Create(const WebForm& webform) { | 28 FormFieldValues* FormFieldValues::Create(const WebForm& webform) { |
28 RefPtr<WebCore::HTMLFormElement> form = WebFormToHTMLFormElement(webform); | 29 RefPtr<WebCore::HTMLFormElement> form = WebFormToHTMLFormElement(webform); |
29 DCHECK(form); | 30 DCHECK(form); |
30 | 31 |
31 WebCore::Frame* frame = form->document()->frame(); | 32 WebCore::Document* document = form->document(); |
| 33 WebCore::Frame* frame = document->frame(); |
32 if (!frame) | 34 if (!frame) |
33 return NULL; | 35 return NULL; |
34 | 36 |
35 WebCore::FrameLoader* loader = frame->loader(); | 37 WebCore::FrameLoader* loader = frame->loader(); |
36 if (!loader) | 38 if (!loader) |
37 return NULL; | 39 return NULL; |
38 | 40 |
| 41 // Construct a new FormFieldValues. |
| 42 FormFieldValues* result = new FormFieldValues(); |
| 43 |
| 44 result->form_name = StringToString16(form->name()); |
| 45 result->source_url = KURLToGURL(document->url()); |
| 46 result->target_url = KURLToGURL(document->completeURL(form->action())); |
| 47 result->ExtractFormFieldValues(webform); |
| 48 |
| 49 return result; |
| 50 } |
| 51 |
| 52 void FormFieldValues::ExtractFormFieldValues(const WebKit::WebForm& webform) { |
| 53 RefPtr<WebCore::HTMLFormElement> form = WebFormToHTMLFormElement(webform); |
| 54 |
39 const WTF::Vector<WebCore::HTMLFormControlElement*>& form_elements = | 55 const WTF::Vector<WebCore::HTMLFormControlElement*>& form_elements = |
40 form->formElements; | 56 form->formElements; |
41 | 57 |
42 // Construct a new FormFieldValues. | |
43 FormFieldValues* result = new FormFieldValues(); | |
44 | |
45 size_t form_element_count = form_elements.size(); | 58 size_t form_element_count = form_elements.size(); |
46 | |
47 for (size_t i = 0; i < form_element_count; i++) { | 59 for (size_t i = 0; i < form_element_count; i++) { |
48 WebCore::HTMLFormControlElement* form_element = form_elements[i]; | 60 WebCore::HTMLFormControlElement* form_element = form_elements[i]; |
49 | 61 |
50 if (!form_element->hasLocalName(WebCore::HTMLNames::inputTag)) | 62 if (!form_element->hasLocalName(WebCore::HTMLNames::inputTag)) |
51 continue; | 63 continue; |
52 | 64 |
53 WebCore::HTMLInputElement* input_element = | 65 WebCore::HTMLInputElement* input_element = |
54 static_cast<WebCore::HTMLInputElement*>(form_element); | 66 static_cast<WebCore::HTMLInputElement*>(form_element); |
55 if (!input_element->isEnabledFormControl()) | 67 if (!input_element->isEnabledFormControl()) |
56 continue; | 68 continue; |
57 | 69 |
58 // Ignore all input types except TEXT. | 70 // Ignore all input types except TEXT. |
59 if (input_element->inputType() != WebCore::HTMLInputElement::TEXT) | 71 if (input_element->inputType() != WebCore::HTMLInputElement::TEXT) |
60 continue; | 72 continue; |
61 | 73 |
62 // For each TEXT input field, store the name and value | 74 // For each TEXT input field, store the name and value |
63 string16 value = StringToString16(input_element->value()); | 75 string16 value = StringToString16(input_element->value()); |
64 TrimWhitespace(value, TRIM_LEADING, &value); | 76 TrimWhitespace(value, TRIM_LEADING, &value); |
65 if (value.length() == 0) | 77 if (value.length() == 0) |
66 continue; | 78 continue; |
67 | 79 |
68 string16 name = StringToString16(WebKit::nameOfInputElement(input_element)); | 80 string16 name = StringToString16(WebKit::nameOfInputElement(input_element)); |
69 if (name.length() == 0) | 81 if (name.length() == 0) |
70 continue; // If we have no name, there is nothing to store. | 82 continue; // If we have no name, there is nothing to store. |
71 | 83 |
72 result->elements.push_back(FormField(name, value)); | 84 elements.push_back(FormField(name, value)); |
73 } | 85 } |
74 | |
75 return result; | |
76 } | 86 } |
77 | 87 |
78 } // namespace webkit_glue | 88 } // namespace webkit_glue |
OLD | NEW |