Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: Source/platform/network/FormData.h

Issue 1311923004: Rename FormData/FormDataBuilder to EncodedFormData/FormDataEncoder respectively. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: update comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/network/EncodedFormDataTest.cpp ('k') | Source/platform/network/FormData.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 FormData_h
21 #define FormData_h
22
23 #include "platform/blob/BlobData.h"
24 #include "platform/weborigin/KURL.h"
25 #include "wtf/Forward.h"
26 #include "wtf/RefCounted.h"
27 #include "wtf/Vector.h"
28 #include "wtf/text/WTFString.h"
29
30 namespace blink {
31
32 class BlobDataHandle;
33
34 class PLATFORM_EXPORT FormDataElement {
35 public:
36 FormDataElement() : m_type(data) { }
37 explicit FormDataElement(const Vector<char>& array) : m_type(data), m_data(a rray) { }
38
39 FormDataElement(const String& filename, long long fileStart, long long fileL ength, double expectedFileModificationTime) : m_type(encodedFile), m_filename(fi lename), m_fileStart(fileStart), m_fileLength(fileLength), m_expectedFileModific ationTime(expectedFileModificationTime) { }
40 explicit FormDataElement(const String& blobUUID, PassRefPtr<BlobDataHandle> optionalHandle) : m_type(encodedBlob), m_blobUUID(blobUUID), m_optionalBlobDataH andle(optionalHandle) { }
41 FormDataElement(const KURL& fileSystemURL, long long start, long long length , double expectedFileModificationTime) : m_type(encodedFileSystemURL), m_fileSys temURL(fileSystemURL), m_fileStart(start), m_fileLength(length), m_expectedFileM odificationTime(expectedFileModificationTime) { }
42
43 bool isSafeToSendToAnotherThread() const;
44
45 enum Type {
46 data,
47 encodedFile,
48 encodedBlob,
49 encodedFileSystemURL
50 } m_type;
51 Vector<char> m_data;
52 String m_filename;
53 String m_blobUUID;
54 RefPtr<BlobDataHandle> m_optionalBlobDataHandle;
55 KURL m_fileSystemURL;
56 long long m_fileStart;
57 long long m_fileLength;
58 double m_expectedFileModificationTime;
59 };
60
61 inline bool operator==(const FormDataElement& a, const FormDataElement& b)
62 {
63 if (&a == &b)
64 return true;
65
66 if (a.m_type != b.m_type)
67 return false;
68 if (a.m_type == FormDataElement::data)
69 return a.m_data == b.m_data;
70 if (a.m_type == FormDataElement::encodedFile)
71 return a.m_filename == b.m_filename && a.m_fileStart == b.m_fileStart && a.m_fileLength == b.m_fileLength && a.m_expectedFileModificationTime == b.m_exp ectedFileModificationTime;
72 if (a.m_type == FormDataElement::encodedBlob)
73 return a.m_blobUUID == b.m_blobUUID;
74 if (a.m_type == FormDataElement::encodedFileSystemURL)
75 return a.m_fileSystemURL == b.m_fileSystemURL;
76
77 return true;
78 }
79
80 inline bool operator!=(const FormDataElement& a, const FormDataElement& b)
81 {
82 return !(a == b);
83 }
84
85 class PLATFORM_EXPORT FormData : public RefCounted<FormData> {
86 public:
87 enum EncodingType {
88 FormURLEncoded, // for application/x-www-form-urlencoded
89 TextPlain, // for text/plain
90 MultipartFormData // for multipart/form-data
91 };
92
93 static PassRefPtr<FormData> create();
94 static PassRefPtr<FormData> create(const void*, size_t);
95 static PassRefPtr<FormData> create(const CString&);
96 static PassRefPtr<FormData> create(const Vector<char>&);
97 PassRefPtr<FormData> copy() const;
98 PassRefPtr<FormData> deepCopy() const;
99 ~FormData();
100
101 void appendData(const void* data, size_t);
102 void appendFile(const String& filePath);
103 void appendFileRange(const String& filename, long long start, long long leng th, double expectedModificationTime);
104 void appendBlob(const String& blobUUID, PassRefPtr<BlobDataHandle> optionalH andle);
105 void appendFileSystemURL(const KURL&);
106 void appendFileSystemURLRange(const KURL&, long long start, long long length , double expectedModificationTime);
107
108 void flatten(Vector<char>&) const; // omits files
109 String flattenToString() const; // omits files
110
111 bool isEmpty() const { return m_elements.isEmpty(); }
112 const Vector<FormDataElement>& elements() const { return m_elements; }
113
114 const Vector<char>& boundary() const { return m_boundary; }
115 void setBoundary(Vector<char> boundary) { m_boundary = boundary; }
116
117 // Identifies a particular form submission instance. A value of 0 is used
118 // to indicate an unspecified identifier.
119 void setIdentifier(int64_t identifier) { m_identifier = identifier; }
120 int64_t identifier() const { return m_identifier; }
121
122 bool containsPasswordData() const { return m_containsPasswordData; }
123 void setContainsPasswordData(bool containsPasswordData) { m_containsPassword Data = containsPasswordData; }
124
125 static EncodingType parseEncodingType(const String& type)
126 {
127 if (equalIgnoringCase(type, "text/plain"))
128 return TextPlain;
129 if (equalIgnoringCase(type, "multipart/form-data"))
130 return MultipartFormData;
131 return FormURLEncoded;
132 }
133
134 // Size of the elements making up the FormData.
135 unsigned long long sizeInBytes() const;
136
137 bool isSafeToSendToAnotherThread() const;
138
139 private:
140 FormData();
141 FormData(const FormData&);
142
143 Vector<FormDataElement> m_elements;
144
145 int64_t m_identifier;
146 Vector<char> m_boundary;
147 bool m_containsPasswordData;
148 };
149
150 inline bool operator==(const FormData& a, const FormData& b)
151 {
152 return a.elements() == b.elements();
153 }
154
155 inline bool operator!=(const FormData& a, const FormData& b)
156 {
157 return !(a == b);
158 }
159
160 } // namespace blink
161
162 #endif
OLDNEW
« no previous file with comments | « Source/platform/network/EncodedFormDataTest.cpp ('k') | Source/platform/network/FormData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698