diff options
Diffstat (limited to 'chromium/content/browser/renderer_host/clipboard_message_filter.cc')
-rw-r--r-- | chromium/content/browser/renderer_host/clipboard_message_filter.cc | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/chromium/content/browser/renderer_host/clipboard_message_filter.cc b/chromium/content/browser/renderer_host/clipboard_message_filter.cc index bacce45dde4..3ea8071cb1c 100644 --- a/chromium/content/browser/renderer_host/clipboard_message_filter.cc +++ b/chromium/content/browser/renderer_host/clipboard_message_filter.cc @@ -9,6 +9,7 @@ #include "base/location.h" #include "base/memory/scoped_ptr.h" #include "base/stl_util.h" +#include "base/strings/utf_string_conversions.h" #include "content/common/clipboard_messages.h" #include "content/public/browser/browser_context.h" #include "ipc/ipc_message_macros.h" @@ -19,18 +20,8 @@ namespace content { - namespace { -// On Windows, the write must be performed on the UI thread because the -// clipboard object from the IO thread cannot create windows so it cannot be -// the "owner" of the clipboard's contents. See http://crbug.com/5823. -void WriteObjectsOnUIThread(ui::Clipboard::ObjectMap* objects) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - static ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); - clipboard->WriteObjects(ui::CLIPBOARD_TYPE_COPY_PASTE, *objects); -} - enum BitmapPolicy { kFilterBitmap, kAllowBitmap, @@ -61,7 +52,8 @@ void SanitizeObjectMap(ui::Clipboard::ObjectMap* objects, } // namespace -ClipboardMessageFilter::ClipboardMessageFilter() {} +ClipboardMessageFilter::ClipboardMessageFilter() + : BrowserMessageFilter(ClipboardMsgStart) {} void ClipboardMessageFilter::OverrideThreadForMessage( const IPC::Message& message, BrowserThread::ID* thread) { @@ -85,10 +77,9 @@ void ClipboardMessageFilter::OverrideThreadForMessage( #endif } -bool ClipboardMessageFilter::OnMessageReceived(const IPC::Message& message, - bool* message_was_ok) { +bool ClipboardMessageFilter::OnMessageReceived(const IPC::Message& message) { bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(ClipboardMessageFilter, message, *message_was_ok) + IPC_BEGIN_MESSAGE_MAP(ClipboardMessageFilter, message) IPC_MESSAGE_HANDLER(ClipboardHostMsg_WriteObjectsAsync, OnWriteObjectsAsync) IPC_MESSAGE_HANDLER(ClipboardHostMsg_WriteObjectsSync, OnWriteObjectsSync) IPC_MESSAGE_HANDLER(ClipboardHostMsg_GetSequenceNumber, OnGetSequenceNumber) @@ -97,12 +88,10 @@ bool ClipboardMessageFilter::OnMessageReceived(const IPC::Message& message, IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadAvailableTypes, OnReadAvailableTypes) 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) - IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadData, OnReadData) #if defined(OS_MACOSX) IPC_MESSAGE_HANDLER(ClipboardHostMsg_FindPboardWriteStringAsync, OnFindPboardWriteString) @@ -141,10 +130,22 @@ void ClipboardMessageFilter::OnWriteObjectsSync( BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - base::Bind(&WriteObjectsOnUIThread, + base::Bind(&ClipboardMessageFilter::WriteObjectsOnUIThread, base::Owned(long_living_objects.release()))); } +// On Windows, the write must be performed on the UI thread because the +// clipboard object from the IO thread cannot create windows so it cannot be +// the "owner" of the clipboard's contents. See http://crbug.com/5823. +// TODO(dcheng): Temporarily a member of ClipboardMessageFilter so it can access +// ui::Clipboard::WriteObjects(). +void ClipboardMessageFilter::WriteObjectsOnUIThread( + const ui::Clipboard::ObjectMap* objects) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + static ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); + clipboard->WriteObjects(ui::CLIPBOARD_TYPE_COPY_PASTE, *objects); +} + void ClipboardMessageFilter::OnWriteObjectsAsync( const ui::Clipboard::ObjectMap& objects) { // This async message doesn't support shared-memory based bitmaps; they must @@ -180,11 +181,33 @@ void ClipboardMessageFilter::OnReadAvailableTypes( GetClipboard()->ReadAvailableTypes(type, types, contains_filenames); } -void ClipboardMessageFilter::OnIsFormatAvailable( - const ui::Clipboard::FormatType& format, - ui::ClipboardType type, - bool* result) { - *result = GetClipboard()->IsFormatAvailable(format, type); +void ClipboardMessageFilter::OnIsFormatAvailable(ClipboardFormat format, + ui::ClipboardType type, + bool* result) { + switch (format) { + case CLIPBOARD_FORMAT_PLAINTEXT: + *result = GetClipboard()->IsFormatAvailable( + ui::Clipboard::GetPlainTextWFormatType(), type) || + GetClipboard()->IsFormatAvailable( + ui::Clipboard::GetPlainTextFormatType(), type); + break; + case CLIPBOARD_FORMAT_HTML: + *result = GetClipboard()->IsFormatAvailable( + ui::Clipboard::GetHtmlFormatType(), type); + break; + case CLIPBOARD_FORMAT_SMART_PASTE: + *result = GetClipboard()->IsFormatAvailable( + ui::Clipboard::GetWebKitSmartPasteFormatType(), type); + break; + case CLIPBOARD_FORMAT_BOOKMARK: +#if defined(OS_WIN) || defined(OS_MACOSX) + *result = GetClipboard()->IsFormatAvailable( + ui::Clipboard::GetUrlWFormatType(), type); +#else + *result = false; +#endif + break; + } } void ClipboardMessageFilter::OnClear(ui::ClipboardType type) { @@ -193,12 +216,17 @@ void ClipboardMessageFilter::OnClear(ui::ClipboardType type) { void ClipboardMessageFilter::OnReadText(ui::ClipboardType type, base::string16* result) { - GetClipboard()->ReadText(type, result); -} - -void ClipboardMessageFilter::OnReadAsciiText(ui::ClipboardType type, - std::string* result) { - GetClipboard()->ReadAsciiText(type, result); + if (GetClipboard()->IsFormatAvailable( + ui::Clipboard::GetPlainTextWFormatType(), type)) { + GetClipboard()->ReadText(type, result); + } else if (GetClipboard()->IsFormatAvailable( + ui::Clipboard::GetPlainTextFormatType(), type)) { + std::string ascii; + GetClipboard()->ReadAsciiText(type, &ascii); + *result = base::ASCIIToUTF16(ascii); + } else { + result->clear(); + } } void ClipboardMessageFilter::OnReadHTML(ui::ClipboardType type, @@ -258,11 +286,6 @@ void ClipboardMessageFilter::OnReadCustomData(ui::ClipboardType clipboard_type, GetClipboard()->ReadCustomData(clipboard_type, type, result); } -void ClipboardMessageFilter::OnReadData(const ui::Clipboard::FormatType& format, - std::string* data) { - GetClipboard()->ReadData(format, data); -} - // static ui::Clipboard* ClipboardMessageFilter::GetClipboard() { // We have a static instance of the clipboard service for use by all message |