Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: ppapi/c/ppb_url_loader.h

Issue 11417145: Provide a safer URLLoader ReadResponseBody API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ppapi/api/ppb_url_loader.idl ('k') | ppapi/cpp/file_io.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2012 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 5
6 /* From ppb_url_loader.idl modified Wed Oct 5 14:06:02 2011. */ 6 /* From ppb_url_loader.idl modified Thu Nov 22 16:52:29 2012. */
7 7
8 #ifndef PPAPI_C_PPB_URL_LOADER_H_ 8 #ifndef PPAPI_C_PPB_URL_LOADER_H_
9 #define PPAPI_C_PPB_URL_LOADER_H_ 9 #define PPAPI_C_PPB_URL_LOADER_H_
10 10
11 #include "ppapi/c/pp_array_output.h"
11 #include "ppapi/c/pp_bool.h" 12 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/pp_completion_callback.h" 13 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_instance.h" 14 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_macros.h" 15 #include "ppapi/c/pp_macros.h"
15 #include "ppapi/c/pp_resource.h" 16 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/pp_stdint.h" 17 #include "ppapi/c/pp_stdint.h"
17 18
18 #define PPB_URLLOADER_INTERFACE_1_0 "PPB_URLLoader;1.0" 19 #define PPB_URLLOADER_INTERFACE_1_0 "PPB_URLLoader;1.0"
19 #define PPB_URLLOADER_INTERFACE PPB_URLLOADER_INTERFACE_1_0 20 #define PPB_URLLOADER_INTERFACE_1_1 "PPB_URLLoader;1.1"
21 #define PPB_URLLOADER_INTERFACE PPB_URLLOADER_INTERFACE_1_1
20 22
21 /** 23 /**
22 * @file 24 * @file
23 * This file defines the <strong>PPB_URLLoader</strong> interface for loading 25 * This file defines the <strong>PPB_URLLoader</strong> interface for loading
24 * URLs. 26 * URLs.
25 */ 27 */
26 28
27 29
28 /** 30 /**
29 * @addtogroup Interfaces 31 * @addtogroup Interfaces
(...skipping 11 matching lines...) Expand all
41 * headers. Refer to <code>PPB_URLResponseInfo</code> for further information. 43 * headers. Refer to <code>PPB_URLResponseInfo</code> for further information.
42 * -# Call ReadResponseBody() to stream the data for the response. 44 * -# Call ReadResponseBody() to stream the data for the response.
43 * 45 *
44 * Alternatively, if <code>PP_URLREQUESTPROPERTY_STREAMTOFILE</code> was set on 46 * Alternatively, if <code>PP_URLREQUESTPROPERTY_STREAMTOFILE</code> was set on
45 * the <code>URLRequestInfo</code> in step #2: 47 * the <code>URLRequestInfo</code> in step #2:
46 * - Call FinishStreamingToFile(), after examining the response headers 48 * - Call FinishStreamingToFile(), after examining the response headers
47 * (step #4), to wait for the downloaded file to be complete. 49 * (step #4), to wait for the downloaded file to be complete.
48 * - Then, access the downloaded file using the GetBodyAsFileRef() function of 50 * - Then, access the downloaded file using the GetBodyAsFileRef() function of
49 * the <code>URLResponseInfo</code> returned in step #4. 51 * the <code>URLResponseInfo</code> returned in step #4.
50 */ 52 */
51 struct PPB_URLLoader_1_0 { 53 struct PPB_URLLoader_1_1 {
52 /** 54 /**
53 * Create() creates a new <code>URLLoader</code> object. The 55 * Create() creates a new <code>URLLoader</code> object. The
54 * <code>URLLoader</code> is associated with a particular instance, so that 56 * <code>URLLoader</code> is associated with a particular instance, so that
55 * any UI dialogs that need to be shown to the user can be positioned 57 * any UI dialogs that need to be shown to the user can be positioned
56 * relative to the window containing the instance. 58 * relative to the window containing the instance.
57 * 59 *
58 * @param[in] instance A <code>PP_Instance</code> identifying one instance 60 * @param[in] instance A <code>PP_Instance</code> identifying one instance
59 * of a module. 61 * of a module.
60 * 62 *
61 * @return A <code>PP_Resource</code> corresponding to a URLLoader if 63 * @return A <code>PP_Resource</code> corresponding to a URLLoader if
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 * @return A <code>PP_Resource</code> corresponding to the 161 * @return A <code>PP_Resource</code> corresponding to the
160 * <code>URLResponseInfo</code> if successful, 0 if the loader is not a valid 162 * <code>URLResponseInfo</code> if successful, 0 if the loader is not a valid
161 * resource or if Open() has not been called. 163 * resource or if Open() has not been called.
162 */ 164 */
163 PP_Resource (*GetResponseInfo)(PP_Resource loader); 165 PP_Resource (*GetResponseInfo)(PP_Resource loader);
164 /** 166 /**
165 * ReadResponseBody() is used to read the response body. The size of the 167 * ReadResponseBody() is used to read the response body. The size of the
166 * buffer must be large enough to hold the specified number of bytes to read. 168 * buffer must be large enough to hold the specified number of bytes to read.
167 * This function might perform a partial read. 169 * This function might perform a partial read.
168 * 170 *
171 * ReadResponseBodyToArray() is preferred to ReadResponseBody() when doing
172 * asynchronous operations.
173 *
169 * @param[in] loader A <code>PP_Resource</code> corresponding to a 174 * @param[in] loader A <code>PP_Resource</code> corresponding to a
170 * <code>URLLoader</code>. 175 * <code>URLLoader</code>.
171 * @param[in,out] buffer A pointer to the buffer for the response body. 176 * @param[in,out] buffer A pointer to the buffer for the response body.
172 * @param[in] bytes_to_read The number of bytes to read. 177 * @param[in] bytes_to_read The number of bytes to read.
173 * @param[in] callback A <code>PP_CompletionCallback</code> to run on 178 * @param[in] callback A <code>PP_CompletionCallback</code> to run on
174 * asynchronous completion. The callback will run if the bytes (full or 179 * asynchronous completion. The callback will run if the bytes (full or
175 * partial) are read or an error occurs asynchronously. This callback will 180 * partial) are read or an error occurs asynchronously. This callback will
176 * run only if this function returns <code>PP_OK_COMPLETIONPENDING</code>. 181 * run only if this function returns <code>PP_OK_COMPLETIONPENDING</code>.
177 * 182 *
178 * @return An int32_t containing the number of bytes read or an error code 183 * @return An int32_t containing the number of bytes read or an error code
(...skipping 29 matching lines...) Expand all
208 * It is NOT valid to call Open() again after a call to this function. 213 * It is NOT valid to call Open() again after a call to this function.
209 * 214 *
210 * <strong>Note:</strong> If the <code>URLLoader</code> object is destroyed 215 * <strong>Note:</strong> If the <code>URLLoader</code> object is destroyed
211 * while it is still open, then it will be implicitly closed so you are not 216 * while it is still open, then it will be implicitly closed so you are not
212 * required to call Close(). 217 * required to call Close().
213 * 218 *
214 * @param[in] loader A <code>PP_Resource</code> corresponding to a 219 * @param[in] loader A <code>PP_Resource</code> corresponding to a
215 * <code>URLLoader</code>. 220 * <code>URLLoader</code>.
216 */ 221 */
217 void (*Close)(PP_Resource loader); 222 void (*Close)(PP_Resource loader);
223 /**
224 * ReadResponseBody() is used to read the response body. The size of the
225 * buffer must be large enough to hold the specified number of bytes to read.
226 * This function might perform a partial read.
227 *
228 * @param[in] loader A <code>PP_Resource</code> corresponding to a
229 * <code>URLLoader</code>.
230 * @param[in,out] output A <code>PP_ArrayOutput</code> to hold the output.
231 * @param[in] max_read_length The number of bytes to read.
232 * @param[in] callback A <code>PP_CompletionCallback</code> to run on
233 * asynchronous completion. The callback will run if the bytes (full or
234 * partial) are read or an error occurs asynchronously. This callback will
235 * run only if this function returns <code>PP_OK_COMPLETIONPENDING</code>.
236 *
237 * @return An int32_t containing the number of bytes read or an error code
238 * from <code>pp_errors.h</code>.
239 */
240 int32_t (*ReadResponseBodyToArray)(PP_Resource loader,
241 int32_t max_read_length,
242 struct PP_ArrayOutput* output,
243 struct PP_CompletionCallback callback);
218 }; 244 };
219 245
220 typedef struct PPB_URLLoader_1_0 PPB_URLLoader; 246 typedef struct PPB_URLLoader_1_1 PPB_URLLoader;
247
248 struct PPB_URLLoader_1_0 {
249 PP_Resource (*Create)(PP_Instance instance);
250 PP_Bool (*IsURLLoader)(PP_Resource resource);
251 int32_t (*Open)(PP_Resource loader,
252 PP_Resource request_info,
253 struct PP_CompletionCallback callback);
254 int32_t (*FollowRedirect)(PP_Resource loader,
255 struct PP_CompletionCallback callback);
256 PP_Bool (*GetUploadProgress)(PP_Resource loader,
257 int64_t* bytes_sent,
258 int64_t* total_bytes_to_be_sent);
259 PP_Bool (*GetDownloadProgress)(PP_Resource loader,
260 int64_t* bytes_received,
261 int64_t* total_bytes_to_be_received);
262 PP_Resource (*GetResponseInfo)(PP_Resource loader);
263 int32_t (*ReadResponseBody)(PP_Resource loader,
264 void* buffer,
265 int32_t bytes_to_read,
266 struct PP_CompletionCallback callback);
267 int32_t (*FinishStreamingToFile)(PP_Resource loader,
268 struct PP_CompletionCallback callback);
269 void (*Close)(PP_Resource loader);
270 };
221 /** 271 /**
222 * @} 272 * @}
223 */ 273 */
224 274
225 #endif /* PPAPI_C_PPB_URL_LOADER_H_ */ 275 #endif /* PPAPI_C_PPB_URL_LOADER_H_ */
226 276
OLDNEW
« no previous file with comments | « ppapi/api/ppb_url_loader.idl ('k') | ppapi/cpp/file_io.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698