summaryrefslogtreecommitdiffstats
path: root/ppapi/thunk/ppb_file_chooser_dev_thunk.cc
blob: fe1aa0dbf77e6b583fc4503e8b0709076d15300d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// From dev/ppb_file_chooser_dev.idl modified Mon Apr  1 08:24:03 2013.

#include "ppapi/c/dev/ppb_file_chooser_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/ppb_file_chooser_api.h"
#include "ppapi/thunk/ppb_instance_api.h"
#include "ppapi/thunk/resource_creation_api.h"
#include "ppapi/thunk/thunk.h"

namespace ppapi {
namespace thunk {

namespace {

PP_Resource Create(PP_Instance instance,
                   PP_FileChooserMode_Dev mode,
                   struct PP_Var accept_types) {
  VLOG(4) << "PPB_FileChooser_Dev::Create()";
  EnterResourceCreation enter(instance);
  if (enter.failed())
    return 0;
  return enter.functions()->CreateFileChooser(instance, mode, accept_types);
}

PP_Bool IsFileChooser(PP_Resource resource) {
  VLOG(4) << "PPB_FileChooser_Dev::IsFileChooser()";
  EnterResource<PPB_FileChooser_API> enter(resource, false);
  return PP_FromBool(enter.succeeded());
}

int32_t Show_0_5(PP_Resource chooser, struct PP_CompletionCallback callback) {
  VLOG(4) << "PPB_FileChooser_Dev::Show()";
  EnterResource<PPB_FileChooser_API> enter(chooser, callback, true);
  if (enter.failed())
    return enter.retval();
  return enter.SetResult(enter.object()->Show0_5(enter.callback()));
}

PP_Resource GetNextChosenFile(PP_Resource chooser) {
  VLOG(4) << "PPB_FileChooser_Dev::GetNextChosenFile()";
  EnterResource<PPB_FileChooser_API> enter(chooser, true);
  if (enter.failed())
    return 0;
  return enter.object()->GetNextChosenFile();
}

int32_t Show(PP_Resource chooser,
             struct PP_ArrayOutput output,
             struct PP_CompletionCallback callback) {
  VLOG(4) << "PPB_FileChooser_Dev::Show()";
  EnterResource<PPB_FileChooser_API> enter(chooser, callback, true);
  if (enter.failed())
    return enter.retval();
  return enter.SetResult(enter.object()->Show(output, enter.callback()));
}

const PPB_FileChooser_Dev_0_5 g_ppb_filechooser_dev_thunk_0_5 = {
  &Create,
  &IsFileChooser,
  &Show_0_5,
  &GetNextChosenFile
};

const PPB_FileChooser_Dev_0_6 g_ppb_filechooser_dev_thunk_0_6 = {
  &Create,
  &IsFileChooser,
  &Show
};

}  // namespace

const PPB_FileChooser_Dev_0_5* GetPPB_FileChooser_Dev_0_5_Thunk() {
  return &g_ppb_filechooser_dev_thunk_0_5;
}

const PPB_FileChooser_Dev_0_6* GetPPB_FileChooser_Dev_0_6_Thunk() {
  return &g_ppb_filechooser_dev_thunk_0_6;
}

}  // namespace thunk
}  // namespace ppapi