Home | History | Annotate | Download | only in thunk
      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 PP_Bool GetSequenceNumber(PP_Instance instance,
     81                           PP_Flash_Clipboard_Type clipboard_type,
     82                           uint64_t* sequence_number) {
     83   EnterInstanceAPI<PPB_Flash_Clipboard_API> enter(instance);
     84   if (enter.failed())
     85     return PP_FALSE;
     86   return enter.functions()->GetSequenceNumber(instance, clipboard_type,
     87                                               sequence_number);
     88 }
     89 
     90 const PPB_Flash_Clipboard_4_0 g_ppb_flash_clipboard_thunk_4_0 = {
     91   &IsFormatAvailable_4_0,
     92   &ReadData_4_0,
     93   &WriteData_4_0
     94 };
     95 
     96 const PPB_Flash_Clipboard_5_0 g_ppb_flash_clipboard_thunk_5_0 = {
     97   &RegisterCustomFormat,
     98   &IsFormatAvailable,
     99   &ReadData,
    100   &WriteData
    101 };
    102 
    103 const PPB_Flash_Clipboard_5_1 g_ppb_flash_clipboard_thunk_5_1 = {
    104   &RegisterCustomFormat,
    105   &IsFormatAvailable,
    106   &ReadData,
    107   &WriteData,
    108   &GetSequenceNumber
    109 };
    110 
    111 }  // namespace
    112 
    113 const PPB_Flash_Clipboard_4_0* GetPPB_Flash_Clipboard_4_0_Thunk() {
    114   return &g_ppb_flash_clipboard_thunk_4_0;
    115 }
    116 
    117 const PPB_Flash_Clipboard_5_0* GetPPB_Flash_Clipboard_5_0_Thunk() {
    118   return &g_ppb_flash_clipboard_thunk_5_0;
    119 }
    120 
    121 const PPB_Flash_Clipboard_5_1* GetPPB_Flash_Clipboard_5_1_Thunk() {
    122   return &g_ppb_flash_clipboard_thunk_5_1;
    123 }
    124 
    125 }  // namespace thunk
    126 }  // namespace ppapi
    127