diff options
author | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-02 22:10:05 +0000 |
---|---|---|
committer | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-02 22:10:05 +0000 |
commit | 4dfb8f00b69ec3dde0660c4790a469df5596a3ab (patch) | |
tree | defc06b4fc11ced9c365bf502c5475bee4b3620a | |
parent | 28cc10a26ffaaf8ff7f4f2e05ab6d03926951167 (diff) | |
download | chromium_src-4dfb8f00b69ec3dde0660c4790a469df5596a3ab.zip chromium_src-4dfb8f00b69ec3dde0660c4790a469df5596a3ab.tar.gz chromium_src-4dfb8f00b69ec3dde0660c4790a469df5596a3ab.tar.bz2 |
Added RTF support to pepper API.
BUG=120435
TEST=out/Release/browser_tests --gtest_filter=*PPAPITest.*Clipboard*
Review URL: http://codereview.chromium.org/9921018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130223 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/browser/renderer_host/clipboard_message_filter.cc | 6 | ||||
-rw-r--r-- | content/browser/renderer_host/clipboard_message_filter.h | 1 | ||||
-rw-r--r-- | content/common/clipboard_messages.h | 3 | ||||
-rw-r--r-- | content/renderer/renderer_clipboard_client.cc | 6 | ||||
-rw-r--r-- | content/renderer/renderer_clipboard_client.h | 2 | ||||
-rw-r--r-- | ppapi/api/private/ppb_flash_clipboard.idl | 17 | ||||
-rw-r--r-- | ppapi/c/private/ppb_flash_clipboard.h | 19 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_clipboard_proxy.cc | 8 | ||||
-rw-r--r-- | ppapi/tests/test_flash_clipboard.cc | 74 | ||||
-rw-r--r-- | ppapi/tests/test_flash_clipboard.h | 4 | ||||
-rw-r--r-- | webkit/glue/clipboard_client.h | 3 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc | 27 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_clipboard_impl.cc | 5 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_clipboard_impl.h | 2 |
14 files changed, 156 insertions, 21 deletions
diff --git a/content/browser/renderer_host/clipboard_message_filter.cc b/content/browser/renderer_host/clipboard_message_filter.cc index f859227..25b2fd7 100644 --- a/content/browser/renderer_host/clipboard_message_filter.cc +++ b/content/browser/renderer_host/clipboard_message_filter.cc @@ -73,6 +73,7 @@ bool ClipboardMessageFilter::OnMessageReceived(const IPC::Message& message, IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadText, OnReadText) IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadAsciiText, OnReadAsciiText) IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadHTML, OnReadHTML) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadRTF, OnReadRTF) IPC_MESSAGE_HANDLER_DELAY_REPLY(ClipboardHostMsg_ReadImage, OnReadImage) IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadCustomData, OnReadCustomData) #if defined(OS_MACOSX) @@ -179,6 +180,11 @@ void ClipboardMessageFilter::OnReadHTML( *url = GURL(src_url_str); } +void ClipboardMessageFilter::OnReadRTF( + ui::Clipboard::Buffer buffer, std::string* result) { + GetClipboard()->ReadRTF(buffer, result); +} + void ClipboardMessageFilter::OnReadImage( ui::Clipboard::Buffer buffer, IPC::Message* reply_msg) { SkBitmap bitmap = GetClipboard()->ReadImage(buffer); diff --git a/content/browser/renderer_host/clipboard_message_filter.h b/content/browser/renderer_host/clipboard_message_filter.h index f1b4f1d..e05540a 100644 --- a/content/browser/renderer_host/clipboard_message_filter.h +++ b/content/browser/renderer_host/clipboard_message_filter.h @@ -43,6 +43,7 @@ class ClipboardMessageFilter : public content::BrowserMessageFilter { void OnReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result); void OnReadHTML(ui::Clipboard::Buffer buffer, string16* markup, GURL* url, uint32* fragment_start, uint32* fragment_end); + void OnReadRTF(ui::Clipboard::Buffer buffer, std::string* result); void OnReadImage(ui::Clipboard::Buffer buffer, IPC::Message* reply_msg); void OnReadImageReply(const SkBitmap& bitmap, IPC::Message* reply_msg); void OnReadCustomData(ui::Clipboard::Buffer buffer, diff --git a/content/common/clipboard_messages.h b/content/common/clipboard_messages.h index 6a4cf6c5..7900a46 100644 --- a/content/common/clipboard_messages.h +++ b/content/common/clipboard_messages.h @@ -70,6 +70,9 @@ IPC_SYNC_MESSAGE_CONTROL1_4(ClipboardHostMsg_ReadHTML, GURL /* url */, uint32 /* fragment start */, uint32 /* fragment end */) +IPC_SYNC_MESSAGE_CONTROL1_1(ClipboardHostMsg_ReadRTF, + ui::Clipboard::Buffer /* buffer */, + std::string /* result */) IPC_SYNC_MESSAGE_CONTROL1_2(ClipboardHostMsg_ReadImage, ui::Clipboard::Buffer /* buffer */, base::SharedMemoryHandle /* PNG-encoded image */, diff --git a/content/renderer/renderer_clipboard_client.cc b/content/renderer/renderer_clipboard_client.cc index be03865..7f496b9 100644 --- a/content/renderer/renderer_clipboard_client.cc +++ b/content/renderer/renderer_clipboard_client.cc @@ -158,6 +158,12 @@ void RendererClipboardClient::ReadHTML(ui::Clipboard::Buffer buffer, fragment_end)); } +void RendererClipboardClient::ReadRTF(ui::Clipboard::Buffer buffer, + std::string* result) { + RenderThreadImpl::current()->Send( + new ClipboardHostMsg_ReadRTF(buffer, result)); +} + void RendererClipboardClient::ReadImage(ui::Clipboard::Buffer buffer, std::string* data) { base::SharedMemoryHandle image_handle; diff --git a/content/renderer/renderer_clipboard_client.h b/content/renderer/renderer_clipboard_client.h index 78c99ab..ff2451e 100644 --- a/content/renderer/renderer_clipboard_client.h +++ b/content/renderer/renderer_clipboard_client.h @@ -29,6 +29,8 @@ class RendererClipboardClient : public webkit_glue::ClipboardClient { virtual void ReadHTML(ui::Clipboard::Buffer buffer, string16* markup, GURL* url, uint32* fragment_start, uint32* fragment_end) OVERRIDE; + virtual void ReadRTF(ui::Clipboard::Buffer buffer, + std::string* result) OVERRIDE; virtual void ReadImage(ui::Clipboard::Buffer buffer, std::string* data) OVERRIDE; virtual void ReadCustomData(ui::Clipboard::Buffer buffer, diff --git a/ppapi/api/private/ppb_flash_clipboard.idl b/ppapi/api/private/ppb_flash_clipboard.idl index 70073a9..24380de 100644 --- a/ppapi/api/private/ppb_flash_clipboard.idl +++ b/ppapi/api/private/ppb_flash_clipboard.idl @@ -40,10 +40,21 @@ enum PP_Flash_Clipboard_Type { enum PP_Flash_Clipboard_Format { /** Indicates an invalid or unsupported clipboard data format. */ PP_FLASH_CLIPBOARD_FORMAT_INVALID = 0, - /** Indicates plain text clipboard data. */ + /** + * Indicates plaintext clipboard data. The format expected/returned is a + * <code>PP_VARTYPE_STRING</code>. + */ PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT = 1, - /** Indicates HTML clipboard data. */ - PP_FLASH_CLIPBOARD_FORMAT_HTML = 2 + /** + * Indicates HTML clipboard data. The format expected/returned is a + * <code>PP_VARTYPE_STRING</code>. + */ + PP_FLASH_CLIPBOARD_FORMAT_HTML = 2, + /** + * Indicates RTF clipboard data. The format expected/returned is a + * <code>PP_VARTYPE_ARRAY_BUFFER</code>. + */ + PP_FLASH_CLIPBOARD_FORMAT_RTF = 3 }; /** diff --git a/ppapi/c/private/ppb_flash_clipboard.h b/ppapi/c/private/ppb_flash_clipboard.h index 7ed50406..3498d61 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 Thu Feb 23 23:15:40 2012. */ +/* From private/ppb_flash_clipboard.idl modified Wed Mar 28 16:49:38 2012. */ #ifndef PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_ #define PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_ @@ -53,10 +53,21 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_Flash_Clipboard_Type, 4); typedef enum { /** Indicates an invalid or unsupported clipboard data format. */ PP_FLASH_CLIPBOARD_FORMAT_INVALID = 0, - /** Indicates plain text clipboard data. */ + /** + * Indicates plaintext clipboard data. The format expected/returned is a + * <code>PP_VARTYPE_STRING</code>. + */ PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT = 1, - /** Indicates HTML clipboard data. */ - PP_FLASH_CLIPBOARD_FORMAT_HTML = 2 + /** + * Indicates HTML clipboard data. The format expected/returned is a + * <code>PP_VARTYPE_STRING</code>. + */ + PP_FLASH_CLIPBOARD_FORMAT_HTML = 2, + /** + * Indicates RTF clipboard data. The format expected/returned is a + * <code>PP_VARTYPE_ARRAY_BUFFER</code>. + */ + PP_FLASH_CLIPBOARD_FORMAT_RTF = 3 } PP_Flash_Clipboard_Format; PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_Flash_Clipboard_Format, 4); /** diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.cc b/ppapi/proxy/ppb_flash_clipboard_proxy.cc index 268a8e4..73b987e 100644 --- a/ppapi/proxy/ppb_flash_clipboard_proxy.cc +++ b/ppapi/proxy/ppb_flash_clipboard_proxy.cc @@ -29,7 +29,8 @@ bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) { bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) { // Purposely excludes |PP_FLASH_CLIPBOARD_FORMAT_INVALID|. return format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT || - format == PP_FLASH_CLIPBOARD_FORMAT_HTML; + format == PP_FLASH_CLIPBOARD_FORMAT_HTML || + format == PP_FLASH_CLIPBOARD_FORMAT_RTF; } } // namespace @@ -86,6 +87,11 @@ int32_t PPB_Flash_Clipboard_Proxy::WriteData( if (!IsValidClipboardType(clipboard_type)) return PP_ERROR_BADARGUMENT; + for (size_t i = 0; i < data_item_count; ++i) { + if (!IsValidClipboardFormat(formats[i])) + return PP_ERROR_BADARGUMENT; + } + std::vector<int> formats_vector(formats, formats + data_item_count); std::vector<SerializedVar> data_items_vector; diff --git a/ppapi/tests/test_flash_clipboard.cc b/ppapi/tests/test_flash_clipboard.cc index 76803b0..8007d52 100644 --- a/ppapi/tests/test_flash_clipboard.cc +++ b/ppapi/tests/test_flash_clipboard.cc @@ -4,12 +4,15 @@ #include "ppapi/tests/test_flash_clipboard.h" +#include <algorithm> #include <vector> #include "ppapi/cpp/instance.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/point.h" #include "ppapi/cpp/private/flash_clipboard.h" +#include "ppapi/cpp/var.h" +#include "ppapi/cpp/var_array_buffer.h" #include "ppapi/tests/testing_instance.h" REGISTER_TEST_CASE(FlashClipboard); @@ -27,21 +30,26 @@ TestFlashClipboard::TestFlashClipboard(TestingInstance* instance) void TestFlashClipboard::RunTests(const std::string& filter) { RUN_TEST(ReadWritePlainText, filter); RUN_TEST(ReadWriteHTML, filter); + RUN_TEST(ReadWriteRTF, filter); RUN_TEST(ReadWriteMultipleFormats, filter); RUN_TEST(Clear, filter); + RUN_TEST(InvalidFormat, filter); } -std::string TestFlashClipboard::ReadStringVar( - PP_Flash_Clipboard_Format format) { +bool TestFlashClipboard::ReadStringVar( + PP_Flash_Clipboard_Format format, + std::string* result) { pp::Var text; bool success = pp::flash::Clipboard::ReadData( instance_, PP_FLASH_CLIPBOARD_TYPE_STANDARD, format, &text); - if (success && text.is_string()) - return text.AsString(); - return std::string(); + if (success && text.is_string()) { + *result = text.AsString(); + return true; + } + return false; } bool TestFlashClipboard::WriteStringVar(PP_Flash_Clipboard_Format format, @@ -74,7 +82,9 @@ bool TestFlashClipboard::IsFormatAvailableMatches( bool TestFlashClipboard::ReadPlainTextMatches(const std::string& expected) { for (int i = 0; i < kMaxIntervals; ++i) { - if (ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) == expected) + std::string result; + bool success = ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, &result); + if (success && result == expected) return true; PlatformSleep(kIntervalMs); @@ -84,11 +94,11 @@ bool TestFlashClipboard::ReadPlainTextMatches(const std::string& expected) { bool TestFlashClipboard::ReadHTMLMatches(const std::string& expected) { for (int i = 0; i < kMaxIntervals; ++i) { - std::string result = ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML); + std::string result; + bool success = ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML, &result); // Markup is inserted around the copied html, so just check that // the pasted string contains the copied string. - bool match = result.find(expected) != std::string::npos; - if (match) + if (success && result.find(expected) != std::string::npos) return true; PlatformSleep(kIntervalMs); @@ -115,6 +125,41 @@ std::string TestFlashClipboard::TestReadWriteHTML() { PASS(); } +std::string TestFlashClipboard::TestReadWriteRTF() { + std::string rtf_string = + "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n" + "This is some {\\b bold} text.\\par\n" + "}"; + pp::VarArrayBuffer array_buffer(rtf_string.size()); + char *bytes = static_cast<char*>(array_buffer.Map()); + std::copy(rtf_string.data(), rtf_string.data() + rtf_string.size(), bytes); + std::vector<PP_Flash_Clipboard_Format> formats_vector(1, + PP_FLASH_CLIPBOARD_FORMAT_RTF); + std::vector<pp::Var> data_vector(1, array_buffer); + ASSERT_TRUE(pp::flash::Clipboard::WriteData( + instance_, + PP_FLASH_CLIPBOARD_TYPE_STANDARD, + formats_vector, + data_vector)); + + ASSERT_TRUE(IsFormatAvailableMatches(PP_FLASH_CLIPBOARD_FORMAT_RTF, true)); + + pp::Var rtf_result; + ASSERT_TRUE(pp::flash::Clipboard::ReadData( + instance_, + PP_FLASH_CLIPBOARD_TYPE_STANDARD, + PP_FLASH_CLIPBOARD_FORMAT_RTF, + &rtf_result)); + ASSERT_TRUE(rtf_result.is_array_buffer()); + pp::VarArrayBuffer array_buffer_result(rtf_result); + ASSERT_TRUE(array_buffer_result.ByteLength() == array_buffer.ByteLength()); + char *bytes_result = static_cast<char*>(array_buffer_result.Map()); + ASSERT_TRUE(std::equal(bytes, bytes + array_buffer.ByteLength(), + bytes_result)); + + PASS(); +} + std::string TestFlashClipboard::TestReadWriteMultipleFormats() { std::vector<PP_Flash_Clipboard_Format> formats; std::vector<pp::Var> data; @@ -153,3 +198,14 @@ std::string TestFlashClipboard::TestClear() { PASS(); } + +std::string TestFlashClipboard::TestInvalidFormat() { + PP_Flash_Clipboard_Format invalid_format = + static_cast<PP_Flash_Clipboard_Format>(-1); + ASSERT_FALSE(WriteStringVar(invalid_format, "text")); + ASSERT_TRUE(IsFormatAvailableMatches(invalid_format, false)); + std::string unused; + ASSERT_FALSE(ReadStringVar(invalid_format, &unused)); + + PASS(); +} diff --git a/ppapi/tests/test_flash_clipboard.h b/ppapi/tests/test_flash_clipboard.h index 9dc4956..e04f89d 100644 --- a/ppapi/tests/test_flash_clipboard.h +++ b/ppapi/tests/test_flash_clipboard.h @@ -20,7 +20,7 @@ class TestFlashClipboard : public TestCase { private: // Helpers. - std::string ReadStringVar(PP_Flash_Clipboard_Format format); + bool ReadStringVar(PP_Flash_Clipboard_Format format, std::string* result); bool WriteStringVar(PP_Flash_Clipboard_Format format, const std::string& text); bool IsFormatAvailableMatches(PP_Flash_Clipboard_Format format, @@ -31,8 +31,10 @@ class TestFlashClipboard : public TestCase { // Tests. std::string TestReadWritePlainText(); std::string TestReadWriteHTML(); + std::string TestReadWriteRTF(); std::string TestReadWriteMultipleFormats(); std::string TestClear(); + std::string TestInvalidFormat(); }; #endif // PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_ diff --git a/webkit/glue/clipboard_client.h b/webkit/glue/clipboard_client.h index a0ddec2..6c9856c 100644 --- a/webkit/glue/clipboard_client.h +++ b/webkit/glue/clipboard_client.h @@ -59,6 +59,9 @@ class ClipboardClient { GURL* url, uint32* fragment_start, uint32* fragment_end) = 0; + // Reads RTF from the clipboard, if available. + virtual void ReadRTF(ui::Clipboard::Buffer buffer, std::string* result) = 0; + // Reads and image from the clipboard, if available. virtual void ReadImage(ui::Clipboard::Buffer buffer, std::string* data) = 0; diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc index 7706144..fdebb2dd 100644 --- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc @@ -12,7 +12,9 @@ #include "base/utf_string_conversions.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_flash_clipboard.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/var.h" +#include "ppapi/shared_impl/var_tracker.h" #include "webkit/glue/clipboard_client.h" #include "webkit/glue/scoped_clipboard_writer_glue.h" #include "webkit/plugins/ppapi/common.h" @@ -92,11 +94,13 @@ PP_Bool PPB_Flash_Clipboard_Impl::IsFormatAvailable( case PP_FLASH_CLIPBOARD_FORMAT_HTML: return BoolToPPBool(client_->IsFormatAvailable( ui::Clipboard::GetHtmlFormatType(), buffer_type)); + case PP_FLASH_CLIPBOARD_FORMAT_RTF: + return BoolToPPBool(client_->IsFormatAvailable( + ui::Clipboard::GetRtfFormatType(), buffer_type)); case PP_FLASH_CLIPBOARD_FORMAT_INVALID: break; } - NOTREACHED(); return PP_FALSE; } @@ -150,11 +154,16 @@ PP_Var PPB_Flash_Clipboard_Impl::ReadData( &fragment_end); return StringVar::StringToPPVar(UTF16ToUTF8(html_stdstr)); } + case PP_FLASH_CLIPBOARD_FORMAT_RTF: { + std::string result; + client_->ReadRTF(buffer_type, &result); + return ::ppapi::PpapiGlobals::Get()->GetVarTracker()-> + MakeArrayBufferPPVar(result.size(), result.data()); + } case PP_FLASH_CLIPBOARD_FORMAT_INVALID: break; } - NOTREACHED(); return PP_MakeUndefined(); } @@ -185,11 +194,23 @@ int32_t PPB_Flash_Clipboard_Impl::WriteDataItem( scw->WriteHTML(UTF8ToUTF16(text_string->value()), ""); return PP_OK; } + case PP_FLASH_CLIPBOARD_FORMAT_RTF: { + ::ppapi::ArrayBufferVar* rtf_data = + ::ppapi::ArrayBufferVar::FromPPVar(data); + if (!rtf_data) + return PP_ERROR_BADARGUMENT; + + if (rtf_data->ByteLength() > kMaxClipboardWriteSize) + return PP_ERROR_NOSPACE; + + scw->WriteRTF(std::string(static_cast<char*>(rtf_data->Map()), + rtf_data->ByteLength())); + return PP_OK; + } case PP_FLASH_CLIPBOARD_FORMAT_INVALID: break; } - NOTREACHED(); return PP_ERROR_BADARGUMENT; } diff --git a/webkit/tools/test_shell/simple_clipboard_impl.cc b/webkit/tools/test_shell/simple_clipboard_impl.cc index ec5a65c..06d6c8b 100644 --- a/webkit/tools/test_shell/simple_clipboard_impl.cc +++ b/webkit/tools/test_shell/simple_clipboard_impl.cc @@ -80,6 +80,11 @@ void SimpleClipboardClient::ReadHTML(ui::Clipboard::Buffer buffer, *url = GURL(url_str); } +void SimpleClipboardClient::ReadRTF(ui::Clipboard::Buffer buffer, + std::string* result) { + GetClipboard()->ReadRTF(buffer, result); +} + void SimpleClipboardClient::ReadImage(ui::Clipboard::Buffer buffer, std::string* data) { SkBitmap bitmap = GetClipboard()->ReadImage(buffer); diff --git a/webkit/tools/test_shell/simple_clipboard_impl.h b/webkit/tools/test_shell/simple_clipboard_impl.h index 389ec36..52571bf 100644 --- a/webkit/tools/test_shell/simple_clipboard_impl.h +++ b/webkit/tools/test_shell/simple_clipboard_impl.h @@ -28,6 +28,8 @@ class SimpleClipboardClient : public webkit_glue::ClipboardClient { virtual void ReadHTML(ui::Clipboard::Buffer buffer, string16* markup, GURL* url, uint32* fragment_start, uint32* fragment_end) OVERRIDE; + virtual void ReadRTF(ui::Clipboard::Buffer buffer, + std::string* result) OVERRIDE; virtual void ReadImage(ui::Clipboard::Buffer buffer, std::string* data) OVERRIDE; virtual void ReadCustomData(ui::Clipboard::Buffer buffer, |