Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PPAPI_CPP_URL_REQUEST_INFO_H_ | 5 #ifndef PPAPI_CPP_URL_REQUEST_INFO_H_ |
| 6 #define PPAPI_CPP_URL_REQUEST_INFO_H_ | 6 #define PPAPI_CPP_URL_REQUEST_INFO_H_ |
| 7 | 7 |
| 8 #include "ppapi/c/ppb_url_request_info.h" | 8 #include "ppapi/c/ppb_url_request_info.h" |
| 9 #include "ppapi/cpp/resource.h" | 9 #include "ppapi/cpp/resource.h" |
| 10 #include "ppapi/cpp/var.h" | 10 #include "ppapi/cpp/var.h" |
| 11 | 11 |
| 12 /// @file | |
| 13 /// This file defines the API for creating and manipulating URL requests. | |
| 12 namespace pp { | 14 namespace pp { |
| 13 | 15 |
| 14 class FileRef; | 16 class FileRef; |
| 15 class Instance; | 17 class Instance; |
| 16 | 18 |
| 19 /// URLRequestInfo provides an API for creating and manipulating URL requests. | |
| 17 class URLRequestInfo : public Resource { | 20 class URLRequestInfo : public Resource { |
| 18 public: | 21 public: |
| 19 // Creates an is_null resource. | 22 /// Default constructor. This constructor creates an |
|
polina
2011/08/03 00:28:33
you changed the other file to say "constructor for
jond
2011/08/04 15:50:33
I'll note this and look at it for a global change.
| |
| 23 /// <code>is_null</code> resource. | |
| 20 URLRequestInfo() {} | 24 URLRequestInfo() {} |
| 21 | 25 |
| 26 /// A constructor used to allocate a new <code>URLLoader</code> in the | |
| 27 /// browser. The resulting object will be <code>is_null</code> if the | |
| 28 /// allocation failed. | |
| 29 /// | |
| 30 /// @param[in] instance An <code>Instance</code>. | |
| 22 explicit URLRequestInfo(Instance* instance); | 31 explicit URLRequestInfo(Instance* instance); |
| 32 | |
| 33 /// The copy constructor for <code>URLRequestInfo</code>. | |
| 34 /// | |
| 35 /// @param[in] other A <code>URLRequestInfo</code> to be copied. | |
| 23 URLRequestInfo(const URLRequestInfo& other); | 36 URLRequestInfo(const URLRequestInfo& other); |
| 24 | 37 |
| 25 // PPB_URLRequestInfo methods: | 38 /// SetProperty() sets a request property. The value of the property must be |
| 39 /// the correct type according to the property being set. | |
| 40 /// | |
| 41 /// @param[in] property A <code>PP_URLRequestProperty</code> identifying the | |
| 42 /// property to set. | |
| 43 /// @param[in] value A <code>Var</code> containing the property value. | |
| 44 /// | |
| 45 /// @return True if successful, false if any of the | |
| 46 /// parameters are invalid. | |
| 26 bool SetProperty(PP_URLRequestProperty property, const Var& value); | 47 bool SetProperty(PP_URLRequestProperty property, const Var& value); |
| 48 | |
| 49 /// AppendDataToBody() appends data to the request body. A content-length | |
| 50 /// request header will be automatically generated. | |
| 51 /// | |
| 52 /// @param[in] data A pointer to a buffer holding the data. | |
| 53 /// @param[in] len The length, in bytes, of the data. | |
| 54 /// | |
| 55 /// @return True if successful, false if any of the | |
| 56 /// parameters are invalid. | |
| 27 bool AppendDataToBody(const void* data, uint32_t len); | 57 bool AppendDataToBody(const void* data, uint32_t len); |
| 28 bool AppendFileToBody(const FileRef& file_ref, | 58 |
| 59 /// AppendFileToBody() is used to append an entire file, to be uploaded, to | |
| 60 /// the request body. A content-length request header will be automatically | |
| 61 /// generated. | |
| 62 /// | |
| 63 /// @param[in] file_ref A <code>FileRef_Dev</code> containing the file | |
|
polina
2011/08/03 00:28:33
Actually this has been moved out of Dev, so there
jond
2011/08/04 15:50:33
I sync'd but got to conflict - so apparently it ke
polina
2011/08/04 22:01:04
Yes, the _Dev's are gone from code. But they still
jond
2011/08/05 17:07:47
Done.
| |
| 64 /// reference. | |
| 65 | |
| 66 /// @param[in] expected_last_modified_time An optional (non-zero) last | |
| 67 /// modified time stamp used to validate that the file was not modified since | |
| 68 /// the given time before it was uploaded. The upload will fail with an error | |
| 69 /// code of <code>PP_ERROR_FILECHANGED</code> if the file has been modified | |
| 70 /// since the given time. If expected_last_modified_time is 0, then no | |
| 71 /// validation is performed. | |
| 72 /// | |
| 73 /// @return True if successful, false if any of the | |
| 74 /// parameters are invalid. | |
| 75 bool AppendFileToBody(const FileRef_Dev& file_ref, | |
| 29 PP_Time expected_last_modified_time = 0); | 76 PP_Time expected_last_modified_time = 0); |
| 30 bool AppendFileRangeToBody(const FileRef& file_ref, | 77 |
| 78 /// AppendFileRangeToBody() is a pointer to a function used to append part or | |
| 79 /// all of a file, to be uploaded, to the request body. A content-length | |
| 80 /// request header will be automatically generated. | |
| 81 /// | |
| 82 /// @param[in] file_ref A <code>FileRef_Dev</code> containing the file | |
| 83 /// reference. | |
| 84 /// @param[in] start_offset An optional starting point offset within the | |
| 85 /// file. | |
| 86 /// @param[in] length An optional number of bytes of the file to | |
| 87 /// be included. If -1, then the sub-range to upload extends to the end of | |
|
polina
2011/08/03 00:28:33
If the value is -1?
jond
2011/08/04 15:50:33
Done.
polina
2011/08/04 22:01:04
Looks like you remove this sentence completely. Wa
jond
2011/08/05 17:07:47
Done.
| |
| 88 /// the file. | |
| 89 /// @param[in] expected_last_modified_time An optional (non-zero) last | |
| 90 /// modified time stamp used to validate that the file was not modified since | |
| 91 /// the given time before it was uploaded. The upload will fail with an error | |
| 92 /// code of <code>PP_ERROR_FILECHANGED</code> if the file has been modified | |
| 93 /// since the given time. If expected_last_modified_time is 0, then no | |
| 94 /// validation is performed. | |
| 95 /// | |
| 96 /// @return True if successful, false if any of the | |
| 97 /// parameters are invalid. | |
| 98 bool AppendFileRangeToBody(const FileRef_Dev& file_ref, | |
| 31 int64_t start_offset, | 99 int64_t start_offset, |
| 32 int64_t length, | 100 int64_t length, |
| 33 PP_Time expected_last_modified_time = 0); | 101 PP_Time expected_last_modified_time = 0); |
| 34 | 102 |
| 35 // Convenient helpers for setting properties: | 103 /// SetURL() sets the <code>PP_URLREQUESTPROPERTY_URL</code> |
| 104 /// property for the request. | |
| 105 /// | |
| 106 /// @param[in] url_string A <code>Var</code> containing the property value. | |
| 107 /// | |
| 108 /// @return True if successful, false if the parameter is invalid. | |
| 36 bool SetURL(const Var& url_string) { | 109 bool SetURL(const Var& url_string) { |
| 37 return SetProperty(PP_URLREQUESTPROPERTY_URL, url_string); | 110 return SetProperty(PP_URLREQUESTPROPERTY_URL, url_string); |
| 38 } | 111 } |
| 112 | |
| 113 /// SetMethod() sets the <code>PP_URLREQUESTPROPERTY_METHOD</code> | |
| 114 /// (corresponding to a string of type <code>PP_VARTYPE_STRING</code>) | |
| 115 /// property for the request. This string is either a POST or GET. Refer to | |
| 116 /// the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html">HTTP | |
| 117 /// Methods</a> documentation for further information. | |
| 118 /// | |
| 119 /// @param[in] method_string A <code>Var</code> containing the property | |
| 120 /// value. | |
| 121 /// | |
| 122 /// @return True if successful, false if the parameter is invalid. | |
| 39 bool SetMethod(const Var& method_string) { | 123 bool SetMethod(const Var& method_string) { |
| 40 return SetProperty(PP_URLREQUESTPROPERTY_METHOD, method_string); | 124 return SetProperty(PP_URLREQUESTPROPERTY_METHOD, method_string); |
| 41 } | 125 } |
| 126 | |
| 127 /// SetHeaders() sets the <code>PP_URLREQUESTPROPERTY_HEADERS</code> | |
| 128 /// (corresponding to a <code>\n</code> delimited string of type | |
| 129 /// <code>PP_VARTYPE_STRING</code>) property for the request. | |
| 130 /// Refer to the | |
| 131 /// <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html"Header | |
| 132 /// Field Definitions</a> documentaiton for further information. | |
| 133 /// | |
| 134 /// @param[in] headers_string A <code>Var</code> containing the property | |
| 135 /// value. | |
| 136 /// | |
| 137 /// @return True if successful, false if the parameter is invalid. | |
| 42 bool SetHeaders(const Var& headers_string) { | 138 bool SetHeaders(const Var& headers_string) { |
| 43 return SetProperty(PP_URLREQUESTPROPERTY_HEADERS, headers_string); | 139 return SetProperty(PP_URLREQUESTPROPERTY_HEADERS, headers_string); |
| 44 } | 140 } |
| 141 /// SetStreamToFile() sets the | |
| 142 /// </code>PP_URLREQUESTPROPERTY_STREAMTOFILE</code> (corresponding | |
| 143 /// to a bool of type <code>PP_VARTYPE_BOOL</code>). The default of the | |
| 144 /// property is false. Set this value to true if you want to download the | |
| 145 /// data to a file. Use URL_Loader::FinishStreamingToFile() to complete | |
| 146 /// the download. | |
| 147 /// | |
| 148 /// @param[in] enable A <code>bool</code> containing the property value. | |
| 149 /// | |
| 150 /// @return True if successful, false if the parameter is invalid. | |
| 45 bool SetStreamToFile(bool enable) { | 151 bool SetStreamToFile(bool enable) { |
| 46 return SetProperty(PP_URLREQUESTPROPERTY_STREAMTOFILE, enable); | 152 return SetProperty(PP_URLREQUESTPROPERTY_STREAMTOFILE, enable); |
| 47 } | 153 } |
| 154 | |
| 155 /// SetFollowRedirects() sets the | |
| 156 /// <code>PP_URLREQUESTPROPERTY_FOLLOWREDIRECT</code> (corresponding | |
| 157 /// to a bool of type <code>PP_VARTYPE_BOOL</code>). The default of the | |
| 158 /// property is true. Set this value to false if you want to use | |
| 159 /// URLLoader::FollowRedirects() to follow the redirects only after examining | |
| 160 /// redirect headers. | |
| 161 /// | |
| 162 /// @param[in] enable A <code>bool</code> containing the property value. | |
| 163 /// | |
| 164 /// @return True if successful, false if the parameter is invalid. | |
| 48 bool SetFollowRedirects(bool enable) { | 165 bool SetFollowRedirects(bool enable) { |
| 49 return SetProperty(PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, enable); | 166 return SetProperty(PP_URLREQUESTPROPERTY_FOLLOWREDIRECTS, enable); |
| 50 } | 167 } |
| 168 | |
| 169 /// SetRecordDownloadProgress() sets the | |
| 170 /// <code>PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGESS</code> | |
| 171 /// (corresponding to a bool of type <code>PP_VARTYPE_BOOL</code>). The | |
| 172 /// default of the property is false. Set this value to true if you want to | |
| 173 /// be able to poll the download progress using | |
| 174 /// URLLoader::GetDownloadProgress(). | |
| 175 /// | |
| 176 /// @param[in] enable A <code>bool</code> containing the property value. | |
| 177 //// | |
| 178 /// @return True if successful, false if the parameter is invalid. | |
| 51 bool SetRecordDownloadProgress(bool enable) { | 179 bool SetRecordDownloadProgress(bool enable) { |
| 52 return SetProperty(PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, enable); | 180 return SetProperty(PP_URLREQUESTPROPERTY_RECORDDOWNLOADPROGRESS, enable); |
| 53 } | 181 } |
| 182 | |
| 183 /// SetRecordUploadProgress() sets the | |
| 184 /// <code>PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS</code> | |
| 185 /// (corresponding to a bool of type <code>PP_VARTYPE_BOOL</code>). The | |
| 186 /// default of the property is false. Set this value to true if you want to | |
| 187 /// be able to poll the upload progress using URLLoader::GetUploadProgress(). | |
| 188 /// | |
| 189 /// @param[in] enable A <code>bool</code> containing the property value. | |
| 190 /// | |
| 191 /// @return True if successful, false if the parameter is invalid. | |
| 54 bool SetRecordUploadProgress(bool enable) { | 192 bool SetRecordUploadProgress(bool enable) { |
| 55 return SetProperty(PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, enable); | 193 return SetProperty(PP_URLREQUESTPROPERTY_RECORDUPLOADPROGRESS, enable); |
| 56 } | 194 } |
| 57 // To use the default referrer, set url to an Undefined Var. | 195 |
| 196 /// SetCustomReferrerURL() sets the | |
| 197 /// <code>PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL</code> | |
| 198 /// (corresponding to a string of type <code>PP_VARTYPE_STRING</code> or | |
| 199 /// might be set to undefined as <code>PP_VARTYPE_UNDEFINED</code>). Set it | |
| 200 /// to a string to set a custom referrer (if empty, the referrer header will | |
| 201 /// be omitted), or to undefined to use the default referrer. Only loaders | |
| 202 /// with universal access (only available on trusted implementations) will | |
| 203 /// accept <code>URLRequestInfo</code> objects that try to set a custom | |
| 204 /// referrer; if given to a loader without universal access, | |
| 205 /// <code>PP_ERROR_BADARGUMENT</code> will result. | |
| 206 /// | |
| 207 /// @param[in] url A <code>Var</code> containing the property value. | |
| 208 /// | |
| 209 /// @return True if successful, false if the parameter is invalid. | |
| 58 bool SetCustomReferrerURL(const Var& url) { | 210 bool SetCustomReferrerURL(const Var& url) { |
| 59 return SetProperty(PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL, url); | 211 return SetProperty(PP_URLREQUESTPROPERTY_CUSTOMREFERRERURL, url); |
| 60 } | 212 } |
| 213 | |
| 214 /// SetAllowCrossOriginRequests() sets the | |
| 215 /// </code>PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS</code> | |
| 216 /// (corresponding to a bool of type <code>PP_VARTYPE_BOOL</code>). The | |
| 217 /// default of the property is false. Whether cross-origin requests are | |
| 218 /// allowed. Cross-origin requests are made using the CORS (Cross-Origin | |
| 219 /// Resource Sharing) algorithm to check whether the request should be | |
| 220 /// allowed. For the complete CORS algorithm, refer to the | |
| 221 /// <a href="http://www.w3.org/TR/access-control">Cross-Origin Resource | |
| 222 /// Sharing</a> documentation. | |
| 223 /// | |
| 224 /// @param[in] enable A <code>bool</code> containing the property value. | |
| 225 /// | |
| 226 /// @return True if successful, false if the parameter is invalid. | |
| 61 bool SetAllowCrossOriginRequests(bool enable) { | 227 bool SetAllowCrossOriginRequests(bool enable) { |
| 62 return SetProperty(PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, enable); | 228 return SetProperty(PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, enable); |
| 63 } | 229 } |
| 230 | |
| 231 /// SetAllowCredentials() sets the | |
| 232 /// <code>PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS</code> | |
| 233 /// (corresponding to a bool of type <code>PP_VARTYPE_BOOL</code>). The | |
| 234 /// default of the property is false. Whether HTTP credentials are sent with | |
| 235 /// cross-origin requests. If false, no credentials are sent with the request | |
| 236 /// and cookies are ignored in the response. If the request is not | |
| 237 /// cross-origin, this property is ignored. | |
| 238 /// | |
| 239 /// @param[in] enable A <code>bool</code> containing the property value. | |
| 240 /// | |
| 241 /// @return True if successful, false if the parameter is invalid. | |
| 64 bool SetAllowCredentials(bool enable) { | 242 bool SetAllowCredentials(bool enable) { |
| 65 return SetProperty(PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, enable); | 243 return SetProperty(PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, enable); |
| 66 } | 244 } |
| 67 // To use the default content transfer encoding, set content_transfer_encoding | 245 |
| 68 // to an Undefined Var. | 246 /// SetCustomContentTransferEncoding() sets the |
| 247 /// <code>PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING</code> | |
| 248 /// (corresponding to a string of type <code>PP_VARTYPE_STRING</code> or | |
| 249 /// might be set to undefined as <code>PP_VARTYPE_UNDEFINED</code>). Set it | |
| 250 /// to a string to set a custom content-transfer-encoding header (if empty, | |
| 251 /// that header will be omitted), or to undefined to use the default (if | |
| 252 /// any). Only loaders with universal access (only available on trusted | |
| 253 /// implementations) will accept <code>URLRequestInfo</code> objects that try | |
| 254 /// to set a custom content transfer encoding; if given to a loader without | |
| 255 /// universal access, <code>PP_ERROR_BADARGUMENT</code> will result. | |
| 256 /// | |
| 257 /// @param[in] content_transfer_encoding A <code>Var</code> containing the | |
| 258 /// property value. To use the default content transfer encoding, set | |
| 259 /// <code>content_transfer_encoding</code> to an undefined <code>Var</code>. | |
| 260 /// | |
| 261 /// @return True if successful, false if the parameter is invalid. | |
| 69 bool SetCustomContentTransferEncoding(const Var& content_transfer_encoding) { | 262 bool SetCustomContentTransferEncoding(const Var& content_transfer_encoding) { |
| 70 return SetProperty(PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING, | 263 return SetProperty(PP_URLREQUESTPROPERTY_CUSTOMCONTENTTRANSFERENCODING, |
| 71 content_transfer_encoding); | 264 content_transfer_encoding); |
| 72 } | 265 } |
| 266 | |
| 267 /// SetPrefetchBufferUpperThreshold() sets the | |
| 268 /// <code>PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD</code> | |
| 269 /// (corresponding to a integer of type <code>PP_VARTYPE_INT32</code>). The | |
| 270 /// default is not defined and is set by the browser possibly depending on | |
| 271 /// system capabilities. Set it to an integer to set an upper threshold for | |
| 272 /// the prefetched buffer of an asynchronous load. When exceeded, the browser | |
| 273 /// will defer loading until | |
| 274 /// <code>PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERERTHRESHOLD</code> is hit, | |
| 275 /// at which time it will begin prefetching again. When setting this | |
| 276 /// property, | |
| 277 /// <code>PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERERTHRESHOLD</code> must | |
| 278 /// also be set. Behavior is undefined if the former is <= the latter. | |
| 279 /// | |
| 280 /// @param[in] size An int32_t containing the property value. | |
| 281 /// | |
| 282 /// @return True if successful, false if the parameter is invalid. | |
| 73 bool SetPrefetchBufferUpperThreshold(int32_t size) { | 283 bool SetPrefetchBufferUpperThreshold(int32_t size) { |
| 74 return SetProperty(PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD, | 284 return SetProperty(PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD, |
| 75 size); | 285 size); |
| 76 } | 286 } |
| 287 | |
| 288 /// SetPrefetchBufferLowerThreshold() sets the | |
| 289 /// <code>PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD</code> | |
| 290 /// (corresponding to a integer of type <code>PP_VARTYPE_INT32</code>). The | |
| 291 /// default is not defined and is set by the browser to a value appropriate | |
| 292 /// for the default | |
| 293 /// <code>PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD</code>. | |
| 294 /// Set it to an integer to set a lower threshold for the prefetched buffer | |
| 295 /// of an asynchronous load. When reached, the browser will resume loading if | |
| 296 /// If <code>PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERERTHRESHOLD</code> had | |
| 297 /// previously been reached. | |
| 298 /// When setting this property, | |
| 299 /// <code>PP_URLREQUESTPROPERTY_PREFETCHBUFFERUPPERTHRESHOLD</code> must also | |
| 300 /// be set. Behavior is undefined if the former is >= the latter. | |
| 301 /// | |
| 302 /// @param[in] size An int32_t containing the property value. | |
| 303 /// | |
| 304 /// @return True if successful, false if the parameter is invalid. | |
| 77 bool SetPrefetchBufferLowerThreshold(int32_t size) { | 305 bool SetPrefetchBufferLowerThreshold(int32_t size) { |
| 78 return SetProperty(PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD, | 306 return SetProperty(PP_URLREQUESTPROPERTY_PREFETCHBUFFERLOWERTHRESHOLD, |
| 79 size); | 307 size); |
| 80 } | 308 } |
| 81 }; | 309 }; |
| 82 | 310 |
| 83 } // namespace pp | 311 } // namespace pp |
| 84 | 312 |
| 85 #endif // PPAPI_CPP_URL_REQUEST_INFO_H_ | 313 #endif // PPAPI_CPP_URL_REQUEST_INFO_H_ |
| OLD | NEW |