summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authorraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-24 23:15:00 +0000
committerraymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-24 23:15:00 +0000
commitfc148a7aed3f536f26c136d5c66b45b8735c069b (patch)
tree8070272863600e0a38ecfa3e7ded91fec7634c98 /ppapi
parente49221987f30d61b7b696de183a6a416f502ffbf (diff)
downloadchromium_src-fc148a7aed3f536f26c136d5c66b45b8735c069b.zip
chromium_src-fc148a7aed3f536f26c136d5c66b45b8735c069b.tar.gz
chromium_src-fc148a7aed3f536f26c136d5c66b45b8735c069b.tar.bz2
Modified the flash cipboard interface to add html clipboard support.
This changes the way the interface works. To write data, the user now passes an array of data items, one for each format they want to write to the clipboard. When reading data, they specify the format they want to read. BUG=110796 TEST=./ui_tests --gtest_filter=*PPAPITest.*Clipboard* passes Review URL: http://codereview.chromium.org/9212066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123581 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/api/private/ppb_flash_clipboard.idl45
-rw-r--r--ppapi/c/private/ppb_flash_clipboard.h50
-rw-r--r--ppapi/cpp/private/flash_clipboard.cc88
-rw-r--r--ppapi/cpp/private/flash_clipboard.h25
-rw-r--r--ppapi/proxy/interface_list.cc2
-rw-r--r--ppapi/proxy/ppapi_messages.h8
-rw-r--r--ppapi/proxy/ppb_flash_clipboard_proxy.cc72
-rw-r--r--ppapi/proxy/ppb_flash_clipboard_proxy.h30
-rw-r--r--ppapi/tests/test_flash_clipboard.cc124
-rw-r--r--ppapi/tests/test_flash_clipboard.h15
-rw-r--r--ppapi/thunk/ppb_flash_clipboard_api.h15
-rw-r--r--ppapi/thunk/ppb_flash_clipboard_thunk.cc49
-rw-r--r--ppapi/thunk/thunk.h2
13 files changed, 399 insertions, 126 deletions
diff --git a/ppapi/api/private/ppb_flash_clipboard.idl b/ppapi/api/private/ppb_flash_clipboard.idl
index 890a7d4..70073a9 100644
--- a/ppapi/api/private/ppb_flash_clipboard.idl
+++ b/ppapi/api/private/ppb_flash_clipboard.idl
@@ -9,7 +9,8 @@
*/
label Chrome {
- M17 = 3.0
+ M17 = 3.0,
+ M19 = 4.0
};
#inline c
@@ -49,9 +50,7 @@ enum PP_Flash_Clipboard_Format {
* The <code>PPB_Flash_Clipboard</code> interface contains pointers to functions
* used by Pepper Flash to access the clipboard.
*
- * TODO(viettrungluu): Support more formats (e.g., HTML)....
*/
-[version=3.0]
interface PPB_Flash_Clipboard {
/**
* Checks whether a given data format is available from the given clipboard.
@@ -63,19 +62,51 @@ interface PPB_Flash_Clipboard {
[in] PP_Flash_Clipboard_Format format);
/**
- * Reads plain text data from the clipboard.
+ * Deprecated in 4.0.
*/
+ [version=3.0, deprecate=4.0]
PP_Var ReadPlainText(
[in] PP_Instance instance_id,
[in] PP_Flash_Clipboard_Type clipboard_type);
/**
- * Writes plain text data to the clipboard. If <code>text</code> is too large,
- * it will return <code>PP_ERROR_NOSPACE</code> and not write to the
- * clipboard.
+ * Deprecated in 4.0.
*/
+ [version=3.0, deprecate=4.0]
int32_t WritePlainText(
[in] PP_Instance instance_id,
[in] PP_Flash_Clipboard_Type clipboard_type,
[in] PP_Var text);
+
+ /**
+ * Reads data in the given <code>format</code> from the clipboard. An
+ * undefined <code>PP_Var</code> is returned if there is an error in reading
+ * the clipboard data and a null <code>PP_Var</code> is returned if there is
+ * no data of the specified <code>format</code> to read.
+ */
+ [version=4.0]
+ PP_Var ReadData([in] PP_Instance instance_id,
+ [in] PP_Flash_Clipboard_Type clipboard_type,
+ [in] PP_Flash_Clipboard_Format format);
+
+ /**
+ * Writes the given array of data items to the clipboard. All existing
+ * clipboard data in any format is erased before writing this data. Thus,
+ * passing an array of size 0 has the effect of clearing the clipboard without
+ * writing any data. Each data item in the array should have a different
+ * <code>PP_Flash_Clipboard_Format</code>. If multiple data items have the
+ * same format, only the last item with that format will be written.
+ * If there is an error writing any of the items in the array to the
+ * clipboard, none will be written and an error code is returned.
+ * The error code will be <code>PP_ERROR_NOSPACE</code> if the value is
+ * too large to be written, <code>PP_ERROR_BADARGUMENT</code> if a PP_Var
+ * cannot be converted into the format supplied or <code>PP_FAILED</code>
+ * if the format is not supported.
+ */
+ [version=4.0]
+ int32_t WriteData([in] PP_Instance instance_id,
+ [in] PP_Flash_Clipboard_Type clipboard_type,
+ [in] uint32_t data_item_count,
+ [in, size_is(data_item_count)] PP_Flash_Clipboard_Format[] formats,
+ [in, size_is(data_item_count)] PP_Var[] data_items);
};
diff --git a/ppapi/c/private/ppb_flash_clipboard.h b/ppapi/c/private/ppb_flash_clipboard.h
index 7b84a27..7ed50406 100644
--- a/ppapi/c/private/ppb_flash_clipboard.h
+++ b/ppapi/c/private/ppb_flash_clipboard.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* From private/ppb_flash_clipboard.idl modified Wed Dec 14 18:08:00 2011. */
+/* From private/ppb_flash_clipboard.idl modified Thu Feb 23 23:15:40 2012. */
#ifndef PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_
#define PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_
@@ -15,7 +15,8 @@
#include "ppapi/c/pp_var.h"
#define PPB_FLASH_CLIPBOARD_INTERFACE_3_0 "PPB_Flash_Clipboard;3.0"
-#define PPB_FLASH_CLIPBOARD_INTERFACE PPB_FLASH_CLIPBOARD_INTERFACE_3_0
+#define PPB_FLASH_CLIPBOARD_INTERFACE_4_0 "PPB_Flash_Clipboard;4.0"
+#define PPB_FLASH_CLIPBOARD_INTERFACE PPB_FLASH_CLIPBOARD_INTERFACE_4_0
/**
* @file
@@ -70,9 +71,8 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_Flash_Clipboard_Format, 4);
* The <code>PPB_Flash_Clipboard</code> interface contains pointers to functions
* used by Pepper Flash to access the clipboard.
*
- * TODO(viettrungluu): Support more formats (e.g., HTML)....
*/
-struct PPB_Flash_Clipboard_3_0 {
+struct PPB_Flash_Clipboard_4_0 {
/**
* Checks whether a given data format is available from the given clipboard.
* Returns true if the given format is available from the given clipboard.
@@ -81,21 +81,47 @@ struct PPB_Flash_Clipboard_3_0 {
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format);
/**
- * Reads plain text data from the clipboard.
+ * Reads data in the given <code>format</code> from the clipboard. An
+ * undefined <code>PP_Var</code> is returned if there is an error in reading
+ * the clipboard data and a null <code>PP_Var</code> is returned if there is
+ * no data of the specified <code>format</code> to read.
*/
- struct PP_Var (*ReadPlainText)(PP_Instance instance_id,
- PP_Flash_Clipboard_Type clipboard_type);
+ struct PP_Var (*ReadData)(PP_Instance instance_id,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format);
/**
- * Writes plain text data to the clipboard. If <code>text</code> is too large,
- * it will return <code>PP_ERROR_NOSPACE</code> and not write to the
- * clipboard.
+ * Writes the given array of data items to the clipboard. All existing
+ * clipboard data in any format is erased before writing this data. Thus,
+ * passing an array of size 0 has the effect of clearing the clipboard without
+ * writing any data. Each data item in the array should have a different
+ * <code>PP_Flash_Clipboard_Format</code>. If multiple data items have the
+ * same format, only the last item with that format will be written.
+ * If there is an error writing any of the items in the array to the
+ * clipboard, none will be written and an error code is returned.
+ * The error code will be <code>PP_ERROR_NOSPACE</code> if the value is
+ * too large to be written, <code>PP_ERROR_BADARGUMENT</code> if a PP_Var
+ * cannot be converted into the format supplied or <code>PP_FAILED</code>
+ * if the format is not supported.
*/
+ int32_t (*WriteData)(PP_Instance instance_id,
+ PP_Flash_Clipboard_Type clipboard_type,
+ uint32_t data_item_count,
+ const PP_Flash_Clipboard_Format formats[],
+ const struct PP_Var data_items[]);
+};
+
+typedef struct PPB_Flash_Clipboard_4_0 PPB_Flash_Clipboard;
+
+struct PPB_Flash_Clipboard_3_0 {
+ PP_Bool (*IsFormatAvailable)(PP_Instance instance_id,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format);
+ struct PP_Var (*ReadPlainText)(PP_Instance instance_id,
+ PP_Flash_Clipboard_Type clipboard_type);
int32_t (*WritePlainText)(PP_Instance instance_id,
PP_Flash_Clipboard_Type clipboard_type,
struct PP_Var text);
};
-
-typedef struct PPB_Flash_Clipboard_3_0 PPB_Flash_Clipboard;
/**
* @}
*/
diff --git a/ppapi/cpp/private/flash_clipboard.cc b/ppapi/cpp/private/flash_clipboard.cc
index 8634eaf..006da19 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;
}
diff --git a/ppapi/cpp/private/flash_clipboard.h b/ppapi/cpp/private/flash_clipboard.h
index db13ce6..65446e3 100644
--- a/ppapi/cpp/private/flash_clipboard.h
+++ b/ppapi/cpp/private/flash_clipboard.h
@@ -6,8 +6,10 @@
#define PPAPI_CPP_PRIVATE_FLASH_CLIPBOARD_H_
#include <string>
+#include <vector>
#include "ppapi/c/private/ppb_flash_clipboard.h"
+#include "ppapi/cpp/var.h"
namespace pp {
@@ -25,16 +27,19 @@ class Clipboard {
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format);
- // Returns true on success, in which case |text_out| will be filled with plain
- // text read from the given clipboard.
- static bool ReadPlainText(Instance* instance,
- PP_Flash_Clipboard_Type clipboard_type,
- std::string* text_out);
-
- // Returns true on success (it may fail if |text| is too big).
- static bool WritePlainText(Instance* instance,
- PP_Flash_Clipboard_Type clipboard_type,
- const std::string& text);
+ // Returns true on success, in which case |out| will be filled with
+ // data read from the given clipboard in the given format.
+ static bool ReadData(Instance* instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format clipboard_format,
+ Var* out);
+
+ // Returns true on success in which case all of |data| will be written to
+ // the clipboard. Otherwise nothing will be written.
+ static bool WriteData(Instance* instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ const std::vector<PP_Flash_Clipboard_Format>& formats,
+ const std::vector<Var>& data_items);
};
} // namespace flash
diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc
index 55b97a0..9bf73c2 100644
--- a/ppapi/proxy/interface_list.cc
+++ b/ppapi/proxy/interface_list.cc
@@ -276,6 +276,8 @@ void InterfaceList::AddFlashInterfaces() {
AddProxy(API_ID_PPB_FLASH_CLIPBOARD,
&ProxyFactory<PPB_Flash_Clipboard_Proxy>);
+ AddPPB(PPB_FLASH_CLIPBOARD_INTERFACE_4_0, API_ID_PPB_FLASH_CLIPBOARD,
+ thunk::GetPPB_Flash_Clipboard_4_0_Thunk());
AddPPB(PPB_FLASH_CLIPBOARD_INTERFACE_3_0, API_ID_PPB_FLASH_CLIPBOARD,
thunk::GetPPB_Flash_Clipboard_3_0_Thunk());
AddPPB(PPB_FLASH_CLIPBOARD_INTERFACE_3_LEGACY, API_ID_PPB_FLASH_CLIPBOARD,
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h
index ff19419..023f11b 100644
--- a/ppapi/proxy/ppapi_messages.h
+++ b/ppapi/proxy/ppapi_messages.h
@@ -734,14 +734,16 @@ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable,
int /* clipboard_type */,
int /* format */,
bool /* result */)
-IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlashClipboard_ReadPlainText,
+IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlashClipboard_ReadData,
PP_Instance /* instance */,
int /* clipboard_type */,
+ int /* format */,
ppapi::proxy::SerializedVar /* result */)
-IPC_MESSAGE_ROUTED3(PpapiHostMsg_PPBFlashClipboard_WritePlainText,
+IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFlashClipboard_WriteData,
PP_Instance /* instance */,
int /* clipboard_type */,
- ppapi::proxy::SerializedVar /* text */)
+ std::vector<int> /* formats */,
+ std::vector<ppapi::proxy::SerializedVar> /* data */)
// PPB_Flash_File_FileRef.
IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBFlashFile_FileRef_OpenFile,
diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.cc b/ppapi/proxy/ppb_flash_clipboard_proxy.cc
index df6cc59..b2166aa 100644
--- a/ppapi/proxy/ppb_flash_clipboard_proxy.cc
+++ b/ppapi/proxy/ppb_flash_clipboard_proxy.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -62,32 +62,45 @@ PP_Bool PPB_Flash_Clipboard_Proxy::IsFormatAvailable(
&result));
return PP_FromBool(result);
}
-
-PP_Var PPB_Flash_Clipboard_Proxy::ReadPlainText(
+PP_Var PPB_Flash_Clipboard_Proxy::ReadData(
PP_Instance instance,
- PP_Flash_Clipboard_Type clipboard_type) {
- if (!IsValidClipboardType(clipboard_type))
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format) {
+ if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format))
return PP_MakeUndefined();
ReceiveSerializedVarReturnValue result;
- dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText(
+ dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadData(
API_ID_PPB_FLASH_CLIPBOARD, instance,
- static_cast<int>(clipboard_type), &result));
+ static_cast<int>(clipboard_type), static_cast<int>(format), &result));
return result.Return(dispatcher());
}
-int32_t PPB_Flash_Clipboard_Proxy::WritePlainText(
+
+int32_t PPB_Flash_Clipboard_Proxy::WriteData(
PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
- const PP_Var& text) {
+ uint32_t data_item_count,
+ const PP_Flash_Clipboard_Format formats[],
+ const PP_Var data_items[]) {
if (!IsValidClipboardType(clipboard_type))
return PP_ERROR_BADARGUMENT;
- dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText(
+ std::vector<int> formats_vector(formats, formats + data_item_count);
+
+ std::vector<SerializedVar> data_items_vector;
+ SerializedVarSendInput::ConvertVector(
+ dispatcher(),
+ data_items,
+ data_item_count,
+ &data_items_vector);
+
+ dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WriteData(
API_ID_PPB_FLASH_CLIPBOARD,
instance,
static_cast<int>(clipboard_type),
- SerializedVarSendInput(dispatcher(), text)));
+ formats_vector,
+ data_items_vector));
// Assume success, since it allows us to avoid a sync IPC.
return PP_OK;
}
@@ -97,10 +110,10 @@ bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable,
OnMsgIsFormatAvailable)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText,
- OnMsgReadPlainText)
- IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText,
- OnMsgWritePlainText)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadData,
+ OnMsgReadData)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WriteData,
+ OnMsgWriteData)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -122,29 +135,44 @@ void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable(
}
}
-void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText(
+void PPB_Flash_Clipboard_Proxy::OnMsgReadData(
PP_Instance instance,
int clipboard_type,
+ int format,
SerializedVarReturnValue result) {
EnterFlashClipboardNoLock enter(instance, true);
if (enter.succeeded()) {
result.Return(dispatcher(),
- enter.functions()->ReadPlainText(
+ enter.functions()->ReadData(
instance,
- static_cast<PP_Flash_Clipboard_Type>(clipboard_type)));
+ static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
+ static_cast<PP_Flash_Clipboard_Format>(format)));
}
}
-void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText(
+void PPB_Flash_Clipboard_Proxy::OnMsgWriteData(
PP_Instance instance,
int clipboard_type,
- SerializedVarReceiveInput text) {
+ std::vector<int> formats,
+ SerializedVarVectorReceiveInput data_items) {
EnterFlashClipboardNoLock enter(instance, true);
if (enter.succeeded()) {
- int32_t result = enter.functions()->WritePlainText(
+ uint32_t data_item_count;
+ PP_Var* data_items_array = data_items.Get(dispatcher(), &data_item_count);
+ CHECK(data_item_count == formats.size());
+
+ scoped_array<PP_Flash_Clipboard_Format> formats_array(
+ new PP_Flash_Clipboard_Format[formats.size()]);
+ for (uint32_t i = 0; i < formats.size(); ++i) {
+ formats_array[i] = static_cast<PP_Flash_Clipboard_Format>(formats[i]);
+ }
+
+ int32_t result = enter.functions()->WriteData(
instance,
static_cast<PP_Flash_Clipboard_Type>(clipboard_type),
- text.Get(dispatcher()));
+ data_item_count,
+ formats_array.get(),
+ data_items_array);
DLOG_IF(WARNING, result != PP_OK)
<< "Write to clipboard failed unexpectedly.";
(void)result; // Prevent warning in release mode.
diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.h b/ppapi/proxy/ppb_flash_clipboard_proxy.h
index 08db677..e7a40bc 100644
--- a/ppapi/proxy/ppb_flash_clipboard_proxy.h
+++ b/ppapi/proxy/ppb_flash_clipboard_proxy.h
@@ -5,6 +5,8 @@
#ifndef PPAPI_PROXY_PPB_FLASH_CLIPBOARD_PROXY_H_
#define PPAPI_PROXY_PPB_FLASH_CLIPBOARD_PROXY_H_
+#include <vector>
+
#include "ppapi/c/pp_instance.h"
#include "ppapi/proxy/interface_proxy.h"
#include "ppapi/thunk/ppb_flash_clipboard_api.h"
@@ -14,6 +16,7 @@ namespace proxy {
class SerializedVarReceiveInput;
class SerializedVarReturnValue;
+class SerializedVarVectorReceiveInput;
class PPB_Flash_Clipboard_Proxy
: public InterfaceProxy,
@@ -30,11 +33,14 @@ class PPB_Flash_Clipboard_Proxy
virtual PP_Bool IsFormatAvailable(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) OVERRIDE;
- virtual PP_Var ReadPlainText(PP_Instance instance,
- PP_Flash_Clipboard_Type clipboard_type) OVERRIDE;
- virtual int32_t WritePlainText(PP_Instance instance,
- PP_Flash_Clipboard_Type clipboard_type,
- const PP_Var& text) OVERRIDE;
+ virtual PP_Var ReadData(PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format) OVERRIDE;
+ virtual int32_t WriteData(PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ uint32_t data_item_count,
+ const PP_Flash_Clipboard_Format formats[],
+ const PP_Var data_items[]) OVERRIDE;
// InterfaceProxy implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);
@@ -47,12 +53,14 @@ class PPB_Flash_Clipboard_Proxy
int clipboard_type,
int format,
bool* result);
- void OnMsgReadPlainText(PP_Instance instance,
- int clipboard_type,
- SerializedVarReturnValue result);
- void OnMsgWritePlainText(PP_Instance instance,
- int clipboard_type,
- SerializedVarReceiveInput text);
+ void OnMsgReadData(PP_Instance instance,
+ int clipboard_type,
+ int format,
+ SerializedVarReturnValue result);
+ void OnMsgWriteData(PP_Instance instance,
+ int clipboard_type,
+ std::vector<int> formats,
+ SerializedVarVectorReceiveInput data_items);
};
} // namespace proxy
diff --git a/ppapi/tests/test_flash_clipboard.cc b/ppapi/tests/test_flash_clipboard.cc
index 3022705..09e4000 100644
--- a/ppapi/tests/test_flash_clipboard.cc
+++ b/ppapi/tests/test_flash_clipboard.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,6 +11,12 @@
REGISTER_TEST_CASE(FlashClipboard);
+// WriteData() sends an async request to the browser process. As a result, the
+// string written may not be reflected by IsFormatAvailable() or ReadPlainText()
+// immediately. We need to wait and retry.
+const int kIntervalMs = 250;
+const int kMaxIntervals = kActionTimeoutMs / kIntervalMs;
+
TestFlashClipboard::TestFlashClipboard(TestingInstance* instance)
: TestCase(instance),
clipboard_interface_(NULL) {
@@ -23,48 +29,116 @@ bool TestFlashClipboard::Init() {
}
void TestFlashClipboard::RunTests(const std::string& filter) {
- RUN_TEST(ReadWrite, filter);
+ RUN_TEST(ReadWritePlainText, filter);
+ RUN_TEST(ReadWriteHTML, filter);
+ RUN_TEST(ReadWriteMultipleFormats, filter);
}
-std::string TestFlashClipboard::TestReadWrite() {
- std::string input_str("Hello, world");
- pp::Var input_var(input_str);
- clipboard_interface_->WritePlainText(instance_->pp_instance(),
- PP_FLASH_CLIPBOARD_TYPE_STANDARD,
- input_var.pp_var());
-
- // WritePlainText() causes an async request sent to the browser process.
- // As a result, the string written may not be reflected by IsFormatAvailable()
- // or ReadPlainText() immediately. We need to wait and retry.
- const int kIntervalMs = 250;
- const int kMaxIntervals = kActionTimeoutMs / kIntervalMs;
-
+PP_Bool TestFlashClipboard::IsFormatAvailable(
+ PP_Flash_Clipboard_Format format) {
PP_Bool is_available = PP_FALSE;
for (int i = 0; i < kMaxIntervals; ++i) {
is_available = clipboard_interface_->IsFormatAvailable(
instance_->pp_instance(),
PP_FLASH_CLIPBOARD_TYPE_STANDARD,
- PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT);
+ format);
if (is_available)
break;
PlatformSleep(kIntervalMs);
}
- ASSERT_TRUE(is_available);
+ return is_available;
+}
+std::string TestFlashClipboard::ReadStringVar(
+ PP_Flash_Clipboard_Format format) {
std::string result_str;
- for (int i = 0; i < kMaxIntervals; ++i) {
- pp::Var result_var(pp::Var::PassRef(),
- clipboard_interface_->ReadPlainText(instance_->pp_instance(),
- PP_FLASH_CLIPBOARD_TYPE_STANDARD));
- ASSERT_TRUE(result_var.is_string());
+ pp::Var result_var(
+ pp::Var::PassRef(),
+ clipboard_interface_->ReadData(instance_->pp_instance(),
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD,
+ format));
+ if (result_var.is_string())
result_str = result_var.AsString();
- if (result_str == input_str)
- break;
+ return result_str;
+}
+int32_t TestFlashClipboard::WriteStringVar(PP_Flash_Clipboard_Format format,
+ const std::string& input) {
+ pp::Var input_var(input);
+ PP_Var data_item = input_var.pp_var();
+ int32_t success = clipboard_interface_->WriteData(
+ instance_->pp_instance(),
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD,
+ 1,
+ &format,
+ &data_item);
+ return success;
+}
+
+bool TestFlashClipboard::ReadAndMatchPlainText(const std::string& input) {
+ for (int i = 0; i < kMaxIntervals; ++i) {
+ if (ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) == input) {
+ return true;
+ }
PlatformSleep(kIntervalMs);
}
+ return false;
+}
+
+bool TestFlashClipboard::ReadAndMatchHTML(const std::string& input) {
+ for (int i = 0; i < kMaxIntervals; ++i) {
+ std::string result = ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML);
+ // Markup is inserted around the copied html, so just check that
+ // the pasted string contains the copied string.
+ bool match = result.find(input) != std::string::npos;
+ if (match) {
+ return true;
+ }
+ PlatformSleep(kIntervalMs);
+ }
+ return false;
+}
+
+std::string TestFlashClipboard::TestReadWritePlainText() {
+ std::string input = "Hello world plain text!";
+ ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT,
+ input) == PP_OK);
+ ASSERT_TRUE(IsFormatAvailable(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT));
+ ASSERT_TRUE(ReadAndMatchPlainText(input));
+
+ PASS();
+}
+
+std::string TestFlashClipboard::TestReadWriteHTML() {
+ std::string input = "Hello world html!";
+ ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML,
+ input) == PP_OK);
+ ASSERT_TRUE(IsFormatAvailable(PP_FLASH_CLIPBOARD_FORMAT_HTML));
+ ASSERT_TRUE(ReadAndMatchHTML(input));
+
+ PASS();
+}
+
+std::string TestFlashClipboard::TestReadWriteMultipleFormats() {
+ pp::Var plain_text_var("plain text");
+ pp::Var html_var("html");
+ PP_Flash_Clipboard_Format formats[] =
+ { PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, PP_FLASH_CLIPBOARD_FORMAT_HTML };
+ PP_Var data_items[] = { plain_text_var.pp_var(), html_var.pp_var() };
+ int32_t success = clipboard_interface_->WriteData(
+ instance_->pp_instance(),
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD,
+ sizeof(data_items) / sizeof(*data_items),
+ formats,
+ data_items);
+ ASSERT_TRUE(success == PP_OK);
+
+ ASSERT_TRUE(IsFormatAvailable(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT));
+ ASSERT_TRUE(IsFormatAvailable(PP_FLASH_CLIPBOARD_FORMAT_HTML));
+
+ ASSERT_TRUE(ReadAndMatchPlainText(plain_text_var.AsString()));
+ ASSERT_TRUE(ReadAndMatchHTML(html_var.AsString()));
- ASSERT_TRUE(result_str == input_str);
PASS();
}
diff --git a/ppapi/tests/test_flash_clipboard.h b/ppapi/tests/test_flash_clipboard.h
index 06d3781..dd377c5 100644
--- a/ppapi/tests/test_flash_clipboard.h
+++ b/ppapi/tests/test_flash_clipboard.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -20,7 +20,18 @@ class TestFlashClipboard : public TestCase {
virtual void RunTests(const std::string& filter);
private:
- std::string TestReadWrite();
+ // Helpers.
+ PP_Bool IsFormatAvailable(PP_Flash_Clipboard_Format format);
+ std::string ReadStringVar(PP_Flash_Clipboard_Format format);
+ int32_t WriteStringVar(PP_Flash_Clipboard_Format format,
+ const std::string& input);
+ bool ReadAndMatchPlainText(const std::string& input);
+ bool ReadAndMatchHTML(const std::string& input);
+
+ // Tests.
+ std::string TestReadWritePlainText();
+ std::string TestReadWriteHTML();
+ std::string TestReadWriteMultipleFormats();
const PPB_Flash_Clipboard* clipboard_interface_;
};
diff --git a/ppapi/thunk/ppb_flash_clipboard_api.h b/ppapi/thunk/ppb_flash_clipboard_api.h
index c91e6a1..02155e1 100644
--- a/ppapi/thunk/ppb_flash_clipboard_api.h
+++ b/ppapi/thunk/ppb_flash_clipboard_api.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -18,11 +18,14 @@ class PPB_Flash_Clipboard_FunctionAPI {
virtual PP_Bool IsFormatAvailable(PP_Instance instance,
PP_Flash_Clipboard_Type clipboard_type,
PP_Flash_Clipboard_Format format) = 0;
- virtual PP_Var ReadPlainText(PP_Instance instance,
- PP_Flash_Clipboard_Type clipboard_type) = 0;
- virtual int32_t WritePlainText(PP_Instance instance,
- PP_Flash_Clipboard_Type clipboard_type,
- const PP_Var& text) = 0;
+ virtual PP_Var ReadData(PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format) = 0;
+ virtual int32_t WriteData(PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ uint32_t data_item_count,
+ const PP_Flash_Clipboard_Format formats[],
+ const PP_Var data_items[]) = 0;
static const ApiID kApiID = API_ID_PPB_FLASH_CLIPBOARD;
};
diff --git a/ppapi/thunk/ppb_flash_clipboard_thunk.cc b/ppapi/thunk/ppb_flash_clipboard_thunk.cc
index ba2fca3..efc7307 100644
--- a/ppapi/thunk/ppb_flash_clipboard_thunk.cc
+++ b/ppapi/thunk/ppb_flash_clipboard_thunk.cc
@@ -24,33 +24,64 @@ PP_Bool IsFormatAvailable(PP_Instance instance,
return enter.functions()->IsFormatAvailable(instance, clipboard_type, format);
}
-PP_Var ReadPlainText(PP_Instance instance,
- PP_Flash_Clipboard_Type clipboard_type) {
+PP_Var ReadData(PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Flash_Clipboard_Format format) {
EnterFlashClipboard enter(instance, true);
if (enter.failed())
return PP_MakeUndefined();
- return enter.functions()->ReadPlainText(instance, clipboard_type);
+ return enter.functions()->ReadData(instance, clipboard_type, format);
}
-int32_t WritePlainText(PP_Instance instance,
- PP_Flash_Clipboard_Type clipboard_type,
- PP_Var text) {
+int32_t WriteData(PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ uint32_t data_item_count,
+ const PP_Flash_Clipboard_Format formats[],
+ const PP_Var data_items[]) {
EnterFlashClipboard enter(instance, true);
if (enter.failed())
return enter.retval();
- return enter.functions()->WritePlainText(instance, clipboard_type, text);
+ return enter.functions()->WriteData(instance,
+ clipboard_type,
+ data_item_count,
+ formats,
+ data_items);
}
-const PPB_Flash_Clipboard g_ppb_flash_clipboard_thunk = {
+PP_Var ReadPlainText(PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type) {
+ return ReadData(instance,
+ clipboard_type,
+ PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT);
+}
+
+int32_t WritePlainText(PP_Instance instance,
+ PP_Flash_Clipboard_Type clipboard_type,
+ PP_Var text) {
+ PP_Flash_Clipboard_Format format = PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT;
+ return WriteData(instance, clipboard_type, 1, &format, &text);
+}
+
+const PPB_Flash_Clipboard_3_0 g_ppb_flash_clipboard_thunk_3_0 = {
&IsFormatAvailable,
&ReadPlainText,
&WritePlainText
};
+const PPB_Flash_Clipboard_4_0 g_ppb_flash_clipboard_thunk_4_0 = {
+ &IsFormatAvailable,
+ &ReadData,
+ &WriteData
+};
+
} // namespace
const PPB_Flash_Clipboard_3_0* GetPPB_Flash_Clipboard_3_0_Thunk() {
- return &g_ppb_flash_clipboard_thunk;
+ return &g_ppb_flash_clipboard_thunk_3_0;
+}
+
+const PPB_Flash_Clipboard_4_0* GetPPB_Flash_Clipboard_4_0_Thunk() {
+ return &g_ppb_flash_clipboard_thunk_4_0;
}
} // namespace thunk
diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h
index f7ac751..49d48ca 100644
--- a/ppapi/thunk/thunk.h
+++ b/ppapi/thunk/thunk.h
@@ -59,6 +59,8 @@ PPAPI_THUNK_EXPORT const PPB_BufferTrusted_0_1*
GetPPB_BufferTrusted_0_1_Thunk();
PPAPI_THUNK_EXPORT const PPB_FileChooserTrusted_0_5*
GetPPB_FileChooser_Trusted_0_5_Thunk();
+PPAPI_THUNK_EXPORT const PPB_Flash_Clipboard_4_0*
+ GetPPB_Flash_Clipboard_4_0_Thunk();
PPAPI_THUNK_EXPORT const PPB_Flash_Clipboard_3_0*
GetPPB_Flash_Clipboard_3_0_Thunk();
PPAPI_THUNK_EXPORT const PPB_Flash_Menu_0_2* GetPPB_Flash_Menu_0_2_Thunk();