1/*
2 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19#ifndef CredentialTransformData_h
20#define CredentialTransformData_h
21
22#include "Credential.h"
23#include "HTMLFormElement.h"
24#include "HTMLInputElement.h"
25#include "KURL.h"
26#include "ProtectionSpace.h"
27
28#include <wtf/RefPtr.h>
29
30namespace WebCore {
31
32struct CredentialTransformData {
33    // If the provided form is suitable for password completion, isValid() will
34    // return true;
35    CredentialTransformData();
36    CredentialTransformData(HTMLFormElement*, bool isForSaving = false);
37    CredentialTransformData(const ProtectionSpace&, const Credential&);
38
39    // If creation failed, return false.
40    bool isValid() const { return m_isValid; }
41
42    ProtectionSpace protectionSpace() const { return m_protectionSpace; }
43    Credential credential() const;
44    void setCredential(const Credential&);
45
46private:
47    bool findPasswordFormFields(const HTMLFormElement*);
48    bool locateSpecificPasswords(const Vector<HTMLInputElement*>& passwords);
49
50    KURL m_action;
51    ProtectionSpace m_protectionSpace;
52    mutable Credential m_credential;
53    RefPtr<HTMLInputElement> m_userNameElement;
54    RefPtr<HTMLInputElement> m_passwordElement;
55    RefPtr<HTMLInputElement> m_oldPasswordElement;
56    bool m_isValid;
57};
58
59} // namespace WebCore
60
61#endif
62