diff options
Diffstat (limited to 'webkit')
25 files changed, 463 insertions, 467 deletions
diff --git a/webkit/api/public/WebForm.h b/webkit/api/public/WebForm.h new file mode 100644 index 0000000..fe2e168 --- /dev/null +++ b/webkit/api/public/WebForm.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2009 Google Inc. 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 WebForm_h +#define WebForm_h + +#include "WebCommon.h" + +#if WEBKIT_IMPLEMENTATION +namespace WebCore { class HTMLFormElement; } +namespace WTF { template <typename T> class PassRefPtr; } +#endif + +namespace WebKit { + class WebFormPrivate; + + // A container for passing around a reference to a form element. Provides + // some information about the form. + class WebForm { + public: + ~WebForm() { reset(); } + + WebForm() : m_private(0) { } + WebForm(const WebForm& f) : m_private(0) { assign(f); } + WebForm& operator=(const WebForm& f) { assign(f); return *this; } + + WEBKIT_API void reset(); + WEBKIT_API void assign(const WebForm&); + + bool isNull() const { return m_private == 0; } + + // Returns true if the form does not have "autocomplete=off" specified. + WEBKIT_API bool isAutoCompleteEnabled() const; + +#if WEBKIT_IMPLEMENTATION + WebForm(const WTF::PassRefPtr<WebCore::HTMLFormElement>&); + WebForm& operator=(const WTF::PassRefPtr<WebCore::HTMLFormElement>&); + operator WTF::PassRefPtr<WebCore::HTMLFormElement>() const; +#endif + + private: + void assign(WebFormPrivate*); + WebFormPrivate* m_private; + }; + +} // namespace WebKit + +#endif diff --git a/webkit/api/public/WebFrameClient.h b/webkit/api/public/WebFrameClient.h index d03cf12..8140997 100644 --- a/webkit/api/public/WebFrameClient.h +++ b/webkit/api/public/WebFrameClient.h @@ -1,10 +1,10 @@ /* * Copyright (C) 2009 Google Inc. 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 @@ -14,7 +14,7 @@ * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -37,6 +37,7 @@ #include "WebNavigationGesture.h" namespace WebKit { + class WebForm; class WebFrame; class WebMediaPlayer; class WebMediaPlayerClient; @@ -47,7 +48,7 @@ namespace WebKit { class WebFrameClient { public: - // Factory methods ----------------------------------------------------- + // Factory methods ----------------------------------------------------- // May return null. virtual WebPlugin* createPlugin( @@ -85,6 +86,9 @@ namespace WebKit { // Navigational notifications ------------------------------------------ + // A form submission is about to occur. + virtual void willSubmitForm(WebFrame*, const WebForm&) = 0; + // A client-side redirect will occur. This may correspond to a <META // refresh> or some script activity. virtual void willPerformClientRedirect( @@ -139,7 +143,7 @@ namespace WebKit { // The navigation resulted in scrolling the page to a named anchor instead // of downloading a new document. - virtual void didChangeLocationWithinPage(WebFrame*, bool isNewNavigation) = 0; + virtual void didChangeLocationWithinPage(WebFrame*, bool isNewNavigation) = 0; // Called upon update to scroll position, document state, and other // non-navigational events related to the data held by WebHistoryItem. diff --git a/webkit/api/src/WebForm.cpp b/webkit/api/src/WebForm.cpp new file mode 100644 index 0000000..3ab7c4a --- /dev/null +++ b/webkit/api/src/WebForm.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2009 Google Inc. 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 "WebForm.h" + +#include "HTMLFormElement.h" +#include <wtf/PassRefPtr.h> + +using namespace WebCore; + +namespace WebKit { + +class WebFormPrivate : public HTMLFormElement { +}; + +void WebForm::reset() +{ + assign(0); +} + +void WebForm::assign(const WebForm& other) +{ + WebFormPrivate* p = const_cast<WebFormPrivate*>(other.m_private); + p->ref(); + assign(p); +} + +bool WebForm::isAutoCompleteEnabled() const +{ + ASSERT(!isNull()); + return m_private->autoComplete(); +} + +WebForm::WebForm(const WTF::PassRefPtr<WebCore::HTMLFormElement>& element) + : m_private(static_cast<WebFormPrivate*>(element.releaseRef())) +{ +} + +WebForm& WebForm::operator=(const WTF::PassRefPtr<WebCore::HTMLFormElement>& element) +{ + assign(static_cast<WebFormPrivate*>(element.releaseRef())); + return *this; +} + +WebForm::operator WTF::PassRefPtr<WebCore::HTMLFormElement>() const +{ + return PassRefPtr<HTMLFormElement>(const_cast<WebFormPrivate*>(m_private)); +} + +void WebForm::assign(WebFormPrivate* p) +{ + // p is already ref'd for us by the caller + if (m_private) + m_private->deref(); + m_private = p; +} + +} // namespace WebKit diff --git a/webkit/glue/autofill_form.cc b/webkit/glue/autofill_form.cc index ff0725c..e484716 100644 --- a/webkit/glue/autofill_form.cc +++ b/webkit/glue/autofill_form.cc @@ -3,35 +3,33 @@ // found in the LICENSE file. #include "config.h" -#include "base/compiler_specific.h" -MSVC_PUSH_WARNING_LEVEL(0); #include "Frame.h" #include "HTMLFormElement.h" #include "HTMLInputElement.h" #include "HTMLNames.h" -MSVC_POP_WARNING(); - #undef LOG #include "base/basictypes.h" #include "base/logging.h" #include "base/string_util.h" +#include "webkit/api/public/WebForm.h" #include "webkit/glue/autofill_form.h" #include "webkit/glue/glue_util.h" -AutofillForm* AutofillForm::CreateAutofillForm( - WebCore::HTMLFormElement* form) { +using WebKit::WebForm; + +namespace webkit_glue { +AutofillForm* AutofillForm::Create(const WebForm& webform) { + RefPtr<WebCore::HTMLFormElement> form = WebFormToHTMLFormElement(webform); DCHECK(form); WebCore::Frame* frame = form->document()->frame(); - if (!frame) return NULL; WebCore::FrameLoader* loader = frame->loader(); - if (!loader) return NULL; @@ -59,8 +57,7 @@ AutofillForm* AutofillForm::CreateAutofillForm( continue; // For each TEXT input field, store the name and value - std::wstring value = webkit_glue::StringToStdWString( - input_element->value()); + std::wstring value = StringToStdWString(input_element->value()); TrimWhitespace(value, TRIM_LEADING, &value); if (value.length() == 0) continue; @@ -78,16 +75,18 @@ AutofillForm* AutofillForm::CreateAutofillForm( // static std::wstring AutofillForm::GetNameForInputElement(WebCore::HTMLInputElement* element) { - std::wstring name = webkit_glue::StringToStdWString(element->name()); + std::wstring name = StringToStdWString(element->name()); std::wstring trimmed_name; TrimWhitespace(name, TRIM_LEADING, &trimmed_name); if (trimmed_name.length() > 0) return trimmed_name; - name = webkit_glue::StringToStdWString(element->id()); + name = StringToStdWString(element->id()); TrimWhitespace(name, TRIM_LEADING, &trimmed_name); if (trimmed_name.length() > 0) return trimmed_name; return std::wstring(); } + +} // namespace webkit_glue diff --git a/webkit/glue/autofill_form.h b/webkit/glue/autofill_form.h index 8375e75..4cf1b20 100644 --- a/webkit/glue/autofill_form.h +++ b/webkit/glue/autofill_form.h @@ -9,13 +9,17 @@ #include <vector> namespace WebCore { - class HTMLInputElement; - class HTMLFormElement; +class HTMLInputElement; } +namespace WebKit { +class WebForm; +} + +namespace webkit_glue { + // The AutofillForm struct represents a single HTML form together with the // values entered in the fields. - class AutofillForm { public: // Struct for storing name/value pairs. @@ -29,7 +33,7 @@ class AutofillForm { std::wstring value; }; - static AutofillForm* CreateAutofillForm(WebCore::HTMLFormElement* form); + static AutofillForm* Create(const WebKit::WebForm& form); // Returns the name that should be used for the specified |element| when // storing autofill data. This is either the field name or its id, an empty @@ -41,4 +45,6 @@ class AutofillForm { std::vector<Element> elements; }; +} // namespace webkit_glue + #endif // WEBKIT_GLUE_AUTOFILL_FORM_H_ diff --git a/webkit/glue/dom_operations.h b/webkit/glue/dom_operations.h index a088ef7..f202def 100644 --- a/webkit/glue/dom_operations.h +++ b/webkit/glue/dom_operations.h @@ -14,6 +14,7 @@ namespace WebCore { class Element; +class HTMLInputElement; class Node; } diff --git a/webkit/glue/editor_client_impl.cc b/webkit/glue/editor_client_impl.cc index f2575c8..07d1b5c 100644 --- a/webkit/glue/editor_client_impl.cc +++ b/webkit/glue/editor_client_impl.cc @@ -35,6 +35,8 @@ #include "webkit/glue/webview.h" #include "webkit/glue/webview_impl.h" +using webkit_glue::AutofillForm; + // Arbitrary depth limit for the undo stack, to keep it from using // unbounded memory. This is the maximum number of distinct undoable // actions -- unbroken stretches of typed characters are coalesced diff --git a/webkit/glue/glue_util.cc b/webkit/glue/glue_util.cc index b85ad71..34bd0fe 100644 --- a/webkit/glue/glue_util.cc +++ b/webkit/glue/glue_util.cc @@ -17,6 +17,7 @@ #include "ChromiumDataObject.h" #include "CString.h" +#include "HTMLFormElement.h" #include "IntPoint.h" #include "IntRect.h" #include "PlatformString.h" @@ -30,6 +31,7 @@ #include "base/sys_string_conversions.h" #include "googleurl/src/gurl.h" #include "webkit/api/public/WebDragData.h" +#include "webkit/api/public/WebForm.h" #include "webkit/api/public/WebPoint.h" #include "webkit/api/public/WebRect.h" #include "webkit/api/public/WebSize.h" @@ -226,6 +228,18 @@ PassRefPtr<WebCore::ChromiumDataObject> WebDragDataToChromiumDataObject( return data; } +// FormElement conversions ----------------------------------------------------- + +WebKit::WebForm HTMLFormElementToWebForm( + const WTF::PassRefPtr<WebCore::HTMLFormElement>& form) { + return form; +} + +WTF::PassRefPtr<WebCore::HTMLFormElement> WebFormToHTMLFormElement( + const WebKit::WebForm& form) { + return form; +} + // WebURLRequest conversions --------------------------------------------------- WebCore::ResourceRequest* WebURLRequestToMutableResourceRequest( diff --git a/webkit/glue/glue_util.h b/webkit/glue/glue_util.h index 553802c..776dc7e 100644 --- a/webkit/glue/glue_util.h +++ b/webkit/glue/glue_util.h @@ -13,6 +13,7 @@ class GURL; namespace WebCore { class ChromiumDataObject; class CString; +class HTMLFormElement; class IntPoint; class IntRect; class IntSize; @@ -25,6 +26,7 @@ struct ResourceRequest; namespace WebKit { class WebCString; class WebDragData; +class WebForm; class WebString; class WebURL; class WebURLRequest; @@ -107,6 +109,12 @@ WebKit::WebDragData ChromiumDataObjectToWebDragData( WTF::PassRefPtr<WebCore::ChromiumDataObject> WebDragDataToChromiumDataObject( const WebKit::WebDragData&); +// WebForm <-> HTMLFormElement +WebKit::WebForm HTMLFormElementToWebForm( + const WTF::PassRefPtr<WebCore::HTMLFormElement>&); +WTF::PassRefPtr<WebCore::HTMLFormElement> WebFormToHTMLFormElement( + const WebKit::WebForm&); + // Exposes the ResourceRequest contained by a WebURLRequest WebCore::ResourceRequest* WebURLRequestToMutableResourceRequest( WebKit::WebURLRequest* req); diff --git a/webkit/glue/password_autocomplete_listener_unittest.cc b/webkit/glue/password_autocomplete_listener_unittest.cc index ef5a4b1..05337d9 100644 --- a/webkit/glue/password_autocomplete_listener_unittest.cc +++ b/webkit/glue/password_autocomplete_listener_unittest.cc @@ -28,6 +28,7 @@ MSVC_POP_WARNING(); #include "testing/gtest/include/gtest/gtest.h" using webkit_glue::PasswordAutocompleteListener; +using webkit_glue::PasswordFormDomManager; using webkit_glue::HTMLInputDelegate; class TestHTMLInputDelegate : public HTMLInputDelegate { diff --git a/webkit/glue/password_form_dom_manager.cc b/webkit/glue/password_form_dom_manager.cc index fb99302..ceef5b4 100644 --- a/webkit/glue/password_form_dom_manager.cc +++ b/webkit/glue/password_form_dom_manager.cc @@ -4,9 +4,6 @@ #include "config.h" -#include "base/compiler_specific.h" - -MSVC_PUSH_WARNING_LEVEL(0); #include "Document.h" #include "DocumentLoader.h" #include "Frame.h" @@ -15,80 +12,127 @@ MSVC_PUSH_WARNING_LEVEL(0); #include "HTMLInputElement.h" #include "HTMLNames.h" #include "KURL.h" -MSVC_POP_WARNING(); - #undef LOG #include "base/logging.h" -#include "base/basictypes.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/password_form_dom_manager.h" +using WebKit::WebForm; + +namespace webkit_glue { + +namespace { + // Maximum number of password fields we will observe before throwing our // hands in the air and giving up with a given form. -static const size_t kMaxPasswords = 3; +const size_t kMaxPasswords = 3; -PasswordForm* PasswordFormDomManager::CreatePasswordForm( - WebCore::HTMLFormElement* form) { - WebCore::Frame* frame = form->document()->frame(); - if (frame == NULL) - return NULL; +// Helper structure to locate username, passwords and submit fields. +struct PasswordFormFields { + WebCore::HTMLInputElement* username; + std::vector<WebCore::HTMLInputElement*> passwords; + WebCore::HTMLFormControlElement* submit; + PasswordFormFields() : username(NULL), submit(NULL) { + } +}; - WebCore::FrameLoader* loader = frame->loader(); - if (loader == NULL) - return NULL; +// Helper to CreatePasswordForm to do the locating of username/password +// fields. +// This method based on Firefox2 code in +// toolkit/components/passwordmgr/base/nsPasswordManager.cpp +// Its license block is - PasswordFormFields fields; - FindPasswordFormFields(form, &fields); +/* ***** BEGIN LICENSE BLOCK ***** +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License Version +* 1.1 (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +* for the specific language governing rights and limitations under the +* License. +* +* The Original Code is Mozilla Password Manager. +* +* The Initial Developer of the Original Code is +* Brian Ryner. +* Portions created by the Initial Developer are Copyright (C) 2003 +* the Initial Developer. All Rights Reserved. +* +* Contributor(s): +* Brian Ryner <bryner@brianryner.com> +* +* Alternatively, the contents of this file may be used under the terms of +* either the GNU General Public License Version 2 or later (the "GPL"), or +* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +* in which case the provisions of the GPL or the LGPL are applicable instead +* of those above. If you wish to allow use of your version of this file only +* under the terms of either the GPL or the LGPL, and not to allow others to +* use your version of this file under the terms of the MPL, indicate your +* decision by deleting the provisions above and replace them with the notice +* and other provisions required by the GPL or the LGPL. If you do not delete +* the provisions above, a recipient may use your version of this file under +* the terms of any one of the MPL, the GPL or the LGPL. +* +* ***** END LICENSE BLOCK ***** */ +void FindPasswordFormFields( + WebCore::HTMLFormElement* form, + PasswordFormFields* fields) { + DCHECK(form && fields); + int first_password_index = 0; + // First, find the password fields and activated submit button + const WTF::Vector<WebCore::HTMLFormControlElement*>& form_elements = + form->formElements; + for (size_t i = 0; i < form_elements.size(); i++) { + WebCore::HTMLFormControlElement* form_element = form_elements[i]; + if (form_element->isActivatedSubmit()) + fields->submit = form_element; - // Get the document URL - WebCore::String origin_string = form->document()->documentURI(); - GURL full_origin(webkit_glue::StringToStdString(origin_string)); + if (!form_element->hasLocalName(WebCore::HTMLNames::inputTag)) + continue; - // Calculate the canonical action URL - GURL full_action(webkit_glue::KURLToGURL(loader->completeURL(form->action()))); - if (!full_action.is_valid()) - return NULL; + WebCore::HTMLInputElement* input_element = + static_cast<WebCore::HTMLInputElement*>(form_element); + if (!input_element->isEnabledFormControl()) + continue; - // Determine the types of the password fields - WebCore::HTMLInputElement* password = NULL; - WebCore::HTMLInputElement* old_password = NULL; - if (!LocateSpecificPasswords(&fields, &password, &old_password)) - return NULL; + if ((fields->passwords.size() < kMaxPasswords) && + (input_element->inputType() == WebCore::HTMLInputElement::PASSWORD) && + (input_element->autoComplete())) { + if (fields->passwords.empty()) + first_password_index = i; + fields->passwords.push_back(input_element); + } + } - return AssemblePasswordFormResult(full_origin, full_action, - fields.submit, fields.username, - old_password, password); -} + if (!fields->passwords.empty()) { + // Then, search backwards for the username field + for (int i = first_password_index - 1; i >= 0; i--) { + WebCore::HTMLFormControlElement* form_element = form_elements[i]; + if (!form_element->hasLocalName(WebCore::HTMLNames::inputTag)) + continue; -// static -void PasswordFormDomManager::InitFillData( - const PasswordForm& form_on_page, - const PasswordFormMap& matches, - const PasswordForm* const preferred_match, - bool wait_for_username_before_autofill, - PasswordFormDomManager::FillData* result) { - DCHECK(preferred_match); - // Fill basic form data. - result->basic_data.origin = form_on_page.origin; - result->basic_data.action = form_on_page.action; - result->basic_data.elements.push_back(form_on_page.username_element); - result->basic_data.values.push_back(preferred_match->username_value); - result->basic_data.elements.push_back(form_on_page.password_element); - result->basic_data.values.push_back(preferred_match->password_value); - result->basic_data.submit = form_on_page.submit_element; - result->wait_for_username = wait_for_username_before_autofill; + WebCore::HTMLInputElement* input_element = + static_cast<WebCore::HTMLInputElement*>(form_element); + if (!input_element->isEnabledFormControl()) + continue; - // Copy additional username/value pairs. - PasswordFormMap::const_iterator iter; - for (iter = matches.begin(); iter != matches.end(); iter++) { - if (iter->second != preferred_match) - result->additional_logins[iter->first] = iter->second->password_value; + if ((input_element->inputType() == WebCore::HTMLInputElement::TEXT) && + (input_element->autoComplete())) { + fields->username = input_element; + break; + } + } } } -// static -bool PasswordFormDomManager::LocateSpecificPasswords( +// Helper to determine which password is the main one, and which is +// an old password (e.g on a "make new password" form), if any. +bool LocateSpecificPasswords( PasswordFormFields* fields, WebCore::HTMLInputElement** password, WebCore::HTMLInputElement** old_password) { @@ -133,100 +177,9 @@ bool PasswordFormDomManager::LocateSpecificPasswords( } return true; } - // This method based on Firefox2 code in - // toolkit/components/passwordmgr/base/nsPasswordManager.cpp - // Its license block is - // - /* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Password Manager. - * - * The Initial Developer of the Original Code is - * Brian Ryner. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Brian Ryner <bryner@brianryner.com> - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -// static -void PasswordFormDomManager::FindPasswordFormFields( - WebCore::HTMLFormElement* form, - PasswordFormFields* fields) { - DCHECK(form && fields); - int first_password_index = 0; - // First, find the password fields and activated submit button - const WTF::Vector<WebCore::HTMLFormControlElement*>& form_elements = - form->formElements; - for (size_t i = 0; i < form_elements.size(); i++) { - WebCore::HTMLFormControlElement* form_element = form_elements[i]; - if (form_element->isActivatedSubmit()) - fields->submit = form_element; - - if (!form_element->hasLocalName(WebCore::HTMLNames::inputTag)) - continue; - - WebCore::HTMLInputElement* input_element = - static_cast<WebCore::HTMLInputElement*>(form_element); - if (!input_element->isEnabledFormControl()) - continue; - - if ((fields->passwords.size() < kMaxPasswords) && - (input_element->inputType() == WebCore::HTMLInputElement::PASSWORD) && - (input_element->autoComplete())) { - if (fields->passwords.empty()) - first_password_index = i; - fields->passwords.push_back(input_element); - } - } - - if (!fields->passwords.empty()) { - // Then, search backwards for the username field - for (int i = first_password_index - 1; i >= 0; 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->isEnabledFormControl()) - continue; - - if ((input_element->inputType() == WebCore::HTMLInputElement::TEXT) && - (input_element->autoComplete())) { - fields->username = input_element; - break; - } - } - } -} -// static -PasswordForm* PasswordFormDomManager::AssemblePasswordFormResult( +// Helper to gather up the final form data and create a PasswordForm. +PasswordForm* AssemblePasswordFormResult( const GURL& full_origin, const GURL& full_action, WebCore::HTMLFormControlElement* submit, @@ -252,24 +205,79 @@ PasswordForm* PasswordFormDomManager::AssemblePasswordFormResult( result->signon_realm = full_origin.GetOrigin().spec(); // Note PasswordManager sets ssl_valid by asking the WebContents' SSLManager. result->submit_element = - submit == NULL ? empty : webkit_glue::StringToStdWString(submit->name()); + submit == NULL ? empty : StringToStdWString(submit->name()); result->username_element = - username == NULL ? empty - : webkit_glue::StringToStdWString(username->name()); + username == NULL ? empty : StringToStdWString(username->name()); result->username_value = - username == NULL ? empty - : webkit_glue::StringToStdWString(username->value()); + username == NULL ? empty : StringToStdWString(username->value()); result->password_element = - password == NULL ? empty - : webkit_glue::StringToStdWString(password->name()); + password == NULL ? empty : StringToStdWString(password->name()); result->password_value = - password == NULL ? empty - : webkit_glue::StringToStdWString(password->value()); + password == NULL ? empty : StringToStdWString(password->value()); result->old_password_element = - old_password == NULL ? empty - : webkit_glue::StringToStdWString(old_password->name()); + old_password == NULL ? empty : StringToStdWString(old_password->name()); result->old_password_value = - old_password == NULL ? empty - : webkit_glue::StringToStdWString(old_password->value()); + old_password == NULL ? empty : StringToStdWString(old_password->value()); return result; } + +} // namespace + +PasswordForm* PasswordFormDomManager::CreatePasswordForm( + const WebForm& webform) { + RefPtr<WebCore::HTMLFormElement> form = WebFormToHTMLFormElement(webform); + + WebCore::Frame* frame = form->document()->frame(); + if (!frame) + return NULL; + + PasswordFormFields fields; + FindPasswordFormFields(form.get(), &fields); + + // Get the document URL + WebCore::String origin_string = form->document()->documentURI(); + GURL full_origin(StringToStdString(origin_string)); + + // Calculate the canonical action URL + GURL full_action(KURLToGURL(frame->loader()->completeURL(form->action()))); + if (!full_action.is_valid()) + return NULL; + + // Determine the types of the password fields + WebCore::HTMLInputElement* password = NULL; + WebCore::HTMLInputElement* old_password = NULL; + if (!LocateSpecificPasswords(&fields, &password, &old_password)) + return NULL; + + return AssemblePasswordFormResult(full_origin, full_action, + fields.submit, fields.username, + old_password, password); +} + +// static +void PasswordFormDomManager::InitFillData( + const PasswordForm& form_on_page, + const PasswordFormMap& matches, + const PasswordForm* const preferred_match, + bool wait_for_username_before_autofill, + PasswordFormDomManager::FillData* result) { + DCHECK(preferred_match); + // Fill basic form data. + result->basic_data.origin = form_on_page.origin; + result->basic_data.action = form_on_page.action; + result->basic_data.elements.push_back(form_on_page.username_element); + result->basic_data.values.push_back(preferred_match->username_value); + result->basic_data.elements.push_back(form_on_page.password_element); + result->basic_data.values.push_back(preferred_match->password_value); + result->basic_data.submit = form_on_page.submit_element; + result->wait_for_username = wait_for_username_before_autofill; + + // Copy additional username/value pairs. + PasswordFormMap::const_iterator iter; + for (iter = matches.begin(); iter != matches.end(); iter++) { + if (iter->second != preferred_match) + result->additional_logins[iter->first] = iter->second->password_value; + } +} + +} // namespace webkit_glue diff --git a/webkit/glue/password_form_dom_manager.h b/webkit/glue/password_form_dom_manager.h index 84dbc93..9963a5d 100644 --- a/webkit/glue/password_form_dom_manager.h +++ b/webkit/glue/password_form_dom_manager.h @@ -2,20 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef WEBKIT_GLUE_PASSWORD_FORM_DOM_MANAGER_H__ -#define WEBKIT_GLUE_PASSWORD_FORM_DOM_MANAGER_H__ +#ifndef WEBKIT_GLUE_PASSWORD_FORM_DOM_MANAGER_H_ +#define WEBKIT_GLUE_PASSWORD_FORM_DOM_MANAGER_H_ #include "webkit/glue/form_data.h" #include "webkit/glue/password_form.h" -namespace WebCore { -class HTMLFormElement; -class HTMLInputElement; -class HTMLFormControlElement; +namespace WebKit { +class WebForm; } class GURL; +namespace webkit_glue { + class PasswordFormDomManager { public: typedef std::map<std::wstring, std::wstring> LoginCollection; @@ -41,7 +41,7 @@ class PasswordFormDomManager { // custom metadata to DOM nodes, so we have to do this every time an event // happens with a given form and compare against previously Create'd forms // to identify..which sucks. - static PasswordForm* CreatePasswordForm(WebCore::HTMLFormElement* form); + static PasswordForm* CreatePasswordForm(const WebKit::WebForm& form); // Create a FillData structure in preparation for autofilling a form, // from basic_data identifying which form to fill, and a collection of @@ -55,77 +55,9 @@ class PasswordFormDomManager { bool wait_for_username_before_autofill, FillData* result); private: - // Helper structure to locate username, passwords and submit fields. - struct PasswordFormFields { - WebCore::HTMLInputElement* username; - std::vector<WebCore::HTMLInputElement*> passwords; - WebCore::HTMLFormControlElement* submit; - PasswordFormFields() : username(NULL), submit(NULL) { - } - }; - - // Helper to CreatePasswordForm to do the locating of username/password - // fields. - // This method based on Firefox2 code in - // toolkit/components/passwordmgr/base/nsPasswordManager.cpp - // Its license block is - - /* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Password Manager. - * - * The Initial Developer of the Original Code is - * Brian Ryner. - * Portions created by the Initial Developer are Copyright (C) 2003 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Brian Ryner <bryner@brianryner.com> - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - static void FindPasswordFormFields(WebCore::HTMLFormElement* form, - PasswordFormFields* fields); - // Helper to determine which password is the main one, and which is - // an old password (e.g on a "make new password" form), if any. - static bool LocateSpecificPasswords( - PasswordFormFields* fields, - WebCore::HTMLInputElement** password, - WebCore::HTMLInputElement** old_password_index); - - // Helper to gather up the final form data and create a PasswordForm. - static PasswordForm* AssemblePasswordFormResult( - const GURL& full_origin, - const GURL& full_action, - WebCore::HTMLFormControlElement* submit, - WebCore::HTMLInputElement* username, - WebCore::HTMLInputElement* old_password, - WebCore::HTMLInputElement* password); - - // This class can't be instantiated. DISALLOW_IMPLICIT_CONSTRUCTORS(PasswordFormDomManager); }; +} // namespace webkit_glue + #endif // WEBKIT_GLUE_PASSWORD_FORM_DOM_MANAGER_H__ 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 diff --git a/webkit/glue/searchable_form_data.h b/webkit/glue/searchable_form_data.h index 2164189..fc76c57 100644 --- a/webkit/glue/searchable_form_data.h +++ b/webkit/glue/searchable_form_data.h @@ -9,22 +9,19 @@ #include "googleurl/src/gurl.h" -namespace WebCore { -class Element; -class HTMLFormElement; +namespace WebKit { +class WebForm; } +namespace webkit_glue { + // SearchableFormData encapsulates a URL and class name of an INPUT field // that correspond to a searchable form request. class SearchableFormData { public: // If form contains elements that constitutes a valid searchable form // request, a SearchableFormData is created and returned. - static SearchableFormData* Create(WebCore::HTMLFormElement* form); - - // If the element is contained in a form that constitutes a valid searchable - // form, a SearchableFormData is created and returned. - static SearchableFormData* Create(WebCore::Element* element); + static SearchableFormData* Create(const WebKit::WebForm& form); // Returns true if the two SearchableFormData are equal, false otherwise. // Either argument may be NULL. If both elements are NULL, true is returned. @@ -53,7 +50,9 @@ class SearchableFormData { const std::wstring element_value_; const std::string encoding_; - DISALLOW_EVIL_CONSTRUCTORS(SearchableFormData); + DISALLOW_COPY_AND_ASSIGN(SearchableFormData); }; +} // namespace webkit_glue + #endif // WEBKIT_GLUE_SEARCHABLE_FORM_H__ diff --git a/webkit/glue/webdatasource.h b/webkit/glue/webdatasource.h index 53e9492..5885db7 100644 --- a/webkit/glue/webdatasource.h +++ b/webkit/glue/webdatasource.h @@ -10,7 +10,6 @@ #include "base/string16.h" class GURL; -class SearchableFormData; class WebFrame; class WebRequest; class WebResponse; @@ -82,21 +81,6 @@ class WebDataSource { // redirect, it will contain the source and destination URL). virtual const std::vector<GURL>& GetRedirectChain() const = 0; - // Returns the SearchableFormData, or NULL if the request wasn't a search - // request. The returned object is owned by the WebDataSource (actually - // the WebDocumentLoader) and shouldn't be freed. - virtual const SearchableFormData* GetSearchableFormData() const = 0; - - // Returns the PasswordFormData, or NULL if the request isn't a form submission - // or doesn't have any password fields. The returned object is owned by the - // WebDataSource (actually the WebDocumentLoader) and shouldn't be freed. - virtual const PasswordForm* GetPasswordFormData() const = 0; - - // Returns true if this request was the result of submitting a form. - // NOTE: this returns false if the user submitted a form, but the form used - // script to do the actuall submission. - virtual bool IsFormSubmit() const = 0; - // Returns the page title. virtual string16 GetPageTitle() const = 0; diff --git a/webkit/glue/webdatasource_impl.cc b/webkit/glue/webdatasource_impl.cc index 6980e13..c0ace9b 100644 --- a/webkit/glue/webdatasource_impl.cc +++ b/webkit/glue/webdatasource_impl.cc @@ -32,8 +32,7 @@ PassRefPtr<WebDataSourceImpl> WebDataSourceImpl::Create( WebDataSourceImpl::WebDataSourceImpl(const WebCore::ResourceRequest& request, const WebCore::SubstituteData& data) - : WebCore::DocumentLoader(request, data), - form_submit_(false) { + : WebCore::DocumentLoader(request, data) { } WebDataSourceImpl::~WebDataSourceImpl() { @@ -79,18 +78,6 @@ void WebDataSourceImpl::AppendRedirect(const GURL& url) { redirect_chain_.push_back(url); } -const SearchableFormData* WebDataSourceImpl::GetSearchableFormData() const { - return searchable_form_data(); -} - -const PasswordForm* WebDataSourceImpl::GetPasswordFormData() const { - return password_form_data(); -} - -bool WebDataSourceImpl::IsFormSubmit() const { - return is_form_submit(); -} - string16 WebDataSourceImpl::GetPageTitle() const { return webkit_glue::StringToString16(title()); } diff --git a/webkit/glue/webdatasource_impl.h b/webkit/glue/webdatasource_impl.h index 912dffb..d2e98bf 100644 --- a/webkit/glue/webdatasource_impl.h +++ b/webkit/glue/webdatasource_impl.h @@ -9,7 +9,6 @@ #include "base/scoped_ptr.h" #include "base/time.h" -#include "webkit/glue/searchable_form_data.h" #include "webkit/glue/webdatasource.h" #include "webkit/glue/webresponse_impl.h" #include "webkit/glue/weburlrequest_impl.h" @@ -33,9 +32,6 @@ class WebDataSourceImpl : public WebCore::DocumentLoader, public WebDataSource { virtual GURL GetUnreachableURL() const; virtual bool HasUnreachableURL() const; virtual const std::vector<GURL>& GetRedirectChain() const; - virtual const SearchableFormData* GetSearchableFormData() const; - virtual const PasswordForm* GetPasswordFormData() const; - virtual bool IsFormSubmit() const; virtual string16 GetPageTitle() const; virtual base::Time GetRequestTime() const; virtual void SetRequestTime(base::Time time); @@ -53,35 +49,6 @@ class WebDataSourceImpl : public WebCore::DocumentLoader, public WebDataSource { void ClearRedirectChain(); void AppendRedirect(const GURL& url); - // Sets the SearchableFormData for this DocumentLoader. - // WebDocumentLoaderImpl will own the SearchableFormData. - void set_searchable_form_data(SearchableFormData* searchable_form_data) { - searchable_form_data_.reset(searchable_form_data); - } - // Returns the SearchableFormData for this DocumentLoader. - // WebDocumentLoaderImpl owns the returned SearchableFormData. - const SearchableFormData* searchable_form_data() const { - return searchable_form_data_.get(); - } - - // Sets the PasswordFormData for this DocumentLoader. - // WebDocumentLoaderImpl will own the PasswordFormData. - void set_password_form_data(PasswordForm* password_form_data) { - password_form_data_.reset(password_form_data); - } - // Returns the PasswordFormData for this DocumentLoader. - // WebDocumentLoaderImpl owns the returned PasswordFormData. - const PasswordForm* password_form_data() const { - return password_form_data_.get(); - } - - void set_form_submit(bool value) { - form_submit_ = value; - } - bool is_form_submit() const { - return form_submit_; - } - void set_request_time(base::Time request_time) { request_time_ = request_time; } @@ -119,13 +86,8 @@ class WebDataSourceImpl : public WebCore::DocumentLoader, public WebDataSource { // who modifies this when to keep it up to date. std::vector<GURL> redirect_chain_; - scoped_ptr<const SearchableFormData> searchable_form_data_; - scoped_ptr<const PasswordForm> password_form_data_; - OwnPtr<ExtraData> extra_data_; - bool form_submit_; - // See webdatasource.h for a description of these time stamps. base::Time request_time_; base::Time start_load_time_; diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h index e630f35..ad80a0d 100644 --- a/webkit/glue/webframe.h +++ b/webkit/glue/webframe.h @@ -5,6 +5,8 @@ #ifndef WEBKIT_GLUE_WEBFRAME_H_ #define WEBKIT_GLUE_WEBFRAME_H_ +#include <vector> + #include "base/scoped_ptr.h" #include "base/string16.h" #include "skia/ext/bitmap_platform_device.h" @@ -20,6 +22,7 @@ class WebTextInput; struct NPObject; namespace WebKit { +class WebForm; struct WebConsoleMessage; struct WebFindOptions; struct WebRect; @@ -59,14 +62,6 @@ class WebFrame { virtual void CallJSGC() = 0; - // WARNING: DON'T USE THIS METHOD unless you know what it is doing. - // - // Returns a pointer to the underlying implementation WebCore::Frame. - // Currently it is a hack to avoid including "Frame.h". The caller - // casts the return value to WebCore::Frame. - // TODO(fqian): Remove this method when V8 supports NP runtime. - virtual void* GetFrameImplementation() = 0; - // This grants the currently loaded Document access to all security origins // (including file URLs). Use with care. The access is revoked when a new // document is loaded into this frame. @@ -214,6 +209,9 @@ class WebFrame { // unless it is AddRef'd separately by the caller. virtual WebView* GetView() const = 0; + // Returns a vector of WebForms (corresponds to document.forms). + virtual void GetForms(std::vector<WebKit::WebForm>* forms) const = 0; + // Returns the serialization of the frame's security origin. virtual std::string GetSecurityOrigin() const = 0; diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 0d78729..f573dcb 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -142,6 +142,7 @@ MSVC_POP_WARNING(); #include "skia/ext/platform_canvas.h" #include "webkit/api/public/WebConsoleMessage.h" #include "webkit/api/public/WebFindOptions.h" +#include "webkit/api/public/WebForm.h" #include "webkit/api/public/WebRect.h" #include "webkit/api/public/WebScriptSource.h" #include "webkit/api/public/WebSize.h" @@ -185,6 +186,7 @@ using WebCore::FrameLoadType; using WebCore::FrameTree; using WebCore::FrameView; using WebCore::HistoryItem; +using WebCore::HTMLFormElement; using WebCore::IntRect; using WebCore::KURL; using WebCore::Node; @@ -204,6 +206,7 @@ using WebCore::XPathResult; using WebKit::WebConsoleMessage; using WebKit::WebFindOptions; +using WebKit::WebForm; using WebKit::WebRect; using WebKit::WebScriptSource; using WebKit::WebSize; @@ -750,6 +753,22 @@ WebView* WebFrameImpl::GetView() const { return GetWebViewImpl(); } +void WebFrameImpl::GetForms(std::vector<WebForm>* results) const { + results->clear(); + if (!frame_) + return; + RefPtr<WebCore::HTMLCollection> forms = frame_->document()->forms(); + unsigned int form_count = forms->length(); + for (unsigned int i = 0; i < form_count; ++i) { + Node* node = forms->item(i); + // Strange but true, sometimes item can be NULL. + if (node) { + results->push_back(webkit_glue::HTMLFormElementToWebForm( + static_cast<HTMLFormElement*>(node))); + } + } +} + std::string WebFrameImpl::GetSecurityOrigin() const { if (frame_) { if (frame_->document()) diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index c7eeb8d..54da684 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -110,6 +110,7 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { virtual WebFrame* GetTop() const; virtual WebFrame* GetChildFrame(const std::wstring& xpath) const; virtual WebView* GetView() const; + virtual void GetForms(std::vector<WebKit::WebForm>* forms) const; virtual std::string GetSecurityOrigin() const; virtual bool CaptureImage(scoped_ptr<skia::BitmapPlatformDevice>* image, bool scroll_to_zero); @@ -119,7 +120,6 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> { virtual void BindToWindowObject(const std::wstring& name, NPObject* object); virtual void CallJSGC(); - virtual void* GetFrameImplementation() { return frame(); } virtual void GrantUniversalAccess(); virtual NPObject* GetWindowNPObject(); diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index a21e401..a4a77a9 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -44,6 +44,7 @@ MSVC_POP_WARNING(); #if defined(OS_WIN) #include "webkit/activex_shim/activex_shared.h" #endif +#include "webkit/api/public/WebForm.h" #include "webkit/glue/autofill_form.h" #include "webkit/glue/alt_404_page_resource_fetcher.h" #include "webkit/glue/glue_util.h" @@ -376,35 +377,6 @@ void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() { // listeners and their associated HTMLInputElements. webframe_->ClearPasswordListeners(); - // The document has now been fully loaded. - // Scan for password forms to be sent to the browser - PassRefPtr<WebCore::HTMLCollection> forms = - webframe_->frame()->document()->forms(); - - std::vector<PasswordForm> passwordForms; - - unsigned int form_count = forms->length(); - for (unsigned int i = 0; i < form_count; ++i) { - // Strange but true, sometimes item can be NULL. - WebCore::Node* item = forms->item(i); - if (item) { - WebCore::HTMLFormElement* form = - static_cast<WebCore::HTMLFormElement*>(item); - - // Honour autocomplete=off. - if (!form->autoComplete()) - continue; - - scoped_ptr<PasswordForm> passwordFormPtr( - PasswordFormDomManager::CreatePasswordForm(form)); - - if (passwordFormPtr.get()) - passwordForms.push_back(*passwordFormPtr); - } - } - - if (d && (passwordForms.size() > 0)) - d->OnPasswordFormsSeen(webview, passwordForms); if (d) d->DidFinishDocumentLoadForFrame(webview, webframe_); data_source->set_finish_document_load_time(base::Time::Now()); @@ -1010,32 +982,12 @@ void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError&) void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> form_ref) { - SearchableFormData* form_data = SearchableFormData::Create(form_ref->form()); - WebDataSourceImpl* ds = WebDataSourceImpl::FromLoader( - webframe_->frame()->loader()->provisionalDocumentLoader()); - // Don't free the SearchableFormData, the datasource will do that. - ds->set_searchable_form_data(form_data); - - PasswordForm* pass_data = - PasswordFormDomManager::CreatePasswordForm(form_ref->form()); - // Don't free the PasswordFormData, the datasource will do that. - ds->set_password_form_data(pass_data); - WebViewImpl* webview = webframe_->GetWebViewImpl(); WebViewDelegate* d = webview->delegate(); - - // Unless autocomplete=off, record what the user put in it for future - // autofilling. - if (form_ref->form()->autoComplete()) { - scoped_ptr<AutofillForm> autofill_form( - AutofillForm::CreateAutofillForm(form_ref->form())); - if (autofill_form.get()) { - d->OnAutofillFormSubmitted(webview, *autofill_form); - } + if (d) { + d->WillSubmitForm(webview, webframe_, + webkit_glue::HTMLFormElementToWebForm(form_ref->form())); } - - ds->set_form_submit(true); - (webframe_->frame()->loader()->*function)(PolicyUse); } diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h index 9c658e2..7002c57 100644 --- a/webkit/glue/webview_delegate.h +++ b/webkit/glue/webview_delegate.h @@ -42,6 +42,7 @@ class AccessibilityObject; namespace WebKit { class WebDragData; +class WebForm; class WebWorker; class WebWorkerClient; class WebMediaPlayer; @@ -50,9 +51,7 @@ struct WebPoint; struct WebRect; } -struct PasswordForm; struct WebPreferences; -class AutofillForm; class FilePath; class SkBitmap; class WebDevToolsAgentDelegate; @@ -418,6 +417,12 @@ class WebViewDelegate : virtual public WebWidgetDelegate { WebFrame* frame, const GURL& source) { } + + // Notifies the delegate that a form is about to be submitted. + virtual void WillSubmitForm(WebView* webview, WebFrame* frame, + const WebKit::WebForm& form) { + } + // // @method webView:willCloseFrame: // @abstract Notifies the delegate that a frame will be closed @@ -470,18 +475,6 @@ class WebViewDelegate : virtual public WebWidgetDelegate { const std::wstring& source_id) { } - // Notification of possible password forms to be filled/submitted by - // the password manager - virtual void OnPasswordFormsSeen(WebView* webview, - const std::vector<PasswordForm>& forms) { - } - - // Notification of the submission of a form so that its contents can be - // recorded for future autofilling. - virtual void OnAutofillFormSubmitted(WebView* webview, - const AutofillForm& form) { - } - // Queries the browser for suggestions to be shown for the form text field // named |field_name|. |text| is the text entered by the user so far and // |node_id| is the id of the node of the input field. diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc index b568a9f..57d594a 100644 --- a/webkit/glue/webview_impl.cc +++ b/webkit/glue/webview_impl.cc @@ -1730,24 +1730,6 @@ bool WebViewImpl::SetDropEffect(bool accept) { } } -SearchableFormData* WebViewImpl::CreateSearchableFormDataForFocusedNode() { - if (!page_.get()) - return NULL; - - if (RefPtr<Frame> focused = page_->focusController()->focusedFrame()) { - RefPtr<Document> document = focused->document(); - if (document.get()) { - RefPtr<Node> focused_node = document->focusedNode(); - if (focused_node.get() && - focused_node->nodeType() == Node::ELEMENT_NODE) { - return SearchableFormData::Create( - static_cast<Element*>(focused_node.get())); - } - } - } - return NULL; -} - void WebViewImpl::AutofillSuggestionsForNode( int64 node_id, const std::vector<std::wstring>& suggestions, diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h index caac1c8..28e3666 100644 --- a/webkit/glue/webview_impl.h +++ b/webkit/glue/webview_impl.h @@ -230,11 +230,6 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> { WebCore::Frame* frame, const WebCore::PlatformKeyboardEvent& e); - // Creates and returns a new SearchableFormData for the focused node. - // It's up to the caller to free the returned SearchableFormData. - // This returns NULL if the focused node is NULL, or not in a valid form. - SearchableFormData* CreateSearchableFormDataForFocusedNode(); - scoped_refptr<WebViewDelegate> delegate_; WebKit::WebSize size_; diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 3e8df1e..7c54e1e 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -4189,6 +4189,7 @@ 'api/public/WebData.h', 'api/public/WebDragData.h', 'api/public/WebFindOptions.h', + 'api/public/WebForm.h', 'api/public/WebHTTPBody.h', 'api/public/WebImage.h', 'api/public/WebInputEvent.h', @@ -4230,6 +4231,7 @@ 'api/src/WebCString.cpp', 'api/src/WebData.cpp', 'api/src/WebDragData.cpp', + 'api/src/WebForm.cpp', 'api/src/WebHTTPBody.cpp', 'api/src/WebImageSkia.cpp', 'api/src/WebInputEvent.cpp', |