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"
32 #include "ResourceLoadInfo.h"
33 #include "ResourceLoadTiming.h"
35 #include <wtf/PassOwnPtr.h>
36 #include <wtf/RefPtr.h>
40 class ResourceResponse;
41 struct CrossThreadResourceResponseData;
43 // Do not use this class directly, use the class ResponseResponse instead
44 class ResourceResponseBase : public FastAllocBase {
46 static PassOwnPtr<ResourceResponse> adopt(PassOwnPtr<CrossThreadResourceResponseData>);
48 // Gets a copy of the data suitable for passing to another thread.
49 PassOwnPtr<CrossThreadResourceResponseData> copyData() const;
51 bool isNull() const { return m_isNull; }
54 const KURL& url() const;
55 void setURL(const KURL& url);
57 const String& mimeType() const;
58 void setMimeType(const String& mimeType);
60 long long expectedContentLength() const;
61 void setExpectedContentLength(long long expectedContentLength);
63 const String& textEncodingName() const;
64 void setTextEncodingName(const String& name);
66 // FIXME should compute this on the fly
67 const String& suggestedFilename() const;
68 void setSuggestedFilename(const String&);
70 int httpStatusCode() const;
71 void setHTTPStatusCode(int);
73 const String& httpStatusText() const;
74 void setHTTPStatusText(const String&);
76 String httpHeaderField(const AtomicString& name) const;
77 String httpHeaderField(const char* name) const;
78 void setHTTPHeaderField(const AtomicString& name, const String& value);
79 const HTTPHeaderMap& httpHeaderFields() const;
81 bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; }
83 bool isAttachment() const;
85 // FIXME: These are used by PluginStream on some platforms. Calculations may differ from just returning plain Last-odified header.
86 // Leaving it for now but this should go away in favor of generic solution.
87 void setLastModifiedDate(time_t);
88 time_t lastModifiedDate() const;
90 // These functions return parsed values of the corresponding response headers.
91 // NaN means that the header was not present or had invalid value.
92 bool cacheControlContainsNoCache() const;
93 bool cacheControlContainsNoStore() const;
94 bool cacheControlContainsMustRevalidate() const;
95 double cacheControlMaxAge() const;
98 double expires() const;
99 double lastModified() const;
101 unsigned connectionID() const;
102 void setConnectionID(unsigned);
104 bool connectionReused() const;
105 void setConnectionReused(bool);
107 bool wasCached() const;
108 void setWasCached(bool);
110 ResourceLoadTiming* resourceLoadTiming() const;
111 void setResourceLoadTiming(PassRefPtr<ResourceLoadTiming>);
113 PassRefPtr<ResourceLoadInfo> resourceLoadInfo() const;
114 void setResourceLoadInfo(PassRefPtr<ResourceLoadInfo>);
116 // The ResourceResponse subclass may "shadow" this method to provide platform-specific memory usage information
117 unsigned memoryUsage() const
119 // average size, mostly due to URL and Header Map strings
123 static bool compare(const ResourceResponse&, const ResourceResponse&);
126 ResourceResponseBase();
127 ResourceResponseBase(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename);
129 void lazyInit() const;
131 // The ResourceResponse subclass may "shadow" this method to lazily initialize platform specific fields
132 void platformLazyInit() { }
134 // The ResourceResponse subclass may "shadow" this method to compare platform specific fields
135 static bool platformCompare(const ResourceResponse&, const ResourceResponse&) { return true; }
139 long long m_expectedContentLength;
140 String m_textEncodingName;
141 String m_suggestedFilename;
142 int m_httpStatusCode;
143 String m_httpStatusText;
144 HTTPHeaderMap m_httpHeaderFields;
145 time_t m_lastModifiedDate;
146 bool m_wasCached : 1;
147 unsigned m_connectionID;
148 bool m_connectionReused : 1;
149 RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
150 RefPtr<ResourceLoadInfo> m_resourceLoadInfo;
155 const ResourceResponse& asResourceResponse() const;
156 void parseCacheControlDirectives() const;
158 mutable bool m_haveParsedCacheControlHeader : 1;
159 mutable bool m_haveParsedAgeHeader : 1;
160 mutable bool m_haveParsedDateHeader : 1;
161 mutable bool m_haveParsedExpiresHeader : 1;
162 mutable bool m_haveParsedLastModifiedHeader : 1;
164 mutable bool m_cacheControlContainsNoCache : 1;
165 mutable bool m_cacheControlContainsNoStore : 1;
166 mutable bool m_cacheControlContainsMustRevalidate : 1;
167 mutable double m_cacheControlMaxAge;
169 mutable double m_age;
170 mutable double m_date;
171 mutable double m_expires;
172 mutable double m_lastModified;
175 inline bool operator==(const ResourceResponse& a, const ResourceResponse& b) { return ResourceResponseBase::compare(a, b); }
176 inline bool operator!=(const ResourceResponse& a, const ResourceResponse& b) { return !(a == b); }
178 struct CrossThreadResourceResponseDataBase : Noncopyable {
181 long long m_expectedContentLength;
182 String m_textEncodingName;
183 String m_suggestedFilename;
184 int m_httpStatusCode;
185 String m_httpStatusText;
186 OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
187 time_t m_lastModifiedDate;
188 RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
191 } // namespace WebCore
193 #endif // ResourceResponseBase_h