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