diff options
author | petersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-28 22:09:49 +0000 |
---|---|---|
committer | petersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-28 22:09:49 +0000 |
commit | 2b5d8c4685ee3b435d70691d0c5a8acccf9b1d57 (patch) | |
tree | 9a4fb3bb5df16c3cabbf4220a1e0a10ffc22b081 /webkit/glue | |
parent | 241639dd034255478926cf4e7dea7447717220cc (diff) | |
download | chromium_src-2b5d8c4685ee3b435d70691d0c5a8acccf9b1d57.zip chromium_src-2b5d8c4685ee3b435d70691d0c5a8acccf9b1d57.tar.gz chromium_src-2b5d8c4685ee3b435d70691d0c5a8acccf9b1d57.tar.bz2 |
Added a class with AutofillForm factory method.
Review URL: http://codereview.chromium.org/8402
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4095 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/autofill_form.cc | 66 | ||||
-rw-r--r-- | webkit/glue/autofill_form.h | 11 |
2 files changed, 76 insertions, 1 deletions
diff --git a/webkit/glue/autofill_form.cc b/webkit/glue/autofill_form.cc new file mode 100644 index 0000000..98c25bf --- /dev/null +++ b/webkit/glue/autofill_form.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "config.h" + +#pragma warning(push, 0) +#include "Frame.h" +#include "HTMLInputElement.h" +#include "HTMLNames.h" +#pragma warning(pop) + +#undef LOG + +#include "base/basictypes.h" +#include "base/logging.h" +#include "webkit/glue/autofill_form.h" +#include "webkit/glue/glue_util.h" + +AutofillForm* AutofillForm::CreateAutofillForm( + WebCore::HTMLFormElement* form) { + + DCHECK(form); + + WebCore::Frame* frame = form->document()->frame(); + + if (!frame) + return NULL; + + WebCore::FrameLoader* loader = frame->loader(); + + if (!loader) + return NULL; + + const WTF::Vector<WebCore::HTMLFormControlElement*>& form_elements = + form->formElements; + + // Construct a new AutofillForm. + AutofillForm* result = new AutofillForm(); + + size_t form_element_count = form_elements.size(); + + for (size_t i = 0; i < form_element_count; i++) { + WebCore::HTMLFormControlElement* form_element = form_elements[i]; + + if (!form_element->hasLocalName(WebCore::HTMLNames::inputTag)) + continue; + + WebCore::HTMLInputElement* input_element = + static_cast<WebCore::HTMLInputElement*>(form_element); + if (!input_element->isEnabled()) + continue; + + // Ignore all input types except TEXT. + if (input_element->inputType() != WebCore::HTMLInputElement::TEXT) + continue; + + // For each TEXT input field, store the name and value + std::wstring name = webkit_glue::StringToString16(input_element->name()); + std::wstring value = webkit_glue::StringToString16(input_element->value()); + + result->elements.push_back(AutofillForm::Element(name, value)); + } + + return result; +}
\ No newline at end of file diff --git a/webkit/glue/autofill_form.h b/webkit/glue/autofill_form.h index a817137..2433e67 100644 --- a/webkit/glue/autofill_form.h +++ b/webkit/glue/autofill_form.h @@ -8,10 +8,17 @@ #include <string> #include <vector> +#include "webkit/glue/autofill_form.h" + +namespace WebCore { + class HTMLFormElement; +} + // The AutofillForm struct represents a single HTML form together with the // values entered in the fields. -struct AutofillForm { +class AutofillForm { + public: // Struct for storing name/value pairs. struct Element { Element() {} @@ -23,6 +30,8 @@ struct AutofillForm { std::wstring value; }; + static AutofillForm* CreateAutofillForm(WebCore::HTMLFormElement* form); + // A vector of all the input fields in the form. std::vector<Element> elements; }; |