diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-02 20:47:06 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-02 20:47:06 +0000 |
commit | ea8c745aa6a3be27b904060832fdf14bb11193bf (patch) | |
tree | 32ba371b6f4d59b7e8bcc987a2912aa645ba73a0 /chrome | |
parent | ac8e3525fa24068878ef8a45f35aba681f852cc9 (diff) | |
download | chromium_src-ea8c745aa6a3be27b904060832fdf14bb11193bf.zip chromium_src-ea8c745aa6a3be27b904060832fdf14bb11193bf.tar.gz chromium_src-ea8c745aa6a3be27b904060832fdf14bb11193bf.tar.bz2 |
Paste from the x clipboard into webkit.
Review URL: http://codereview.chromium.org/51008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13031 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.h | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view.h | 4 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_gtk.cc | 14 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_gtk.h | 7 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 8 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 9 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 3 |
8 files changed, 54 insertions, 0 deletions
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index cd08a0c..84994bb 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -772,6 +772,8 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { OnRemoveAutofillEntry) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFeedList, OnMsgUpdateFeedList) IPC_MESSAGE_HANDLER(ViewHostMsg_ExtensionRequest, OnExtensionRequest) + IPC_MESSAGE_HANDLER(ViewHostMsg_PasteFromSelectionClipboard, + OnPasteFromSelectionClipboard) // Have the super handle all other messages. IPC_MESSAGE_UNHANDLED(RenderWidgetHost::OnMessageReceived(msg)) IPC_END_MESSAGE_MAP_EX() @@ -1364,3 +1366,8 @@ void RenderViewHost::SendExtensionResponse(int callback_id, const std::string& response) { Send(new ViewMsg_ExtensionResponse(routing_id(), callback_id, response)); } + +void RenderViewHost::OnPasteFromSelectionClipboard() { + if (view()) + view()->PasteFromSelectionClipboard(); +} diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 6cfe2b2..c150259 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -565,6 +565,8 @@ class RenderViewHost : public RenderWidgetHost { void OnExtensionRequest(const std::string& name, const std::string& args, int callback_id); + void OnPasteFromSelectionClipboard(); + // Helper function to send a navigation message. If a cross-site request is // in progress, we may be suspended while waiting for the onbeforeunload // handler, so this function might buffer the message rather than sending it. diff --git a/chrome/browser/renderer_host/render_widget_host_view.h b/chrome/browser/renderer_host/render_widget_host_view.h index 7d24eec..255f6644 100644 --- a/chrome/browser/renderer_host/render_widget_host_view.h +++ b/chrome/browser/renderer_host/render_widget_host_view.h @@ -112,6 +112,10 @@ class RenderWidgetHostView { // the page has changed. virtual void SetTooltipText(const std::wstring& tooltip_text) = 0; + // Tells the View to get the text from the selection clipboard and send it + // back to the renderer asynchronously. + virtual void PasteFromSelectionClipboard() { } + // Allocate a backing store for this view virtual BackingStore* AllocBackingStore(const gfx::Size& size) = 0; diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc index a0328aa..21b45d1 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/string_util.h" #include "chrome/common/native_web_keyboard_event.h" +#include "chrome/common/render_messages.h" #include "chrome/common/x11_util.h" #include "chrome/browser/renderer_host/backing_store.h" #include "chrome/browser/renderer_host/render_widget_host.h" @@ -320,6 +321,11 @@ BackingStore* RenderWidgetHostViewGtk::AllocBackingStore( use_render, use_shared_memory); } +void RenderWidgetHostViewGtk::PasteFromSelectionClipboard() { + GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_request_text(x_clipboard, ReceivedSelectionText, this); +} + void RenderWidgetHostViewGtk::Paint(const gfx::Rect& damage_rect) { BackingStore* backing_store = host_->GetBackingStore(); @@ -380,3 +386,11 @@ void RenderWidgetHostViewGtk::ShowCurrentCursor() { if (gdk_cursor) gdk_cursor_unref(gdk_cursor); } + +void RenderWidgetHostViewGtk::ReceivedSelectionText(GtkClipboard* clipboard, + const gchar* text, gpointer userdata) { + RenderWidgetHostViewGtk* host_view = + reinterpret_cast<RenderWidgetHostViewGtk*>(userdata); + host_view->host_->Send(new ViewMsg_InsertText(host_view->host_->routing_id(), + UTF8ToUTF16(text))); +} diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.h b/chrome/browser/renderer_host/render_widget_host_view_gtk.h index 6a7a792..f3fc7ba 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_gtk.h +++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.h @@ -14,6 +14,8 @@ class RenderWidgetHost; +typedef struct _GtkClipboard GtkClipboard; + // ----------------------------------------------------------------------------- // See comments in render_widget_host_view.h about this class and its members. // ----------------------------------------------------------------------------- @@ -56,6 +58,7 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { void RenderViewGone(); void Destroy(); void SetTooltipText(const std::wstring& tooltip_text); + void PasteFromSelectionClipboard(); BackingStore* AllocBackingStore(const gfx::Size& size); // --------------------------------------------------------------------------- @@ -67,6 +70,10 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView { // Update the display cursor for the render view. void ShowCurrentCursor(); + static void ReceivedSelectionText(GtkClipboard* clipboard, + const gchar* text, + gpointer userdata); + // The model object. RenderWidgetHost *const host_; // The native UI widget. diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 5a32a0b..5e664c3 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -254,6 +254,10 @@ IPC_BEGIN_MESSAGES(View) IPC_MESSAGE_ROUTED1(ViewMsg_Zoom, int /* One of PageZoom::Function */) + // Insert text in the currently focused input area. + IPC_MESSAGE_ROUTED1(ViewMsg_InsertText, + string16 /* text */) + // Change encoding of page in the renderer. IPC_MESSAGE_ROUTED1(ViewMsg_SetPageEncoding, std::wstring /*new encoding name*/) @@ -803,6 +807,10 @@ IPC_BEGIN_MESSAGES(ViewHost) int32 /* page_id */, GURL /* url of the favicon */) + // Request that the browser get the text from the selection clipboard and send + // it back to the renderer via ViewMsg_SelectionClipboardResponse. + IPC_MESSAGE_ROUTED0(ViewHostMsg_PasteFromSelectionClipboard) + // Used to tell the parent that the user right clicked on an area of the // content area, and a context menu should be shown for it. The params // object contains information about the node(s) that were selected when the diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index d2c052c..1011647 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -358,6 +358,7 @@ void RenderView::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) + IPC_MESSAGE_HANDLER(ViewMsg_InsertText, OnInsertText) IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) IPC_MESSAGE_HANDLER(ViewMsg_InspectElement, OnInspectElement) IPC_MESSAGE_HANDLER(ViewMsg_ShowJavaScriptConsole, OnShowJavaScriptConsole) @@ -2362,6 +2363,10 @@ void RenderView::OnZoom(int function) { } } +void RenderView::OnInsertText(const string16& text) { + webview()->InsertText(text); +} + void RenderView::OnSetPageEncoding(const std::wstring& encoding_name) { webview()->SetPageEncoding(encoding_name); } @@ -2425,6 +2430,10 @@ WebDevToolsAgentDelegate* RenderView::GetWebDevToolsAgentDelegate() { return devtools_agent_; } +void RenderView::PasteFromSelectionClipboard() { + Send(new ViewHostMsg_PasteFromSelectionClipboard(routing_id_)); +} + WebFrame* RenderView::GetChildFrame(const std::wstring& frame_xpath) const { WebFrame* web_frame; if (frame_xpath.empty()) { diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index d6bf327..7f20d60 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -285,6 +285,8 @@ class RenderView : public RenderWidget, virtual WebDevToolsAgentDelegate* GetWebDevToolsAgentDelegate(); + virtual void PasteFromSelectionClipboard(); + virtual void OnPasswordFormsSeen(WebView* webview, const std::vector<PasswordForm>& forms); @@ -487,6 +489,7 @@ class RenderView : public RenderWidget, void OnCancelDownload(int32 download_id); void OnFind(const WebKit::WebFindInPageRequest& request); void OnZoom(int function); + void OnInsertText(const string16& text); void OnSetPageEncoding(const std::wstring& encoding_name); void OnGetAllSavableResourceLinksForCurrentPage(const GURL& page_url); void OnGetSerializedHtmlDataForCurrentPageWithLocalLinks( |