OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | |
5 #include "ppapi/c/pp_errors.h" | 6 #include "ppapi/c/pp_errors.h" |
6 #include "ppapi/c/private/ppb_flash_clipboard.h" | 7 #include "ppapi/c/private/ppb_flash_clipboard.h" |
7 #include "ppapi/thunk/enter.h" | 8 #include "ppapi/thunk/enter.h" |
8 #include "ppapi/thunk/thunk.h" | 9 #include "ppapi/thunk/thunk.h" |
yzshen1
2012/10/29 17:58:04
sort.
raymes
2012/10/29 18:44:58
Done.
| |
9 #include "ppapi/thunk/ppb_flash_api.h" | 10 #include "ppapi/thunk/ppb_flash_clipboard_api.h" |
10 | 11 |
11 namespace ppapi { | 12 namespace ppapi { |
12 namespace thunk { | 13 namespace thunk { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 PP_Bool IsFormatAvailable(PP_Instance instance, | 17 uint32_t RegisterCustomFormat(PP_Instance instance, |
17 PP_Flash_Clipboard_Type clipboard_type, | 18 const char* format_name) { |
18 PP_Flash_Clipboard_Format format) { | |
19 EnterInstance enter(instance); | 19 EnterInstance enter(instance); |
20 if (enter.failed()) | 20 if (enter.failed()) |
21 return PP_FALSE; | 21 return PP_FALSE; |
22 return enter.functions()->GetFlashAPI()->IsClipboardFormatAvailable( | 22 return enter.functions()->GetFlashClipboardAPI( |
23 instance, clipboard_type, format); | 23 instance)->RegisterCustomFormat(instance, format_name); |
24 } | |
25 | |
26 PP_Bool IsFormatAvailable(PP_Instance instance, | |
27 PP_Flash_Clipboard_Type clipboard_type, | |
28 uint32_t format) { | |
29 EnterInstance enter(instance); | |
30 if (enter.failed()) | |
31 return PP_FALSE; | |
32 return enter.functions()->GetFlashClipboardAPI( | |
33 instance)->IsFormatAvailable(instance, clipboard_type, format); | |
24 } | 34 } |
25 | 35 |
26 PP_Var ReadData(PP_Instance instance, | 36 PP_Var ReadData(PP_Instance instance, |
27 PP_Flash_Clipboard_Type clipboard_type, | 37 PP_Flash_Clipboard_Type clipboard_type, |
28 PP_Flash_Clipboard_Format format) { | 38 uint32_t format) { |
29 EnterInstance enter(instance); | 39 EnterInstance enter(instance); |
30 if (enter.failed()) | 40 if (enter.failed()) |
31 return PP_MakeUndefined(); | 41 return PP_MakeUndefined(); |
32 return enter.functions()->GetFlashAPI()->ReadClipboardData( | 42 return enter.functions()->GetFlashClipboardAPI(instance)->ReadData( |
33 instance, clipboard_type, format); | 43 instance, clipboard_type, format); |
34 } | 44 } |
35 | 45 |
36 int32_t WriteData(PP_Instance instance, | 46 int32_t WriteData(PP_Instance instance, |
37 PP_Flash_Clipboard_Type clipboard_type, | 47 PP_Flash_Clipboard_Type clipboard_type, |
38 uint32_t data_item_count, | 48 uint32_t data_item_count, |
39 const PP_Flash_Clipboard_Format formats[], | 49 const uint32_t formats[], |
40 const PP_Var data_items[]) { | 50 const PP_Var data_items[]) { |
41 EnterInstance enter(instance); | 51 EnterInstance enter(instance); |
42 if (enter.failed()) | 52 if (enter.failed()) |
43 return enter.retval(); | 53 return enter.retval(); |
44 return enter.functions()->GetFlashAPI()->WriteClipboardData( | 54 return enter.functions()->GetFlashClipboardAPI(instance)->WriteData( |
45 instance, clipboard_type, data_item_count, formats, data_items); | 55 instance, clipboard_type, data_item_count, formats, data_items); |
46 } | 56 } |
47 | 57 |
48 PP_Var ReadPlainText(PP_Instance instance, | 58 PP_Bool IsFormatAvailable_4_0(PP_Instance instance, |
49 PP_Flash_Clipboard_Type clipboard_type) { | 59 PP_Flash_Clipboard_Type clipboard_type, |
50 return ReadData(instance, | 60 PP_Flash_Clipboard_Format format) { |
51 clipboard_type, | 61 return IsFormatAvailable(instance, clipboard_type, |
52 PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT); | 62 static_cast<uint32_t>(format)); |
53 } | 63 } |
54 | 64 |
55 int32_t WritePlainText(PP_Instance instance, | 65 PP_Var ReadData_4_0(PP_Instance instance, |
56 PP_Flash_Clipboard_Type clipboard_type, | 66 PP_Flash_Clipboard_Type clipboard_type, |
57 PP_Var text) { | 67 PP_Flash_Clipboard_Format format) { |
58 PP_Flash_Clipboard_Format format = PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT; | 68 return ReadData(instance, clipboard_type, static_cast<uint32_t>(format)); |
59 return WriteData(instance, clipboard_type, 1, &format, &text); | |
60 } | 69 } |
61 | 70 |
62 const PPB_Flash_Clipboard_3_0 g_ppb_flash_clipboard_thunk_3_0 = { | 71 int32_t WriteData_4_0(PP_Instance instance, |
63 &IsFormatAvailable, | 72 PP_Flash_Clipboard_Type clipboard_type, |
64 &ReadPlainText, | 73 uint32_t data_item_count, |
65 &WritePlainText | 74 const PP_Flash_Clipboard_Format formats[], |
75 const PP_Var data_items[]) { | |
76 scoped_array<uint32_t> new_formats(new uint32_t[data_item_count]); | |
yzshen1
2012/10/29 17:58:04
[Haven't tried myself]
will new uint32_t[0] run co
raymes
2012/10/29 18:44:58
Yes, but we can't dereference the pointer. If the
| |
77 for (uint32_t i = 0; i < data_item_count; ++i) | |
78 new_formats[i] = static_cast<uint32_t>(formats[i]); | |
79 return WriteData(instance, clipboard_type, data_item_count, | |
80 new_formats.get(), data_items); | |
81 } | |
82 | |
83 const PPB_Flash_Clipboard_4_0 g_ppb_flash_clipboard_thunk_4_0 = { | |
84 &IsFormatAvailable_4_0, | |
85 &ReadData_4_0, | |
86 &WriteData_4_0 | |
66 }; | 87 }; |
67 | 88 |
68 const PPB_Flash_Clipboard_4_0 g_ppb_flash_clipboard_thunk_4_0 = { | 89 const PPB_Flash_Clipboard_5_0 g_ppb_flash_clipboard_thunk_5_0 = { |
90 &RegisterCustomFormat, | |
69 &IsFormatAvailable, | 91 &IsFormatAvailable, |
70 &ReadData, | 92 &ReadData, |
71 &WriteData | 93 &WriteData |
72 }; | 94 }; |
73 | 95 |
74 } // namespace | 96 } // namespace |
75 | 97 |
76 const PPB_Flash_Clipboard_3_0* GetPPB_Flash_Clipboard_3_0_Thunk() { | |
77 return &g_ppb_flash_clipboard_thunk_3_0; | |
78 } | |
79 | |
80 const PPB_Flash_Clipboard_4_0* GetPPB_Flash_Clipboard_4_0_Thunk() { | 98 const PPB_Flash_Clipboard_4_0* GetPPB_Flash_Clipboard_4_0_Thunk() { |
81 return &g_ppb_flash_clipboard_thunk_4_0; | 99 return &g_ppb_flash_clipboard_thunk_4_0; |
82 } | 100 } |
83 | 101 |
102 const PPB_Flash_Clipboard_5_0* GetPPB_Flash_Clipboard_5_0_Thunk() { | |
103 return &g_ppb_flash_clipboard_thunk_5_0; | |
104 } | |
105 | |
84 } // namespace thunk | 106 } // namespace thunk |
85 } // namespace ppapi | 107 } // namespace ppapi |
OLD | NEW |