| 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..343f2ebdecde9732df70ca3ad53928df044e7d0b 100644
|
| --- a/ppapi/cpp/private/flash_clipboard.cc
|
| +++ b/ppapi/cpp/private/flash_clipboard.cc
|
| @@ -7,6 +7,7 @@
|
| #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"
|
|
|
| @@ -22,6 +23,43 @@ template <> const char* interface_name<PPB_Flash_Clipboard>() {
|
|
|
| namespace flash {
|
|
|
| +void ClipboardData::SetPlainText(const std::string& text) {
|
| + SetTextVar(text, PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT);
|
| +}
|
| +
|
| +void ClipboardData::SetHTML(const std::string& html) {
|
| + SetTextVar(html, PP_FLASH_CLIPBOARD_FORMAT_HTML);
|
| +}
|
| +
|
| +void ClipboardData::SetTextVar(const std::string& text,
|
| + PP_Flash_Clipboard_Format format) {
|
| + uint32_t index = GetFormatIndex(format);
|
| + data_items_[index].format = format;
|
| + data_items_[index].data = Var(text).pp_var();
|
| +}
|
| +
|
| +uint32_t ClipboardData::GetFormatIndex(PP_Flash_Clipboard_Format format) {
|
| + for (uint32_t i = 0; i < data_item_count_; ++i) {
|
| + if (data_items_[i].format == format) {
|
| + return i;
|
| + }
|
| + }
|
| + uint32_t index = data_item_count_;
|
| + ++data_item_count_;
|
| + PP_DCHECK(index <= ClipboardData::kMaxFormats);
|
| + return index;
|
| +}
|
| +
|
| +void ClipboardData::Clear() {
|
| + data_item_count_ = 0;
|
| +}
|
| +
|
| +PP_Flash_Clipboard_Data_Item const*
|
| + ClipboardData::GetDataItems(uint32_t* data_item_count_out) const {
|
| + *data_item_count_out = data_item_count_;
|
| + return data_items_;
|
| +}
|
| +
|
| // static
|
| bool Clipboard::IsAvailable() {
|
| return has_interface<PPB_Flash_Clipboard>();
|
| @@ -40,15 +78,17 @@ bool Clipboard::IsFormatAvailable(Instance* instance,
|
| }
|
|
|
| // static
|
| -bool Clipboard::ReadPlainText(Instance* instance,
|
| - PP_Flash_Clipboard_Type clipboard_type,
|
| - std::string* text_out) {
|
| +bool Clipboard::ReadTextVar(Instance* instance,
|
| + PP_Flash_Clipboard_Type clipboard_type,
|
| + PP_Flash_Clipboard_Format clipboard_format,
|
| + std::string* text_out) {
|
| bool rv = false;
|
| if (has_interface<PPB_Flash_Clipboard>()) {
|
| Var v(Var::PassRef(),
|
| - get_interface<PPB_Flash_Clipboard>()->ReadPlainText(
|
| + get_interface<PPB_Flash_Clipboard>()->ReadData(
|
| instance->pp_instance(),
|
| - clipboard_type));
|
| + clipboard_type,
|
| + clipboard_format));
|
| if (v.is_string()) {
|
| rv = true;
|
| *text_out = v.AsString();
|
| @@ -58,15 +98,39 @@ bool Clipboard::ReadPlainText(Instance* instance,
|
| }
|
|
|
| // static
|
| -bool Clipboard::WritePlainText(Instance* instance,
|
| - PP_Flash_Clipboard_Type clipboard_type,
|
| - const std::string& text) {
|
| +bool Clipboard::ReadPlainText(Instance* instance,
|
| + PP_Flash_Clipboard_Type clipboard_type,
|
| + std::string* text_out) {
|
| + return ReadTextVar(instance,
|
| + clipboard_type,
|
| + PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT,
|
| + text_out);
|
| +}
|
| +
|
| +// static
|
| +bool Clipboard::ReadHTML(Instance* instance,
|
| + PP_Flash_Clipboard_Type clipboard_type,
|
| + std::string* html_out) {
|
| + return ReadTextVar(instance,
|
| + clipboard_type,
|
| + PP_FLASH_CLIPBOARD_FORMAT_HTML,
|
| + html_out);
|
| +}
|
| +
|
| +// static
|
| +bool Clipboard::WriteData(Instance* instance,
|
| + PP_Flash_Clipboard_Type clipboard_type,
|
| + const ClipboardData& data) {
|
| bool rv = false;
|
| + uint32_t data_item_count;
|
| + PP_Flash_Clipboard_Data_Item const* data_items =
|
| + data.GetDataItems(&data_item_count);
|
| if (has_interface<PPB_Flash_Clipboard>()) {
|
| - rv = (get_interface<PPB_Flash_Clipboard>()->WritePlainText(
|
| + rv = (get_interface<PPB_Flash_Clipboard>()->WriteData(
|
| instance->pp_instance(),
|
| clipboard_type,
|
| - Var(text).pp_var()) == PP_OK);
|
| + data_item_count,
|
| + data_items) == PP_OK);
|
| }
|
| return rv;
|
| }
|
|
|