summaryrefslogtreecommitdiffstats
path: root/WebKit/android/WebCoreSupport/autofill
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-05-13 16:40:46 +0100
committerBen Murdoch <benm@google.com>2011-05-16 11:35:03 +0100
commita2c606d1d8312a5d063e4a11e5911d9c8e4a3d19 (patch)
tree614d69ba96a23bc057e539a3c8a7d4961a68254b /WebKit/android/WebCoreSupport/autofill
parent65f03d4f644ce73618e5f4f50dd694b26f55ae12 (diff)
downloadexternal_webkit-a2c606d1d8312a5d063e4a11e5911d9c8e4a3d19.zip
external_webkit-a2c606d1d8312a5d063e4a11e5911d9c8e4a3d19.tar.gz
external_webkit-a2c606d1d8312a5d063e4a11e5911d9c8e4a3d19.tar.bz2
Merge WebKit at r75993: Move WebKit/android files to Source
Change-Id: Ifa871f8320bdb3a09fe189fffecc23f702c394b9
Diffstat (limited to 'WebKit/android/WebCoreSupport/autofill')
-rw-r--r--WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.cpp51
-rw-r--r--WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.h54
-rw-r--r--WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.cpp139
-rw-r--r--WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.h96
-rw-r--r--WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.cpp871
-rw-r--r--WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.h187
-rw-r--r--WebKit/android/WebCoreSupport/autofill/MainThreadProxy.cpp35
-rw-r--r--WebKit/android/WebCoreSupport/autofill/MainThreadProxy.h37
-rw-r--r--WebKit/android/WebCoreSupport/autofill/StringUtils.h73
-rw-r--r--WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp296
-rw-r--r--WebKit/android/WebCoreSupport/autofill/WebAutoFill.h127
11 files changed, 0 insertions, 1966 deletions
diff --git a/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.cpp b/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.cpp
deleted file mode 100644
index 5bc4c92..0000000
--- a/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "AutoFillHostAndroid.h"
-
-#include "autofill/WebAutoFill.h"
-
-namespace android {
-
-AutoFillHostAndroid::AutoFillHostAndroid(WebAutoFill* autoFill)
- : mAutoFill(autoFill)
-{
-}
-
-void AutoFillHostAndroid::AutoFillSuggestionsReturned(const std::vector<string16>& names, const std::vector<string16>& labels, const std::vector<string16>& icons, const std::vector<int>& uniqueIds)
-{
- // TODO: what do we do with icons?
- if (mAutoFill)
- mAutoFill->querySuccessful(names[0], labels[0], uniqueIds[0]);
-}
-
-void AutoFillHostAndroid::AutoFillFormDataFilled(int queryId, const webkit_glue::FormData& form)
-{
- if (mAutoFill)
- mAutoFill->fillFormInPage(queryId, form);
-}
-
-}
diff --git a/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.h b/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.h
deleted file mode 100644
index 9677b46..0000000
--- a/WebKit/android/WebCoreSupport/autofill/AutoFillHostAndroid.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef AutoFillHostAndroid_h
-#define AutoFillHostAndroid_h
-
-#include "ChromiumIncludes.h"
-
-#include <vector>
-
-namespace webkit_glue {
-class FormData;
-}
-
-namespace android {
-class WebAutoFill;
-
-// This class receives the callbacks from the AutoFillManager in the Chromium code.
-class AutoFillHostAndroid : public AutoFillHost {
-public:
- AutoFillHostAndroid(WebAutoFill* autoFill);
- virtual ~AutoFillHostAndroid() { }
-
- virtual void AutoFillSuggestionsReturned(const std::vector<string16>& names, const std::vector<string16>& labels, const std::vector<string16>& icons, const std::vector<int>& uniqueIds);
- virtual void AutoFillFormDataFilled(int queryId, const webkit_glue::FormData&);
-
-private:
- WebAutoFill* mAutoFill;
-};
-}
-
-#endif
diff --git a/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.cpp b/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.cpp
deleted file mode 100644
index 6af0875..0000000
--- a/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (c) 2010 The Chromium Authors. All rights reserved.
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "FormFieldAndroid.h"
-
-#include "ChromiumIncludes.h"
-#include "Element.h"
-#include "HTMLFormControlElement.h"
-#include "HTMLInputElement.h"
-#include "HTMLNames.h"
-#include "HTMLOptionElement.h"
-#include "HTMLSelectElement.h"
-#include "StringUtils.h"
-#include <wtf/Vector.h>
-
-using WebCore::Element;
-using WebCore::HTMLFormControlElement;
-using WebCore::HTMLInputElement;
-using WebCore::HTMLOptionElement;
-using WebCore::HTMLSelectElement;
-
-using namespace WebCore::HTMLNames;
-
-// TODO: This file is taken from chromium/webkit/glue/form_field.cc and
-// customised to use WebCore types rather than WebKit API types. It would
-// be nice and would ease future merge pain if the two could be combined.
-
-namespace webkit_glue {
-
-FormField::FormField()
- : max_length_(0),
- is_autofilled_(false) {
-}
-
-// TODO: This constructor should probably be deprecated and the
-// functionality moved to FormManager.
-FormField::FormField(const HTMLFormControlElement& element)
- : max_length_(0),
- is_autofilled_(false) {
- name_ = nameForAutoFill(element);
-
- // TODO: Extract the field label. For now we just use the field
- // name.
- label_ = name_;
-
- form_control_type_ = formControlType(element);
- if (form_control_type_ == kText) {
- const HTMLInputElement& input_element = static_cast<const HTMLInputElement&>(element);
- value_ = WTFStringToString16(input_element.value());
- max_length_ = input_element.size();
- is_autofilled_ = input_element.isAutofilled();
- } else if (form_control_type_ == kSelectOne) {
- const HTMLSelectElement& const_select_element = static_cast<const HTMLSelectElement&>(element);
- HTMLSelectElement& select_element = const_cast<HTMLSelectElement&>(const_select_element);
- value_ = WTFStringToString16(select_element.value());
-
- // For select-one elements copy option strings.
- WTF::Vector<Element*> list_items = select_element.listItems();
- option_strings_.reserve(list_items.size());
- for (size_t i = 0; i < list_items.size(); ++i) {
- if (list_items[i]->hasTagName(optionTag))
- option_strings_.push_back(WTFStringToString16(static_cast<HTMLOptionElement*>(list_items[i])->value()));
- }
- }
-
- TrimWhitespace(value_, TRIM_LEADING, &value_);
-}
-
-FormField::FormField(const string16& label, const string16& name, const string16& value, const string16& form_control_type, int max_length, bool is_autofilled)
- : label_(label),
- name_(name),
- value_(value),
- form_control_type_(form_control_type),
- max_length_(max_length),
- is_autofilled_(is_autofilled) {
-}
-
-FormField::~FormField() {
-}
-
-bool FormField::operator==(const FormField& field) const {
- // A FormField stores a value, but the value is not part of the identity of
- // the field, so we don't want to compare the values.
- return (label_ == field.label_ &&
- name_ == field.name_ &&
- form_control_type_ == field.form_control_type_ &&
- max_length_ == field.max_length_);
-}
-
-bool FormField::operator!=(const FormField& field) const {
- return !operator==(field);
-}
-
-bool FormField::StrictlyEqualsHack(const FormField& field) const {
- return (label_ == field.label_ &&
- name_ == field.name_ &&
- value_ == field.value_ &&
- form_control_type_ == field.form_control_type_ &&
- max_length_ == field.max_length_);
-}
-
-std::ostream& operator<<(std::ostream& os, const FormField& field) {
- return os
- << UTF16ToUTF8(field.label())
- << " "
- << UTF16ToUTF8(field.name())
- << " "
- << UTF16ToUTF8(field.value())
- << " "
- << UTF16ToUTF8(field.form_control_type())
- << " "
- << field.max_length();
-}
-
-} // namespace webkit_glue
diff --git a/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.h b/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.h
deleted file mode 100644
index c5e3ecc..0000000
--- a/WebKit/android/WebCoreSupport/autofill/FormFieldAndroid.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (c) 2010 The Chromium Authors. All rights reserved.
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef FormFieldAndroid_h
-#define FormFieldAndroid_h
-
-#include <base/string16.h>
-#include <vector>
-
-// TODO: This file is taken from chromium/webkit/glue/form_field.h and
-// customised to use WebCore types rather than WebKit API types. It would
-// be nice and would ease future merge pain if the two could be combined.
-
-namespace WebCore {
-class HTMLFormControlElement;
-}
-
-namespace webkit_glue {
-
-// Stores information about a field in a form.
-class FormField {
-public:
- FormField();
- explicit FormField(const WebCore::HTMLFormControlElement& element);
- FormField(const string16& label, const string16& name, const string16& value, const string16& form_control_type, int max_length, bool is_autofilled);
- virtual ~FormField();
-
- const string16& label() const { return label_; }
- const string16& name() const { return name_; }
- const string16& value() const { return value_; }
- const string16& form_control_type() const { return form_control_type_; }
- int max_length() const { return max_length_; }
- bool is_autofilled() const { return is_autofilled_; }
-
- // Returns option string for elements for which they make sense (select-one,
- // for example) for the rest of elements return an empty array.
- const std::vector<string16>& option_strings() const { return option_strings_; }
-
- void set_label(const string16& label) { label_ = label; }
- void set_name(const string16& name) { name_ = name; }
- void set_value(const string16& value) { value_ = value; }
- void set_form_control_type(const string16& form_control_type) { form_control_type_ = form_control_type; }
- void set_max_length(int max_length) { max_length_ = max_length; }
- void set_autofilled(bool is_autofilled) { is_autofilled_ = is_autofilled; }
- void set_option_strings(const std::vector<string16>& strings) { option_strings_ = strings; }
-
- // Equality tests for identity which does not include |value_| or |size_|.
- // Use |StrictlyEqualsHack| method to test all members.
- // TODO: These operators need to be revised when we implement field
- // ids.
- bool operator==(const FormField& field) const;
- bool operator!=(const FormField& field) const;
-
- // Test equality of all data members.
- // TODO: This will be removed when we implement field ids.
- bool StrictlyEqualsHack(const FormField& field) const;
-
-private:
- string16 label_;
- string16 name_;
- string16 value_;
- string16 form_control_type_;
- int max_length_;
- bool is_autofilled_;
- std::vector<string16> option_strings_;
-};
-
-// So we can compare FormFields with EXPECT_EQ().
-std::ostream& operator<<(std::ostream& os, const FormField& field);
-
-} // namespace webkit_glue
-
-#endif // WEBKIT_GLUE_FORM_FIELD_H_
diff --git a/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.cpp b/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.cpp
deleted file mode 100644
index 9652794..0000000
--- a/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.cpp
+++ /dev/null
@@ -1,871 +0,0 @@
-/*
- * Copyright (c) 2010 The Chromium Authors. All rights reserved.
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "FormManagerAndroid.h"
-
-#include "DocumentLoader.h"
-#include "Element.h"
-#include "Frame.h"
-#include "FrameLoader.h"
-#include "HTMLCollection.h"
-#include "HTMLFormControlElement.h"
-#include "HTMLFormElement.h"
-#include "HTMLInputElement.h"
-#include "HTMLLabelElement.h"
-#include "HTMLNames.h"
-#include "HTMLOptionElement.h"
-#include "HTMLSelectElement.h"
-#include "Node.h"
-#include "NodeList.h"
-#include "HTMLCollection.h"
-#include "FormAssociatedElement.h"
-#include "FormFieldAndroid.h"
-#include "QualifiedName.h"
-#include "StringUtils.h"
-
-// TODO: This file is taken from chromium/chrome/renderer/form_manager.cc and
-// customised to use WebCore types rather than WebKit API types. It would be
-// nice and would ease future merge pain if the two could be combined.
-
-using webkit_glue::FormData;
-using webkit_glue::FormField;
-using WebCore::Element;
-using WebCore::FormAssociatedElement;
-using WebCore::HTMLCollection;
-using WebCore::HTMLElement;
-using WebCore::HTMLFormControlElement;
-using WebCore::HTMLFormElement;
-using WebCore::HTMLInputElement;
-using WebCore::HTMLLabelElement;
-using WebCore::HTMLOptionElement;
-using WebCore::HTMLSelectElement;
-using WebCore::Node;
-using WebCore::NodeList;
-
-using namespace WebCore::HTMLNames;
-
-namespace {
-
-// The number of fields required by AutoFill. Ideally we could send the forms
-// to AutoFill no matter how many fields are in the forms; however, finding the
-// label for each field is a costly operation and we can't spare the cycles if
-// it's not necessary.
-// Note the on ANDROID we reduce this from Chromium's 3 as it allows us to
-// autofill simple name/email forms for example. This improves the mobile
-// device experience where form filling can be time consuming and frustrating.
-const size_t kRequiredAutoFillFields = 2;
-
-// The maximum length allowed for form data.
-const size_t kMaxDataLength = 1024;
-
-// This is a helper function for the FindChildText() function.
-// Returns the aggregated values of the descendants or siblings of |node| that
-// are non-empty text nodes. This is a faster alternative to |innerText()| for
-// performance critical operations. It does a full depth-first search so
-// can be used when the structure is not directly known. The text is
-// accumulated after the whitespace has been stropped. Search depth is limited
-// with the |depth| parameter.
-string16 FindChildTextInner(Node* node, int depth) {
- string16 element_text;
- if (!node || depth <= 0)
- return element_text;
-
- string16 node_text = WTFStringToString16(node->nodeValue());
- TrimWhitespace(node_text, TRIM_ALL, &node_text);
- if (!node_text.empty())
- element_text = node_text;
-
- string16 child_text = FindChildTextInner(node->firstChild(), depth-1);
- if (!child_text.empty())
- element_text = element_text + child_text;
-
- string16 sibling_text = FindChildTextInner(node->nextSibling(), depth-1);
- if (!sibling_text.empty())
- element_text = element_text + sibling_text;
-
- return element_text;
-}
-
-// Returns the node value of the first decendant of |element| that is a
-// non-empty text node. "Non-empty" in this case means non-empty after the
-// whitespace has been stripped. Search is limited to withing 10 siblings and/or
-// descendants.
-string16 FindChildText(Element* element) {
- Node* child = element->firstChild();
-
- const int kChildSearchDepth = 10;
- return FindChildTextInner(child, kChildSearchDepth);
-}
-
-string16 InferLabelFromPrevious(const HTMLFormControlElement& element) {
- string16 inferred_label;
- Node* previous = element.previousSibling();
- if (!previous)
- return string16();
-
- if (previous->isTextNode()) {
- inferred_label = WTFStringToString16(previous->nodeValue());
- TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label);
- }
-
- // If we didn't find text, check for previous paragraph.
- // Eg. <p>Some Text</p><input ...>
- // Note the lack of whitespace between <p> and <input> elements.
- if (inferred_label.empty() && previous->isElementNode()) {
- Element* element = static_cast<Element*>(previous);
- if (element->hasTagName(pTag))
- inferred_label = FindChildText(element);
- }
-
- // If we didn't find paragraph, check for previous paragraph to this.
- // Eg. <p>Some Text</p> <input ...>
- // Note the whitespace between <p> and <input> elements.
- if (inferred_label.empty()) {
- Node* sibling = previous->previousSibling();
- if (sibling && sibling->isElementNode()) {
- Element* element = static_cast<Element*>(sibling);
- if (element->hasTagName(pTag))
- inferred_label = FindChildText(element);
- }
- }
-
- // Look for text node prior to <img> tag.
- // Eg. Some Text<img/><input ...>
- if (inferred_label.empty()) {
- while (inferred_label.empty() && previous) {
- if (previous->isTextNode()) {
- inferred_label = WTFStringToString16(previous->nodeValue());
- TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label);
- } else if (previous->isElementNode()) {
- Element* element = static_cast<Element*>(previous);
- if (!element->hasTagName(imgTag))
- break;
- } else
- break;
- previous = previous->previousSibling();
- }
- }
-
- // Look for label node prior to <input> tag.
- // Eg. <label>Some Text</label><input ...>
- if (inferred_label.empty()) {
- while (inferred_label.empty() && previous) {
- if (previous->isTextNode()) {
- inferred_label = WTFStringToString16(previous->nodeValue());
- TrimWhitespace(inferred_label, TRIM_ALL, &inferred_label);
- } else if (previous->isElementNode()) {
- Element* element = static_cast<Element*>(previous);
- if (element->hasTagName(labelTag)) {
- inferred_label = FindChildText(element);
- } else {
- break;
- }
- } else {
- break;
- }
-
- previous = previous->previousSibling();
- }
- }
-
- return inferred_label;
-}
-
-// Helper for |InferLabelForElement()| that infers a label, if possible, from
-// surrounding table structure.
-// Eg. <tr><td>Some Text</td><td><input ...></td></tr>
-// Eg. <tr><td><b>Some Text</b></td><td><b><input ...></b></td></tr>
-string16 InferLabelFromTable(const HTMLFormControlElement& element) {
- string16 inferred_label;
- Node* parent = element.parentNode();
- while (parent && parent->isElementNode() && !static_cast<Element*>(parent)->hasTagName(tdTag))
- parent = parent->parentNode();
-
- // Check all previous siblings, skipping non-element nodes, until we find a
- // non-empty text block.
- Node* previous = parent;
- while(previous) {
- if (previous->isElementNode()) {
- Element* e = static_cast<Element*>(previous);
- if (e->hasTagName(tdTag)) {
- inferred_label = FindChildText(e);
- if (!inferred_label.empty())
- break;
- }
- }
- previous = previous->previousSibling();
- }
- return inferred_label;
-}
-
-// Helper for |InferLabelForElement()| that infers a label, if possible, from
-// a surrounding div table.
-// Eg. <div>Some Text<span><input ...></span></div>
-string16 InferLabelFromDivTable(const HTMLFormControlElement& element) {
- Node* parent = element.parentNode();
- while (parent && parent->isElementNode() && !static_cast<Element*>(parent)->hasTagName(divTag))
- parent = parent->parentNode();
-
- if (!parent || !parent->isElementNode())
- return string16();
-
- Element* e = static_cast<Element*>(parent);
- if (!e || !e->hasTagName(divTag))
- return string16();
-
- return FindChildText(e);
-}
-
-// Helper for |InferLabelForElement()| that infers a label, if possible, from
-// a surrounding definition list.
-// Eg. <dl><dt>Some Text</dt><dd><input ...></dd></dl>
-// Eg. <dl><dt><b>Some Text</b></dt><dd><b><input ...></b></dd></dl>
-string16 InferLabelFromDefinitionList(const HTMLFormControlElement& element) {
- string16 inferred_label;
- Node* parent = element.parentNode();
- while (parent && parent->isElementNode() && !static_cast<Element*>(parent)->hasTagName(ddTag))
- parent = parent->parentNode();
-
- if (parent && parent->isElementNode()) {
- Element* element = static_cast<Element*>(parent);
- if (element->hasTagName(ddTag)) {
- Node* previous = parent->previousSibling();
-
- // Skip by any intervening text nodes.
- while (previous && previous->isTextNode())
- previous = previous->previousSibling();
-
- if (previous && previous->isElementNode()) {
- element = static_cast<Element*>(previous);
- if (element->hasTagName(dtTag))
- inferred_label = FindChildText(element);
- }
- }
- }
- return inferred_label;
-}
-
-void GetOptionStringsFromElement(HTMLFormControlElement* element, std::vector<string16>* option_strings) {
- DCHECK(element);
- DCHECK(option_strings);
- option_strings->clear();
- if (formControlType(*element) == kSelectOne) {
- HTMLSelectElement* select_element = static_cast<HTMLSelectElement*>(element);
-
- // For select-one elements copy option strings.
- WTF::Vector<Element*> list_items = select_element->listItems();
- option_strings->reserve(list_items.size());
- for (size_t i = 0; i < list_items.size(); ++i) {
- if (list_items[i]->hasTagName(optionTag))
- option_strings->push_back(WTFStringToString16(static_cast<HTMLOptionElement*>(list_items[i])->value()));
- }
- }
-}
-
-} // namespace
-
-namespace android {
-
-struct FormManager::FormElement {
- RefPtr<HTMLFormElement> form_element;
- std::vector<RefPtr<HTMLFormControlElement> > control_elements;
- std::vector<string16> control_values;
-};
-
-FormManager::FormManager() {
-}
-
-FormManager::~FormManager() {
- Reset();
-}
-
-// static
-void FormManager::HTMLFormControlElementToFormField(HTMLFormControlElement* element, ExtractMask extract_mask, FormField* field) {
- DCHECK(field);
-
- // The label is not officially part of a HTMLFormControlElement; however, the
- // labels for all form control elements are scraped from the DOM and set in
- // WebFormElementToFormData.
- field->set_name(nameForAutoFill(*element));
- field->set_form_control_type(formControlType(*element));
-
- if (extract_mask & EXTRACT_OPTIONS) {
- std::vector<string16> option_strings;
- GetOptionStringsFromElement(element, &option_strings);
- field->set_option_strings(option_strings);
- }
-
- if (formControlType(*element) == kText) {
- HTMLInputElement* input_element = static_cast<HTMLInputElement*>(element);
- field->set_max_length(input_element->maxLength());
- field->set_autofilled(input_element->isAutofilled());
- }
-
- if (!(extract_mask & EXTRACT_VALUE))
- return;
-
- // TODO: In WebKit, move value() and setValue() to
- // WebFormControlElement.
- string16 value;
- if (formControlType(*element) == kText ||
- formControlType(*element) == kHidden) {
- HTMLInputElement* input_element = static_cast<HTMLInputElement*>(element);
- value = WTFStringToString16(input_element->value());
- } else if (formControlType(*element) == kSelectOne) {
- HTMLSelectElement* select_element = static_cast<HTMLSelectElement*>(element);
- value = WTFStringToString16(select_element->value());
-
- // Convert the |select_element| value to text if requested.
- if (extract_mask & EXTRACT_OPTION_TEXT) {
- Vector<Element*> list_items = select_element->listItems();
- for (size_t i = 0; i < list_items.size(); ++i) {
- if (list_items[i]->hasTagName(optionTag) &&
- WTFStringToString16(static_cast<HTMLOptionElement*>(list_items[i])->value()) == value) {
- value = WTFStringToString16(static_cast<HTMLOptionElement*>(list_items[i])->text());
- break;
- }
- }
- }
- }
-
- // TODO: This is a temporary stop-gap measure designed to prevent
- // a malicious site from DOS'ing the browser with extremely large profile
- // data. The correct solution is to parse this data asynchronously.
- // See http://crbug.com/49332.
- if (value.size() > kMaxDataLength)
- value = value.substr(0, kMaxDataLength);
-
- field->set_value(value);
-}
-
-// static
-string16 FormManager::LabelForElement(const HTMLFormControlElement& element) {
- // Don't scrape labels for hidden elements.
- if (formControlType(element) == kHidden)
- return string16();
-
- RefPtr<NodeList> labels = element.document()->getElementsByTagName("label");
- for (unsigned i = 0; i < labels->length(); ++i) {
- Node* e = labels->item(i);
- if (e->hasTagName(labelTag)) {
- HTMLLabelElement* label = static_cast<HTMLLabelElement*>(e);
- if (label->control() == &element)
- return FindChildText(label);
- }
- }
-
- // Infer the label from context if not found in label element.
- return FormManager::InferLabelForElement(element);
-}
-
-// static
-bool FormManager::HTMLFormElementToFormData(HTMLFormElement* element, RequirementsMask requirements, ExtractMask extract_mask, FormData* form) {
- DCHECK(form);
-
- Frame* frame = element->document()->frame();
- if (!frame)
- return false;
-
- if (requirements & REQUIRE_AUTOCOMPLETE && !element->autoComplete())
- return false;
-
- form->name = WTFStringToString16(element->name());
- form->method = WTFStringToString16(element->method());
- form->origin = GURL(WTFStringToString16(frame->loader()->documentLoader()->url().string()));
- form->action = GURL(WTFStringToString16(frame->document()->completeURL(element->action())));
- form->user_submitted = element->wasUserSubmitted();
-
- // If the completed URL is not valid, just use the action we get from
- // WebKit.
- if (!form->action.is_valid())
- form->action = GURL(WTFStringToString16(element->action()));
-
- // A map from a FormField's name to the FormField itself.
- std::map<string16, FormField*> name_map;
-
- // The extracted FormFields. We use pointers so we can store them in
- // |name_map|.
- ScopedVector<FormField> form_fields;
-
- WTF::Vector<WebCore::FormAssociatedElement*> control_elements = element->associatedElements();
-
- // A vector of bools that indicate whether each field in the form meets the
- // requirements and thus will be in the resulting |form|.
- std::vector<bool> fields_extracted(control_elements.size(), false);
-
- for (size_t i = 0; i < control_elements.size(); ++i) {
- if (!control_elements[i]->isFormControlElement())
- continue;
-
- HTMLFormControlElement* control_element = static_cast<HTMLFormControlElement*>(control_elements[i]);
- if (!(control_element->hasTagName(inputTag) || control_element->hasTagName(selectTag)))
- continue;
-
- if (requirements & REQUIRE_AUTOCOMPLETE &&
- formControlType(*control_element) == kText) {
- const WebCore::HTMLInputElement* input_element = static_cast<const WebCore::HTMLInputElement*>(control_element);
- if (!input_element->autoComplete())
- continue;
- }
-
- if (requirements & REQUIRE_ENABLED && !control_element->isEnabledFormControl())
- continue;
-
- // Create a new FormField, fill it out and map it to the field's name.
- FormField* field = new FormField;
- HTMLFormControlElementToFormField(control_element, extract_mask, field);
- form_fields.push_back(field);
- // TODO: A label element is mapped to a form control element's id.
- // field->name() will contain the id only if the name does not exist. Add
- // an id() method to HTMLFormControlElement and use that here.
- name_map[field->name()] = field;
- fields_extracted[i] = true;
- }
-
- // Don't extract field labels if we have no fields.
- if (form_fields.empty())
- return false;
-
- // Loop through the label elements inside the form element. For each label
- // element, get the corresponding form control element, use the form control
- // element's name as a key into the <name, FormField> map to find the
- // previously created FormField and set the FormField's label to the
- // label.firstChild().nodeValue() of the label element.
- RefPtr<WebCore::NodeList> labels = element->getElementsByTagName("label");
- for (unsigned i = 0; i < labels->length(); ++i) {
- HTMLLabelElement* label = static_cast<WebCore::HTMLLabelElement*>(labels->item(i));
- HTMLFormControlElement* field_element = label->control();
- if (!field_element || field_element->type() == "hidden")
- continue;
-
- std::map<string16, FormField*>::iterator iter =
- name_map.find(nameForAutoFill(*field_element));
- if (iter != name_map.end())
- iter->second->set_label(FindChildText(label));
- }
-
- // Loop through the form control elements, extracting the label text from the
- // DOM. We use the |fields_extracted| vector to make sure we assign the
- // extracted label to the correct field, as it's possible |form_fields| will
- // not contain all of the elements in |control_elements|.
- for (size_t i = 0, field_idx = 0; i < control_elements.size() && field_idx < form_fields.size(); ++i) {
- // This field didn't meet the requirements, so don't try to find a label for
- // it.
- if (!fields_extracted[i])
- continue;
-
- if (!control_elements[i]->isFormControlElement())
- continue;
-
- const HTMLFormControlElement* control_element = static_cast<HTMLFormControlElement*>(control_elements[i]);
- if (form_fields[field_idx]->label().empty())
- form_fields[field_idx]->set_label(FormManager::InferLabelForElement(*control_element));
-
- ++field_idx;
-
- }
- // Copy the created FormFields into the resulting FormData object.
- for (ScopedVector<FormField>::const_iterator iter = form_fields.begin(); iter != form_fields.end(); ++iter)
- form->fields.push_back(**iter);
-
- return true;
-}
-
-void FormManager::ExtractForms(Frame* frame) {
-
- ResetFrame(frame);
-
- WTF::PassRefPtr<HTMLCollection> web_forms = frame->document()->forms();
-
- for (size_t i = 0; i < web_forms->length(); ++i) {
- FormElement* form_element = new FormElement;
- HTMLFormElement* html_form_element = static_cast<HTMLFormElement*>(web_forms->item(i));
- form_element->form_element = html_form_element;
-
- WTF::Vector<FormAssociatedElement*> control_elements = html_form_element->associatedElements();
- for (size_t j = 0; j < control_elements.size(); ++j) {
- if (!control_elements[j]->isFormControlElement())
- continue;
-
- HTMLFormControlElement* element = static_cast<HTMLFormControlElement*>(control_elements[j]);
- form_element->control_elements.push_back(element);
-
- // Save original values of "select-one" inputs so we can restore them
- // when |ClearFormWithNode()| is invoked.
- if (formControlType(*element) == kSelectOne) {
- HTMLSelectElement* select_element = static_cast<HTMLSelectElement*>(element);
- string16 value = WTFStringToString16(select_element->value());
- form_element->control_values.push_back(value);
- } else
- form_element->control_values.push_back(string16());
- }
-
- form_elements_.push_back(form_element);
- }
-}
-
-void FormManager::GetFormsInFrame(const Frame* frame, RequirementsMask requirements, std::vector<FormData>* forms) {
- DCHECK(frame);
- DCHECK(forms);
-
- for (FormElementList::const_iterator form_iter = form_elements_.begin(); form_iter != form_elements_.end(); ++form_iter) {
- FormElement* form_element = *form_iter;
-
- if (form_element->form_element->document()->frame() != frame)
- continue;
-
- // We need at least |kRequiredAutoFillFields| fields before appending this
- // form to |forms|.
- if (form_element->control_elements.size() < kRequiredAutoFillFields)
- continue;
-
- if (requirements & REQUIRE_AUTOCOMPLETE && !form_element->form_element->autoComplete())
- continue;
-
- FormData form;
- HTMLFormElementToFormData(form_element->form_element.get(), requirements, EXTRACT_VALUE, &form);
- if (form.fields.size() >= kRequiredAutoFillFields)
- forms->push_back(form);
- }
-}
-
-bool FormManager::FindFormWithFormControlElement(HTMLFormControlElement* element, RequirementsMask requirements, FormData* form) {
- DCHECK(form);
-
- const Frame* frame = element->document()->frame();
- if (!frame)
- return false;
-
- for (FormElementList::const_iterator iter = form_elements_.begin(); iter != form_elements_.end(); ++iter) {
- const FormElement* form_element = *iter;
-
- if (form_element->form_element->document()->frame() != frame)
- continue;
-
- for (std::vector<RefPtr<HTMLFormControlElement> >::const_iterator iter = form_element->control_elements.begin(); iter != form_element->control_elements.end(); ++iter) {
- HTMLFormControlElement* candidate = iter->get();
- if (nameForAutoFill(*candidate) == nameForAutoFill(*element)) {
- ExtractMask extract_mask = static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS);
- return HTMLFormElementToFormData(form_element->form_element.get(), requirements, extract_mask, form);
- }
- }
- }
- return false;
-}
-
-bool FormManager::FillForm(const FormData& form, Node* node) {
- FormElement* form_element = NULL;
- if (!FindCachedFormElement(form, &form_element))
- return false;
-
- RequirementsMask requirements = static_cast<RequirementsMask>(REQUIRE_AUTOCOMPLETE | REQUIRE_ENABLED | REQUIRE_EMPTY);
- ForEachMatchingFormField(form_element, node, requirements, form, NewCallback(this, &FormManager::FillFormField));
-
- return true;
-}
-
-bool FormManager::PreviewForm(const FormData& form, Node* node) {
- FormElement* form_element = NULL;
- if (!FindCachedFormElement(form, &form_element))
- return false;
-
- RequirementsMask requirements = static_cast<RequirementsMask>(REQUIRE_AUTOCOMPLETE | REQUIRE_ENABLED | REQUIRE_EMPTY);
- ForEachMatchingFormField(form_element, node, requirements, form, NewCallback(this, &FormManager::PreviewFormField));
-
- return true;
-}
-
-bool FormManager::ClearFormWithNode(Node* node) {
- FormElement* form_element = NULL;
- if (!FindCachedFormElementWithNode(node, &form_element))
- return false;
-
- for (size_t i = 0; i < form_element->control_elements.size(); ++i) {
- HTMLFormControlElement* element = form_element->control_elements[i].get();
- if (formControlType(*element) == kText) {
- HTMLInputElement* input_element = static_cast<HTMLInputElement*>(element);
-
- // We don't modify the value of disabled fields.
- if (!input_element->isEnabledFormControl())
- continue;
-
- input_element->setValue("");
- input_element->setAutofilled(false);
- // Clearing the value in the focused node (above) can cause selection
- // to be lost. We force selection range to restore the text cursor.
- if (node == input_element) {
- int length = input_element->value().length();
- input_element->setSelectionRange(length, length);
- }
- } else if (formControlType(*element) == kSelectOne) {
- HTMLSelectElement* select_element = static_cast<HTMLSelectElement*>(element);
- select_element->setValue(form_element->control_values[i].c_str());
- }
- }
-
- return true;
-}
-
-bool FormManager::ClearPreviewedFormWithNode(Node* node, bool was_autofilled) {
- FormElement* form_element = NULL;
- if (!FindCachedFormElementWithNode(node, &form_element))
- return false;
-
- for (size_t i = 0; i < form_element->control_elements.size(); ++i) {
- HTMLFormControlElement* element = form_element->control_elements[i].get();
-
- // Only input elements can be previewed.
- if (formControlType(*element) != kText)
- continue;
-
- // If the input element has not been auto-filled, FormManager has not
- // previewed this field, so we have nothing to reset.
- HTMLInputElement* input_element = static_cast<HTMLInputElement*>(element);
- if (!input_element->isAutofilled())
- continue;
-
- // There might be unrelated elements in this form which have already been
- // auto-filled. For example, the user might have already filled the address
- // part of a form and now be dealing with the credit card section. We only
- // want to reset the auto-filled status for fields that were previewed.
- if (input_element->suggestedValue().isEmpty())
- continue;
-
- // Clear the suggested value. For the initiating node, also restore the
- // original value.
- input_element->setSuggestedValue("");
- bool is_initiating_node = (node == input_element);
- if (is_initiating_node) {
- // Call |setValue()| to force the renderer to update the field's displayed
- // value.
- input_element->setValue(input_element->value());
- input_element->setAutofilled(was_autofilled);
- } else {
- input_element->setAutofilled(false);
- }
-
- // Clearing the suggested value in the focused node (above) can cause
- // selection to be lost. We force selection range to restore the text
- // cursor.
- if (is_initiating_node) {
- int length = input_element->value().length();
- input_element->setSelectionRange(length, length);
- }
- }
-
- return true;
-}
-
-void FormManager::Reset() {
- STLDeleteElements(&form_elements_);
-}
-
-void FormManager::ResetFrame(const Frame* frame) {
- FormElementList::iterator iter = form_elements_.begin();
- while (iter != form_elements_.end()) {
- if ((*iter)->form_element->document()->frame() == frame) {
- delete *iter;
- iter = form_elements_.erase(iter);
- } else
- ++iter;
- }
-}
-
-bool FormManager::FormWithNodeIsAutoFilled(Node* node) {
- FormElement* form_element = NULL;
- if (!FindCachedFormElementWithNode(node, &form_element))
- return false;
-
- for (size_t i = 0; i < form_element->control_elements.size(); ++i) {
- HTMLFormControlElement* element = form_element->control_elements[i].get();
- if (formControlType(*element) != kText)
- continue;
-
- HTMLInputElement* input_element = static_cast<HTMLInputElement*>(element);
- if (input_element->isAutofilled())
- return true;
- }
-
- return false;
-}
-
-// static
-string16 FormManager::InferLabelForElement(const HTMLFormControlElement& element) {
- // Don't scrape labels for hidden elements.
- if (formControlType(element) == kHidden)
- return string16();
-
- string16 inferred_label = InferLabelFromPrevious(element);
-
- // If we didn't find a label, check for table cell case.
- if (inferred_label.empty())
- inferred_label = InferLabelFromTable(element);
-
- // If we didn't find a label, check for div table case.
- if (inferred_label.empty())
- inferred_label = InferLabelFromDivTable(element);
-
- // If we didn't find a label, check for definition list case.
- if (inferred_label.empty())
- inferred_label = InferLabelFromDefinitionList(element);
-
- return inferred_label;
-}
-
-bool FormManager::FindCachedFormElementWithNode(Node* node,
- FormElement** form_element) {
- for (FormElementList::const_iterator form_iter = form_elements_.begin(); form_iter != form_elements_.end(); ++form_iter) {
- for (std::vector<RefPtr<HTMLFormControlElement> >::const_iterator iter = (*form_iter)->control_elements.begin(); iter != (*form_iter)->control_elements.end(); ++iter) {
- if (iter->get() == node) {
- *form_element = *form_iter;
- return true;
- }
- }
- }
-
- return false;
-}
-
-bool FormManager::FindCachedFormElement(const FormData& form, FormElement** form_element) {
- for (FormElementList::iterator form_iter = form_elements_.begin(); form_iter != form_elements_.end(); ++form_iter) {
- // TODO: matching on form name here which is not guaranteed to
- // be unique for the page, nor is it guaranteed to be non-empty. Need to
- // find a way to uniquely identify the form cross-process. For now we'll
- // check form name and form action for identity.
- // http://crbug.com/37990 test file sample8.html.
- // Also note that WebString() == WebString(string16()) does not seem to
- // evaluate to |true| for some reason TBD, so forcing to string16.
- string16 element_name(WTFStringToString16((*form_iter)->form_element->name()));
- GURL action(WTFStringToString16((*form_iter)->form_element->document()->completeURL((*form_iter)->form_element->action()).string()));
- if (element_name == form.name && action == form.action) {
- *form_element = *form_iter;
- return true;
- }
- }
-
- return false;
-}
-
-
-void FormManager::ForEachMatchingFormField(FormElement* form, Node* node, RequirementsMask requirements, const FormData& data, Callback* callback) {
- // It's possible that the site has injected fields into the form after the
- // page has loaded, so we can't assert that the size of the cached control
- // elements is equal to the size of the fields in |form|. Fortunately, the
- // one case in the wild where this happens, paypal.com signup form, the fields
- // are appended to the end of the form and are not visible.
- for (size_t i = 0, j = 0; i < form->control_elements.size() && j < data.fields.size(); ++i) {
- HTMLFormControlElement* element = form->control_elements[i].get();
- string16 element_name = nameForAutoFill(*element);
-
- if (element_name.empty())
- continue;
-
- // Search forward in the |form| for a corresponding field.
- size_t k = j;
- while (k < data.fields.size() && element_name != data.fields[k].name())
- k++;
-
- if (k >= data.fields.size())
- continue;
-
- DCHECK_EQ(data.fields[k].name(), element_name);
-
- bool is_initiating_node = false;
-
- // More than likely |requirements| will contain REQUIRE_AUTOCOMPLETE and/or
- // REQUIRE_EMPTY, which both require text form control elements, so special-
- // case this type of element.
- if (formControlType(*element) == kText) {
- HTMLInputElement* input_element = static_cast<HTMLInputElement*>(element);
-
- // TODO: WebKit currently doesn't handle the autocomplete
- // attribute for select control elements, but it probably should.
- if (requirements & REQUIRE_AUTOCOMPLETE && !input_element->autoComplete())
- continue;
-
- is_initiating_node = (input_element == node);
- // Don't require the node that initiated the auto-fill process to be
- // empty. The user is typing in this field and we should complete the
- // value when the user selects a value to fill out.
- if (requirements & REQUIRE_EMPTY && !is_initiating_node && !input_element->value().isEmpty())
- continue;
- }
-
- if (requirements & REQUIRE_ENABLED && !element->isEnabledFormControl())
- continue;
-
- callback->Run(element, &data.fields[k], is_initiating_node);
-
- // We found a matching form field so move on to the next.
- ++j;
- }
-
- delete callback;
-}
-
-void FormManager::FillFormField(HTMLFormControlElement* field, const FormField* data, bool is_initiating_node) {
- // Nothing to fill.
- if (data->value().empty())
- return;
-
- if (formControlType(*field) == kText) {
- HTMLInputElement* input_element = static_cast<HTMLInputElement*>(field);
-
- // If the maxlength attribute contains a negative value, maxLength()
- // returns the default maxlength value.
- input_element->setValue(data->value().substr(0, input_element->maxLength()).c_str());
- input_element->setAutofilled(true);
- if (is_initiating_node) {
- int length = input_element->value().length();
- input_element->setSelectionRange(length, length);
- }
- } else if (formControlType(*field) == kSelectOne) {
- HTMLSelectElement* select_element = static_cast<HTMLSelectElement*>(field);
- select_element->setValue(data->value().c_str());
- }
-}
-
-void FormManager::PreviewFormField(HTMLFormControlElement* field, const FormField* data, bool is_initiating_node) {
- // Nothing to preview.
- if (data->value().empty())
- return;
-
- // Only preview input fields.
- if (formControlType(*field) != kText)
- return;
-
- HTMLInputElement* input_element = static_cast<HTMLInputElement*>(field);
-
- // If the maxlength attribute contains a negative value, maxLength()
- // returns the default maxlength value.
- input_element->setSuggestedValue(data->value().substr(0, input_element->maxLength()).c_str());
- input_element->setAutofilled(true);
- if (is_initiating_node)
- input_element->setSelectionRange(0, input_element->suggestedValue().length());
-}
-
-}
diff --git a/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.h b/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.h
deleted file mode 100644
index e844981..0000000
--- a/WebKit/android/WebCoreSupport/autofill/FormManagerAndroid.h
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright (c) 2010 The Chromium Authors. All rights reserved.
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef FormManagerAndroid_h
-#define FormManagerAndroid_h
-
-#include "ChromiumIncludes.h"
-
-#include <map>
-#include <vector>
-
-// TODO: This file is taken from chromium/chrome/renderer/form_manager.h and
-// customised to use WebCore types rather than WebKit API types. It would be
-// nice and would ease future merge pain if the two could be combined.
-
-namespace webkit_glue {
-struct FormData;
-class FormField;
-} // namespace webkit_glue
-
-namespace WebCore {
-class Frame;
-class HTMLFormControlElement;
-class HTMLFormElement;
-class Node;
-}
-
-using WebCore::Frame;
-using WebCore::HTMLFormControlElement;
-using WebCore::HTMLFormElement;
-using WebCore::Node;
-
-namespace android {
-
-// Manages the forms in a Document.
-class FormManager {
-public:
- // A bit field mask for form requirements.
- enum RequirementsMask {
- REQUIRE_NONE = 0, // No requirements.
- REQUIRE_AUTOCOMPLETE = 1 << 0, // Require that autocomplete != off.
- REQUIRE_ENABLED = 1 << 1, // Require that disabled attribute is off.
- REQUIRE_EMPTY = 1 << 2, // Require that the fields are empty.
- };
-
- // A bit field mask to extract data from HTMLFormControlElement.
- enum ExtractMask {
- EXTRACT_NONE = 0,
- EXTRACT_VALUE = 1 << 0, // Extract value from HTMLFormControlElement.
- EXTRACT_OPTION_TEXT = 1 << 1, // Extract option text from HTMLFormSelectElement. Only valid when |EXTRACT_VALUE| is set. This is used for form submission where humand readable value is captured.
- EXTRACT_OPTIONS = 1 << 2, // Extract options from HTMLFormControlElement.
- };
-
- FormManager();
- virtual ~FormManager();
-
- // Fills out a FormField object from a given HTMLFormControlElement.
- // |extract_mask|: See the enum ExtractMask above for details.
- static void HTMLFormControlElementToFormField(HTMLFormControlElement* element, ExtractMask extract_mask, webkit_glue::FormField* field);
-
- // Returns the corresponding label for |element|. WARNING: This method can
- // potentially be very slow. Do not use during any code paths where the page
- // is loading.
- static string16 LabelForElement(const HTMLFormControlElement& element);
-
- // Fills out a FormData object from a given WebFormElement. If |get_values|
- // is true, the fields in |form| will have the values filled out. Returns
- // true if |form| is filled out; it's possible that |element| won't meet the
- // requirements in |requirements|. This also returns false if there are no
- // fields in |form|.
- // TODO: Remove the user of this in RenderView and move this to
- // private.
- static bool HTMLFormElementToFormData(HTMLFormElement* element, RequirementsMask requirements, ExtractMask extract_mask, webkit_glue::FormData* form);
-
- // Scans the DOM in |frame| extracting and storing forms.
- void ExtractForms(Frame* frame);
-
- // Returns a vector of forms in |frame| that match |requirements|.
- void GetFormsInFrame(const Frame* frame, RequirementsMask requirements, std::vector<webkit_glue::FormData>* forms);
-
- // Finds the form that contains |element| and returns it in |form|. Returns
- // false if the form is not found.
- bool FindFormWithFormControlElement(HTMLFormControlElement* element, RequirementsMask requirements, webkit_glue::FormData* form);
-
- // Fills the form represented by |form|. |form| should have the name set to
- // the name of the form to fill out, and the number of elements and values
- // must match the number of stored elements in the form. |node| is the form
- // control element that initiated the auto-fill process.
- // TODO: Is matching on name alone good enough? It's possible to
- // store multiple forms with the same names from different frames.
- bool FillForm(const webkit_glue::FormData& form, Node* node);
-
- // Previews the form represented by |form|. |node| is the form control element
- // that initiated the preview process. Same conditions as FillForm.
- bool PreviewForm(const webkit_glue::FormData& form, Node* node);
-
- // Clears the values of all input elements in the form that contains |node|.
- // Returns false if the form is not found.
- bool ClearFormWithNode(Node* node);
-
- // Clears the placeholder values and the auto-filled background for any fields
- // in the form containing |node| that have been previewed. Resets the
- // autofilled state of |node| to |was_autofilled|. Returns false if the form
- // is not found.
- bool ClearPreviewedFormWithNode(Node* node, bool was_autofilled);
-
- // Resets the stored set of forms.
- void Reset();
-
- // Resets the forms for the specified |frame|.
- void ResetFrame(const Frame* frame);
-
- // Returns true if |form| has any auto-filled fields.
- bool FormWithNodeIsAutoFilled(Node* node);
-
-private:
- // Stores the HTMLFormElement and the form control elements for a form.
- // Original form values are stored so when we clear a form we can reset
- // "select-one" values to their original state.
- struct FormElement;
-
- // Type for cache of FormElement objects.
- typedef std::vector<FormElement*> FormElementList;
-
- // The callback type used by ForEachMatchingFormField().
- typedef Callback3<HTMLFormControlElement*, const webkit_glue::FormField*, bool>::Type Callback;
-
- // Infers corresponding label for |element| from surrounding context in the
- // DOM. Contents of preceeding <p> tag or preceeding text element found in
- // the form.
- static string16 InferLabelForElement(const HTMLFormControlElement& element);
-
- // Finds the cached FormElement that contains |node|.
- bool FindCachedFormElementWithNode(Node* node, FormElement** form_element);
-
- // Uses the data in |form| to find the cached FormElement.
- bool FindCachedFormElement(const webkit_glue::FormData& form, FormElement** form_element);
-
- // For each field in |data| that matches the corresponding field in |form|
- // and meets the |requirements|, |callback| is called with the actual
- // WebFormControlElement and the FormField data from |form|. The field that
- // matches |node| is not required to be empty if |requirements| includes
- // REQUIRE_EMPTY. This method owns |callback|.
- void ForEachMatchingFormField(FormElement* form, Node* node, RequirementsMask requirements, const webkit_glue::FormData& data, Callback* callback);
-
- // A ForEachMatchingFormField() callback that sets |field|'s value using the
- // value in |data|. This method also sets the autofill attribute, causing the
- // background to be yellow.
- void FillFormField(HTMLFormControlElement* field, const webkit_glue::FormField* data, bool is_initiating_node);
-
- // A ForEachMatchingFormField() callback that sets |field|'s placeholder value
- // using the value in |data|, causing the test to be greyed-out. This method
- // also sets the autofill attribute, causing the background to be yellow.
- void PreviewFormField(HTMLFormControlElement* field, const webkit_glue::FormField* data, bool is_initiaiting_node);
-
- // The cached FormElement objects.
- FormElementList form_elements_;
-
- DISALLOW_COPY_AND_ASSIGN(FormManager);
-};
-
-} // namespace android
-
-#endif // FormManagerAndroid_h
diff --git a/WebKit/android/WebCoreSupport/autofill/MainThreadProxy.cpp b/WebKit/android/WebCoreSupport/autofill/MainThreadProxy.cpp
deleted file mode 100644
index 598b9c4..0000000
--- a/WebKit/android/WebCoreSupport/autofill/MainThreadProxy.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#include "config.h"
-#include "MainThreadProxy.h"
-
-#include <wtf/MainThread.h>
-
-void MainThreadProxy::CallOnMainThread(CallOnMainThreadFunction f, void* c)
-{
- callOnMainThread(f, c);
-}
diff --git a/WebKit/android/WebCoreSupport/autofill/MainThreadProxy.h b/WebKit/android/WebCoreSupport/autofill/MainThreadProxy.h
deleted file mode 100644
index d9310bb..0000000
--- a/WebKit/android/WebCoreSupport/autofill/MainThreadProxy.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef MAIN_THREAD_PROXY_H
-#define MAIN_THREAD_PROXY_H
-
-typedef void CallOnMainThreadFunction(void*);
-
-class MainThreadProxy
-{
-public:
- static void CallOnMainThread(CallOnMainThreadFunction, void*);
-};
-
-#endif
diff --git a/WebKit/android/WebCoreSupport/autofill/StringUtils.h b/WebKit/android/WebCoreSupport/autofill/StringUtils.h
deleted file mode 100644
index aa408a5..0000000
--- a/WebKit/android/WebCoreSupport/autofill/StringUtils.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2010 The Android Open Source Project. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#ifndef AutoFillStringUtils_h_
-#define AutoFillStringUtils_h_
-
-#include "ChromiumIncludes.h"
-#include "HTMLFormControlElement.h"
-#include <wtf/text/WTFString.h>
-
-using WebCore::HTMLFormControlElement;
-
-const string16 kText = ASCIIToUTF16("text");
-const string16 kHidden = ASCIIToUTF16("hidden");
-const string16 kSelectOne = ASCIIToUTF16("select-one");
-
-inline string16 WTFStringToString16(const WTF::String& wtfString)
-{
- WTF::String str = wtfString;
-
- if (str.charactersWithNullTermination())
- return string16(str.charactersWithNullTermination());
- else
- return string16();
-}
-
-inline string16 nameForAutoFill(const HTMLFormControlElement& element)
-{
- // Taken from WebKit/chromium/src/WebFormControlElement.cpp, ported
- // to use WebCore types for accessing element properties.
- String name = element.name();
- String trimmedName = name.stripWhiteSpace();
- if (!trimmedName.isEmpty())
- return WTFStringToString16(trimmedName);
- name = element.getIdAttribute();
- trimmedName = name.stripWhiteSpace();
- if (!trimmedName.isEmpty())
- return WTFStringToString16(trimmedName);
- return string16();
-}
-
-inline string16 formControlType(const HTMLFormControlElement& element)
-{
- // Taken from WebKit/chromium/src/WebFormControlElement.cpp, ported
- // to use WebCore types for accessing element properties.
- return WTFStringToString16(element.type());
-}
-
-#endif
-
diff --git a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp
deleted file mode 100644
index a80636c..0000000
--- a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "WebAutoFill.h"
-
-#if ENABLE(WEB_AUTOFILL)
-
-#include "AutoFillHostAndroid.h"
-#include "Frame.h"
-#include "FormData.h"
-#include "FormManagerAndroid.h"
-#include "FrameLoader.h"
-#include "HTMLFormControlElement.h"
-#include "MainThreadProxy.h"
-#include "Node.h"
-#include "Page.h"
-#include "Settings.h"
-#include "WebFrame.h"
-#include "WebRequestContext.h"
-#include "WebUrlLoaderClient.h"
-#include "WebViewCore.h"
-
-#define NO_PROFILE_SET 0
-#define FORM_NOT_AUTOFILLABLE -1
-
-namespace android
-{
-WebAutoFill::WebAutoFill()
- : mQueryId(1)
- , mWebViewCore(0)
- , mLastSearchDomVersion(0)
- , mParsingForms(false)
-{
- mTabContents = new TabContents();
- setEmptyProfile();
-}
-
-void WebAutoFill::init()
-{
- if (mAutoFillManager)
- return;
-
- mFormManager = new FormManager();
- // We use the WebView's WebRequestContext, which may be a private browsing context.
- ASSERT(mWebViewCore);
- mAutoFillManager = new AutoFillManager(mTabContents.get());
- mAutoFillHost = new AutoFillHostAndroid(this);
- mTabContents->SetProfileRequestContext(new AndroidURLRequestContextGetter(mWebViewCore->webRequestContext(), WebUrlLoaderClient::ioThread()));
- mTabContents->SetAutoFillHost(mAutoFillHost.get());
-}
-
-WebAutoFill::~WebAutoFill()
-{
- cleanUpQueryMap();
- mUniqueIdMap.clear();
-}
-
-void WebAutoFill::cleanUpQueryMap()
-{
- for (AutoFillQueryFormDataMap::iterator it = mQueryMap.begin(); it != mQueryMap.end(); it++)
- delete it->second;
- mQueryMap.clear();
-}
-
-void WebAutoFill::searchDocument(WebCore::Frame* frame)
-{
- if (!enabled())
- return;
-
- MutexLocker lock(mFormsSeenMutex);
-
- init();
-
- cleanUpQueryMap();
- mUniqueIdMap.clear();
- mForms.clear();
- mQueryId = 1;
-
- ASSERT(mFormManager);
- ASSERT(mAutoFillManager);
-
- mAutoFillManager->Reset();
- mFormManager->Reset();
-
- mFormManager->ExtractForms(frame);
- mFormManager->GetFormsInFrame(frame, FormManager::REQUIRE_AUTOCOMPLETE, &mForms);
-
- // Needs to be done on a Chrome thread as it will make a URL request to the AutoFill server.
- // TODO: Use our own Autofill thread instead of the IO thread.
- // TODO: For now, block here. Would like to make this properly async.
- base::Thread* thread = WebUrlLoaderClient::ioThread();
- mParsingForms = true;
- thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &WebAutoFill::formsSeenImpl));
- while (mParsingForms)
- mFormsSeenCondition.wait(mFormsSeenMutex);
-}
-
-// Called on the Chromium IO thread.
-void WebAutoFill::formsSeenImpl()
-{
- MutexLocker lock(mFormsSeenMutex);
- mAutoFillManager->FormsSeen(mForms);
- mParsingForms = false;
- mFormsSeenCondition.signal();
-}
-
-void WebAutoFill::formFieldFocused(WebCore::HTMLFormControlElement* formFieldElement)
-{
- ASSERT(formFieldElement);
-
- Document* doc = formFieldElement->document();
- Frame* frame = doc->frame();
-
- // FIXME: AutoFill only works in main frame for now. Should consider
- // child frames.
- if (frame != frame->page()->mainFrame())
- return;
-
- unsigned domVersion = doc->domTreeVersion();
- ASSERT(domVersion > 0);
-
- if (mLastSearchDomVersion != domVersion) {
- // Need to extract forms as DOM version has changed since the last time
- // we searched.
- searchDocument(formFieldElement->document()->frame());
- mLastSearchDomVersion = domVersion;
- }
-
- if (!enabled()) {
- // In case that we've just been disabled and the last time we got autofill
- // suggestions and told Java about them, clear that bit Java side now
- // we're disabled.
- mWebViewCore->setWebTextViewAutoFillable(FORM_NOT_AUTOFILLABLE, string16());
- return;
- }
-
- // Get the FormField from the Node.
- webkit_glue::FormField* formField = new webkit_glue::FormField;
- FormManager::HTMLFormControlElementToFormField(formFieldElement, FormManager::EXTRACT_NONE, formField);
- formField->set_label(FormManager::LabelForElement(*formFieldElement));
-
- webkit_glue::FormData* form = new webkit_glue::FormData;
- mFormManager->FindFormWithFormControlElement(formFieldElement, FormManager::REQUIRE_AUTOCOMPLETE, form);
- mQueryMap[mQueryId] = new FormDataAndField(form, formField);
-
- bool suggestions = mAutoFillManager->GetAutoFillSuggestions(*form, *formField);
-
- mQueryId++;
- if (!suggestions) {
- ASSERT(mWebViewCore);
- // Tell Java no autofill suggestions for this form.
- mWebViewCore->setWebTextViewAutoFillable(FORM_NOT_AUTOFILLABLE, string16());
- return;
- }
-}
-
-void WebAutoFill::querySuccessful(const string16& value, const string16& label, int uniqueId)
-{
- if (!enabled())
- return;
-
- // Store the unique ID for the query and inform java that autofill suggestions for this form are available.
- // Pass java the queryId so that it can pass it back if the user decides to use autofill.
- mUniqueIdMap[mQueryId] = uniqueId;
-
- ASSERT(mWebViewCore);
- mWebViewCore->setWebTextViewAutoFillable(mQueryId, mAutoFillProfile->Label());
-}
-
-void WebAutoFill::fillFormFields(int queryId)
-{
- if (!enabled())
- return;
-
- webkit_glue::FormData* form = mQueryMap[queryId]->form();
- webkit_glue::FormField* field = mQueryMap[queryId]->field();
- ASSERT(form);
- ASSERT(field);
-
- AutoFillQueryToUniqueIdMap::iterator iter = mUniqueIdMap.find(queryId);
- if (iter == mUniqueIdMap.end()) {
- // The user has most likely tried to AutoFill the form again without
- // refocussing the form field. The UI should protect against this
- // but stop here to be certain.
- return;
- }
- mAutoFillManager->FillAutoFillFormData(queryId, *form, *field, iter->second);
- mUniqueIdMap.erase(iter);
-}
-
-void WebAutoFill::fillFormInPage(int queryId, const webkit_glue::FormData& form)
-{
- if (!enabled())
- return;
-
- // FIXME: Pass a pointer to the Node that triggered the AutoFill flow here instead of 0.
- // The consquence of passing 0 is that we should always fail the test in FormManader::ForEachMathcingFormField():169
- // that says "only overwrite an elements current value if the user triggered autofill through that element"
- // for elements that have a value already. But by a quirk of Android text views we are OK. We should still
- // fix this though.
- mFormManager->FillForm(form, 0);
-}
-
-bool WebAutoFill::enabled() const
-{
- Page* page = mWebViewCore->mainFrame()->page();
- return page ? page->settings()->autoFillEnabled() : false;
-}
-
-void WebAutoFill::setProfile(const string16& fullName, const string16& emailAddress, const string16& companyName,
- const string16& addressLine1, const string16& addressLine2, const string16& city,
- const string16& state, const string16& zipCode, const string16& country, const string16& phoneNumber)
-{
- if (!mAutoFillProfile)
- mAutoFillProfile.set(new AutoFillProfile());
-
- // Update the profile.
- // Constants for AutoFill field types are found in external/chromium/chrome/browser/autofill/field_types.h.
- mAutoFillProfile->SetInfo(AutoFillType(NAME_FULL), fullName);
- mAutoFillProfile->SetInfo(AutoFillType(EMAIL_ADDRESS), emailAddress);
- mAutoFillProfile->SetInfo(AutoFillType(COMPANY_NAME), companyName);
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), addressLine1);
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), addressLine2);
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), city);
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), state);
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), zipCode);
- mAutoFillProfile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), country);
- mAutoFillProfile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), phoneNumber);
-
- std::vector<AutoFillProfile> profiles;
- profiles.push_back(*mAutoFillProfile);
- updateProfileLabel();
- mTabContents->profile()->GetPersonalDataManager()->SetProfiles(&profiles);
-}
-
-bool WebAutoFill::updateProfileLabel()
-{
- std::vector<AutoFillProfile*> profiles;
- profiles.push_back(mAutoFillProfile.get());
- return AutoFillProfile::AdjustInferredLabels(&profiles);
-}
-
-void WebAutoFill::clearProfiles()
-{
- if (!mAutoFillProfile)
- return;
- // For now Chromium only ever knows about one profile, so we can just
- // remove it. If we support multiple profiles in the future
- // we need to remove them all here.
- std::string profileGuid = mAutoFillProfile->guid();
- mTabContents->profile()->GetPersonalDataManager()->RemoveProfile(profileGuid);
- setEmptyProfile();
-}
-
-void WebAutoFill::setEmptyProfile()
-{
- // Set an empty profile. This will ensure that when autofill is enabled,
- // we will still search the document for autofillable forms and inform
- // java of their presence so we can invite the user to set up
- // their own profile.
-
- // Chromium code will strip the values sent into the profile so we need them to be
- // at least one non-whitespace character long. We need to set all fields of the
- // profile to a non-empty string so that any field type can trigger the autofill
- // suggestion. AutoFill will not detect form fields if the profile value for that
- // field is an empty string.
- static const string16 empty = string16(ASCIIToUTF16("a"));
- setProfile(empty, empty, empty, empty, empty, empty, empty, empty, empty, empty);
-}
-
-}
-
-#endif
diff --git a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h b/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h
deleted file mode 100644
index 97e478e..0000000
--- a/WebKit/android/WebCoreSupport/autofill/WebAutoFill.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef WebAutoFill_h
-#define WebAutoFill_h
-
-#if ENABLE(WEB_AUTOFILL)
-
-#include "ChromiumIncludes.h"
-
-#include <map>
-#include <vector>
-#include <wtf/Noncopyable.h>
-#include <wtf/OwnPtr.h>
-#include <wtf/ThreadingPrimitives.h>
-
-class AutoFillManager;
-class AutoFillProfile;
-class AutoFillHost;
-
-namespace WebCore {
-class Frame;
-class HTMLFormControlElement;
-}
-
-namespace android
-{
-class FormManager;
-class WebViewCore;
-
-class FormDataAndField {
-public:
- FormDataAndField(webkit_glue::FormData* form, webkit_glue::FormField* field)
- : mForm(form)
- , mField(field)
- {
- }
-
- webkit_glue::FormData* form() { return mForm.get(); }
- webkit_glue::FormField* field() { return mField.get(); }
-
-private:
- OwnPtr<webkit_glue::FormData> mForm;
- OwnPtr<webkit_glue::FormField> mField;
-};
-
-class WebAutoFill : public Noncopyable
-{
-public:
- WebAutoFill();
- virtual ~WebAutoFill();
- void formFieldFocused(WebCore::HTMLFormControlElement*);
- void fillFormFields(int queryId);
- void querySuccessful(const string16& value, const string16& label, int uniqueId);
- void fillFormInPage(int queryId, const webkit_glue::FormData& form);
- void setWebViewCore(WebViewCore* webViewCore) { mWebViewCore = webViewCore; }
- bool enabled() const;
-
- void setProfile(const string16& fullName, const string16& emailAddress, const string16& companyName,
- const string16& addressLine1, const string16& addressLine2, const string16& city,
- const string16& state, const string16& zipCode, const string16& country, const string16& phoneNumber);
- void clearProfiles();
-
- bool updateProfileLabel();
-
- void reset() { mLastSearchDomVersion = 0; }
-
-private:
- void init();
- void searchDocument(WebCore::Frame*);
- void setEmptyProfile();
- void formsSeenImpl();
- void cleanUpQueryMap();
-
- OwnPtr<FormManager> mFormManager;
- OwnPtr<AutoFillManager> mAutoFillManager;
- OwnPtr<AutoFillHost> mAutoFillHost;
- OwnPtr<TabContents> mTabContents;
- OwnPtr<AutoFillProfile> mAutoFillProfile;
-
- typedef std::vector<webkit_glue::FormData, std::allocator<webkit_glue::FormData> > FormList;
- FormList mForms;
-
- typedef std::map<int, FormDataAndField*> AutoFillQueryFormDataMap;
- AutoFillQueryFormDataMap mQueryMap;
-
- typedef std::map<int, int> AutoFillQueryToUniqueIdMap;
- AutoFillQueryToUniqueIdMap mUniqueIdMap;
- int mQueryId;
-
- WebViewCore* mWebViewCore;
-
- unsigned mLastSearchDomVersion;
-
- WTF::Mutex mFormsSeenMutex; // Guards mFormsSeenCondition and mParsingForms.
- WTF::ThreadCondition mFormsSeenCondition;
- bool volatile mParsingForms;
-};
-
-}
-
-DISABLE_RUNNABLE_METHOD_REFCOUNT(android::WebAutoFill);
-
-#endif // ENABLE(WEB_AUTOFILL)
-#endif // WebAutoFill_h