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