OSDN Git Service

Reconcile with honeycomb-release honeycomb-mr1-release
[android-x86/external-webkit.git] / Source / WebCore / platform / network / 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 #include "ResourceLoadInfo.h"
33 #include "ResourceLoadTiming.h"
34
35 #include <wtf/PassOwnPtr.h>
36 #include <wtf/RefPtr.h>
37
38 namespace WebCore {
39
40 class ResourceResponse;
41 struct CrossThreadResourceResponseData;
42
43 // Do not use this class directly, use the class ResponseResponse instead
44 class ResourceResponseBase : public FastAllocBase {
45 public:
46     static PassOwnPtr<ResourceResponse> adopt(PassOwnPtr<CrossThreadResourceResponseData>);
47
48     // Gets a copy of the data suitable for passing to another thread.
49     PassOwnPtr<CrossThreadResourceResponseData> copyData() const;
50
51     bool isNull() const { return m_isNull; }
52     bool isHTTP() const;
53
54     const KURL& url() const;
55     void setURL(const KURL& url);
56
57     const String& mimeType() const;
58     void setMimeType(const String& mimeType);
59
60     long long expectedContentLength() const;
61     void setExpectedContentLength(long long expectedContentLength);
62
63     const String& textEncodingName() const;
64     void setTextEncodingName(const String& name);
65
66     // FIXME should compute this on the fly
67     const String& suggestedFilename() const;
68     void setSuggestedFilename(const String&);
69
70     int httpStatusCode() const;
71     void setHTTPStatusCode(int);
72     
73     const String& httpStatusText() const;
74     void setHTTPStatusText(const String&);
75     
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;
80
81     bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; }
82
83     bool isAttachment() const;
84     
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; 
89
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;
96     double date() const;
97     double age() const;
98     double expires() const;
99     double lastModified() const;
100
101     unsigned connectionID() const;
102     void setConnectionID(unsigned);
103
104     bool connectionReused() const;
105     void setConnectionReused(bool);
106
107     bool wasCached() const;
108     void setWasCached(bool);
109
110     ResourceLoadTiming* resourceLoadTiming() const;
111     void setResourceLoadTiming(PassRefPtr<ResourceLoadTiming>);
112
113     PassRefPtr<ResourceLoadInfo> resourceLoadInfo() const;
114     void setResourceLoadInfo(PassRefPtr<ResourceLoadInfo>);
115
116     // The ResourceResponse subclass may "shadow" this method to provide platform-specific memory usage information
117     unsigned memoryUsage() const
118     {
119         // average size, mostly due to URL and Header Map strings
120         return 1280;
121     }
122
123     static bool compare(const ResourceResponse&, const ResourceResponse&);
124
125 protected:
126     ResourceResponseBase();
127     ResourceResponseBase(const KURL& url, const String& mimeType, long long expectedLength, const String& textEncodingName, const String& filename);
128
129     void lazyInit() const;
130
131     // The ResourceResponse subclass may "shadow" this method to lazily initialize platform specific fields
132     void platformLazyInit() { }
133
134     // The ResourceResponse subclass may "shadow" this method to compare platform specific fields
135     static bool platformCompare(const ResourceResponse&, const ResourceResponse&) { return true; }
136
137     KURL m_url;
138     String m_mimeType;
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;
151
152     bool m_isNull : 1;
153     
154 private:
155     const ResourceResponse& asResourceResponse() const;
156     void parseCacheControlDirectives() const;
157
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;
163
164     mutable bool m_cacheControlContainsNoCache : 1;
165     mutable bool m_cacheControlContainsNoStore : 1;
166     mutable bool m_cacheControlContainsMustRevalidate : 1;
167     mutable double m_cacheControlMaxAge;
168
169     mutable double m_age;
170     mutable double m_date;
171     mutable double m_expires;
172     mutable double m_lastModified;
173 };
174
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); }
177
178 struct CrossThreadResourceResponseDataBase : Noncopyable {
179     KURL m_url;
180     String m_mimeType;
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;
189 };
190
191 } // namespace WebCore
192
193 #endif // ResourceResponseBase_h