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 INSIDE_BLINK 38 namespace WebCore { class ResourceRequest; } 39 #endif 40 41 namespace blink { 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 TargetIsPing = 15, 85 TargetIsServiceWorker = 16, 86 TargetIsUnspecified = 17, 87 }; 88 89 class ExtraData { 90 public: 91 virtual ~ExtraData() { } 92 }; 93 94 ~WebURLRequest() { reset(); } 95 96 WebURLRequest() : m_private(0) { } 97 WebURLRequest(const WebURLRequest& r) : m_private(0) { assign(r); } 98 WebURLRequest& operator=(const WebURLRequest& r) 99 { 100 assign(r); 101 return *this; 102 } 103 104 explicit WebURLRequest(const WebURL& url) : m_private(0) 105 { 106 initialize(); 107 setURL(url); 108 } 109 110 BLINK_PLATFORM_EXPORT void initialize(); 111 BLINK_PLATFORM_EXPORT void reset(); 112 BLINK_PLATFORM_EXPORT void assign(const WebURLRequest&); 113 114 BLINK_PLATFORM_EXPORT bool isNull() const; 115 116 BLINK_PLATFORM_EXPORT WebURL url() const; 117 BLINK_PLATFORM_EXPORT void setURL(const WebURL&); 118 119 // Used to implement third-party cookie blocking. 120 BLINK_PLATFORM_EXPORT WebURL firstPartyForCookies() const; 121 BLINK_PLATFORM_EXPORT void setFirstPartyForCookies(const WebURL&); 122 123 BLINK_PLATFORM_EXPORT bool allowCookies() const; 124 BLINK_PLATFORM_EXPORT void setAllowCookies(bool); 125 126 // Controls whether user name, password, and cookies may be sent with the 127 // request. (If false, this overrides allowCookies.) 128 BLINK_PLATFORM_EXPORT bool allowStoredCredentials() const; 129 BLINK_PLATFORM_EXPORT void setAllowStoredCredentials(bool); 130 131 BLINK_PLATFORM_EXPORT CachePolicy cachePolicy() const; 132 BLINK_PLATFORM_EXPORT void setCachePolicy(CachePolicy); 133 134 BLINK_PLATFORM_EXPORT WebString httpMethod() const; 135 BLINK_PLATFORM_EXPORT void setHTTPMethod(const WebString&); 136 137 BLINK_PLATFORM_EXPORT WebString httpHeaderField(const WebString& name) const; 138 BLINK_PLATFORM_EXPORT void setHTTPHeaderField(const WebString& name, const WebString& value); 139 BLINK_PLATFORM_EXPORT void addHTTPHeaderField(const WebString& name, const WebString& value); 140 BLINK_PLATFORM_EXPORT void clearHTTPHeaderField(const WebString& name); 141 BLINK_PLATFORM_EXPORT void visitHTTPHeaderFields(WebHTTPHeaderVisitor*) const; 142 143 BLINK_PLATFORM_EXPORT WebHTTPBody httpBody() const; 144 BLINK_PLATFORM_EXPORT void setHTTPBody(const WebHTTPBody&); 145 146 // Controls whether upload progress events are generated when a request 147 // has a body. 148 BLINK_PLATFORM_EXPORT bool reportUploadProgress() const; 149 BLINK_PLATFORM_EXPORT void setReportUploadProgress(bool); 150 151 // Controls whether load timing info is collected for the request. 152 BLINK_PLATFORM_EXPORT bool reportLoadTiming() const; 153 BLINK_PLATFORM_EXPORT void setReportLoadTiming(bool); 154 155 // Controls whether actual headers sent and received for request are 156 // collected and reported. 157 BLINK_PLATFORM_EXPORT bool reportRawHeaders() const; 158 BLINK_PLATFORM_EXPORT void setReportRawHeaders(bool); 159 160 BLINK_PLATFORM_EXPORT TargetType targetType() const; 161 BLINK_PLATFORM_EXPORT void setTargetType(TargetType); 162 163 // True if the request was user initiated. 164 BLINK_PLATFORM_EXPORT bool hasUserGesture() const; 165 BLINK_PLATFORM_EXPORT void setHasUserGesture(bool); 166 167 // A consumer controlled value intended to be used to identify the 168 // requestor. 169 BLINK_PLATFORM_EXPORT int requestorID() const; 170 BLINK_PLATFORM_EXPORT void setRequestorID(int); 171 172 // A consumer controlled value intended to be used to identify the 173 // process of the requestor. 174 BLINK_PLATFORM_EXPORT int requestorProcessID() const; 175 BLINK_PLATFORM_EXPORT void setRequestorProcessID(int); 176 177 // Allows the request to be matched up with its app cache host. 178 BLINK_PLATFORM_EXPORT int appCacheHostID() const; 179 BLINK_PLATFORM_EXPORT void setAppCacheHostID(int); 180 181 // If true, the response body will be downloaded to a file managed by the 182 // WebURLLoader. See WebURLResponse::downloadedFilePath. 183 BLINK_PLATFORM_EXPORT bool downloadToFile() const; 184 BLINK_PLATFORM_EXPORT void setDownloadToFile(bool); 185 186 // Extra data associated with the underlying resource request. Resource 187 // requests can be copied. If non-null, each copy of a resource requests 188 // holds a pointer to the extra data, and the extra data pointer will be 189 // deleted when the last resource request is destroyed. Setting the extra 190 // data pointer will cause the underlying resource request to be 191 // dissociated from any existing non-null extra data pointer. 192 BLINK_PLATFORM_EXPORT ExtraData* extraData() const; 193 BLINK_PLATFORM_EXPORT void setExtraData(ExtraData*); 194 195 BLINK_PLATFORM_EXPORT Priority priority() const; 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