summaryrefslogtreecommitdiffstats
path: root/webkit/glue/dom_operations.cc
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/glue/dom_operations.cc')
-rw-r--r--webkit/glue/dom_operations.cc165
1 files changed, 3 insertions, 162 deletions
diff --git a/webkit/glue/dom_operations.cc b/webkit/glue/dom_operations.cc
index aab6f36..2d0fb68 100644
--- a/webkit/glue/dom_operations.cc
+++ b/webkit/glue/dom_operations.cc
@@ -9,30 +9,28 @@
#include "base/compiler_specific.h"
#include "base/string_number_conversions.h"
#include "base/string_split.h"
+#include "base/string_util.h"
#include "third_party/WebKit/WebKit/chromium/public/WebAnimationController.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
#include "third_party/WebKit/WebKit/chromium/public/WebNodeCollection.h"
#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
-#include "webkit/glue/form_data.h"
-#include "webkit/glue/password_form_dom_manager.h"
-#include "webkit/glue/webpasswordautocompletelistener_impl.h"
using WebKit::WebAnimationController;
using WebKit::WebDocument;
using WebKit::WebElement;
-using WebKit::WebFormElement;
using WebKit::WebFrame;
using WebKit::WebInputElement;
using WebKit::WebNode;
using WebKit::WebNodeCollection;
using WebKit::WebNodeList;
+using WebKit::WebString;
using WebKit::WebVector;
using WebKit::WebView;
@@ -153,163 +151,6 @@ void GetAllSavableResourceLinksForFrame(WebFrame* current_frame,
namespace webkit_glue {
-// Map element name to a list of pointers to corresponding elements to simplify
-// form filling.
-typedef std::map<string16, WebKit::WebInputElement>
- FormInputElementMap;
-
-// Utility struct for form lookup and autofill. When we parse the DOM to lookup
-// a form, in addition to action and origin URL's we have to compare all
-// necessary form elements. To avoid having to look these up again when we want
-// to fill the form, the FindFormElements function stores the pointers
-// in a FormElements* result, referenced to ensure they are safe to use.
-struct FormElements {
- WebFormElement form_element;
- FormInputElementMap input_elements;
- FormElements() {
- }
-};
-
-typedef std::vector<FormElements*> FormElementsList;
-
-// Internal implementation of FillForm API.
-static bool FillFormImpl(FormElements* fe, const FormData& data) {
- if (!fe->form_element.autoComplete())
- return false;
-
- std::map<string16, string16> data_map;
- for (size_t i = 0; i < data.fields.size(); i++)
- data_map[data.fields[i].name()] = data.fields[i].value();
-
- for (FormInputElementMap::iterator it = fe->input_elements.begin();
- it != fe->input_elements.end(); ++it) {
- WebKit::WebInputElement& element = it->second;
- if (!element.value().isEmpty()) // Don't overwrite pre-filled values.
- continue;
- if (element.isPasswordField() &&
- (!element.isEnabledFormControl() || element.hasAttribute("readonly"))) {
- continue; // Don't fill uneditable password fields.
- }
- if (!element.isValidValue(data_map[it->first]))
- continue;
-
- element.setValue(data_map[it->first]);
- element.setAutofilled(true);
- element.dispatchFormControlChangeEvent();
- }
-
- return false;
-}
-
-// Helper to search the given form element for the specified input elements
-// in |data|, and add results to |result|.
-static bool FindFormInputElements(WebFormElement* fe,
- const FormData& data,
- FormElements* result) {
- // Loop through the list of elements we need to find on the form in
- // order to autofill it. If we don't find any one of them, abort
- // processing this form; it can't be the right one.
- for (size_t j = 0; j < data.fields.size(); j++) {
- WebVector<WebNode> temp_elements;
- fe->getNamedElements(data.fields[j].name(), temp_elements);
- if (temp_elements.isEmpty()) {
- // We didn't find a required element. This is not the right form.
- // Make sure no input elements from a partially matched form
- // in this iteration remain in the result set.
- // Note: clear will remove a reference from each InputElement.
- result->input_elements.clear();
- return false;
- }
- // This element matched, add it to our temporary result. It's possible
- // there are multiple matches, but for purposes of identifying the form
- // one suffices and if some function needs to deal with multiple
- // matching elements it can get at them through the FormElement*.
- // Note: This assignment adds a reference to the InputElement.
- result->input_elements[data.fields[j].name()] =
- temp_elements[0].to<WebInputElement>();
- }
- return true;
-}
-
-// Helper to locate form elements identified by |data|.
-static void FindFormElements(WebView* view,
- const FormData& data,
- FormElementsList* results) {
- DCHECK(view);
- DCHECK(results);
- WebFrame* main_frame = view->mainFrame();
- if (!main_frame)
- return;
-
- GURL::Replacements rep;
- rep.ClearQuery();
- rep.ClearRef();
-
- // Loop through each frame.
- for (WebFrame* f = main_frame; f; f = f->traverseNext(false)) {
- WebDocument doc = f->document();
- if (!doc.isHTMLDocument())
- continue;
-
- GURL full_origin(f->url());
- if (data.origin != full_origin.ReplaceComponents(rep))
- continue;
-
- WebVector<WebFormElement> forms;
- f->forms(forms);
-
- for (size_t i = 0; i < forms.size(); ++i) {
- WebFormElement fe = forms[i];
- // Action URL must match.
- GURL full_action(f->document().completeURL(fe.action()));
- if (data.action != full_action.ReplaceComponents(rep))
- continue;
-
- scoped_ptr<FormElements> curr_elements(new FormElements);
- if (!FindFormInputElements(&fe, data, curr_elements.get()))
- continue;
-
- // We found the right element.
- // Note: this assignment adds a reference to |fe|.
- curr_elements->form_element = fe;
- results->push_back(curr_elements.release());
- }
- }
-}
-
-void FillPasswordForm(WebView* view,
- const PasswordFormFillData& data) {
- FormElementsList forms;
- // We own the FormElements* in forms.
- FindFormElements(view, data.basic_data, &forms);
- FormElementsList::iterator iter;
- for (iter = forms.begin(); iter != forms.end(); ++iter) {
- scoped_ptr<FormElements> form_elements(*iter);
-
- // If wait_for_username is true, we don't want to initially fill the form
- // until the user types in a valid username.
- if (!data.wait_for_username)
- FillFormImpl(form_elements.get(), data.basic_data);
-
- // Attach autocomplete listener to enable selecting alternate logins.
- // First, get pointers to username element.
- WebInputElement username_element =
- form_elements->input_elements[data.basic_data.fields[0].name()];
-
- // Get pointer to password element. (We currently only support single
- // password forms).
- WebInputElement password_element =
- form_elements->input_elements[data.basic_data.fields[1].name()];
-
- username_element.document().frame()->registerPasswordListener(
- username_element,
- new WebPasswordAutocompleteListenerImpl(
- new WebInputElementDelegate(username_element),
- new WebInputElementDelegate(password_element),
- data));
- }
-}
-
WebString GetSubResourceLinkFromElement(const WebElement& element) {
const char* attribute_name = NULL;
if (element.hasTagName("img") ||