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 "ppapi/cpp/private/flash_clipboard.h" | 5 #include "ppapi/cpp/private/flash_clipboard.h" |
6 | 6 |
7 #include <vector> | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
7 #include "ppapi/c/pp_bool.h" | 10 #include "ppapi/c/pp_bool.h" |
8 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/cpp/instance.h" | 12 #include "ppapi/cpp/instance.h" |
13 #include "ppapi/cpp/logging.h" | |
10 #include "ppapi/cpp/module_impl.h" | 14 #include "ppapi/cpp/module_impl.h" |
11 #include "ppapi/cpp/var.h" | 15 #include "ppapi/cpp/var.h" |
12 | 16 |
13 namespace pp { | 17 namespace pp { |
14 | 18 |
15 namespace { | 19 namespace { |
16 | 20 |
17 template <> const char* interface_name<PPB_Flash_Clipboard>() { | 21 template <> const char* interface_name<PPB_Flash_Clipboard>() { |
18 return PPB_FLASH_CLIPBOARD_INTERFACE; | 22 return PPB_FLASH_CLIPBOARD_INTERFACE; |
19 } | 23 } |
20 | 24 |
25 template <> const char* interface_name<PPB_Flash_Clipboard_3_0>() { | |
26 return PPB_FLASH_CLIPBOARD_INTERFACE_3_0; | |
27 } | |
28 | |
21 } // namespace | 29 } // namespace |
22 | 30 |
23 namespace flash { | 31 namespace flash { |
24 | 32 |
25 // static | 33 // static |
26 bool Clipboard::IsAvailable() { | 34 bool Clipboard::IsAvailable() { |
27 return has_interface<PPB_Flash_Clipboard>(); | 35 return has_interface<PPB_Flash_Clipboard>(); |
28 } | 36 } |
29 | 37 |
30 // static | 38 // static |
31 bool Clipboard::IsFormatAvailable(Instance* instance, | 39 bool Clipboard::IsFormatAvailable(Instance* instance, |
32 PP_Flash_Clipboard_Type clipboard_type, | 40 PP_Flash_Clipboard_Type clipboard_type, |
33 PP_Flash_Clipboard_Format format) { | 41 PP_Flash_Clipboard_Format format) { |
34 bool rv = false; | 42 bool rv = false; |
35 if (has_interface<PPB_Flash_Clipboard>()) { | 43 if (has_interface<PPB_Flash_Clipboard>()) { |
36 rv = PP_ToBool(get_interface<PPB_Flash_Clipboard>()->IsFormatAvailable( | 44 rv = PP_ToBool(get_interface<PPB_Flash_Clipboard>()->IsFormatAvailable( |
37 instance->pp_instance(), clipboard_type, format)); | 45 instance->pp_instance(), clipboard_type, format)); |
38 } | 46 } |
39 return rv; | 47 return rv; |
40 } | 48 } |
41 | 49 |
42 // static | 50 // static |
43 bool Clipboard::ReadPlainText(Instance* instance, | 51 bool Clipboard::ReadData( |
44 PP_Flash_Clipboard_Type clipboard_type, | 52 Instance* instance, |
45 std::string* text_out) { | 53 PP_Flash_Clipboard_Type clipboard_type, |
54 PP_Flash_Clipboard_Format clipboard_format, | |
55 PP_Var* out) { | |
46 bool rv = false; | 56 bool rv = false; |
47 if (has_interface<PPB_Flash_Clipboard>()) { | 57 if (has_interface<PPB_Flash_Clipboard>()) { |
48 Var v(Var::PassRef(), | 58 *out = get_interface<PPB_Flash_Clipboard>()->ReadData( |
viettrungluu
2012/02/09 00:47:37
nit: indentation
raymes
2012/02/09 17:28:22
Done.
| |
49 get_interface<PPB_Flash_Clipboard>()->ReadPlainText( | 59 instance->pp_instance(), |
50 instance->pp_instance(), | 60 clipboard_type, |
51 clipboard_type)); | 61 clipboard_format); |
52 if (v.is_string()) { | 62 rv = true; |
53 rv = true; | 63 } |
54 *text_out = v.AsString(); | 64 else if (has_interface<PPB_Flash_Clipboard_3_0>() && |
viettrungluu
2012/02/09 00:47:37
nit (here and elsewhere): the '}' should be on the
raymes
2012/02/09 17:28:22
Done.
| |
55 } | 65 clipboard_format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) { |
66 *out = get_interface<PPB_Flash_Clipboard_3_0>()->ReadPlainText( | |
67 instance->pp_instance(), | |
68 clipboard_type); | |
69 rv = true; | |
56 } | 70 } |
57 return rv; | 71 return rv; |
58 } | 72 } |
59 | 73 |
60 // static | 74 // static |
61 bool Clipboard::WritePlainText(Instance* instance, | 75 bool Clipboard::WriteData( |
62 PP_Flash_Clipboard_Type clipboard_type, | 76 Instance* instance, |
63 const std::string& text) { | 77 PP_Flash_Clipboard_Type clipboard_type, |
78 const std::vector<PP_Flash_Clipboard_Data_Item>& data_items) { | |
64 bool rv = false; | 79 bool rv = false; |
80 | |
65 if (has_interface<PPB_Flash_Clipboard>()) { | 81 if (has_interface<PPB_Flash_Clipboard>()) { |
66 rv = (get_interface<PPB_Flash_Clipboard>()->WritePlainText( | 82 scoped_array<PP_Flash_Clipboard_Data_Item> data_items_array( |
viettrungluu
2012/02/09 00:47:37
Not necessary; std::vectors are actually stored as
raymes
2012/02/09 17:28:22
Done.
| |
67 instance->pp_instance(), | 83 new PP_Flash_Clipboard_Data_Item[data_items.size()]); |
68 clipboard_type, | 84 |
69 Var(text).pp_var()) == PP_OK); | 85 for (uint32_t i = 0; i < data_items.size(); ++i) { |
86 data_items_array[i] = data_items[i]; | |
87 } | |
88 | |
89 rv = (get_interface<PPB_Flash_Clipboard>()->WriteData( | |
90 instance->pp_instance(), | |
91 clipboard_type, | |
92 data_items.size(), | |
93 data_items_array.get()) == PP_OK); | |
70 } | 94 } |
95 else if (has_interface<PPB_Flash_Clipboard_3_0>()) { | |
96 // Take the last plaintext item and write it according to the API. | |
97 for (std::vector<PP_Flash_Clipboard_Data_Item>::const_reverse_iterator | |
98 i = data_items.rbegin(); i != data_items.rend(); ++i) { | |
99 if (i->format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) { | |
100 rv = (get_interface<PPB_Flash_Clipboard_3_0>()->WritePlainText( | |
101 instance->pp_instance(), | |
102 clipboard_type, | |
103 i->data) == PP_OK); | |
104 break; | |
105 } | |
106 } | |
107 } | |
108 | |
71 return rv; | 109 return rv; |
72 } | 110 } |
73 | 111 |
74 } // namespace flash | 112 } // namespace flash |
75 } // namespace pp | 113 } // namespace pp |
OLD | NEW |