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