| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * This library is free software; you can redistribute it and/or | |
| 5 * modify it under the terms of the GNU Library General Public | |
| 6 * License as published by the Free Software Foundation; either | |
| 7 * version 2 of the License, or (at your option) any later version. | |
| 8 * | |
| 9 * This library is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 * Library General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU Library General Public License | |
| 15 * along with this library; see the file COPYING.LIB. If not, write to | |
| 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 17 * Boston, MA 02110-1301, USA. | |
| 18 */ | |
| 19 | |
| 20 #ifndef SKY_ENGINE_PLATFORM_NETWORK_FORMDATA_H_ | |
| 21 #define SKY_ENGINE_PLATFORM_NETWORK_FORMDATA_H_ | |
| 22 | |
| 23 #include "sky/engine/platform/weborigin/KURL.h" | |
| 24 #include "sky/engine/wtf/Forward.h" | |
| 25 #include "sky/engine/wtf/RefCounted.h" | |
| 26 #include "sky/engine/wtf/Vector.h" | |
| 27 #include "sky/engine/wtf/text/WTFString.h" | |
| 28 | |
| 29 namespace blink { | |
| 30 | |
| 31 class PLATFORM_EXPORT FormDataElement { | |
| 32 public: | |
| 33 FormDataElement() : m_type(data) { } | |
| 34 explicit FormDataElement(const Vector<char>& array) : m_type(data), m_data(a
rray) { } | |
| 35 | |
| 36 enum Type { | |
| 37 data, | |
| 38 } m_type; | |
| 39 Vector<char> m_data; | |
| 40 }; | |
| 41 | |
| 42 inline bool operator==(const FormDataElement& a, const FormDataElement& b) | |
| 43 { | |
| 44 if (&a == &b) | |
| 45 return true; | |
| 46 | |
| 47 if (a.m_type != b.m_type) | |
| 48 return false; | |
| 49 if (a.m_type == FormDataElement::data) | |
| 50 return a.m_data == b.m_data; | |
| 51 | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 inline bool operator!=(const FormDataElement& a, const FormDataElement& b) | |
| 56 { | |
| 57 return !(a == b); | |
| 58 } | |
| 59 | |
| 60 class PLATFORM_EXPORT FormData : public RefCounted<FormData> { | |
| 61 public: | |
| 62 enum EncodingType { | |
| 63 FormURLEncoded, // for application/x-www-form-urlencoded | |
| 64 TextPlain, // for text/plain | |
| 65 MultipartFormData // for multipart/form-data | |
| 66 }; | |
| 67 | |
| 68 static PassRefPtr<FormData> create(); | |
| 69 static PassRefPtr<FormData> create(const void*, size_t); | |
| 70 static PassRefPtr<FormData> create(const CString&); | |
| 71 static PassRefPtr<FormData> create(const Vector<char>&); | |
| 72 PassRefPtr<FormData> copy() const; | |
| 73 PassRefPtr<FormData> deepCopy() const; | |
| 74 ~FormData(); | |
| 75 | |
| 76 void appendData(const void* data, size_t); | |
| 77 | |
| 78 void flatten(Vector<char>&) const; // omits files | |
| 79 String flattenToString() const; // omits files | |
| 80 | |
| 81 bool isEmpty() const { return m_elements.isEmpty(); } | |
| 82 const Vector<FormDataElement>& elements() const { return m_elements; } | |
| 83 | |
| 84 const Vector<char>& boundary() const { return m_boundary; } | |
| 85 void setBoundary(Vector<char> boundary) { m_boundary = boundary; } | |
| 86 | |
| 87 bool alwaysStream() const { return m_alwaysStream; } | |
| 88 void setAlwaysStream(bool alwaysStream) { m_alwaysStream = alwaysStream; } | |
| 89 | |
| 90 // Identifies a particular form submission instance. A value of 0 is used | |
| 91 // to indicate an unspecified identifier. | |
| 92 void setIdentifier(int64_t identifier) { m_identifier = identifier; } | |
| 93 int64_t identifier() const { return m_identifier; } | |
| 94 | |
| 95 bool containsPasswordData() const { return m_containsPasswordData; } | |
| 96 void setContainsPasswordData(bool containsPasswordData) { m_containsPassword
Data = containsPasswordData; } | |
| 97 | |
| 98 static EncodingType parseEncodingType(const String& type) | |
| 99 { | |
| 100 if (equalIgnoringCase(type, "text/plain")) | |
| 101 return TextPlain; | |
| 102 if (equalIgnoringCase(type, "multipart/form-data")) | |
| 103 return MultipartFormData; | |
| 104 return FormURLEncoded; | |
| 105 } | |
| 106 | |
| 107 // Size of the elements making up the FormData. | |
| 108 unsigned long long sizeInBytes() const; | |
| 109 | |
| 110 private: | |
| 111 FormData(); | |
| 112 FormData(const FormData&); | |
| 113 | |
| 114 Vector<FormDataElement> m_elements; | |
| 115 | |
| 116 int64_t m_identifier; | |
| 117 bool m_alwaysStream; | |
| 118 Vector<char> m_boundary; | |
| 119 bool m_containsPasswordData; | |
| 120 }; | |
| 121 | |
| 122 inline bool operator==(const FormData& a, const FormData& b) | |
| 123 { | |
| 124 return a.elements() == b.elements(); | |
| 125 } | |
| 126 | |
| 127 inline bool operator!=(const FormData& a, const FormData& b) | |
| 128 { | |
| 129 return !(a == b); | |
| 130 } | |
| 131 | |
| 132 } // namespace blink | |
| 133 | |
| 134 #endif // SKY_ENGINE_PLATFORM_NETWORK_FORMDATA_H_ | |
| OLD | NEW |