Commit 9155da1c authored by ziran.sun@samsung.com's avatar ziran.sun@samsung.com

Remove WebPasswordFormData and util files

Functioins in there files have been rewritten in
components/autofill/content/renderer/password_form_conversion_utils.
This is to refact old Blink code on WebPasswordFormData and utils files.

R=gcasto@chromium.org, tkent
BUG=None

Review URL: https://codereview.chromium.org/246233005

git-svn-id: svn://svn.chromium.org/blink/trunk@172999 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d9e2b847
/*
* 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 "public/web/WebPasswordFormData.h"
#include "HTMLNames.h"
#include "core/dom/Document.h"
#include "core/html/HTMLFormElement.h"
#include "core/html/HTMLInputElement.h"
#include "platform/weborigin/KURL.h"
#include "web/WebPasswordFormUtils.h"
using namespace WebCore;
namespace blink {
namespace {
// 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,
HTMLInputElement** password,
HTMLInputElement** oldPassword)
{
ASSERT(fields);
ASSERT(password);
ASSERT(oldPassword);
switch (fields->passwords.size()) {
case 1:
// Single password, easy.
*password = fields->passwords[0];
break;
case 2:
if (fields->passwords[0]->value() == fields->passwords[1]->value())
// Treat two identical passwords as a single password.
*password = fields->passwords[0];
else {
// Assume first is old password, second is new (no choice but to guess).
*oldPassword = fields->passwords[0];
*password = fields->passwords[1];
}
break;
case 3:
if (fields->passwords[0]->value() == fields->passwords[1]->value()
&& fields->passwords[0]->value() == fields->passwords[2]->value()) {
// All three passwords the same? Just treat as one and hope.
*password = fields->passwords[0];
} else if (fields->passwords[0]->value() == fields->passwords[1]->value()) {
// Two the same and one different -> old password is duplicated one.
*oldPassword = fields->passwords[0];
*password = fields->passwords[2];
} else if (fields->passwords[1]->value() == fields->passwords[2]->value()) {
*oldPassword = fields->passwords[0];
*password = fields->passwords[1];
} else {
// Three different passwords, or first and last match with middle
// different. No idea which is which, so no luck.
return false;
}
break;
default:
return false;
}
return true;
}
// Helped method to clear url of unneeded parts.
KURL stripURL(const KURL& url)
{
KURL strippedURL = url;
strippedURL.setUser(String());
strippedURL.setPass(String());
strippedURL.setQuery(String());
strippedURL.setFragmentIdentifier(String());
return strippedURL;
}
WebString getElementNameOrId(const HTMLInputElement& element)
{
return element.nameForAutofill();
}
// Helper to gather up the final form data and create a PasswordForm.
void assemblePasswordFormResult(const KURL& fullOrigin,
const KURL& fullAction,
HTMLFormControlElement* submit,
HTMLInputElement* userName,
const Vector<String>& alternateUserNames,
HTMLInputElement* oldPassword,
HTMLInputElement* password,
WebPasswordFormData* result)
{
// We want to keep the path but strip any authentication data, as well as
// query and ref portions of URL, for the form action and form origin.
result->action = stripURL(fullAction);
result->origin = stripURL(fullOrigin);
// Naming is confusing here because we have both the HTML form origin URL
// the page where the form was seen), and the "origin" components of the url
// (scheme, host, and port).
KURL signonRealmURL = stripURL(fullOrigin);
signonRealmURL.setPath("");
result->signonRealm = signonRealmURL;
result->possibleUserNames = alternateUserNames;
if (submit)
result->submitElement = submit->name();
if (userName) {
result->userNameElement = getElementNameOrId(*userName);
result->userNameValue = userName->value();
}
if (password) {
result->passwordElement = getElementNameOrId(*password);
result->passwordValue = password->value();
result->passwordShouldAutocomplete = password->shouldAutocomplete();
}
if (oldPassword) {
result->oldPasswordElement = getElementNameOrId(*oldPassword);
result->oldPasswordValue = oldPassword->value();
}
}
} // namespace
WebPasswordFormData::WebPasswordFormData(const WebFormElement& webForm)
{
RefPtr<HTMLFormElement> form = webForm.operator PassRefPtr<HTMLFormElement>();
PasswordFormFields fields;
findPasswordFormFields(form.get(), &fields);
// Get the document URL
KURL fullOrigin = form->document().url();
// Calculate the canonical action URL
String action = form->action();
if (action.isNull())
action = ""; // missing 'action' attribute implies current URL
KURL fullAction = form->document().completeURL(action);
if (!fullAction.isValid())
return;
// Determine the types of the password fields
HTMLInputElement* password = 0;
HTMLInputElement* oldPassword = 0;
if (!locateSpecificPasswords(&fields, &password, &oldPassword))
return;
assemblePasswordFormResult(fullOrigin, fullAction,
fields.submit, fields.userName,
fields.alternateUserNames,
oldPassword, password, this);
}
} // namespace blink
/* ***** 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 ***** */
// Helper to WebPasswordFormData to do the locating of username/password
// fields.
// This method based on Firefox2 code in
// toolkit/components/passwordmgr/base/nsPasswordManager.cpp
#include "config.h"
#include "web/WebPasswordFormUtils.h"
#include "HTMLNames.h"
#include "core/html/HTMLFormElement.h"
#include "core/html/HTMLInputElement.h"
using namespace WebCore;
namespace blink {
// 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 maxPasswords = 3;
void findPasswordFormFields(HTMLFormElement* form, PasswordFormFields* fields)
{
ASSERT(form);
ASSERT(fields);
HTMLInputElement* latestInputElement = 0;
const Vector<FormAssociatedElement*>& formElements = form->associatedElements();
for (size_t i = 0; i < formElements.size(); i++) {
if (!formElements[i]->isFormControlElement())
continue;
HTMLFormControlElement* control = toHTMLFormControlElement(formElements[i]);
if (control->isActivatedSubmit())
fields->submit = control;
if (!isHTMLInputElement(*control))
continue;
HTMLInputElement& inputElement = toHTMLInputElement(*control);
if (inputElement.isDisabledFormControl())
continue;
if ((fields->passwords.size() < maxPasswords)
&& inputElement.isPasswordField()) {
// We assume that the username is the input element before the
// first password element.
if (fields->passwords.isEmpty() && latestInputElement) {
fields->userName = latestInputElement;
// Remove the selected username from alternateUserNames.
if (!fields->alternateUserNames.isEmpty() && !latestInputElement->value().isEmpty())
fields->alternateUserNames.removeLast();
}
fields->passwords.append(&inputElement);
}
// Various input types such as text, url, email can be a username field.
if (inputElement.isTextField() && !inputElement.isPasswordField()) {
latestInputElement = &inputElement;
// We ignore elements that have no value. Unlike userName, alternateUserNames
// is used only for autofill, not for form identification, and blank autofill
// entries are not useful.
if (!inputElement.value().isEmpty())
fields->alternateUserNames.append(inputElement.value());
}
}
}
} // namespace blink
/*
* 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 WebPasswordFormUtils_h
#define WebPasswordFormUtils_h
#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class HTMLInputElement;
class HTMLFormControlElement;
class HTMLFormElement;
}
namespace blink {
// Helper structure to locate username, passwords and submit fields.
//
// Note that we don't check autocomplete property here. The applications using
// password forms can use WebPasswordFormData.passwordShouldAutocomplete to
// implement their own heuristics related autocomplete.
struct PasswordFormFields {
WebCore::HTMLInputElement* userName;
Vector<String> alternateUserNames;
Vector<WebCore::HTMLInputElement*> passwords;
WebCore::HTMLFormControlElement* submit;
PasswordFormFields() : userName(0), submit(0) { }
};
void findPasswordFormFields(WebCore::HTMLFormElement* form,
PasswordFormFields* fields);
} // namespace blink
#endif
...@@ -193,9 +193,6 @@ ...@@ -193,9 +193,6 @@
'WebPageSerializer.cpp', 'WebPageSerializer.cpp',
'WebPageSerializerImpl.cpp', 'WebPageSerializerImpl.cpp',
'WebPageSerializerImpl.h', 'WebPageSerializerImpl.h',
'WebPasswordFormData.cpp',
'WebPasswordFormUtils.cpp',
'WebPasswordFormUtils.h',
'WebPerformance.cpp', 'WebPerformance.cpp',
'WebPluginContainerImpl.cpp', 'WebPluginContainerImpl.cpp',
'WebPluginContainerImpl.h', 'WebPluginContainerImpl.h',
......
/*
* 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 WebPasswordFormData_h
#define WebPasswordFormData_h
#include "../platform/WebString.h"
#include "../platform/WebURL.h"
#include "../platform/WebVector.h"
#include "WebFormElement.h"
namespace blink {
struct WebPasswordFormData {
// If the provided form is suitable for password completion, isValid() will
// return true;
BLINK_EXPORT WebPasswordFormData(const WebFormElement&);
// If creation failed, return false.
bool isValid() const { return action.isValid(); }
// The action target of the form. This is the primary data used by the
// PasswordManager for form autofill; that is, the action of the saved
// credentials must match the action of the form on the page to be autofilled.
// If this is empty / not available, it will result in a "restricted"
// IE-like autofill policy, where we wait for the user to type in his
// username before autofilling the password. In these cases, after successful
// login the action URL will automatically be assigned by the
// PasswordManager.
//
// When parsing an HTML form, this must always be set.
WebURL action;
// The "Realm" for the sign-on (scheme, host, port for SCHEME_HTML, and
// contains the HTTP realm for dialog-based forms).
// The signon_realm is effectively the primary key used for retrieving
// data from the database, so it must not be empty.
WebString signonRealm;
// The URL (minus query parameters) containing the form. This is the primary
// data used by the PasswordManager to decide (in longest matching prefix
// fashion) whether or not a given PasswordForm result from the database is a
// good fit for a particular form on a page, so it must not be empty.
WebURL origin;
// The name of the submit button used. Optional; only used in scoring
// of PasswordForm results from the database to make matches as tight as
// possible.
//
// When parsing an HTML form, this must always be set.
WebString submitElement;
// The name of the username input element. Optional (improves scoring).
//
// When parsing an HTML form, this must always be set.
WebString userNameElement;
// The username. Optional.
//
// When parsing an HTML form, this is typically empty unless the site
// has implemented some form of autofill.
WebString userNameValue;
// If the form has more than one field which could possibly contain the
// username, the extra are placed here. Used for autofill in cases where
// our heuristics for determining the username are wrong. Optional.
//
// When parsing an HTML form, this is typically empty.
WebVector<WebString> possibleUserNames;
// The name of the password input element, Optional (improves scoring).
//
// When parsing an HTML form, this must always be set.
WebString passwordElement;
// The password. Required.
//
// When parsing an HTML form, this is typically empty.
WebString passwordValue;
// Value of shouldAutocomplete for the password element.
bool passwordShouldAutocomplete;
// If the form was a change password form, the name of the
// 'old password' input element. Optional.
WebString oldPasswordElement;
// The old password. Optional.
WebString oldPasswordValue;
WebPasswordFormData()
: passwordShouldAutocomplete(false)
{
}
};
} // namespace blink
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment