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 WebURLRequest_h 32 #define WebURLRequest_h 33 34 #include "WebCommon.h" 35 #include "WebHTTPBody.h" 36 37 #if WEBKIT_IMPLEMENTATION 38 namespace WebCore { class ResourceRequest; } 39 #endif 40 41 namespace WebKit { 42 43 class WebCString; 44 class WebHTTPBody; 45 class WebHTTPHeaderVisitor; 46 class WebString; 47 class WebURL; 48 class WebURLRequestPrivate; 49 50 class WebURLRequest { 51 public: 52 enum CachePolicy { 53 UseProtocolCachePolicy, // normal load 54 ReloadIgnoringCacheData, // reload 55 ReturnCacheDataElseLoad, // back/forward or encoding change - allow stale data 56 ReturnCacheDataDontLoad, // results of a post - allow stale data and only use cache 57 }; 58 59 enum Priority { 60 PriorityUnresolved = -1, 61 PriorityVeryLow, 62 PriorityLow, 63 PriorityMedium, 64 PriorityHigh, 65 PriorityVeryHigh, 66 }; 67 68 enum TargetType { 69 TargetIsMainFrame = 0, 70 TargetIsSubframe = 1, 71 TargetIsSubresource = 2, 72 TargetIsStyleSheet = 3, 73 TargetIsScript = 4, 74 TargetIsFontResource = 5, 75 TargetIsImage = 6, 76 TargetIsObject = 7, 77 TargetIsMedia = 8, 78 TargetIsWorker = 9, 79 TargetIsSharedWorker = 10, 80 TargetIsPrefetch = 11, 81 TargetIsFavicon = 12, 82 TargetIsXHR = 13, 83 TargetIsTextTrack = 14, 84 TargetIsUnspecified = 15, 85 }; 86 87 class ExtraData { 88 public: 89 virtual ~ExtraData() { } 90 }; 91 92 ~WebURLRequest() { reset(); } 93 94 WebURLRequest() : m_private(0) { } 95 WebURLRequest(const WebURLRequest& r) : m_private(0) { assign(r); } 96 WebURLRequest& operator=(const WebURLRequest& r) 97 { 98 assign(r); 99 return *this; 100 } 101 102 explicit WebURLRequest(const WebURL& url) : m_private(0) 103 { 104 initialize(); 105 setURL(url); 106 } 107 108 WEBKIT_EXPORT void initialize(); 109 WEBKIT_EXPORT void reset(); 110 WEBKIT_EXPORT void assign(const WebURLRequest&); 111 112 WEBKIT_EXPORT bool isNull() const; 113 114 WEBKIT_EXPORT WebURL url() const; 115 WEBKIT_EXPORT void setURL(const WebURL&); 116 117 // Used to implement third-party cookie blocking. 118 WEBKIT_EXPORT WebURL firstPartyForCookies() const; 119 WEBKIT_EXPORT void setFirstPartyForCookies(const WebURL&); 120 121 WEBKIT_EXPORT bool allowCookies() const; 122 WEBKIT_EXPORT void setAllowCookies(bool); 123 124 // Controls whether user name, password, and cookies may be sent with the 125 // request. (If false, this overrides allowCookies.) 126 WEBKIT_EXPORT bool allowStoredCredentials() const; 127 WEBKIT_EXPORT void setAllowStoredCredentials(bool); 128 129 WEBKIT_EXPORT CachePolicy cachePolicy() const; 130 WEBKIT_EXPORT void setCachePolicy(CachePolicy); 131 132 WEBKIT_EXPORT WebString httpMethod() const; 133 WEBKIT_EXPORT void setHTTPMethod(const WebString&); 134 135 WEBKIT_EXPORT WebString httpHeaderField(const WebString& name) const; 136 WEBKIT_EXPORT void setHTTPHeaderField(const WebString& name, const WebString& value); 137 WEBKIT_EXPORT void addHTTPHeaderField(const WebString& name, const WebString& value); 138 WEBKIT_EXPORT void clearHTTPHeaderField(const WebString& name); 139 WEBKIT_EXPORT void visitHTTPHeaderFields(WebHTTPHeaderVisitor*) const; 140 141 WEBKIT_EXPORT WebHTTPBody httpBody() const; 142 WEBKIT_EXPORT void setHTTPBody(const WebHTTPBody&); 143 144 // Controls whether upload progress events are generated when a request 145 // has a body. 146 WEBKIT_EXPORT bool reportUploadProgress() const; 147 WEBKIT_EXPORT void setReportUploadProgress(bool); 148 149 // Controls whether load timing info is collected for the request. 150 WEBKIT_EXPORT bool reportLoadTiming() const; 151 WEBKIT_EXPORT void setReportLoadTiming(bool); 152 153 // Controls whether actual headers sent and received for request are 154 // collected and reported. 155 WEBKIT_EXPORT bool reportRawHeaders() const; 156 WEBKIT_EXPORT void setReportRawHeaders(bool); 157 158 WEBKIT_EXPORT TargetType targetType() const; 159 WEBKIT_EXPORT void setTargetType(TargetType); 160 161 // True if the request was user initiated. 162 WEBKIT_EXPORT bool hasUserGesture() const; 163 WEBKIT_EXPORT void setHasUserGesture(bool); 164 165 // A consumer controlled value intended to be used to identify the 166 // requestor. 167 WEBKIT_EXPORT int requestorID() const; 168 WEBKIT_EXPORT void setRequestorID(int); 169 170 // A consumer controlled value intended to be used to identify the 171 // process of the requestor. 172 WEBKIT_EXPORT int requestorProcessID() const; 173 WEBKIT_EXPORT void setRequestorProcessID(int); 174 175 // Allows the request to be matched up with its app cache host. 176 WEBKIT_EXPORT int appCacheHostID() const; 177 WEBKIT_EXPORT void setAppCacheHostID(int); 178 179 // If true, the response body will be downloaded to a file managed by the 180 // WebURLLoader. See WebURLResponse::downloadedFilePath. 181 WEBKIT_EXPORT bool downloadToFile() const; 182 WEBKIT_EXPORT void setDownloadToFile(bool); 183 184 // Extra data associated with the underlying resource request. Resource 185 // requests can be copied. If non-null, each copy of a resource requests 186 // holds a pointer to the extra data, and the extra data pointer will be 187 // deleted when the last resource request is destroyed. Setting the extra 188 // data pointer will cause the underlying resource request to be 189 // dissociated from any existing non-null extra data pointer. 190 WEBKIT_EXPORT ExtraData* extraData() const; 191 WEBKIT_EXPORT void setExtraData(ExtraData*); 192 193 WEBKIT_EXPORT Priority priority() const; 194 195 #if WEBKIT_IMPLEMENTATION 196 WebCore::ResourceRequest& toMutableResourceRequest(); 197 const WebCore::ResourceRequest& toResourceRequest() const; 198 #endif 199 200 protected: 201 void assign(WebURLRequestPrivate*); 202 203 private: 204 WebURLRequestPrivate* m_private; 205 }; 206 207 } // namespace WebKit 208 209 #endif 210