summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 06:40:21 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 06:40:21 +0000
commit70b2726ad5be0486c9e0654056c3bcae80cd0b41 (patch)
treef6b2c531c6774b67e2a1578fefa26784a6ca40a3 /chrome/browser/autocomplete
parent0b1fff4feffee827a4dda10de099b64f039ab3dc (diff)
downloadchromium_src-70b2726ad5be0486c9e0654056c3bcae80cd0b41.zip
chromium_src-70b2726ad5be0486c9e0654056c3bcae80cd0b41.tar.gz
chromium_src-70b2726ad5be0486c9e0654056c3bcae80cd0b41.tar.bz2
Copy percent-escaped URL when copying all the text from the address bar (Mac)
BUG=31104 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 notepad and check if the pasted text contains %E4%B8%8A%E5%9C%B0, not 上地. Paste the copied text into Safari'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. 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". Paste the copied text into TextEdit and check if the pasted text isn't garbled and correctly contains 上地. Check if the link in TextEdit is pointing to encoded URL (http://www.google.com/...%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 notepad. Then check if the pasted text is NOT encoded. Review URL: http://codereview.chromium.org/549172 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37955 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm30
2 files changed, 31 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
index 066a353..b544ae7 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
@@ -79,6 +79,7 @@ class AutocompleteEditViewMac : public AutocompleteEditView,
// Implement the AutocompleteTextFieldObserver interface.
virtual void OnControlKeyChanged(bool pressed);
+ virtual void OnCopy();
virtual void OnPaste();
virtual bool CanPasteAndGo();
virtual int GetPasteActionStringId();
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index 0ee2f7b..852b393 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -7,6 +7,7 @@
#include <Carbon/Carbon.h> // kVK_Return
#include "app/clipboard/clipboard.h"
+#include "app/clipboard/scoped_clipboard_writer.h"
#include "app/resource_bundle.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
@@ -18,6 +19,7 @@
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/toolbar_model.h"
#include "grit/generated_resources.h"
+#include "net/base/escape.h"
// Focus-handling between |field_| and |model_| is a bit subtle.
// Other platforms detect change of focus, which is inconvenient
@@ -679,6 +681,34 @@ void AutocompleteEditViewMac::OnDidResignKey() {
ClosePopup();
}
+void AutocompleteEditViewMac::OnCopy() {
+ const NSRange selection = GetSelectedRange();
+ if (selection.length == 0)
+ return;
+
+ const std::wstring& text = GetText();
+ const string16 text16 = WideToUTF16(text);
+
+ ScopedClipboardWriter scw(g_browser_process->clipboard());
+ // If the entire contents are being copied and it looks like an URL,
+ // copy as a hyperlink.
+ if (IsSelectAll()) {
+ GURL url;
+ if (model_->GetURLForText(text, &url)) {
+ if ((url.SchemeIs("http") || url.SchemeIs("https")) &&
+ !model_->user_input_in_progress())
+ scw.WriteText(UTF8ToUTF16(url.spec()));
+ else
+ scw.WriteText(text16);
+ scw.WriteBookmark(text16, url.spec());
+ scw.WriteHyperlink(EscapeForHTML(WideToUTF8(text)), url.spec());
+ return;
+ }
+ }
+
+ scw.WriteText(text16.substr(selection.location, selection.length));
+}
+
void AutocompleteEditViewMac::OnPaste() {
// This code currently expects |field_| to be focussed.
DCHECK([field_ currentEditor]);