diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-29 22:50:47 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-29 22:50:47 +0000 |
commit | 5e6bcba5758b5349ae525886e31a35f703edabab (patch) | |
tree | 75741275dca8373161859e25496b4b43361991d2 /chrome/browser/tab_contents | |
parent | 0e6e842461b895583cbf14b0203c7f5be303bf93 (diff) | |
download | chromium_src-5e6bcba5758b5349ae525886e31a35f703edabab.zip chromium_src-5e6bcba5758b5349ae525886e31a35f703edabab.tar.gz chromium_src-5e6bcba5758b5349ae525886e31a35f703edabab.tar.bz2 |
When copying urls in the render view context menu, copy them to PRIMARY as well as CLIPBOARD.
BUG=12716
Review URL: http://codereview.chromium.org/115949
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17254 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
4 files changed, 27 insertions, 12 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index cc4a95c..2ee2726 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -642,16 +642,15 @@ void RenderViewContextMenu::WriteTextToClipboard( } void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { - if (url.SchemeIs(chrome::kMailToScheme)) { - WriteTextToClipboard(UTF8ToUTF16(url.path())); - } else { - std::wstring languages = - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); - // Unescaping path and query is not a good idea because other - // applications may not enocode non-ASCII characters in UTF-8. - // So the 4th parameter of net::FormatUrl() should be false. - // See crbug.com/2820. - WriteTextToClipboard(WideToUTF16( - net::FormatUrl(url, languages, false, false, NULL, NULL))); - } + std::string utf8_text = url.SchemeIs(chrome::kMailToScheme) ? url.path() : + // Unescaping path and query is not a good idea because other + // applications may not enocode non-ASCII characters in UTF-8. + // So the 4th parameter of net::FormatUrl() should be false. + // See crbug.com/2820. + WideToUTF8(net::FormatUrl( + url, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), + false, false, NULL, NULL)); + + WriteTextToClipboard(UTF8ToUTF16(utf8_text)); + DidWriteURLToClipboard(utf8_text); } diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h index 54c611f..0fc13cd 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.h +++ b/chrome/browser/tab_contents/render_view_context_menu.h @@ -51,6 +51,10 @@ class RenderViewContextMenu { // Finish creating the submenu and attach it to the main menu. virtual void FinishSubMenu() = 0; + // For Linux, we want to know when we have written a URL to the clipboard. + // Most platforms won't care. + virtual void DidWriteURLToClipboard(const std::string& url) { }; + // Delegate functions -------------------------------------------------------- bool IsItemCommandEnabled(int id) const; diff --git a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc index 0362366..bf147dc 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc @@ -4,6 +4,8 @@ #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" +#include <gtk/gtk.h> + #include "base/string_util.h" #include "webkit/glue/context_menu.h" @@ -81,6 +83,15 @@ void RenderViewContextMenuGtk::FinishSubMenu() { making_submenu_ = false; } +// When a URL is copied from a render view context menu (via "copy link +// location", for example), we additionally stick it in the X clipboard. This +// matches other linux browsers. +void RenderViewContextMenuGtk::DidWriteURLToClipboard( + const std::string& url) { + GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); + gtk_clipboard_set_text(x_clipboard, url.c_str(), url.length()); +} + void RenderViewContextMenuGtk::AppendItem( int id, const std::wstring& label, MenuItemType type) { MenuCreateMaterial menu_create_material = { diff --git a/chrome/browser/tab_contents/render_view_context_menu_gtk.h b/chrome/browser/tab_contents/render_view_context_menu_gtk.h index b6855f2..62c0066 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_gtk.h +++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.h @@ -43,6 +43,7 @@ class RenderViewContextMenuGtk : public RenderViewContextMenu, virtual void AppendSeparator(); virtual void StartSubMenu(int id, const std::wstring& label); virtual void FinishSubMenu(); + virtual void DidWriteURLToClipboard(const std::string& url); private: void AppendItem(int id, const std::wstring& label, MenuItemType type); |