]> git.saurik.com Git - iphone-api.git/blob - WebCore/ResourceResponseBase.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / ResourceResponseBase.h
1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #ifndef ResourceResponseBase_h
28 #define ResourceResponseBase_h
29
30 #include "HTTPHeaderMap.h"
31 #include "KURL.h"
32
33 #include <memory>
34
35 namespace WebCore {
36
37 class ResourceResponse;
38 struct CrossThreadResourceResponseData;
39
40 // Do not use this class directly, use the class ResponseResponse instead
41 class ResourceResponseBase {
42 public:
43 static std::auto_ptr<ResourceResponse> adopt(std::auto_ptr<CrossThreadResourceResponseData>);
44
45 // Gets a copy of the data suitable for passing to another thread.
46 std::auto_ptr<CrossThreadResourceResponseData> copyData() const;
47
48 bool isNull() const { return m_isNull; }
49 bool isHTTP() const;
50
51 const KURL& url() const;
52 void setUrl(const KURL& url);
53
54 const String& mimeType() const;
55 void setMimeType(const String& mimeType);
56
57 long long expectedContentLength() const;
58 void setExpectedContentLength(long long expectedContentLength);
59
60 const String& textEncodingName() const;
61 void setTextEncodingName(const String& name);
62
63 // FIXME should compute this on the fly
64 const String& suggestedFilename() const;
65 void setSuggestedFilename(const String&);
66
67 int httpStatusCode() const;
68 void setHTTPStatusCode(int);
69
70 const String& httpStatusText() const;
71 void setHTTPStatusText(const String&);
72
73 String httpHeaderField(const AtomicString& name) const;
74 void setHTTPHeaderField(const AtomicString& name, const String& value);
75 const HTTPHeaderMap& httpHeaderFields() const;
76
77 bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; }
78
79 bool isAttachment() const;
80
81 void setExpirationDate(time_t);
82 time_t expirationDate() const;
83
84 void setLastModifiedDate(time_t);
85 time_t lastModifiedDate() const;
86
87 bool cacheControlContainsNoCache() const
88 {
89 if (!m_haveParsedCacheControl)
90 parseCacheControlDirectives();
91 return m_cacheControlContainsNoCache;
92 }
93 bool cacheControlContainsMustRevalidate() const
94 {
95 if (!m_haveParsedCacheControl)
96 parseCacheControlDirectives();
97 return m_cacheControlContainsMustRevalidate;
98 }
99
100 static bool compare(const ResourceResponse& a, const ResourceResponse& b);
101
102 protected:
103 ResourceResponseBase()
104 : m_expectedContentLength(0)
105 , m_httpStatusCode(0)
106 , m_expirationDate(0)
107 , m_lastModifiedDate(0)
108 , m_isNull(true)
109 , m_haveParsedCacheControl(false)
110 {
111 }
112
113 ResourceResponseBase(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename)
114 : m_url(url)
115 , m_mimeType(mimeType)
116 , m_expectedContentLength(expectedLength)
117 , m_textEncodingName(textEncodingName)
118 , m_suggestedFilename(filename)
119 , m_httpStatusCode(0)
120 , m_expirationDate(0)
121 , m_lastModifiedDate(0)
122 , m_isNull(false)
123 , m_haveParsedCacheControl(false)
124 {
125 }
126
127 void lazyInit() const;
128
129 // The ResourceResponse subclass may "shadow" this method to lazily initialize platform specific fields
130 void platformLazyInit() { }
131
132 // The ResourceResponse subclass may "shadow" this method to compare platform specific fields
133 static bool platformCompare(const ResourceResponse&, const ResourceResponse&) { return true; }
134
135 KURL m_url;
136 String m_mimeType;
137 long long m_expectedContentLength;
138 String m_textEncodingName;
139 String m_suggestedFilename;
140 int m_httpStatusCode;
141 String m_httpStatusText;
142 HTTPHeaderMap m_httpHeaderFields;
143 time_t m_expirationDate;
144 time_t m_lastModifiedDate;
145 bool m_isNull : 1;
146
147 private:
148 void parseCacheControlDirectives() const;
149
150 mutable bool m_haveParsedCacheControl : 1;
151 mutable bool m_cacheControlContainsMustRevalidate : 1;
152 mutable bool m_cacheControlContainsNoCache : 1;
153 };
154
155 inline bool operator==(const ResourceResponse& a, const ResourceResponse& b) { return ResourceResponseBase::compare(a, b); }
156 inline bool operator!=(const ResourceResponse& a, const ResourceResponse& b) { return !(a == b); }
157
158 struct CrossThreadResourceResponseData {
159 KURL m_url;
160 String m_mimeType;
161 long long m_expectedContentLength;
162 String m_textEncodingName;
163 String m_suggestedFilename;
164 int m_httpStatusCode;
165 String m_httpStatusText;
166 OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
167 time_t m_expirationDate;
168 time_t m_lastModifiedDate;
169 bool m_haveParsedCacheControl : 1;
170 bool m_cacheControlContainsMustRevalidate : 1;
171 bool m_cacheControlContainsNoCache : 1;
172 };
173
174 } // namespace WebCore
175
176 #endif // ResourceResponseBase_h