1 /* 2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> 4 * Copyright (C) 2009 Google Inc. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef ResourceRequestBase_h 29 #define ResourceRequestBase_h 30 31 #include "FormData.h" 32 #include "KURL.h" 33 #include "HTTPHeaderMap.h" 34 35 #include <memory> 36 #include <wtf/OwnPtr.h> 37 38 namespace WebCore { 39 40 enum ResourceRequestCachePolicy { 41 UseProtocolCachePolicy, // normal load 42 ReloadIgnoringCacheData, // reload 43 ReturnCacheDataElseLoad, // back/forward or encoding change - allow stale data 44 ReturnCacheDataDontLoad, // results of a post - allow stale data and only use cache 45 }; 46 47 const int unspecifiedTimeoutInterval = INT_MAX; 48 49 struct ResourceRequest; 50 struct CrossThreadResourceRequestData; 51 52 // Do not use this type directly. Use ResourceRequest instead. 53 class ResourceRequestBase { 54 public: 55 static std::auto_ptr<ResourceRequest> adopt(std::auto_ptr<CrossThreadResourceRequestData>); 56 57 // Gets a copy of the data suitable for passing to another thread. 58 std::auto_ptr<CrossThreadResourceRequestData> copyData() const; 59 60 bool isNull() const; 61 bool isEmpty() const; 62 63 const KURL& url() const; 64 void setURL(const KURL& url); 65 66 void removeCredentials(); 67 68 ResourceRequestCachePolicy cachePolicy() const; 69 void setCachePolicy(ResourceRequestCachePolicy cachePolicy); 70 71 double timeoutInterval() const; 72 void setTimeoutInterval(double timeoutInterval); 73 74 const KURL& firstPartyForCookies() const; 75 void setFirstPartyForCookies(const KURL& firstPartyForCookies); 76 77 const String& httpMethod() const; 78 void setHTTPMethod(const String& httpMethod); 79 80 const HTTPHeaderMap& httpHeaderFields() const; 81 String httpHeaderField(const AtomicString& name) const; 82 void setHTTPHeaderField(const AtomicString& name, const String& value); 83 void addHTTPHeaderField(const AtomicString& name, const String& value); 84 void addHTTPHeaderFields(const HTTPHeaderMap& headerFields); 85 httpContentType()86 String httpContentType() const { return httpHeaderField("Content-Type"); } setHTTPContentType(const String & httpContentType)87 void setHTTPContentType(const String& httpContentType) { setHTTPHeaderField("Content-Type", httpContentType); } 88 httpReferrer()89 String httpReferrer() const { return httpHeaderField("Referer"); } setHTTPReferrer(const String & httpReferrer)90 void setHTTPReferrer(const String& httpReferrer) { setHTTPHeaderField("Referer", httpReferrer); } clearHTTPReferrer()91 void clearHTTPReferrer() { m_httpHeaderFields.remove("Referer"); } 92 httpOrigin()93 String httpOrigin() const { return httpHeaderField("Origin"); } setHTTPOrigin(const String & httpOrigin)94 void setHTTPOrigin(const String& httpOrigin) { setHTTPHeaderField("Origin", httpOrigin); } clearHTTPOrigin()95 void clearHTTPOrigin() { m_httpHeaderFields.remove("Origin"); } 96 httpUserAgent()97 String httpUserAgent() const { return httpHeaderField("User-Agent"); } setHTTPUserAgent(const String & httpUserAgent)98 void setHTTPUserAgent(const String& httpUserAgent) { setHTTPHeaderField("User-Agent", httpUserAgent); } 99 httpAccept()100 String httpAccept() const { return httpHeaderField("Accept"); } setHTTPAccept(const String & httpAccept)101 void setHTTPAccept(const String& httpAccept) { setHTTPHeaderField("Accept", httpAccept); } 102 103 void setResponseContentDispositionEncodingFallbackArray(const String& encoding1, const String& encoding2 = String(), const String& encoding3 = String()); 104 105 FormData* httpBody() const; 106 void setHTTPBody(PassRefPtr<FormData> httpBody); 107 108 bool allowHTTPCookies() const; 109 void setAllowHTTPCookies(bool allowHTTPCookies); 110 111 bool isConditional() const; 112 113 // Whether the associated ResourceHandleClient needs to be notified of 114 // upload progress made for that resource. reportUploadProgress()115 bool reportUploadProgress() const { return m_reportUploadProgress; } setReportUploadProgress(bool reportUploadProgress)116 void setReportUploadProgress(bool reportUploadProgress) { m_reportUploadProgress = reportUploadProgress; } 117 118 protected: 119 // Used when ResourceRequest is initialized from a platform representation of the request ResourceRequestBase()120 ResourceRequestBase() 121 : m_resourceRequestUpdated(false) 122 , m_platformRequestUpdated(true) 123 , m_reportUploadProgress(false) 124 { 125 } 126 ResourceRequestBase(const KURL & url,ResourceRequestCachePolicy policy)127 ResourceRequestBase(const KURL& url, ResourceRequestCachePolicy policy) 128 : m_url(url) 129 , m_cachePolicy(policy) 130 , m_timeoutInterval(unspecifiedTimeoutInterval) 131 , m_httpMethod("GET") 132 , m_allowHTTPCookies(true) 133 , m_resourceRequestUpdated(true) 134 , m_platformRequestUpdated(false) 135 , m_reportUploadProgress(false) 136 { 137 } 138 139 void updatePlatformRequest() const; 140 void updateResourceRequest() const; 141 142 KURL m_url; 143 144 ResourceRequestCachePolicy m_cachePolicy; 145 double m_timeoutInterval; 146 KURL m_firstPartyForCookies; 147 String m_httpMethod; 148 HTTPHeaderMap m_httpHeaderFields; 149 Vector<String> m_responseContentDispositionEncodingFallbackArray; 150 RefPtr<FormData> m_httpBody; 151 bool m_allowHTTPCookies; 152 mutable bool m_resourceRequestUpdated; 153 mutable bool m_platformRequestUpdated; 154 bool m_reportUploadProgress; 155 156 private: 157 const ResourceRequest& asResourceRequest() const; 158 }; 159 160 bool equalIgnoringHeaderFields(const ResourceRequestBase&, const ResourceRequestBase&); 161 162 bool operator==(const ResourceRequestBase&, const ResourceRequestBase&); 163 inline bool operator!=(ResourceRequestBase& a, const ResourceRequestBase& b) { return !(a == b); } 164 165 struct CrossThreadResourceRequestData { 166 KURL m_url; 167 168 ResourceRequestCachePolicy m_cachePolicy; 169 double m_timeoutInterval; 170 KURL m_firstPartyForCookies; 171 172 String m_httpMethod; 173 OwnPtr<CrossThreadHTTPHeaderMapData> m_httpHeaders; 174 Vector<String> m_responseContentDispositionEncodingFallbackArray; 175 RefPtr<FormData> m_httpBody; 176 bool m_allowHTTPCookies; 177 }; 178 179 unsigned initializeMaximumHTTPConnectionCountPerHost(); 180 181 } // namespace WebCore 182 183 #endif // ResourceRequestBase_h 184