diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-10 18:49:17 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-10 18:49:17 +0000 |
commit | 7e358974036ac5668c6fd779d9f0faaa3137baab (patch) | |
tree | 446456170dc2782167fdce833efa7497e7223f74 /content | |
parent | 4848b9f891c3d572f7dc88478e2a1ca84c28f92d (diff) | |
download | chromium_src-7e358974036ac5668c6fd779d9f0faaa3137baab.zip chromium_src-7e358974036ac5668c6fd779d9f0faaa3137baab.tar.gz chromium_src-7e358974036ac5668c6fd779d9f0faaa3137baab.tar.bz2 |
Move the clipboard messages to their own message filter.
BUG=75525
TEST=none
Review URL: http://codereview.chromium.org/6657013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77664 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/renderer_host/clipboard_message_filter.cc | 162 | ||||
-rw-r--r-- | content/browser/renderer_host/clipboard_message_filter.h | 59 | ||||
-rw-r--r-- | content/browser/renderer_host/clipboard_message_filter_mac.mm (renamed from content/browser/renderer_host/render_message_filter_mac.mm) | 6 | ||||
-rw-r--r-- | content/browser/renderer_host/render_message_filter.cc | 169 | ||||
-rw-r--r-- | content/browser/renderer_host/render_message_filter.h | 44 | ||||
-rw-r--r-- | content/browser/renderer_host/render_message_filter_gtk.cc | 131 | ||||
-rw-r--r-- | content/content_browser.gypi | 4 |
7 files changed, 227 insertions, 348 deletions
diff --git a/content/browser/renderer_host/clipboard_message_filter.cc b/content/browser/renderer_host/clipboard_message_filter.cc new file mode 100644 index 0000000..8cb3b9d --- /dev/null +++ b/content/browser/renderer_host/clipboard_message_filter.cc @@ -0,0 +1,162 @@ +// Copyright (c) 2011 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. + +#include "content/browser/renderer_host/clipboard_message_filter.h" + +#include "chrome/browser/browser_process.h" +#include "chrome/browser/clipboard_dispatcher.h" +#include "chrome/common/clipboard_messages.h" +#include "googleurl/src/gurl.h" +#include "ipc/ipc_message_macros.h" + +namespace { + +// Completes a clipboard write initiated by the renderer. The write must be +// performed on the UI thread because the clipboard service from the IO thread +// cannot create windows so it cannot be the "owner" of the clipboard's +// contents. +class WriteClipboardTask : public Task { + public: + explicit WriteClipboardTask(ui::Clipboard::ObjectMap* objects) + : objects_(objects) {} + ~WriteClipboardTask() {} + + void Run() { + g_browser_process->clipboard()->WriteObjects(*objects_.get()); + } + + private: + scoped_ptr<ui::Clipboard::ObjectMap> objects_; +}; + +} // namespace + +ClipboardMessageFilter::ClipboardMessageFilter() { +} + +void ClipboardMessageFilter::OverrideThreadForMessage( + const IPC::Message& message, BrowserThread::ID* thread) { +#if defined(USE_X11) + if (IPC_MESSAGE_CLASS(message) == ClipboardMsgStart) + *thread = BrowserThread::UI; +#endif +} + +bool ClipboardMessageFilter::OnMessageReceived(const IPC::Message& message, + bool* message_was_ok) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(ClipboardMessageFilter, message, *message_was_ok) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_WriteObjectsAsync, OnWriteObjectsAsync) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_WriteObjectsSync, OnWriteObjectsSync) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_IsFormatAvailable, OnIsFormatAvailable) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadText, OnReadText) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadAsciiText, OnReadAsciiText) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadHTML, OnReadHTML) +#if defined(OS_MACOSX) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_FindPboardWriteStringAsync, + OnFindPboardWriteString) +#endif + IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadAvailableTypes, + OnReadAvailableTypes) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadData, OnReadData) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadFilenames, OnReadFilenames) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +ClipboardMessageFilter::~ClipboardMessageFilter() { +} + +void ClipboardMessageFilter::OnWriteObjectsSync( + const ui::Clipboard::ObjectMap& objects, + base::SharedMemoryHandle bitmap_handle) { + DCHECK(base::SharedMemory::IsHandleValid(bitmap_handle)) + << "Bad bitmap handle"; + // We cannot write directly from the IO thread, and cannot service the IPC + // on the UI thread. We'll copy the relevant data and get a handle to any + // shared memory so it doesn't go away when we resume the renderer, and post + // a task to perform the write on the UI thread. + ui::Clipboard::ObjectMap* long_living_objects = + new ui::Clipboard::ObjectMap(objects); + + // Splice the shared memory handle into the clipboard data. + ui::Clipboard::ReplaceSharedMemHandle(long_living_objects, bitmap_handle, + peer_handle()); + + BrowserThread::PostTask( + BrowserThread::UI, + FROM_HERE, + new WriteClipboardTask(long_living_objects)); +} + +void ClipboardMessageFilter::OnWriteObjectsAsync( + const ui::Clipboard::ObjectMap& objects) { + // We cannot write directly from the IO thread, and cannot service the IPC + // on the UI thread. We'll copy the relevant data and post a task to preform + // the write on the UI thread. + ui::Clipboard::ObjectMap* long_living_objects = + new ui::Clipboard::ObjectMap(objects); + + // This async message doesn't support shared-memory based bitmaps; they must + // be removed otherwise we might dereference a rubbish pointer. + long_living_objects->erase(ui::Clipboard::CBF_SMBITMAP); + + BrowserThread::PostTask( + BrowserThread::UI, + FROM_HERE, + new WriteClipboardTask(long_living_objects)); +} + +void ClipboardMessageFilter::OnIsFormatAvailable( + ui::Clipboard::FormatType format, ui::Clipboard::Buffer buffer, + bool* result) { + *result = GetClipboard()->IsFormatAvailable(format, buffer); +} + +void ClipboardMessageFilter::OnReadText( + ui::Clipboard::Buffer buffer, string16* result) { + GetClipboard()->ReadText(buffer, result); +} + +void ClipboardMessageFilter::OnReadAsciiText( + ui::Clipboard::Buffer buffer, std::string* result) { + GetClipboard()->ReadAsciiText(buffer, result); +} + +void ClipboardMessageFilter::OnReadHTML( + ui::Clipboard::Buffer buffer, string16* markup, GURL* url) { + std::string src_url_str; + GetClipboard()->ReadHTML(buffer, markup, &src_url_str); + *url = GURL(src_url_str); +} + +void ClipboardMessageFilter::OnReadAvailableTypes( + ui::Clipboard::Buffer buffer, bool* succeeded, std::vector<string16>* types, + bool* contains_filenames) { + *contains_filenames = false; + *succeeded = ClipboardDispatcher::ReadAvailableTypes( + buffer, types, contains_filenames); +} + +void ClipboardMessageFilter::OnReadData( + ui::Clipboard::Buffer buffer, const string16& type, bool* succeeded, + string16* data, string16* metadata) { + *succeeded = ClipboardDispatcher::ReadData(buffer, type, data, metadata); +} + +void ClipboardMessageFilter::OnReadFilenames( + ui::Clipboard::Buffer buffer, bool* succeeded, + std::vector<string16>* filenames) { + *succeeded = ClipboardDispatcher::ReadFilenames(buffer, filenames); +} + +// static +ui::Clipboard* ClipboardMessageFilter::GetClipboard() { + // We have a static instance of the clipboard service for use by all message + // filters. This instance lives for the life of the browser processes. + static ui::Clipboard* clipboard = new ui::Clipboard; + + return clipboard; +} diff --git a/content/browser/renderer_host/clipboard_message_filter.h b/content/browser/renderer_host/clipboard_message_filter.h new file mode 100644 index 0000000..f755d91 --- /dev/null +++ b/content/browser/renderer_host/clipboard_message_filter.h @@ -0,0 +1,59 @@ +// Copyright (c) 2011 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. + +#ifndef CONTENT_BROWSER_RENDERER_HOST_CLIPBOARD_MESSAGE_FILTER_H_ +#define CONTENT_BROWSER_RENDERER_HOST_CLIPBOARD_MESSAGE_FILTER_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "content/browser/browser_message_filter.h" +#include "ui/base/clipboard/clipboard.h" + +class GURL; + +class ClipboardMessageFilter : public BrowserMessageFilter { + public: + ClipboardMessageFilter(); + + virtual void OverrideThreadForMessage(const IPC::Message& message, + BrowserThread::ID* thread); + virtual bool OnMessageReceived(const IPC::Message& message, + bool* message_was_ok); + private: + ~ClipboardMessageFilter(); + + void OnWriteObjectsAsync(const ui::Clipboard::ObjectMap& objects); + void OnWriteObjectsSync(const ui::Clipboard::ObjectMap& objects, + base::SharedMemoryHandle bitmap_handle); + + void OnIsFormatAvailable(ui::Clipboard::FormatType format, + ui::Clipboard::Buffer buffer, + bool* result); + void OnReadText(ui::Clipboard::Buffer buffer, string16* result); + void OnReadAsciiText(ui::Clipboard::Buffer buffer, std::string* result); + void OnReadHTML(ui::Clipboard::Buffer buffer, string16* markup, GURL* url); +#if defined(OS_MACOSX) + void OnFindPboardWriteString(const string16& text); +#endif + void OnReadAvailableTypes(ui::Clipboard::Buffer buffer, + bool* succeeded, + std::vector<string16>* types, + bool* contains_filenames); + void OnReadData(ui::Clipboard::Buffer buffer, const string16& type, + bool* succeeded, string16* data, string16* metadata); + void OnReadFilenames(ui::Clipboard::Buffer buffer, bool* succeeded, + std::vector<string16>* filenames); + + // We have our own clipboard because we want to access the clipboard on the + // IO thread instead of forwarding (possibly synchronous) messages to the UI + // thread. This instance of the clipboard should be accessed only on the IO + // thread. + static ui::Clipboard* GetClipboard(); + + DISALLOW_COPY_AND_ASSIGN(ClipboardMessageFilter); +}; + +#endif // CONTENT_BROWSER_RENDERER_HOST_CLIPBOARD_MESSAGE_FILTER_H_ diff --git a/content/browser/renderer_host/render_message_filter_mac.mm b/content/browser/renderer_host/clipboard_message_filter_mac.mm index 4cbcef9..72cfc53 100644 --- a/content/browser/renderer_host/render_message_filter_mac.mm +++ b/content/browser/renderer_host/clipboard_message_filter_mac.mm @@ -2,11 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/renderer_host/render_message_filter.h" +#include "content/browser/renderer_host/clipboard_message_filter.h" #import <Cocoa/Cocoa.h> -#include "base/message_loop.h" #include "base/sys_string_conversions.h" #import "chrome/browser/ui/cocoa/find_pasteboard.h" #include "content/browser/browser_thread.h" @@ -30,8 +29,7 @@ class WriteFindPboardTask : public Task { }; // Called on the IO thread. -void RenderMessageFilter::OnClipboardFindPboardWriteString( - const string16& text) { +void ClipboardMessageFilter::OnFindPboardWriteString(const string16& text) { if (text.length() <= kMaxFindPboardStringLength) { NSString* nsText = base::SysUTF16ToNSString(text); if (nsText) { diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index a181ab4..32d6214 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -16,7 +16,6 @@ #include "chrome/browser/automation/automation_resource_message_filter.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_plugin_browsing_context.h" -#include "chrome/browser/clipboard_dispatcher.h" #include "chrome/browser/download/download_types.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/metrics/histogram_synchronizer.h" @@ -123,24 +122,6 @@ class ContextMenuMessageDispatcher : public Task { DISALLOW_COPY_AND_ASSIGN(ContextMenuMessageDispatcher); }; -// Completes a clipboard write initiated by the renderer. The write must be -// performed on the UI thread because the clipboard service from the IO thread -// cannot create windows so it cannot be the "owner" of the clipboard's -// contents. -class WriteClipboardTask : public Task { - public: - explicit WriteClipboardTask(ui::Clipboard::ObjectMap* objects) - : objects_(objects) {} - ~WriteClipboardTask() {} - - void Run() { - g_browser_process->clipboard()->WriteObjects(*objects_.get()); - } - - private: - scoped_ptr<ui::Clipboard::ObjectMap> objects_; -}; - // Common functionality for converting a sync renderer message to a callback // function in the browser. Derive from this, create it on the heap when // issuing your callback. When done, write your reply parameters into @@ -383,28 +364,6 @@ bool RenderMessageFilter::OnMessageReceived(const IPC::Message& message, IPC_MESSAGE_HANDLER(ViewHostMsg_RendererHistograms, OnRendererHistograms) IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_UpdateRect, render_widget_helper_->DidReceiveUpdateMsg(message)) - IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardWriteObjectsAsync, - OnClipboardWriteObjectsAsync) - IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardWriteObjectsSync, - OnClipboardWriteObjectsSync) - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClipboardIsFormatAvailable, - OnClipboardIsFormatAvailable) - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClipboardReadText, - OnClipboardReadText) - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClipboardReadAsciiText, - OnClipboardReadAsciiText) - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClipboardReadHTML, - OnClipboardReadHTML) -#if defined(OS_MACOSX) - IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardFindPboardWriteStringAsync, - OnClipboardFindPboardWriteString) -#endif - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClipboardReadAvailableTypes, - OnClipboardReadAvailableTypes) - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClipboardReadData, - OnClipboardReadData) - IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ClipboardReadFilenames, - OnClipboardReadFilenames) IPC_MESSAGE_HANDLER(ViewHostMsg_CheckNotificationPermission, OnCheckNotificationPermission) IPC_MESSAGE_HANDLER(ViewHostMsg_RevealFolderInOS, OnRevealFolderInOS) @@ -798,125 +757,6 @@ void RenderMessageFilter::OnDownloadUrl(const IPC::Message& message, context); } -void RenderMessageFilter::OnClipboardWriteObjectsSync( - const ui::Clipboard::ObjectMap& objects, - base::SharedMemoryHandle bitmap_handle) { - DCHECK(base::SharedMemory::IsHandleValid(bitmap_handle)) - << "Bad bitmap handle"; - // We cannot write directly from the IO thread, and cannot service the IPC - // on the UI thread. We'll copy the relevant data and get a handle to any - // shared memory so it doesn't go away when we resume the renderer, and post - // a task to perform the write on the UI thread. - ui::Clipboard::ObjectMap* long_living_objects = - new ui::Clipboard::ObjectMap(objects); - - // Splice the shared memory handle into the clipboard data. - ui::Clipboard::ReplaceSharedMemHandle(long_living_objects, bitmap_handle, - peer_handle()); - - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - new WriteClipboardTask(long_living_objects)); -} - -void RenderMessageFilter::OnClipboardWriteObjectsAsync( - const ui::Clipboard::ObjectMap& objects) { - // We cannot write directly from the IO thread, and cannot service the IPC - // on the UI thread. We'll copy the relevant data and post a task to preform - // the write on the UI thread. - ui::Clipboard::ObjectMap* long_living_objects = - new ui::Clipboard::ObjectMap(objects); - - // This async message doesn't support shared-memory based bitmaps; they must - // be removed otherwise we might dereference a rubbish pointer. - long_living_objects->erase(ui::Clipboard::CBF_SMBITMAP); - - BrowserThread::PostTask( - BrowserThread::UI, - FROM_HERE, - new WriteClipboardTask(long_living_objects)); -} - -#if !defined(USE_X11) -// On non-X11 platforms, clipboard actions can be performed on the IO thread. -// On X11, since the clipboard is linked with GTK, we either have to do this -// with GTK on the UI thread, or with Xlib on the BACKGROUND_X11 thread. In an -// ideal world, we would do the latter. However, for now we're going to -// terminate these calls on the UI thread. This risks deadlock in the case of -// plugins, but it's better than crashing which is what doing on the IO thread -// gives us. -// -// See resource_message_filter_gtk.cc for the Linux implementation of these -// functions. - -void RenderMessageFilter::OnClipboardIsFormatAvailable( - ui::Clipboard::FormatType format, ui::Clipboard::Buffer buffer, - IPC::Message* reply) { - const bool result = GetClipboard()->IsFormatAvailable(format, buffer); - ViewHostMsg_ClipboardIsFormatAvailable::WriteReplyParams(reply, result); - Send(reply); -} - -void RenderMessageFilter::OnClipboardReadText(ui::Clipboard::Buffer buffer, - IPC::Message* reply) { - string16 result; - GetClipboard()->ReadText(buffer, &result); - ViewHostMsg_ClipboardReadText::WriteReplyParams(reply, result); - Send(reply); -} - -void RenderMessageFilter::OnClipboardReadAsciiText(ui::Clipboard::Buffer buffer, - IPC::Message* reply) { - std::string result; - GetClipboard()->ReadAsciiText(buffer, &result); - ViewHostMsg_ClipboardReadAsciiText::WriteReplyParams(reply, result); - Send(reply); -} - -void RenderMessageFilter::OnClipboardReadHTML(ui::Clipboard::Buffer buffer, - IPC::Message* reply) { - std::string src_url_str; - string16 markup; - GetClipboard()->ReadHTML(buffer, &markup, &src_url_str); - const GURL src_url = GURL(src_url_str); - - ViewHostMsg_ClipboardReadHTML::WriteReplyParams(reply, markup, src_url); - Send(reply); -} - -void RenderMessageFilter::OnClipboardReadAvailableTypes( - ui::Clipboard::Buffer buffer, IPC::Message* reply) { - std::vector<string16> types; - bool contains_filenames = false; - bool result = ClipboardDispatcher::ReadAvailableTypes( - buffer, &types, &contains_filenames); - ViewHostMsg_ClipboardReadAvailableTypes::WriteReplyParams( - reply, result, types, contains_filenames); - Send(reply); -} - -void RenderMessageFilter::OnClipboardReadData( - ui::Clipboard::Buffer buffer, const string16& type, IPC::Message* reply) { - string16 data; - string16 metadata; - bool result = ClipboardDispatcher::ReadData(buffer, type, &data, &metadata); - ViewHostMsg_ClipboardReadData::WriteReplyParams( - reply, result, data, metadata); - Send(reply); -} - -void RenderMessageFilter::OnClipboardReadFilenames( - ui::Clipboard::Buffer buffer, IPC::Message* reply) { - std::vector<string16> filenames; - bool result = ClipboardDispatcher::ReadFilenames(buffer, &filenames); - ViewHostMsg_ClipboardReadFilenames::WriteReplyParams( - reply, result, filenames); - Send(reply); -} - -#endif - void RenderMessageFilter::OnCheckNotificationPermission( const GURL& source_url, int* result) { *result = WebKit::WebNotificationPresenter::PermissionNotAllowed; @@ -1049,15 +889,6 @@ void RenderMessageFilter::OnResolveProxyCompleted( Send(reply_msg); } -// static -ui::Clipboard* RenderMessageFilter::GetClipboard() { - // We have a static instance of the clipboard service for use by all message - // filters. This instance lives for the life of the browser processes. - static ui::Clipboard* clipboard = new ui::Clipboard; - - return clipboard; -} - ChromeURLRequestContext* RenderMessageFilter::GetRequestContextForURL( const GURL& url) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h index e2aaa07..2cb4547 100644 --- a/content/browser/renderer_host/render_message_filter.h +++ b/content/browser/renderer_host/render_message_filter.h @@ -16,6 +16,7 @@ #include "app/surface/transport_dib.h" #include "base/file_path.h" #include "base/linked_ptr.h" +#include "base/shared_memory.h" #include "base/string16.h" #include "base/task.h" #include "build/build_config.h" @@ -26,7 +27,6 @@ #include "content/browser/renderer_host/resource_dispatcher_host.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCache.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h" -#include "ui/base/clipboard/clipboard.h" #include "ui/gfx/native_widget_types.h" class ChromeURLRequestContext; @@ -175,27 +175,6 @@ class RenderMessageFilter : public BrowserMessageFilter, void OnRendererTcmalloc(base::ProcessId pid, const std::string& output); #endif void OnReceiveContextMenuMsg(const IPC::Message& msg); - // Clipboard messages - void OnClipboardWriteObjectsAsync(const ui::Clipboard::ObjectMap& objects); - void OnClipboardWriteObjectsSync(const ui::Clipboard::ObjectMap& objects, - base::SharedMemoryHandle bitmap_handle); - - void OnClipboardIsFormatAvailable(ui::Clipboard::FormatType format, - ui::Clipboard::Buffer buffer, - IPC::Message* reply); - void OnClipboardReadText(ui::Clipboard::Buffer buffer, IPC::Message* reply); - void OnClipboardReadAsciiText(ui::Clipboard::Buffer buffer, - IPC::Message* reply); - void OnClipboardReadHTML(ui::Clipboard::Buffer buffer, IPC::Message* reply); -#if defined(OS_MACOSX) - void OnClipboardFindPboardWriteString(const string16& text); -#endif - void OnClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer, - IPC::Message* reply); - void OnClipboardReadData(ui::Clipboard::Buffer buffer, const string16& type, - IPC::Message* reply); - void OnClipboardReadFilenames(ui::Clipboard::Buffer buffer, - IPC::Message* reply); void OnCheckNotificationPermission(const GURL& source_url, int* permission_level); @@ -300,32 +279,11 @@ class RenderMessageFilter : public BrowserMessageFilter, void DoOnGetScreenInfo(gfx::NativeViewId view, IPC::Message* reply_msg); void DoOnGetWindowRect(gfx::NativeViewId view, IPC::Message* reply_msg); void DoOnGetRootWindowRect(gfx::NativeViewId view, IPC::Message* reply_msg); - void DoOnClipboardIsFormatAvailable(ui::Clipboard::FormatType format, - ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg); - void DoOnClipboardReadText(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg); - void DoOnClipboardReadAsciiText(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg); - void DoOnClipboardReadHTML(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg); - void DoOnClipboardReadAvailableTypes(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg); - void DoOnClipboardReadData(ui::Clipboard::Buffer buffer, const string16& type, - IPC::Message* reply_msg); - void DoOnClipboardReadFilenames(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg); #endif bool CheckBenchmarkingEnabled() const; bool CheckPreparsedJsCachingEnabled() const; - // We have our own clipboard because we want to access the clipboard on the - // IO thread instead of forwarding (possibly synchronous) messages to the UI - // thread. This instance of the clipboard should be accessed only on the IO - // thread. - static ui::Clipboard* GetClipboard(); - // Cached resource request dispatcher host and plugin service, guaranteed to // be non-null if Init succeeds. We do not own the objects, they are managed // by the BrowserProcess, which has a wider scope than we do. diff --git a/content/browser/renderer_host/render_message_filter_gtk.cc b/content/browser/renderer_host/render_message_filter_gtk.cc index 4a46691..9deac18 100644 --- a/content/browser/renderer_host/render_message_filter_gtk.cc +++ b/content/browser/renderer_host/render_message_filter_gtk.cc @@ -89,66 +89,6 @@ void RenderMessageFilter::DoOnGetRootWindowRect(gfx::NativeViewId view, Send(reply_msg); } -void RenderMessageFilter::DoOnClipboardIsFormatAvailable( - ui::Clipboard::FormatType format, ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - const bool result = GetClipboard()->IsFormatAvailable(format, buffer); - - ViewHostMsg_ClipboardIsFormatAvailable::WriteReplyParams(reply_msg, result); - Send(reply_msg); -} - -void RenderMessageFilter::DoOnClipboardReadText(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - string16 result; - GetClipboard()->ReadText(buffer, &result); - - ViewHostMsg_ClipboardReadText::WriteReplyParams(reply_msg, result); - Send(reply_msg); -} - -void RenderMessageFilter::DoOnClipboardReadAsciiText( - ui::Clipboard::Buffer buffer, IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::string result; - GetClipboard()->ReadAsciiText(buffer, &result); - - ViewHostMsg_ClipboardReadAsciiText::WriteReplyParams(reply_msg, result); - Send(reply_msg); -} - -void RenderMessageFilter::DoOnClipboardReadHTML(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::string src_url_str; - string16 markup; - GetClipboard()->ReadHTML(buffer, &markup, &src_url_str); - const GURL src_url = GURL(src_url_str); - - ViewHostMsg_ClipboardReadHTML::WriteReplyParams(reply_msg, markup, src_url); - Send(reply_msg); -} - -void RenderMessageFilter::DoOnClipboardReadAvailableTypes( - ui::Clipboard::Buffer buffer, IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - Send(reply_msg); -} - -void RenderMessageFilter::DoOnClipboardReadData(ui::Clipboard::Buffer buffer, - const string16& type, - IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - Send(reply_msg); -} -void RenderMessageFilter::DoOnClipboardReadFilenames( - ui::Clipboard::Buffer buffer, IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - Send(reply_msg); -} - void RenderMessageFilter::OnGetScreenInfo(gfx::NativeViewId view, IPC::Message* reply_msg) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); @@ -176,74 +116,3 @@ void RenderMessageFilter::OnGetRootWindowRect(gfx::NativeViewId view, this, &RenderMessageFilter::DoOnGetRootWindowRect, view, reply_msg)); } -void RenderMessageFilter::OnClipboardIsFormatAvailable( - ui::Clipboard::FormatType format, ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &RenderMessageFilter::DoOnClipboardIsFormatAvailable, format, - buffer, reply_msg)); -} - -void RenderMessageFilter::OnClipboardReadText(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &RenderMessageFilter::DoOnClipboardReadText, buffer, - reply_msg)); -} - -void RenderMessageFilter::OnClipboardReadAsciiText(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &RenderMessageFilter::DoOnClipboardReadAsciiText, buffer, - reply_msg)); -} - -void RenderMessageFilter::OnClipboardReadHTML(ui::Clipboard::Buffer buffer, - IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &RenderMessageFilter::DoOnClipboardReadHTML, buffer, - reply_msg)); -} - -void RenderMessageFilter::OnClipboardReadAvailableTypes( - ui::Clipboard::Buffer buffer, IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &RenderMessageFilter::DoOnClipboardReadAvailableTypes, buffer, - reply_msg)); -} - -void RenderMessageFilter::OnClipboardReadData(ui::Clipboard::Buffer buffer, - const string16& type, - IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &RenderMessageFilter::DoOnClipboardReadData, buffer, type, - reply_msg)); -} - -void RenderMessageFilter::OnClipboardReadFilenames( - ui::Clipboard::Buffer buffer, IPC::Message* reply_msg) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableMethod( - this, &RenderMessageFilter::DoOnClipboardReadFilenames, buffer, - reply_msg)); -} diff --git a/content/content_browser.gypi b/content/content_browser.gypi index f1bbae9..133bea4 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -195,6 +195,9 @@ 'browser/renderer_host/blob_message_filter.h', 'browser/renderer_host/buffered_resource_handler.cc', 'browser/renderer_host/buffered_resource_handler.h', + 'browser/renderer_host/clipboard_message_filter.cc', + 'browser/renderer_host/clipboard_message_filter.h', + 'browser/renderer_host/clipboard_message_filter_mac.mm', 'browser/renderer_host/cross_site_resource_handler.cc', 'browser/renderer_host/cross_site_resource_handler.h', 'browser/renderer_host/database_message_filter.cc', @@ -221,7 +224,6 @@ 'browser/renderer_host/render_message_filter.cc', 'browser/renderer_host/render_message_filter.h', 'browser/renderer_host/render_message_filter_gtk.cc', - 'browser/renderer_host/render_message_filter_mac.mm', 'browser/renderer_host/render_message_filter_win.cc', 'browser/renderer_host/render_process_host.cc', 'browser/renderer_host/render_process_host.h', |