Index: ppapi/cpp/private/flash_clipboard.cc |
diff --git a/ppapi/cpp/private/flash_clipboard.cc b/ppapi/cpp/private/flash_clipboard.cc |
index 8634eafc8adde463a9fa2be7609ab2a8dfca857d..32b71d9a4590d23dd4aa5dcac8a09a1f6bba850e 100644 |
--- a/ppapi/cpp/private/flash_clipboard.cc |
+++ b/ppapi/cpp/private/flash_clipboard.cc |
@@ -4,6 +4,8 @@ |
#include "ppapi/cpp/private/flash_clipboard.h" |
+#include <vector> |
+ |
#include "ppapi/c/pp_bool.h" |
#include "ppapi/c/pp_errors.h" |
#include "ppapi/cpp/instance.h" |
@@ -18,13 +20,18 @@ template <> const char* interface_name<PPB_Flash_Clipboard>() { |
return PPB_FLASH_CLIPBOARD_INTERFACE; |
} |
+template <> const char* interface_name<PPB_Flash_Clipboard_3_0>() { |
+ return PPB_FLASH_CLIPBOARD_INTERFACE_3_0; |
+} |
+ |
} // namespace |
namespace flash { |
// static |
bool Clipboard::IsAvailable() { |
- return has_interface<PPB_Flash_Clipboard>(); |
+ return has_interface<PPB_Flash_Clipboard>() || |
+ has_interface<PPB_Flash_Clipboard_3_0>(); |
} |
// static |
@@ -40,34 +47,56 @@ bool Clipboard::IsFormatAvailable(Instance* instance, |
} |
// static |
-bool Clipboard::ReadPlainText(Instance* instance, |
- PP_Flash_Clipboard_Type clipboard_type, |
- std::string* text_out) { |
+bool Clipboard::ReadData( |
+ Instance* instance, |
dmichael (off chromium)
2012/02/23 18:13:25
brettw's been working on a change to replace Insta
raymes
2012/02/24 07:28:28
Ok
On 2012/02/23 18:13:25, dmichael wrote:
|
+ PP_Flash_Clipboard_Type clipboard_type, |
+ PP_Flash_Clipboard_Format clipboard_format, |
+ PP_Var* out) { |
bool rv = false; |
if (has_interface<PPB_Flash_Clipboard>()) { |
- Var v(Var::PassRef(), |
- get_interface<PPB_Flash_Clipboard>()->ReadPlainText( |
- instance->pp_instance(), |
- clipboard_type)); |
- if (v.is_string()) { |
- rv = true; |
- *text_out = v.AsString(); |
- } |
+ *out = get_interface<PPB_Flash_Clipboard>()->ReadData( |
+ instance->pp_instance(), |
+ clipboard_type, |
+ clipboard_format); |
+ rv = true; |
+ } else if (has_interface<PPB_Flash_Clipboard_3_0>() && |
+ clipboard_format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) { |
+ *out = get_interface<PPB_Flash_Clipboard_3_0>()->ReadPlainText( |
+ instance->pp_instance(), |
+ clipboard_type); |
dmichael (off chromium)
2012/02/23 18:13:25
Do you really need backwards compatibility here? T
raymes
2012/02/24 07:28:28
Spoke to vtl and he says that the backward compat
dmichael (off chromium)
2012/02/24 19:35:44
Okay, vtl understands what you need for Flash more
raymes
2012/02/24 21:38:17
According to vtl, both are needed.
On 2012/02/24 1
|
+ rv = true; |
} |
return rv; |
} |
// static |
-bool Clipboard::WritePlainText(Instance* instance, |
- PP_Flash_Clipboard_Type clipboard_type, |
- const std::string& text) { |
+bool Clipboard::WriteData( |
+ Instance* instance, |
+ PP_Flash_Clipboard_Type clipboard_type, |
+ const std::vector<PP_Flash_Clipboard_Data_Item>& data_items) { |
bool rv = false; |
+ |
if (has_interface<PPB_Flash_Clipboard>()) { |
- rv = (get_interface<PPB_Flash_Clipboard>()->WritePlainText( |
- instance->pp_instance(), |
- clipboard_type, |
- Var(text).pp_var()) == PP_OK); |
+ new PP_Flash_Clipboard_Data_Item[data_items.size()]; |
dmichael (off chromium)
2012/02/23 18:13:25
What is this line doing? Looks like a blatant leak
raymes
2012/02/24 07:28:28
=( undeleted line from an older patchset. Good cat
|
+ rv = (get_interface<PPB_Flash_Clipboard>()->WriteData( |
+ instance->pp_instance(), |
+ clipboard_type, |
+ data_items.size(), |
+ &data_items[0]) == PP_OK); |
dmichael (off chromium)
2012/02/23 18:13:25
probably best to return early if data_items.empty(
raymes
2012/02/24 07:28:28
Done.
|
+ } else if (has_interface<PPB_Flash_Clipboard_3_0>()) { |
+ // Take the last plaintext item and write it according to the API. |
dmichael (off chromium)
2012/02/23 18:13:25
I think this backwards-compat part should probably
raymes
2012/02/24 07:28:28
The backward compat code is apparently necessary.
dmichael (off chromium)
2012/02/24 19:35:44
It might be that I don't understand how the clipbo
raymes
2012/02/24 21:38:17
Ah I see what you're saying. The thing is that eac
dmichael (off chromium)
2012/02/24 21:49:36
That makes sense, thanks for explaining. I think a
|
+ for (std::vector<PP_Flash_Clipboard_Data_Item>::const_reverse_iterator |
+ i = data_items.rbegin(); i != data_items.rend(); ++i) { |
+ if (i->format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) { |
+ rv = (get_interface<PPB_Flash_Clipboard_3_0>()->WritePlainText( |
+ instance->pp_instance(), |
+ clipboard_type, |
+ i->data) == PP_OK); |
+ break; |
+ } |
+ } |
} |
+ |
return rv; |
} |