OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef PPAPI_C_DEV_PPB_URL_LOADER_DEV_H_ | |
6 #define PPAPI_C_DEV_PPB_URL_LOADER_DEV_H_ | |
7 | |
8 #include "ppapi/c/pp_bool.h" | |
9 #include "ppapi/c/pp_instance.h" | |
10 #include "ppapi/c/pp_resource.h" | |
11 #include "ppapi/c/pp_stdint.h" | |
12 | |
13 struct PP_CompletionCallback; | |
14 | |
15 #define PPB_URLLOADER_DEV_INTERFACE "PPB_URLLoader(Dev);0.2" | |
16 | |
17 // The interface for loading URLs. | |
18 // | |
19 // Typical steps for loading an URL: | |
20 // 1- Create an URLLoader object. | |
21 // 2- Create an URLRequestInfo object and set properties on it. | |
22 // 3- Call URLLoader's Open method passing the URLRequestInfo. | |
23 // 4- When Open completes, call GetResponseInfo to examine the response headers. | |
24 // 5- Then call ReadResponseBody to stream the data for the response. | |
25 // | |
26 // Alternatively, if PP_URLREQUESTPROPERTY_STREAMTOFILE was set on the | |
27 // URLRequestInfo, then call FinishStreamingToFile at step #5 to wait for the | |
28 // downloaded file to be complete. The downloaded file may be accessed via the | |
29 // GetBody method of the URLResponseInfo returned in step #4. | |
30 // | |
31 struct PPB_URLLoader_Dev { | |
32 // Create a new URLLoader object. Returns 0 if the instance is invalid. The | |
33 // URLLoader is associated with a particular instance, so that any UI dialogs | |
34 // that need to be shown to the user can be positioned relative to the window | |
35 // containing the instance. It is also important for security reasons to | |
36 // know the origin of the URL request. | |
37 PP_Resource (*Create)(PP_Instance instance); | |
38 | |
39 // Returns PP_TRUE if the given resource is an URLLoader. Returns PP_FALSE if | |
40 // the resource is invalid or some type other than an URLLoader. | |
41 PP_Bool (*IsURLLoader)(PP_Resource resource); | |
42 | |
43 // Begins loading the URLRequestInfo. Completes when response headers are | |
44 // received or when an error occurs. Use the GetResponseInfo method to | |
45 // access the response headers. | |
46 int32_t (*Open)(PP_Resource loader, | |
47 PP_Resource request_info, | |
48 struct PP_CompletionCallback callback); | |
49 | |
50 // If the current URLResponseInfo object corresponds to a redirect, then call | |
51 // this method to follow the redirect. | |
52 int32_t (*FollowRedirect)(PP_Resource loader, | |
53 struct PP_CompletionCallback callback); | |
54 | |
55 // Returns the current upload progress, which is meaningful after Open has | |
56 // been called. Progress only refers to the request body and does not include | |
57 // the headers. | |
58 // | |
59 // This data is only available if the URLRequestInfo passed to Open() had the | |
60 // PP_URLREQUESTPROPERTY_REPORTUPLOADPROGRESS flag set to PP_TRUE. | |
61 // | |
62 // This method returns PP_FALSE if upload progress is not available. | |
63 PP_Bool (*GetUploadProgress)(PP_Resource loader, | |
64 int64_t* bytes_sent, | |
65 int64_t* total_bytes_to_be_sent); | |
66 | |
67 // Returns the current download progress, which is meaningful after Open has | |
68 // been called. Progress only refers to the response body and does not | |
69 // include the headers. | |
70 // | |
71 // This data is only available if the URLRequestInfo passed to Open() had the | |
72 // PP_URLREQUESTPROPERTY_REPORTDOWNLOADPROGRESS flag set to PP_TRUE. | |
73 // | |
74 // The total bytes to be received may be unknown, in which case | |
75 // total_bytes_to_be_received will be set to -1. This method returns PP_FALSE | |
76 // if download progress is not available. | |
77 PP_Bool (*GetDownloadProgress)(PP_Resource loader, | |
78 int64_t* bytes_received, | |
79 int64_t* total_bytes_to_be_received); | |
80 | |
81 // Returns the current URLResponseInfo object. | |
82 PP_Resource (*GetResponseInfo)(PP_Resource loader); | |
83 | |
84 // Call this method to read the response body. The size of the buffer must | |
85 // be large enough to hold the specified number of bytes to read. May | |
86 // perform a partial read. Returns the number of bytes read or an error | |
87 // code. | |
88 int32_t (*ReadResponseBody)(PP_Resource loader, | |
89 char* buffer, | |
90 int32_t bytes_to_read, | |
91 struct PP_CompletionCallback callback); | |
92 | |
93 // If PP_URLREQUESTPROPERTY_STREAMTOFILE was set on the URLRequestInfo passed | |
94 // to the Open method, then this method may be used to wait for the response | |
95 // body to be completely downloaded to the file provided by URLResponseInfo's | |
96 // GetBody method. | |
97 int32_t (*FinishStreamingToFile)(PP_Resource loader, | |
98 struct PP_CompletionCallback callback); | |
99 | |
100 // Cancels any IO that may be pending, and closes the URLLoader object. Any | |
101 // pending callbacks will still run, reporting PP_ERROR_ABORTED if pending IO | |
102 // was interrupted. It is NOT valid to call Open again after a call to this | |
103 // method. Note: If the URLLoader object is destroyed, and it is still open, | |
104 // then it will be implicitly closed, so you are not required to call the | |
105 // Close method. | |
106 void (*Close)(PP_Resource loader); | |
107 }; | |
108 | |
109 #endif // PPAPI_C_DEV_PPB_URL_LOADER_DEV_H_ | |
OLD | NEW |