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#pragma once
32
33#include "FormState.h"
34#include "FrameLoaderTypes.h"
35#include <wtf/URL.h>
36
37namespace WebCore {
38
39class Event;
40class FormData;
41class FrameLoadRequest;
42
43class FormSubmission : public RefCounted<FormSubmission> {
44public:
45 enum class Method { Get, Post };
46
47 class Attributes {
48 public:
49 Method method() const { return m_method; }
50 static Method parseMethodType(const String&);
51 void updateMethodType(const String&);
52 static ASCIILiteral methodString(Method method) { return method == Method::Post ? "post"_s : "get"_s; }
53
54 const String& action() const { return m_action; }
55 void parseAction(const String&);
56
57 const String& target() const { return m_target; }
58 void setTarget(const String& target) { m_target = target; }
59
60 const String& encodingType() const { return m_encodingType; }
61 static String parseEncodingType(const String&);
62 void updateEncodingType(const String&);
63 bool isMultiPartForm() const { return m_isMultiPartForm; }
64
65 const String& acceptCharset() const { return m_acceptCharset; }
66 void setAcceptCharset(const String& value) { m_acceptCharset = value; }
67
68 private:
69 Method m_method { Method::Get };
70 bool m_isMultiPartForm { false };
71 String m_action;
72 String m_target;
73 String m_encodingType { "application/x-www-form-urlencoded"_s };
74 String m_acceptCharset;
75 };
76
77 static Ref<FormSubmission> create(HTMLFormElement&, const Attributes&, Event*, LockHistory, FormSubmissionTrigger);
78
79 void populateFrameLoadRequest(FrameLoadRequest&);
80 URL requestURL() const;
81
82 Method method() const { return m_method; }
83 const URL& action() const { return m_action; }
84 const String& target() const { return m_target; }
85 const String& contentType() const { return m_contentType; }
86 FormState& state() const { return *m_formState; }
87 Ref<FormState> takeState() { return m_formState.releaseNonNull(); }
88 FormData& data() const { return m_formData; }
89 const String boundary() const { return m_boundary; }
90 LockHistory lockHistory() const { return m_lockHistory; }
91 Event* event() const { return m_event.get(); }
92 const String& referrer() const { return m_referrer; }
93 const String& origin() const { return m_origin; }
94
95 void clearTarget() { m_target = { }; }
96 void setReferrer(const String& referrer) { m_referrer = referrer; }
97 void setOrigin(const String& origin) { m_origin = origin; }
98
99private:
100 FormSubmission(Method, const URL& action, const String& target, const String& contentType, Ref<FormState>&&, Ref<FormData>&&, const String& boundary, LockHistory, Event*);
101
102 // FIXME: Hold an instance of Attributes instead of individual members.
103 Method m_method;
104 URL m_action;
105 String m_target;
106 String m_contentType;
107 RefPtr<FormState> m_formState;
108 Ref<FormData> m_formData;
109 String m_boundary;
110 LockHistory m_lockHistory;
111 RefPtr<Event> m_event;
112 String m_referrer;
113 String m_origin;
114};
115
116} // namespace WebCore
117