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 "base/memory/scoped_ptr.h" 6 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/private/ppb_flash_clipboard.h" 8 #include "ppapi/thunk/enter.h" 9 #include "ppapi/thunk/ppb_flash_clipboard_api.h" 10 #include "ppapi/thunk/thunk.h" 11 12 namespace ppapi { 13 namespace thunk { 14 15 namespace { 16 17 uint32_t RegisterCustomFormat(PP_Instance instance, 18 const char* format_name) { 19 EnterInstanceAPI<PPB_Flash_Clipboard_API> enter(instance); 20 if (enter.failed()) 21 return PP_FALSE; 22 return enter.functions()->RegisterCustomFormat(instance, format_name); 23 } 24 25 PP_Bool IsFormatAvailable(PP_Instance instance, 26 PP_Flash_Clipboard_Type clipboard_type, 27 uint32_t format) { 28 EnterInstanceAPI<PPB_Flash_Clipboard_API> enter(instance); 29 if (enter.failed()) 30 return PP_FALSE; 31 return enter.functions()->IsFormatAvailable(instance, clipboard_type, format); 32 } 33 34 PP_Var ReadData(PP_Instance instance, 35 PP_Flash_Clipboard_Type clipboard_type, 36 uint32_t format) { 37 EnterInstanceAPI<PPB_Flash_Clipboard_API> enter(instance); 38 if (enter.failed()) 39 return PP_MakeUndefined(); 40 return enter.functions()->ReadData(instance, clipboard_type, format); 41 } 42 43 int32_t WriteData(PP_Instance instance, 44 PP_Flash_Clipboard_Type clipboard_type, 45 uint32_t data_item_count, 46 const uint32_t formats[], 47 const PP_Var data_items[]) { 48 EnterInstanceAPI<PPB_Flash_Clipboard_API> enter(instance); 49 if (enter.failed()) 50 return enter.retval(); 51 return enter.functions()->WriteData( 52 instance, clipboard_type, data_item_count, formats, data_items); 53 } 54 55 PP_Bool IsFormatAvailable_4_0(PP_Instance instance, 56 PP_Flash_Clipboard_Type clipboard_type, 57 PP_Flash_Clipboard_Format format) { 58 return IsFormatAvailable(instance, clipboard_type, 59 static_cast<uint32_t>(format)); 60 } 61 62 PP_Var ReadData_4_0(PP_Instance instance, 63 PP_Flash_Clipboard_Type clipboard_type, 64 PP_Flash_Clipboard_Format format) { 65 return ReadData(instance, clipboard_type, static_cast<uint32_t>(format)); 66 } 67 68 int32_t WriteData_4_0(PP_Instance instance, 69 PP_Flash_Clipboard_Type clipboard_type, 70 uint32_t data_item_count, 71 const PP_Flash_Clipboard_Format formats[], 72 const PP_Var data_items[]) { 73 scoped_ptr<uint32_t[]> new_formats(new uint32_t[data_item_count]); 74 for (uint32_t i = 0; i < data_item_count; ++i) 75 new_formats[i] = static_cast<uint32_t>(formats[i]); 76 return WriteData(instance, clipboard_type, data_item_count, 77 new_formats.get(), data_items); 78 } 79 80 const PPB_Flash_Clipboard_4_0 g_ppb_flash_clipboard_thunk_4_0 = { 81 &IsFormatAvailable_4_0, 82 &ReadData_4_0, 83 &WriteData_4_0 84 }; 85 86 const PPB_Flash_Clipboard_5_0 g_ppb_flash_clipboard_thunk_5_0 = { 87 &RegisterCustomFormat, 88 &IsFormatAvailable, 89 &ReadData, 90 &WriteData 91 }; 92 93 } // namespace 94 95 const PPB_Flash_Clipboard_4_0* GetPPB_Flash_Clipboard_4_0_Thunk() { 96 return &g_ppb_flash_clipboard_thunk_4_0; 97 } 98 99 const PPB_Flash_Clipboard_5_0* GetPPB_Flash_Clipboard_5_0_Thunk() { 100 return &g_ppb_flash_clipboard_thunk_5_0; 101 } 102 103 } // namespace thunk 104 } // namespace ppapi 105