1/*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef FormSubmission_h
32#define FormSubmission_h
33
34#include "FormState.h"
35#include "FrameLoaderTypes.h"
36#include "URL.h"
37
38namespace WebCore {
39
40class Document;
41class Event;
42class FormData;
43struct FrameLoadRequest;
44class HTMLFormElement;
45class TextEncoding;
46
47class FormSubmission : public RefCounted<FormSubmission> {
48public:
49    enum Method { GetMethod, PostMethod };
50
51    class Attributes {
52        WTF_MAKE_NONCOPYABLE(Attributes);
53    public:
54        Attributes()
55            : m_method(GetMethod)
56            , m_isMultiPartForm(false)
57            , m_encodingType("application/x-www-form-urlencoded")
58        {
59        }
60
61        Method method() const { return m_method; }
62        static Method parseMethodType(const String&);
63        void updateMethodType(const String&);
64        static String methodString(Method method) { return method == PostMethod ? "post" : "get"; }
65
66        const String& action() const { return m_action; }
67        void parseAction(const String&);
68
69        const String& target() const { return m_target; }
70        void setTarget(const String& target) { m_target = target; }
71
72        const String& encodingType() const { return m_encodingType; }
73        static String parseEncodingType(const String&);
74        void updateEncodingType(const String&);
75        bool isMultiPartForm() const { return m_isMultiPartForm; }
76
77        const String& acceptCharset() const { return m_acceptCharset; }
78        void setAcceptCharset(const String& value) { m_acceptCharset = value; }
79
80        void copyFrom(const Attributes&);
81
82    private:
83        Method m_method;
84        bool m_isMultiPartForm;
85
86        String m_action;
87        String m_target;
88        String m_encodingType;
89        String m_acceptCharset;
90    };
91
92    static PassRefPtr<FormSubmission> create(HTMLFormElement*, const Attributes&, PassRefPtr<Event> event, LockHistory, FormSubmissionTrigger);
93
94    void populateFrameLoadRequest(FrameLoadRequest&);
95
96    URL requestURL() const;
97
98    Method method() const { return m_method; }
99    const URL& action() const { return m_action; }
100    const String& target() const { return m_target; }
101    void clearTarget() { m_target = String(); }
102    const String& contentType() const { return m_contentType; }
103    FormState* state() const { return m_formState.get(); }
104    FormData* data() const { return m_formData.get(); }
105    const String boundary() const { return m_boundary; }
106    LockHistory lockHistory() const { return m_lockHistory; }
107    Event* event() const { return m_event.get(); }
108
109    const String& referrer() const { return m_referrer; }
110    void setReferrer(const String& referrer) { m_referrer = referrer; }
111    const String& origin() const { return m_origin; }
112    void setOrigin(const String& origin) { m_origin = origin; }
113
114private:
115    FormSubmission(Method, const URL& action, const String& target, const String& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, LockHistory, PassRefPtr<Event>);
116
117    // FIXME: Hold an instance of Attributes instead of individual members.
118    Method m_method;
119    URL m_action;
120    String m_target;
121    String m_contentType;
122    RefPtr<FormState> m_formState;
123    RefPtr<FormData> m_formData;
124    String m_boundary;
125    LockHistory m_lockHistory;
126    RefPtr<Event> m_event;
127    String m_referrer;
128    String m_origin;
129};
130
131}
132
133#endif // FormSubmission_h
134