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