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