Chromium Code Reviews| 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..30302c16355492719054e89aa6851adba9a54abc 100644 |
| --- a/ppapi/cpp/private/flash_clipboard.cc |
| +++ b/ppapi/cpp/private/flash_clipboard.cc |
| @@ -4,9 +4,13 @@ |
| #include "ppapi/cpp/private/flash_clipboard.h" |
| +#include <vector> |
| + |
| +#include "base/memory/scoped_ptr.h" |
| #include "ppapi/c/pp_bool.h" |
| #include "ppapi/c/pp_errors.h" |
| #include "ppapi/cpp/instance.h" |
| +#include "ppapi/cpp/logging.h" |
| #include "ppapi/cpp/module_impl.h" |
| #include "ppapi/cpp/var.h" |
| @@ -18,6 +22,10 @@ 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 { |
| @@ -40,34 +48,64 @@ 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, |
| + 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( |
|
viettrungluu
2012/02/09 00:47:37
nit: indentation
raymes
2012/02/09 17:28:22
Done.
|
| + instance->pp_instance(), |
| + clipboard_type, |
| + clipboard_format); |
| + rv = true; |
| + } |
| + 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.
|
| + clipboard_format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) { |
| + *out = get_interface<PPB_Flash_Clipboard_3_0>()->ReadPlainText( |
| + instance->pp_instance(), |
| + clipboard_type); |
| + 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); |
| + 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.
|
| + new PP_Flash_Clipboard_Data_Item[data_items.size()]); |
| + |
| + for (uint32_t i = 0; i < data_items.size(); ++i) { |
| + data_items_array[i] = data_items[i]; |
| + } |
| + |
| + rv = (get_interface<PPB_Flash_Clipboard>()->WriteData( |
| + instance->pp_instance(), |
| + clipboard_type, |
| + data_items.size(), |
| + data_items_array.get()) == PP_OK); |
| } |
| + else if (has_interface<PPB_Flash_Clipboard_3_0>()) { |
| + // Take the last plaintext item and write it according to the API. |
| + 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; |
| } |