summaryrefslogtreecommitdiffstats
path: root/webkit/glue/searchable_form_data.cc
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 17:21:10 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-15 17:21:10 +0000
commitdaa8c58ee49795d292312bbf217999c93693919c (patch)
tree561a327f148d74b0522871f15103e25a27b841f5 /webkit/glue/searchable_form_data.cc
parent0b97342d07fd3ef047432b52809d31d10432ee85 (diff)
downloadchromium_src-daa8c58ee49795d292312bbf217999c93693919c.zip
chromium_src-daa8c58ee49795d292312bbf217999c93693919c.tar.gz
chromium_src-daa8c58ee49795d292312bbf217999c93693919c.tar.bz2
Extract form related classes from the guts of WebFrameImpl.
Instead of having WebFrameImpl generate SearchableFormData, PasswordForm, and AutofillForm classes, allow the embedder (RenderView) to do so. This is done to help minimize the dependencies WebFrameImpl has on other code, which will make it easier to move WebFrame and WebDataSource into the WebKit API. Most significant change: Now, RenderView always sets a NavigationState on WebDataSource instances. We used to only do so for browser initiated navigations. This is done so that we can store things like SearchableFormData and friends on the NavigationState. To facilitate this change, it was necessary to add a way through the WebKit API to refer to a HTMLFormElement. This CL introduces WebForm, which is like a RefPtr<HTMLFormElement>, so you can just copy a WebForm around by value and the right thing happens. Some of the other changes are about moving more things into the webkit_glue namespace. On hindsight, I probably should have done that as a separate CL. BUG=10041 TEST=none R=brettw Review URL: http://codereview.chromium.org/126083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18395 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/searchable_form_data.cc')
-rw-r--r--webkit/glue/searchable_form_data.cc49
1 files changed, 18 insertions, 31 deletions
diff --git a/webkit/glue/searchable_form_data.cc b/webkit/glue/searchable_form_data.cc
index 6187897..5955745a 100644
--- a/webkit/glue/searchable_form_data.cc
+++ b/webkit/glue/searchable_form_data.cc
@@ -36,10 +36,15 @@ MSVC_POP_WARNING();
#include "webkit/glue/searchable_form_data.h"
#include "webkit/glue/webframe_impl.h"
+using WebCore::HTMLFormElement;
using WebCore::HTMLInputElement;
using WebCore::HTMLOptionElement;
+using WebKit::WebForm;
+
+namespace webkit_glue {
namespace {
+
// TODO(eseidel): appendString and appendEncodedString do *not* follow Google
// style because they are copy/paste from WebKit and will go away as soon as the
// WebKit functions are made public.
@@ -154,8 +159,7 @@ bool IsSelectInDefaultState(WebCore::HTMLSelectElement* select) {
// least one item is selected, determine which one.
HTMLOptionElement* initial_selected = NULL;
while (node) {
- HTMLOptionElement* option_element =
- webkit_glue::CastToHTMLOptionElement(node);
+ HTMLOptionElement* option_element = CastToHTMLOptionElement(node);
if (option_element) {
if (!initial_selected)
initial_selected = option_element;
@@ -171,8 +175,7 @@ bool IsSelectInDefaultState(WebCore::HTMLSelectElement* select) {
return initial_selected->selected();
} else {
while (node) {
- HTMLOptionElement* option_element =
- webkit_glue::CastToHTMLOptionElement(node);
+ HTMLOptionElement* option_element = CastToHTMLOptionElement(node);
if (option_element &&
option_element->selected() != option_element->defaultSelected()) {
return false;
@@ -296,37 +299,20 @@ WebCore::HTMLInputElement* GetTextElement(
} // namespace
-SearchableFormData* SearchableFormData::Create(WebCore::Element* element) {
- if (!element->isFormControlElement() || !element->isHTMLElement()) {
- return NULL;
- }
-
- WebCore::Frame* frame = element->document()->frame();
- if (frame == NULL)
- return NULL;
+SearchableFormData* SearchableFormData::Create(const WebForm& webform) {
+ RefPtr<HTMLFormElement> form = WebFormToHTMLFormElement(webform);
- WebCore::HTMLFormControlElement* input_element =
- static_cast<WebCore::HTMLFormControlElement*>(element);
-
- WebCore::HTMLFormElement* form = input_element->form();
- if (form == NULL)
- return NULL;
-
- return Create(form);
-}
-
-SearchableFormData* SearchableFormData::Create(WebCore::HTMLFormElement* form) {
WebCore::Frame* frame = form->document()->frame();
if (frame == NULL)
return NULL;
// Only consider forms that GET data and the action targets an http page.
- if (!IsFormMethodGet(form) || !IsHTTPFormSubmit(form))
+ if (!IsFormMethodGet(form.get()) || !IsHTTPFormSubmit(form.get()))
return NULL;
Vector<char> enc_string;
WebCore::HTMLFormControlElement* first_submit_button =
- GetButtonToActivate(form);
+ GetButtonToActivate(form.get());
if (first_submit_button) {
// The form does not have an active submit button, make the first button
@@ -337,7 +323,7 @@ SearchableFormData* SearchableFormData::Create(WebCore::HTMLFormElement* form) {
std::string encoding;
WebCore::HTMLInputElement* text_element =
- GetTextElement(form, &enc_string, &encoding);
+ GetTextElement(form.get(), &enc_string, &encoding);
if (first_submit_button)
first_submit_button->setActivatedSubmit(false);
@@ -354,11 +340,10 @@ SearchableFormData* SearchableFormData::Create(WebCore::HTMLFormElement* form) {
WebCore::FrameLoader* loader = frame->loader();
WebCore::KURL url = loader->completeURL(action.isNull() ? "" : action);
url.setQuery(form_data->flattenToString());
- std::wstring current_value = webkit_glue::StringToStdWString(
- static_cast<WebCore::HTMLInputElement*>(text_element)->value());
- std::wstring text_name =
- webkit_glue::StringToStdWString(text_element->name());
- GURL gurl(webkit_glue::KURLToGURL(url));
+ std::wstring current_value = StringToStdWString(
+ static_cast<WebCore::HTMLInputElement*>(text_element)->value());
+ std::wstring text_name = StringToStdWString(text_element->name());
+ GURL gurl(KURLToGURL(url));
return new SearchableFormData(gurl, text_name, current_value, encoding);
}
@@ -382,3 +367,5 @@ SearchableFormData::SearchableFormData(const GURL& url,
element_value_(element_value),
encoding_(encoding) {
}
+
+} // namespace webkit_glue