- add sources.
[platform/framework/web/crosswalk.git] / src / ppapi / thunk / ppb_flash_file_fileref_thunk.cc
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 #include "ppapi/c/pp_errors.h"
6 #include "ppapi/c/private/ppb_flash_file.h"
7 #include "ppapi/thunk/enter.h"
8 #include "ppapi/thunk/ppb_file_ref_api.h"
9 #include "ppapi/thunk/ppb_flash_file_api.h"
10 #include "ppapi/thunk/thunk.h"
11
12 namespace ppapi {
13 namespace thunk {
14
15 namespace {
16
17 // Returns 0 on failure.
18 PP_Instance GetInstanceFromFileRef(PP_Resource file_ref) {
19   thunk::EnterResource<thunk::PPB_FileRef_API> enter(file_ref, true);
20   if (enter.failed())
21     return 0;
22   return enter.resource()->pp_instance();
23 }
24
25 int32_t OpenFile(PP_Resource file_ref_id, int32_t mode, PP_FileHandle* file) {
26   // TODO(brettw): this function should take an instance.
27   // To work around this, use the PP_Instance from the resource.
28   PP_Instance instance = GetInstanceFromFileRef(file_ref_id);
29   EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
30   if (enter.failed())
31     return PP_ERROR_BADARGUMENT;
32   return enter.functions()->OpenFileRef(instance, file_ref_id, mode, file);
33 }
34
35 int32_t QueryFile(PP_Resource file_ref_id, struct PP_FileInfo* info) {
36   // TODO(brettw): this function should take an instance.
37   // To work around this, use the PP_Instance from the resource.
38   PP_Instance instance = GetInstanceFromFileRef(file_ref_id);
39   EnterInstanceAPI<PPB_Flash_File_API> enter(instance);
40   if (enter.failed())
41     return PP_ERROR_BADARGUMENT;
42   return enter.functions()->QueryFileRef(instance, file_ref_id, info);
43 }
44
45 const PPB_Flash_File_FileRef g_ppb_flash_file_fileref_thunk = {
46   &OpenFile,
47   &QueryFile
48 };
49
50 }  // namespace
51
52 const PPB_Flash_File_FileRef* GetPPB_Flash_File_FileRef_Thunk() {
53   return &g_ppb_flash_file_fileref_thunk;
54 }
55
56 }  // namespace thunk
57 }  // namespace ppapi