diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-01 07:47:06 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-01 07:47:06 +0000 |
commit | 6db4b6c354f638cfe9beb849ca0ad0beb1bb4a8d (patch) | |
tree | 11755a262eac67de13cbcc570abe7c3ea3351406 /chrome/browser/autocomplete | |
parent | e50130bb863d3d904d8c1bccb9ab86c1bdcf88e5 (diff) | |
download | chromium_src-6db4b6c354f638cfe9beb849ca0ad0beb1bb4a8d.zip chromium_src-6db4b6c354f638cfe9beb849ca0ad0beb1bb4a8d.tar.gz chromium_src-6db4b6c354f638cfe9beb849ca0ad0beb1bb4a8d.tar.bz2 |
Always percent-escape the copied URL when all the text in the address bar is selected.
BUG=29397
TEST=Visit http://www.google.com/search?ie=UTF-8&q=上地 and select entire text in Omnibox, then copy the text.
Paste the copied text into other applications such as gedit and check if the pasted text contains %E4%B8%8A%E5%9C%B0, not 上地.
Paste the copied text into Firefox's URL bar and type return. Check if you are navigated to the same website.
Paste the copied text into textareas in Chrome and check if the pasted text contains %E4%B8%8A%E5%9C%B0.
TEST=Visit http://www.google.com/search?ie=UTF-8&q=上地 again and select "q=上地" in Omnibox, then copy the text.
Paste it into somewhere and check if you see "q=上地".
TEST=Copy "上地" from somewhere and paste it into Omnibox.
Copy from Omnibox and paste it into other apps such as gedit. Then check if the pasted text is NOT encoded.
TEST=Paste the copied text into Gmail's rich text editing mode and check if the pasted text contains 上地. Right click the link you pasted in Gmail and check if you see "Go to: http://www.google.com/...%E4%B8%8A%E5%9C%B0".
TEST=Steps described in http://codereview.chromium.org/173098.
Review URL: http://codereview.chromium.org/465053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37686 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc index e6d5f1f..39815fa 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc @@ -9,6 +9,8 @@ #include <algorithm> +#include "app/clipboard/clipboard.h" +#include "app/clipboard/scoped_clipboard_writer.h" #include "app/gfx/font.h" #include "app/gfx/gtk_util.h" #include "app/l10n_util.h" @@ -18,6 +20,7 @@ #include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/autocomplete/autocomplete_popup_model.h" #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/defaults.h" #include "chrome/browser/gtk/view_id_util.h" @@ -27,6 +30,7 @@ #include "chrome/common/notification_service.h" #include "googleurl/src/gurl.h" #include "grit/generated_resources.h" +#include "net/base/escape.h" #if defined(TOOLKIT_VIEWS) #include "chrome/browser/views/location_bar_view.h" @@ -1095,6 +1099,40 @@ void AutocompleteEditViewGtk::HandleCopyOrCutClipboard() { if (!clipboard) return; + GURL url; + if (IsSelectAll() && model_->GetURLForText(GetText(), &url)) { + // If the whole control is selected and the selected text is a valid URL, + // we assume the user is trying to copy a URL and write this to the + // clipboard as a hyperlink. + ScopedClipboardWriter scw(g_browser_process->clipboard()); + string16 text16(WideToUTF16(GetText())); + string16 url_spec16(UTF8ToUTF16(url.spec())); + if (!model_->user_input_in_progress() && + (url.SchemeIs("http") || url.SchemeIs("https"))) { + // If the scheme is http or https and the user isn't editing, + // we should copy the true URL instead of the (unescaped) display + // string to avoid encoding and escaping issues when pasting this text + // elsewhere. + scw.WriteText(url_spec16); + } else { + scw.WriteText(text16); + } + + scw.WriteHyperlink(UTF16ToUTF8(EscapeForHTML(text16)), url.spec()); + + // Update PRIMARY selection if it is not owned by the text_buffer. + if (gtk_clipboard_get_owner(clipboard) != G_OBJECT(text_buffer_)) { + std::string utf8_text(UTF16ToUTF8(text16)); + gtk_clipboard_set_text(clipboard, utf8_text.c_str(), utf8_text.length()); + } + + // Stop propagating the signal. + static guint signal_id = + g_signal_lookup("copy-clipboard", GTK_TYPE_TEXT_VIEW); + g_signal_stop_emission(text_view_, signal_id, 0); + return; + } + // Passing gtk_text_buffer_copy_clipboard() a text buffer that already owns // the clipboard that's being updated clears the highlighted text, which we // don't want to do (and it also appears to at least sometimes trigger a |