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 defined(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 TargetType { 60 TargetIsMainFrame = 0, 61 TargetIsSubFrame = 1, // Temporary for backward compatibility. 62 TargetIsSubframe = 1, 63 TargetIsSubResource = 2, // Temporary for backward comptibility. 64 TargetIsSubresource = 2, 65 TargetIsStyleSheet = 3, 66 TargetIsScript = 4, 67 TargetIsFontResource = 5, 68 TargetIsImage = 6, 69 TargetIsObject = 7, 70 TargetIsMedia = 8 71 }; 72 ~WebURLRequest()73 ~WebURLRequest() { reset(); } 74 WebURLRequest()75 WebURLRequest() : m_private(0) { } WebURLRequest(const WebURLRequest & r)76 WebURLRequest(const WebURLRequest& r) : m_private(0) { assign(r); } 77 WebURLRequest& operator=(const WebURLRequest& r) 78 { 79 assign(r); 80 return *this; 81 } 82 WebURLRequest(const WebURL & url)83 explicit WebURLRequest(const WebURL& url) : m_private(0) 84 { 85 initialize(); 86 setURL(url); 87 } 88 89 WEBKIT_API void initialize(); 90 WEBKIT_API void reset(); 91 WEBKIT_API void assign(const WebURLRequest&); 92 93 WEBKIT_API bool isNull() const; 94 95 WEBKIT_API WebURL url() const; 96 WEBKIT_API void setURL(const WebURL&); 97 98 // Used to implement third-party cookie blocking. 99 WEBKIT_API WebURL firstPartyForCookies() const; 100 WEBKIT_API void setFirstPartyForCookies(const WebURL&); 101 102 WEBKIT_API bool allowCookies() const; 103 WEBKIT_API void setAllowCookies(bool allowCookies); 104 105 // Controls whether user name, password, and cookies may be sent with the 106 // request. (If false, this overrides allowCookies.) 107 WEBKIT_API bool allowStoredCredentials() const; 108 WEBKIT_API void setAllowStoredCredentials(bool allowStoredCredentials); 109 110 WEBKIT_API CachePolicy cachePolicy() const; 111 WEBKIT_API void setCachePolicy(CachePolicy); 112 113 WEBKIT_API WebString httpMethod() const; 114 WEBKIT_API void setHTTPMethod(const WebString&); 115 116 WEBKIT_API WebString httpHeaderField(const WebString& name) const; 117 WEBKIT_API void setHTTPHeaderField(const WebString& name, const WebString& value); 118 WEBKIT_API void addHTTPHeaderField(const WebString& name, const WebString& value); 119 WEBKIT_API void clearHTTPHeaderField(const WebString& name); 120 WEBKIT_API void visitHTTPHeaderFields(WebHTTPHeaderVisitor*) const; 121 122 WEBKIT_API WebHTTPBody httpBody() const; 123 WEBKIT_API void setHTTPBody(const WebHTTPBody&); 124 125 // Controls whether upload progress events are generated when a request 126 // has a body. 127 WEBKIT_API bool reportUploadProgress() const; 128 WEBKIT_API void setReportUploadProgress(bool); 129 130 WEBKIT_API TargetType targetType() const; 131 WEBKIT_API void setTargetType(TargetType); 132 133 // A consumer controlled value intended to be used to identify the 134 // requestor. 135 WEBKIT_API int requestorID() const; 136 WEBKIT_API void setRequestorID(int); 137 138 // A consumer controlled value intended to be used to identify the 139 // process of the requestor. 140 WEBKIT_API int requestorProcessID() const; 141 WEBKIT_API void setRequestorProcessID(int); 142 143 // Allows the request to be matched up with its app cache host. 144 WEBKIT_API int appCacheHostID() const; 145 WEBKIT_API void setAppCacheHostID(int id); 146 147 #if defined(WEBKIT_IMPLEMENTATION) 148 WebCore::ResourceRequest& toMutableResourceRequest(); 149 const WebCore::ResourceRequest& toResourceRequest() const; 150 #endif 151 152 protected: 153 void assign(WebURLRequestPrivate*); 154 155 private: 156 WebURLRequestPrivate* m_private; 157 }; 158 159 } // namespace WebKit 160 161 #endif 162