Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / loader / FormSubmission.h
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 "core/loader/FormState.h"
35 #include "platform/weborigin/KURL.h"
36 #include "platform/weborigin/Referrer.h"
37
38 namespace WTF{
39 class TextEncoding;
40 }
41
42 namespace WebCore {
43
44 class Document;
45 class Event;
46 class FormData;
47 struct FrameLoadRequest;
48 class HTMLFormElement;
49
50 class FormSubmission : public RefCounted<FormSubmission> {
51 public:
52     enum Method { GetMethod, PostMethod, DialogMethod };
53
54     class Attributes {
55         WTF_MAKE_NONCOPYABLE(Attributes);
56     public:
57         Attributes()
58             : m_method(GetMethod)
59             , m_isMultiPartForm(false)
60             , m_encodingType("application/x-www-form-urlencoded", AtomicString::ConstructFromLiteral)
61         {
62         }
63
64         Method method() const { return m_method; }
65         static Method parseMethodType(const String&);
66         void updateMethodType(const String&);
67         static String methodString(Method);
68
69         const String& action() const { return m_action; }
70         void parseAction(const String&);
71
72         const AtomicString& target() const { return m_target; }
73         void setTarget(const AtomicString& target) { m_target = target; }
74
75         const AtomicString& encodingType() const { return m_encodingType; }
76         static AtomicString parseEncodingType(const String&);
77         void updateEncodingType(const String&);
78         bool isMultiPartForm() const { return m_isMultiPartForm; }
79
80         const String& acceptCharset() const { return m_acceptCharset; }
81         void setAcceptCharset(const String& value) { m_acceptCharset = value; }
82
83         void copyFrom(const Attributes&);
84
85     private:
86         Method m_method;
87         bool m_isMultiPartForm;
88
89         String m_action;
90         AtomicString m_target;
91         AtomicString m_encodingType;
92         String m_acceptCharset;
93     };
94
95     static PassRefPtr<FormSubmission> create(HTMLFormElement*, const Attributes&, PassRefPtr<Event> event, FormSubmissionTrigger);
96
97     void populateFrameLoadRequest(FrameLoadRequest&);
98
99     KURL requestURL() const;
100
101     Method method() const { return m_method; }
102     const KURL& action() const { return m_action; }
103     const AtomicString& target() const { return m_target; }
104     void clearTarget() { m_target = nullAtom; }
105     const AtomicString& contentType() const { return m_contentType; }
106     FormState* state() const { return m_formState.get(); }
107     FormData* data() const { return m_formData.get(); }
108     const String boundary() const { return m_boundary; }
109     Event* event() const { return m_event.get(); }
110
111     const Referrer& referrer() const { return m_referrer; }
112     void setReferrer(const Referrer& referrer) { m_referrer = referrer; }
113     const String& origin() const { return m_origin; }
114     void setOrigin(const String& origin) { m_origin = origin; }
115
116     const String& result() const { return m_result; }
117
118 private:
119     FormSubmission(Method, const KURL& action, const AtomicString& target, const AtomicString& contentType, PassRefPtr<FormState>, PassRefPtr<FormData>, const String& boundary, PassRefPtr<Event>);
120     // FormSubmission for DialogMethod
121     FormSubmission(const String& result);
122
123     // FIXME: Hold an instance of Attributes instead of individual members.
124     Method m_method;
125     KURL m_action;
126     AtomicString m_target;
127     AtomicString m_contentType;
128     RefPtr<FormState> m_formState;
129     RefPtr<FormData> m_formData;
130     String m_boundary;
131     RefPtr<Event> m_event;
132     Referrer m_referrer;
133     String m_origin;
134     String m_result;
135 };
136
137 }
138
139 #endif // FormSubmission_h