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.
4
5// From ppb_url_request_info.idl modified Tue Aug 20 08:13:36 2013.
6
7#include "ppapi/c/pp_errors.h"
8#include "ppapi/c/ppb_url_request_info.h"
9#include "ppapi/shared_impl/tracked_callback.h"
10#include "ppapi/thunk/enter.h"
11#include "ppapi/thunk/ppapi_thunk_export.h"
12#include "ppapi/thunk/ppb_url_request_info_api.h"
13
14namespace ppapi {
15namespace thunk {
16
17namespace {
18
19PP_Resource Create(PP_Instance instance) {
20  VLOG(4) << "PPB_URLRequestInfo::Create()";
21  EnterResourceCreation enter(instance);
22  if (enter.failed())
23    return 0;
24  return enter.functions()->CreateURLRequestInfo(instance);
25}
26
27PP_Bool IsURLRequestInfo(PP_Resource resource) {
28  VLOG(4) << "PPB_URLRequestInfo::IsURLRequestInfo()";
29  EnterResource<PPB_URLRequestInfo_API> enter(resource, false);
30  return PP_FromBool(enter.succeeded());
31}
32
33PP_Bool SetProperty(PP_Resource request,
34                    PP_URLRequestProperty property,
35                    struct PP_Var value) {
36  VLOG(4) << "PPB_URLRequestInfo::SetProperty()";
37  EnterResource<PPB_URLRequestInfo_API> enter(request, true);
38  if (enter.failed())
39    return PP_FALSE;
40  return enter.object()->SetProperty(property, value);
41}
42
43PP_Bool AppendDataToBody(PP_Resource request, const void* data, uint32_t len) {
44  VLOG(4) << "PPB_URLRequestInfo::AppendDataToBody()";
45  EnterResource<PPB_URLRequestInfo_API> enter(request, true);
46  if (enter.failed())
47    return PP_FALSE;
48  return enter.object()->AppendDataToBody(data, len);
49}
50
51PP_Bool AppendFileToBody(PP_Resource request,
52                         PP_Resource file_ref,
53                         int64_t start_offset,
54                         int64_t number_of_bytes,
55                         PP_Time expected_last_modified_time) {
56  VLOG(4) << "PPB_URLRequestInfo::AppendFileToBody()";
57  EnterResource<PPB_URLRequestInfo_API> enter(request, true);
58  if (enter.failed())
59    return PP_FALSE;
60  return enter.object()->AppendFileToBody(file_ref,
61                                          start_offset,
62                                          number_of_bytes,
63                                          expected_last_modified_time);
64}
65
66const PPB_URLRequestInfo_1_0 g_ppb_urlrequestinfo_thunk_1_0 = {
67  &Create,
68  &IsURLRequestInfo,
69  &SetProperty,
70  &AppendDataToBody,
71  &AppendFileToBody
72};
73
74}  // namespace
75
76PPAPI_THUNK_EXPORT const PPB_URLRequestInfo_1_0*
77    GetPPB_URLRequestInfo_1_0_Thunk() {
78  return &g_ppb_urlrequestinfo_thunk_1_0;
79}
80
81}  // namespace thunk
82}  // namespace ppapi
83