summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/private/flash_clipboard.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi/cpp/private/flash_clipboard.cc')
-rw-r--r--ppapi/cpp/private/flash_clipboard.cc62
1 files changed, 57 insertions, 5 deletions
diff --git a/ppapi/cpp/private/flash_clipboard.cc b/ppapi/cpp/private/flash_clipboard.cc
index c63f747..77e68ba 100644
--- a/ppapi/cpp/private/flash_clipboard.cc
+++ b/ppapi/cpp/private/flash_clipboard.cc
@@ -24,13 +24,18 @@ template <> const char* interface_name<PPB_Flash_Clipboard_5_0>() {
return PPB_FLASH_CLIPBOARD_INTERFACE_5_0;
}
+template <> const char* interface_name<PPB_Flash_Clipboard_5_1>() {
+ return PPB_FLASH_CLIPBOARD_INTERFACE_5_1;
+}
+
} // namespace
namespace flash {
// static
bool Clipboard::IsAvailable() {
- return has_interface<PPB_Flash_Clipboard_5_0>() ||
+ return has_interface<PPB_Flash_Clipboard_5_1>() ||
+ has_interface<PPB_Flash_Clipboard_5_0>() ||
has_interface<PPB_Flash_Clipboard_4_0>() ;
}
@@ -38,7 +43,10 @@ bool Clipboard::IsAvailable() {
uint32_t Clipboard::RegisterCustomFormat(const InstanceHandle& instance,
const std::string& format_name) {
uint32_t rv = PP_FLASH_CLIPBOARD_FORMAT_INVALID;
- if (has_interface<PPB_Flash_Clipboard_5_0>()) {
+ if (has_interface<PPB_Flash_Clipboard_5_1>()) {
+ rv = get_interface<PPB_Flash_Clipboard_5_1>()->RegisterCustomFormat(
+ instance.pp_instance(), format_name.c_str());
+ } else if (has_interface<PPB_Flash_Clipboard_5_0>()) {
rv = get_interface<PPB_Flash_Clipboard_5_0>()->RegisterCustomFormat(
instance.pp_instance(), format_name.c_str());
}
@@ -50,7 +58,10 @@ bool Clipboard::IsFormatAvailable(const InstanceHandle& instance,
PP_Flash_Clipboard_Type clipboard_type,
uint32_t format) {
bool rv = false;
- if (has_interface<PPB_Flash_Clipboard_5_0>()) {
+ if (has_interface<PPB_Flash_Clipboard_5_1>()) {
+ rv = PP_ToBool(get_interface<PPB_Flash_Clipboard_5_1>()->IsFormatAvailable(
+ instance.pp_instance(), clipboard_type, format));
+ } else if (has_interface<PPB_Flash_Clipboard_5_0>()) {
rv = PP_ToBool(get_interface<PPB_Flash_Clipboard_5_0>()->IsFormatAvailable(
instance.pp_instance(), clipboard_type, format));
} else if (has_interface<PPB_Flash_Clipboard_4_0>()) {
@@ -68,7 +79,14 @@ bool Clipboard::ReadData(
uint32_t format,
Var* out) {
bool rv = false;
- if (has_interface<PPB_Flash_Clipboard_5_0>()) {
+ if (has_interface<PPB_Flash_Clipboard_5_1>()) {
+ PP_Var result = get_interface<PPB_Flash_Clipboard_5_1>()->ReadData(
+ instance.pp_instance(),
+ clipboard_type,
+ format);
+ *out = Var(PASS_REF, result);
+ rv = true;
+ } else if (has_interface<PPB_Flash_Clipboard_5_0>()) {
PP_Var result = get_interface<PPB_Flash_Clipboard_5_0>()->ReadData(
instance.pp_instance(),
clipboard_type,
@@ -96,7 +114,29 @@ bool Clipboard::WriteData(
return false;
bool rv = false;
- if (has_interface<PPB_Flash_Clipboard_5_0>()) {
+ if (has_interface<PPB_Flash_Clipboard_5_1>()) {
+ // 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 uint32_t* 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_5_1>()->WriteData(
+ instance.pp_instance(),
+ clipboard_type,
+ data_items.size(),
+ formats_ptr,
+ data_items_ptr) == PP_OK);
+ } else if (has_interface<PPB_Flash_Clipboard_5_0>()) {
// 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)
@@ -148,5 +188,17 @@ bool Clipboard::WriteData(
return rv;
}
+// static
+bool Clipboard::GetSequenceNumber(const InstanceHandle& instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ uint64_t* sequence_number) {
+ if (has_interface<PPB_Flash_Clipboard_5_1>()) {
+ return PP_ToBool(
+ get_interface<PPB_Flash_Clipboard_5_1>()->GetSequenceNumber(
+ instance.pp_instance(), clipboard_type, sequence_number));
+ }
+ return false;
+}
+
} // namespace flash
} // namespace pp