1 /* 2 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef WebURLResponse_h 32 #define WebURLResponse_h 33 34 #include "WebCommon.h" 35 #include "WebPrivateOwnPtr.h" 36 37 #if WEBKIT_IMPLEMENTATION 38 namespace WebCore { class ResourceResponse; } 39 #endif 40 41 namespace WebKit { 42 43 class WebCString; 44 class WebHTTPHeaderVisitor; 45 class WebHTTPLoadInfo; 46 class WebString; 47 class WebURL; 48 class WebURLLoadTiming; 49 class WebURLResponsePrivate; 50 51 class WebURLResponse { 52 public: 53 enum HTTPVersion { Unknown, HTTP_0_9, HTTP_1_0, HTTP_1_1 }; 54 55 class ExtraData { 56 public: 57 virtual ~ExtraData() { } 58 }; 59 60 ~WebURLResponse() { reset(); } 61 62 WebURLResponse() : m_private(0) { } 63 WebURLResponse(const WebURLResponse& r) : m_private(0) { assign(r); } 64 WebURLResponse& operator=(const WebURLResponse& r) 65 { 66 assign(r); 67 return *this; 68 } 69 70 explicit WebURLResponse(const WebURL& url) : m_private(0) 71 { 72 initialize(); 73 setURL(url); 74 } 75 76 WEBKIT_EXPORT void initialize(); 77 WEBKIT_EXPORT void reset(); 78 WEBKIT_EXPORT void assign(const WebURLResponse&); 79 80 WEBKIT_EXPORT bool isNull() const; 81 82 WEBKIT_EXPORT WebURL url() const; 83 WEBKIT_EXPORT void setURL(const WebURL&); 84 85 WEBKIT_EXPORT unsigned connectionID() const; 86 WEBKIT_EXPORT void setConnectionID(unsigned); 87 88 WEBKIT_EXPORT bool connectionReused() const; 89 WEBKIT_EXPORT void setConnectionReused(bool); 90 91 WEBKIT_EXPORT WebURLLoadTiming loadTiming(); 92 WEBKIT_EXPORT void setLoadTiming(const WebURLLoadTiming&); 93 94 WEBKIT_EXPORT WebHTTPLoadInfo httpLoadInfo(); 95 WEBKIT_EXPORT void setHTTPLoadInfo(const WebHTTPLoadInfo&); 96 97 WEBKIT_EXPORT double responseTime() const; 98 WEBKIT_EXPORT void setResponseTime(double); 99 100 WEBKIT_EXPORT WebString mimeType() const; 101 WEBKIT_EXPORT void setMIMEType(const WebString&); 102 103 WEBKIT_EXPORT long long expectedContentLength() const; 104 WEBKIT_EXPORT void setExpectedContentLength(long long); 105 106 WEBKIT_EXPORT WebString textEncodingName() const; 107 WEBKIT_EXPORT void setTextEncodingName(const WebString&); 108 109 WEBKIT_EXPORT WebString suggestedFileName() const; 110 WEBKIT_EXPORT void setSuggestedFileName(const WebString&); 111 112 WEBKIT_EXPORT HTTPVersion httpVersion() const; 113 WEBKIT_EXPORT void setHTTPVersion(HTTPVersion); 114 115 WEBKIT_EXPORT int httpStatusCode() const; 116 WEBKIT_EXPORT void setHTTPStatusCode(int); 117 118 WEBKIT_EXPORT WebString httpStatusText() const; 119 WEBKIT_EXPORT void setHTTPStatusText(const WebString&); 120 121 WEBKIT_EXPORT WebString httpHeaderField(const WebString& name) const; 122 WEBKIT_EXPORT void setHTTPHeaderField(const WebString& name, const WebString& value); 123 WEBKIT_EXPORT void addHTTPHeaderField(const WebString& name, const WebString& value); 124 WEBKIT_EXPORT void clearHTTPHeaderField(const WebString& name); 125 WEBKIT_EXPORT void visitHTTPHeaderFields(WebHTTPHeaderVisitor*) const; 126 127 WEBKIT_EXPORT double lastModifiedDate() const; 128 WEBKIT_EXPORT void setLastModifiedDate(double); 129 130 WEBKIT_EXPORT long long appCacheID() const; 131 WEBKIT_EXPORT void setAppCacheID(long long); 132 133 WEBKIT_EXPORT WebURL appCacheManifestURL() const; 134 WEBKIT_EXPORT void setAppCacheManifestURL(const WebURL&); 135 136 // A consumer controlled value intended to be used to record opaque 137 // security info related to this request. 138 WEBKIT_EXPORT WebCString securityInfo() const; 139 WEBKIT_EXPORT void setSecurityInfo(const WebCString&); 140 141 #if WEBKIT_IMPLEMENTATION 142 WebCore::ResourceResponse& toMutableResourceResponse(); 143 const WebCore::ResourceResponse& toResourceResponse() const; 144 #endif 145 146 // Flag whether this request was served from the disk cache entry. 147 WEBKIT_EXPORT bool wasCached() const; 148 WEBKIT_EXPORT void setWasCached(bool); 149 150 // Flag whether this request was loaded via the SPDY protocol or not. 151 // SPDY is an experimental web protocol, see http://dev.chromium.org/spdy 152 WEBKIT_EXPORT bool wasFetchedViaSPDY() const; 153 WEBKIT_EXPORT void setWasFetchedViaSPDY(bool); 154 155 // Flag whether this request was loaded after the TLS/Next-Protocol-Negotiation was used. 156 // This is related to SPDY. 157 WEBKIT_EXPORT bool wasNpnNegotiated() const; 158 WEBKIT_EXPORT void setWasNpnNegotiated(bool); 159 160 // Flag whether this request was made when "Alternate-Protocol: xxx" 161 // is present in server's response. 162 WEBKIT_EXPORT bool wasAlternateProtocolAvailable() const; 163 WEBKIT_EXPORT void setWasAlternateProtocolAvailable(bool); 164 165 // Flag whether this request was loaded via an explicit proxy (HTTP, SOCKS, etc). 166 WEBKIT_EXPORT bool wasFetchedViaProxy() const; 167 WEBKIT_EXPORT void setWasFetchedViaProxy(bool); 168 169 // Flag whether this request is part of a multipart response. 170 WEBKIT_EXPORT bool isMultipartPayload() const; 171 WEBKIT_EXPORT void setIsMultipartPayload(bool); 172 173 // This indicates the location of a downloaded response if the 174 // WebURLRequest had the downloadToFile flag set to true. This file path 175 // remains valid for the lifetime of the WebURLLoader used to create it. 176 WEBKIT_EXPORT WebString downloadFilePath() const; 177 WEBKIT_EXPORT void setDownloadFilePath(const WebString&); 178 179 // Remote IP address of the socket which fetched this resource. 180 WEBKIT_EXPORT WebString remoteIPAddress() const; 181 WEBKIT_EXPORT void setRemoteIPAddress(const WebString&); 182 183 // Remote port number of the socket which fetched this resource. 184 WEBKIT_EXPORT unsigned short remotePort() const; 185 WEBKIT_EXPORT void setRemotePort(unsigned short); 186 187 // Extra data associated with the underlying resource response. Resource 188 // responses can be copied. If non-null, each copy of a resource response 189 // holds a pointer to the extra data, and the extra data pointer will be 190 // deleted when the last resource response is destroyed. Setting the extra 191 // data pointer will cause the underlying resource response to be 192 // dissociated from any existing non-null extra data pointer. 193 WEBKIT_EXPORT ExtraData* extraData() const; 194 WEBKIT_EXPORT void setExtraData(ExtraData*); 195 196 protected: 197 void assign(WebURLResponsePrivate*); 198 199 private: 200 WebURLResponsePrivate* m_private; 201 }; 202 203 } // namespace WebKit 204 205 #endif 206