[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 5 | #include "base/memory/scoped_ptr.h" |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 6 | #include "ppapi/c/pp_errors.h" |
| 7 | #include "ppapi/c/private/ppb_flash_clipboard.h" |
| 8 | #include "ppapi/thunk/enter.h" |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 9 | #include "ppapi/thunk/ppb_flash_clipboard_api.h" |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 10 | #include "ppapi/thunk/thunk.h" |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 11 | |
| 12 | namespace ppapi { |
| 13 | namespace thunk { |
| 14 | |
| 15 | namespace { |
| 16 | |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 17 | uint32_t RegisterCustomFormat(PP_Instance instance, |
| 18 | const char* format_name) { |
[email protected] | 109dcfb | 2012-11-29 17:59:19 | [diff] [blame] | 19 | EnterInstanceAPI<PPB_Flash_Clipboard_API> enter(instance); |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 20 | if (enter.failed()) |
| 21 | return PP_FALSE; |
[email protected] | 109dcfb | 2012-11-29 17:59:19 | [diff] [blame] | 22 | return enter.functions()->RegisterCustomFormat(instance, format_name); |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | PP_Bool IsFormatAvailable(PP_Instance instance, |
| 26 | PP_Flash_Clipboard_Type clipboard_type, |
| 27 | uint32_t format) { |
[email protected] | 109dcfb | 2012-11-29 17:59:19 | [diff] [blame] | 28 | EnterInstanceAPI<PPB_Flash_Clipboard_API> enter(instance); |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 29 | if (enter.failed()) |
| 30 | return PP_FALSE; |
[email protected] | 109dcfb | 2012-11-29 17:59:19 | [diff] [blame] | 31 | return enter.functions()->IsFormatAvailable(instance, clipboard_type, format); |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 32 | } |
| 33 | |
[email protected] | fc148a7 | 2012-02-24 23:15:00 | [diff] [blame] | 34 | PP_Var ReadData(PP_Instance instance, |
| 35 | PP_Flash_Clipboard_Type clipboard_type, |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 36 | uint32_t format) { |
[email protected] | 109dcfb | 2012-11-29 17:59:19 | [diff] [blame] | 37 | EnterInstanceAPI<PPB_Flash_Clipboard_API> enter(instance); |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 38 | if (enter.failed()) |
| 39 | return PP_MakeUndefined(); |
[email protected] | 109dcfb | 2012-11-29 17:59:19 | [diff] [blame] | 40 | return enter.functions()->ReadData(instance, clipboard_type, format); |
[email protected] | fc148a7 | 2012-02-24 23:15:00 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int32_t WriteData(PP_Instance instance, |
| 44 | PP_Flash_Clipboard_Type clipboard_type, |
| 45 | uint32_t data_item_count, |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 46 | const uint32_t formats[], |
[email protected] | fc148a7 | 2012-02-24 23:15:00 | [diff] [blame] | 47 | const PP_Var data_items[]) { |
[email protected] | 109dcfb | 2012-11-29 17:59:19 | [diff] [blame] | 48 | EnterInstanceAPI<PPB_Flash_Clipboard_API> enter(instance); |
[email protected] | fc148a7 | 2012-02-24 23:15:00 | [diff] [blame] | 49 | if (enter.failed()) |
| 50 | return enter.retval(); |
[email protected] | 109dcfb | 2012-11-29 17:59:19 | [diff] [blame] | 51 | return enter.functions()->WriteData( |
[email protected] | d1e33ca | 2012-04-25 19:26:40 | [diff] [blame] | 52 | instance, clipboard_type, data_item_count, formats, data_items); |
[email protected] | fc148a7 | 2012-02-24 23:15:00 | [diff] [blame] | 53 | } |
| 54 | |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 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)); |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 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)); |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 66 | } |
| 67 | |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 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[]) { |
[email protected] | e832895 | 2013-04-09 17:35:42 | [diff] [blame] | 73 | scoped_ptr<uint32_t[]> new_formats(new uint32_t[data_item_count]); |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 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 | } |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 79 | |
[email protected] | 3391ebb | 2014-01-28 01:45:33 | [diff] [blame] | 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 | |
[email protected] | fc148a7 | 2012-02-24 23:15:00 | [diff] [blame] | 90 | const PPB_Flash_Clipboard_4_0 g_ppb_flash_clipboard_thunk_4_0 = { |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 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, |
[email protected] | fc148a7 | 2012-02-24 23:15:00 | [diff] [blame] | 98 | &IsFormatAvailable, |
| 99 | &ReadData, |
| 100 | &WriteData |
| 101 | }; |
| 102 | |
[email protected] | 3391ebb | 2014-01-28 01:45:33 | [diff] [blame] | 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 | |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 111 | } // namespace |
| 112 | |
[email protected] | fc148a7 | 2012-02-24 23:15:00 | [diff] [blame] | 113 | const PPB_Flash_Clipboard_4_0* GetPPB_Flash_Clipboard_4_0_Thunk() { |
| 114 | return &g_ppb_flash_clipboard_thunk_4_0; |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 115 | } |
| 116 | |
[email protected] | a1686e27 | 2012-11-01 23:39:34 | [diff] [blame] | 117 | const PPB_Flash_Clipboard_5_0* GetPPB_Flash_Clipboard_5_0_Thunk() { |
| 118 | return &g_ppb_flash_clipboard_thunk_5_0; |
| 119 | } |
| 120 | |
[email protected] | 3391ebb | 2014-01-28 01:45:33 | [diff] [blame] | 121 | const PPB_Flash_Clipboard_5_1* GetPPB_Flash_Clipboard_5_1_Thunk() { |
| 122 | return &g_ppb_flash_clipboard_thunk_5_1; |
| 123 | } |
| 124 | |
[email protected] | fe833c9 | 2011-10-22 16:13:22 | [diff] [blame] | 125 | } // namespace thunk |
| 126 | } // namespace ppapi |