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