summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 21:42:14 +0000
committerericu@google.com <ericu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-01 21:42:14 +0000
commit0c4c3884b89e0c5fb3adbbb0f3cdf092cda84a10 (patch)
treee942cc54be97b815ae60fdd7bbd65a2aa624d843 /chrome/browser
parent2ef2712ec860306a843c0e18afbdc339da4917cd (diff)
downloadchromium_src-0c4c3884b89e0c5fb3adbbb0f3cdf092cda84a10.zip
chromium_src-0c4c3884b89e0c5fb3adbbb0f3cdf092cda84a10.tar.gz
chromium_src-0c4c3884b89e0c5fb3adbbb0f3cdf092cda84a10.tar.bz2
The "Copy URL" link is always greyed out in the Chrome menu on popups [crbug.com/13488].
This turns out to be because it was never implemented. Tested manually on Windows; I'll test on Linux before submitting. BUG=13488 TEST=Tested manually on Windows and added a unit test for the new Clipboard function. Review URL: http://codereview.chromium.org/210042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser.cc22
-rw-r--r--chrome/browser/browser.h1
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc25
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.h5
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_gtk.cc9
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_gtk.h1
6 files changed, 24 insertions, 39 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 3df24ae..ae1b5538 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/keyboard_codes.h"
#include "base/logging.h"
+#include "base/scoped_clipboard_writer.h"
#include "base/string_util.h"
#include "base/thread.h"
#include "chrome/app/chrome_dll_resource.h"
@@ -856,6 +857,22 @@ void Browser::RestoreTab() {
service->RestoreMostRecentEntry(this);
}
+void Browser::WriteCurrentURLToClipboard() {
+ // TODO(ericu): There isn't currently a metric for this. Should there be?
+ // We don't appear to track the action when it comes from the
+ // RenderContextViewMenu.
+ // UserMetrics::RecordAction(L"$Metric_Name_Goes_Here$", profile_);
+
+ TabContents* contents = GetSelectedTabContents();
+ if (!contents->ShouldDisplayURL())
+ return;
+
+ net::WriteURLToClipboard(
+ contents->GetURL(),
+ profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
+ g_browser_process->clipboard());
+}
+
void Browser::ConvertPopupToTabbedBrowser() {
UserMetrics::RecordAction(L"ShowAsTab", profile_);
int tab_strip_index = tabstrip_model_.selected_index();
@@ -1347,6 +1364,7 @@ void Browser::ExecuteCommandWithDisposition(
case IDC_SELECT_LAST_TAB: SelectLastTab(); break;
case IDC_DUPLICATE_TAB: DuplicateTab(); break;
case IDC_RESTORE_TAB: RestoreTab(); break;
+ case IDC_COPY_URL: WriteCurrentURLToClipboard(); break;
case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break;
case IDC_FULLSCREEN: ToggleFullscreenMode(); break;
case IDC_EXIT: Exit(); break;
@@ -2300,6 +2318,7 @@ void Browser::InitCommandState() {
command_updater_.UpdateCommandEnabled(IDC_CUT, true);
command_updater_.UpdateCommandEnabled(IDC_COPY, true);
command_updater_.UpdateCommandEnabled(IDC_PASTE, true);
+ command_updater_.UpdateCommandEnabled(IDC_COPY_URL, true);
// Find-in-page
command_updater_.UpdateCommandEnabled(IDC_FIND, true);
@@ -2367,9 +2386,6 @@ void Browser::InitCommandState() {
// Page-related commands
command_updater_.UpdateCommandEnabled(IDC_STAR, normal_window);
- // Clipboard commands
- command_updater_.UpdateCommandEnabled(IDC_COPY_URL, normal_window);
-
// Show various bits of UI
command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
normal_window);
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index d881059..be4e1c2 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -325,6 +325,7 @@ class Browser : public TabStripModelDelegate,
void SelectLastTab();
void DuplicateTab();
void RestoreTab();
+ void WriteCurrentURLToClipboard();
void ConvertPopupToTabbedBrowser();
void ToggleFullscreenMode();
void Exit();
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index f8f9dcd..ba62b06 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -801,28 +801,11 @@ void RenderViewContextMenu::Inspect(int x, int y) {
source_tab_contents_->render_view_host(), x, y);
}
-void RenderViewContextMenu::WriteTextToClipboard(const string16& text) {
- Clipboard* clipboard = g_browser_process->clipboard();
-
- if (!clipboard)
- return;
-
- ScopedClipboardWriter scw(clipboard);
- scw.WriteText(text);
-}
-
void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) {
- 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, UnescapeRule::NONE, NULL, NULL));
-
- WriteTextToClipboard(UTF8ToUTF16(utf8_text));
- DidWriteURLToClipboard(utf8_text);
+ net::WriteURLToClipboard(
+ url,
+ profile_->GetPrefs()->GetString(prefs::kAcceptLanguages),
+ g_browser_process->clipboard());
}
void RenderViewContextMenu::MediaPlayerActionAt(
diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h
index 8e0f199..82a1778 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.h
+++ b/chrome/browser/tab_contents/render_view_context_menu.h
@@ -58,10 +58,6 @@ 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;
@@ -99,7 +95,6 @@ class RenderViewContextMenu {
void Inspect(int x, int y);
// Writes the specified text/url to the system clipboard
- void WriteTextToClipboard(const string16& text);
void WriteURLToClipboard(const GURL& url);
void MediaPlayerActionAt(int x, int y, const MediaPlayerAction& action);
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 dcfdb74..70381be 100644
--- a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc
@@ -94,15 +94,6 @@ 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 string16& 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 d4fca48..8d7a5d0 100644
--- a/chrome/browser/tab_contents/render_view_context_menu_gtk.h
+++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.h
@@ -47,7 +47,6 @@ class RenderViewContextMenuGtk : public RenderViewContextMenu,
virtual void AppendSeparator();
virtual void StartSubMenu(int id, const string16& label);
virtual void FinishSubMenu();
- virtual void DidWriteURLToClipboard(const std::string& url);
private:
void AppendItem(int id, const string16& label, MenuItemType type);