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
3 // found in the LICENSE file.
5 // From ppb_url_loader.idl modified Tue May 7 14:43:00 2013.
9 #include "ppapi/c/pp_completion_callback.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/ppb_url_loader.h"
12 #include "ppapi/shared_impl/tracked_callback.h"
13 #include "ppapi/thunk/enter.h"
14 #include "ppapi/thunk/ppapi_thunk_export.h"
15 #include "ppapi/thunk/ppb_url_loader_api.h"
22 PP_Resource
Create(PP_Instance instance
) {
23 VLOG(4) << "PPB_URLLoader::Create()";
24 EnterResourceCreation
enter(instance
);
27 return enter
.functions()->CreateURLLoader(instance
);
30 PP_Bool
IsURLLoader(PP_Resource resource
) {
31 VLOG(4) << "PPB_URLLoader::IsURLLoader()";
32 EnterResource
<PPB_URLLoader_API
> enter(resource
, false);
33 return PP_FromBool(enter
.succeeded());
36 int32_t Open(PP_Resource loader
,
37 PP_Resource request_info
,
38 struct PP_CompletionCallback callback
) {
39 VLOG(4) << "PPB_URLLoader::Open()";
40 EnterResource
<PPB_URLLoader_API
> enter(loader
, callback
, true);
42 return enter
.retval();
43 return enter
.SetResult(enter
.object()->Open(request_info
, enter
.callback()));
46 int32_t FollowRedirect(PP_Resource loader
,
47 struct PP_CompletionCallback callback
) {
48 VLOG(4) << "PPB_URLLoader::FollowRedirect()";
49 EnterResource
<PPB_URLLoader_API
> enter(loader
, callback
, true);
51 return enter
.retval();
52 return enter
.SetResult(enter
.object()->FollowRedirect(enter
.callback()));
55 PP_Bool
GetUploadProgress(PP_Resource loader
,
57 int64_t* total_bytes_to_be_sent
) {
58 VLOG(4) << "PPB_URLLoader::GetUploadProgress()";
59 EnterResource
<PPB_URLLoader_API
> enter(loader
, true);
61 memset(bytes_sent
, 0, sizeof(*bytes_sent
));
62 memset(total_bytes_to_be_sent
, 0, sizeof(*total_bytes_to_be_sent
));
65 return enter
.object()->GetUploadProgress(bytes_sent
, total_bytes_to_be_sent
);
68 PP_Bool
GetDownloadProgress(PP_Resource loader
,
69 int64_t* bytes_received
,
70 int64_t* total_bytes_to_be_received
) {
71 VLOG(4) << "PPB_URLLoader::GetDownloadProgress()";
72 EnterResource
<PPB_URLLoader_API
> enter(loader
, true);
74 memset(bytes_received
, 0, sizeof(*bytes_received
));
75 memset(total_bytes_to_be_received
, 0, sizeof(*total_bytes_to_be_received
));
78 return enter
.object()->GetDownloadProgress(bytes_received
,
79 total_bytes_to_be_received
);
82 PP_Resource
GetResponseInfo(PP_Resource loader
) {
83 VLOG(4) << "PPB_URLLoader::GetResponseInfo()";
84 EnterResource
<PPB_URLLoader_API
> enter(loader
, true);
87 return enter
.object()->GetResponseInfo();
90 int32_t ReadResponseBody(PP_Resource loader
,
92 int32_t bytes_to_read
,
93 struct PP_CompletionCallback callback
) {
94 VLOG(4) << "PPB_URLLoader::ReadResponseBody()";
95 EnterResource
<PPB_URLLoader_API
> enter(loader
, callback
, true);
97 return enter
.retval();
98 return enter
.SetResult(enter
.object()->ReadResponseBody(buffer
, bytes_to_read
,
102 int32_t FinishStreamingToFile(PP_Resource loader
,
103 struct PP_CompletionCallback callback
) {
104 VLOG(4) << "PPB_URLLoader::FinishStreamingToFile()";
105 EnterResource
<PPB_URLLoader_API
> enter(loader
, callback
, true);
107 return enter
.retval();
108 return enter
.SetResult(
109 enter
.object()->FinishStreamingToFile(enter
.callback()));
112 void Close(PP_Resource loader
) {
113 VLOG(4) << "PPB_URLLoader::Close()";
114 EnterResource
<PPB_URLLoader_API
> enter(loader
, true);
117 enter
.object()->Close();
120 const PPB_URLLoader_1_0 g_ppb_urlloader_thunk_1_0
= {&Create
,
125 &GetDownloadProgress
,
128 &FinishStreamingToFile
,
133 PPAPI_THUNK_EXPORT
const PPB_URLLoader_1_0
* GetPPB_URLLoader_1_0_Thunk() {
134 return &g_ppb_urlloader_thunk_1_0
;