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..006da19c2a9380c780273630979878816343fb53 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,77 @@ 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, |
+ PP_Flash_Clipboard_Type clipboard_type, |
+ PP_Flash_Clipboard_Format clipboard_format, |
+ 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(); |
- } |
+ PP_Var result = get_interface<PPB_Flash_Clipboard>()->ReadData( |
+ instance->pp_instance(), |
+ clipboard_type, |
+ clipboard_format); |
+ *out = Var(Var::PassRef(), result); |
+ rv = true; |
+ } else if (has_interface<PPB_Flash_Clipboard_3_0>() && |
+ clipboard_format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) { |
+ PP_Var result = get_interface<PPB_Flash_Clipboard_3_0>()->ReadPlainText( |
+ instance->pp_instance(), |
+ clipboard_type); |
+ *out = Var(Var::PassRef(), result); |
+ 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_Format>& formats, |
+ const std::vector<Var>& data_items) { |
+ if (formats.size() != data_items.size()) |
+ return false; |
+ |
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); |
+ // Convert vector of pp::Var into a vector of PP_Var. |
+ std::vector<PP_Var> data_items_vector; |
+ for (uint32_t i = 0; i < data_items.size(); ++i) |
+ data_items_vector.push_back(data_items[i].pp_var()); |
+ |
+ // Ensure that we don't dereference the memory in empty vectors. We still |
+ // want to call WriteData because it has the effect of clearing the |
+ // clipboard. |
+ const PP_Flash_Clipboard_Format* formats_ptr(NULL); |
+ const PP_Var* data_items_ptr(NULL); |
+ if (data_items.size() > 0) { |
+ formats_ptr = &formats[0]; |
+ data_items_ptr = &data_items_vector[0]; |
+ } |
+ |
+ rv = (get_interface<PPB_Flash_Clipboard>()->WriteData( |
+ instance->pp_instance(), |
+ clipboard_type, |
+ data_items.size(), |
+ formats_ptr, |
+ data_items_ptr) == PP_OK); |
+ } else if (has_interface<PPB_Flash_Clipboard_3_0>()) { |
+ // The API specifies that only the last item of each format needs to be |
+ // written. Since we are only writing plain text items for the 3_0 |
+ // interface, we just need to write the last one in the array. |
+ for (int32_t i = formats.size() - 1; i >= 0; --i) { |
+ if (formats[i] == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) { |
+ rv = (get_interface<PPB_Flash_Clipboard_3_0>()->WritePlainText( |
+ instance->pp_instance(), |
+ clipboard_type, |
+ data_items[i].pp_var()) == PP_OK); |
+ break; |
+ } |
+ } |
} |
+ |
return rv; |
} |