2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef ResourceResponseBase_h
28 #define ResourceResponseBase_h
30 #include "HTTPHeaderMap.h"
37 class ResourceResponse
;
38 struct CrossThreadResourceResponseData
;
40 // Do not use this class directly, use the class ResponseResponse instead
41 class ResourceResponseBase
{
43 static std::auto_ptr
<ResourceResponse
> adopt(std::auto_ptr
<CrossThreadResourceResponseData
>);
45 // Gets a copy of the data suitable for passing to another thread.
46 std::auto_ptr
<CrossThreadResourceResponseData
> copyData() const;
48 bool isNull() const { return m_isNull
; }
51 const KURL
& url() const;
52 void setUrl(const KURL
& url
);
54 const String
& mimeType() const;
55 void setMimeType(const String
& mimeType
);
57 long long expectedContentLength() const;
58 void setExpectedContentLength(long long expectedContentLength
);
60 const String
& textEncodingName() const;
61 void setTextEncodingName(const String
& name
);
63 // FIXME should compute this on the fly
64 const String
& suggestedFilename() const;
65 void setSuggestedFilename(const String
&);
67 int httpStatusCode() const;
68 void setHTTPStatusCode(int);
70 const String
& httpStatusText() const;
71 void setHTTPStatusText(const String
&);
73 String
httpHeaderField(const AtomicString
& name
) const;
74 void setHTTPHeaderField(const AtomicString
& name
, const String
& value
);
75 const HTTPHeaderMap
& httpHeaderFields() const;
77 bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; }
79 bool isAttachment() const;
81 void setExpirationDate(time_t);
82 time_t expirationDate() const;
84 void setLastModifiedDate(time_t);
85 time_t lastModifiedDate() const;
87 bool cacheControlContainsNoCache() const
89 if (!m_haveParsedCacheControl
)
90 parseCacheControlDirectives();
91 return m_cacheControlContainsNoCache
;
93 bool cacheControlContainsMustRevalidate() const
95 if (!m_haveParsedCacheControl
)
96 parseCacheControlDirectives();
97 return m_cacheControlContainsMustRevalidate
;
100 static bool compare(const ResourceResponse
& a
, const ResourceResponse
& b
);
103 ResourceResponseBase()
104 : m_expectedContentLength(0)
105 , m_httpStatusCode(0)
106 , m_expirationDate(0)
107 , m_lastModifiedDate(0)
109 , m_haveParsedCacheControl(false)
113 ResourceResponseBase(const KURL
& url
, const String
& mimeType
, long long expectedLength
, const String
& textEncodingName
, const String
& filename
)
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)
123 , m_haveParsedCacheControl(false)
127 void lazyInit() const;
129 // The ResourceResponse subclass may "shadow" this method to lazily initialize platform specific fields
130 void platformLazyInit() { }
132 // The ResourceResponse subclass may "shadow" this method to compare platform specific fields
133 static bool platformCompare(const ResourceResponse
&, const ResourceResponse
&) { return true; }
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
;
148 void parseCacheControlDirectives() const;
150 mutable bool m_haveParsedCacheControl
: 1;
151 mutable bool m_cacheControlContainsMustRevalidate
: 1;
152 mutable bool m_cacheControlContainsNoCache
: 1;
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
); }
158 struct CrossThreadResourceResponseData
{
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;
174 } // namespace WebCore
176 #endif // ResourceResponseBase_h