summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/omnibox
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 18:26:35 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-15 18:26:35 +0000
commitb1ce30692a03d1d245b3f73713d24c22b5c6c805 (patch)
tree6fbc814807233f9591e7f2bb92d8c4d3074bd601 /chrome/browser/ui/omnibox
parente1f58efa6839a6d98883522b5c41b3b862130b3a (diff)
downloadchromium_src-b1ce30692a03d1d245b3f73713d24c22b5c6c805.zip
chromium_src-b1ce30692a03d1d245b3f73713d24c22b5c6c805.tar.gz
chromium_src-b1ce30692a03d1d245b3f73713d24c22b5c6c805.tar.bz2
Support 'Paste and Go' action in omnibox Aura.
BUG=123057 TEST=manually done Review URL: https://chromiumcodereview.appspot.com/10386085 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137181 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/omnibox')
-rw-r--r--chrome/browser/ui/omnibox/omnibox_view.cc40
-rw-r--r--chrome/browser/ui/omnibox/omnibox_view.h5
2 files changed, 44 insertions, 1 deletions
diff --git a/chrome/browser/ui/omnibox/omnibox_view.cc b/chrome/browser/ui/omnibox/omnibox_view.cc
index 533e4e4..3eefe8f 100644
--- a/chrome/browser/ui/omnibox/omnibox_view.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,8 @@
#include "base/string_util.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "ui/base/clipboard/clipboard.h"
string16 OmniboxView::StripJavascriptSchemas(const string16& text) {
const string16 kJsPrefix(ASCIIToUTF16(chrome::kJavaScriptScheme) +
@@ -20,3 +22,39 @@ string16 OmniboxView::StripJavascriptSchemas(const string16& text) {
return out;
}
+// static
+string16 OmniboxView::GetClipboardText() {
+ // Try text format.
+ ui::Clipboard* clipboard = g_browser_process->clipboard();
+ if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
+ ui::Clipboard::BUFFER_STANDARD)) {
+ string16 text;
+ clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
+ // Note: Unlike in the find popup and textfield view, here we completely
+ // remove whitespace strings containing newlines. We assume users are
+ // most likely pasting in URLs that may have been split into multiple
+ // lines in terminals, email programs, etc., and so linebreaks indicate
+ // completely bogus whitespace that would just cause the input to be
+ // invalid.
+ return StripJavascriptSchemas(CollapseWhitespace(text, true));
+ }
+
+ // Try bookmark format.
+ //
+ // It is tempting to try bookmark format first, but the URL we get out of a
+ // bookmark has been cannonicalized via GURL. This means if a user copies
+ // and pastes from the URL bar to itself, the text will get fixed up and
+ // cannonicalized, which is not what the user expects. By pasting in this
+ // order, we are sure to paste what the user copied.
+ if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(),
+ ui::Clipboard::BUFFER_STANDARD)) {
+ std::string url_str;
+ clipboard->ReadBookmark(NULL, &url_str);
+ // pass resulting url string through GURL to normalize
+ GURL url(url_str);
+ if (url.is_valid())
+ return StripJavascriptSchemas(UTF8ToUTF16(url.spec()));
+ }
+
+ return string16();
+}
diff --git a/chrome/browser/ui/omnibox/omnibox_view.h b/chrome/browser/ui/omnibox/omnibox_view.h
index ba17dd6..368e466 100644
--- a/chrome/browser/ui/omnibox/omnibox_view.h
+++ b/chrome/browser/ui/omnibox/omnibox_view.h
@@ -217,6 +217,11 @@ class OmniboxView {
// input text.
static string16 StripJavascriptSchemas(const string16& text);
+ // Returns the current clipboard contents as a string that can be pasted in.
+ // In addition to just getting CF_UNICODETEXT out, this can also extract URLs
+ // from bookmarks on the clipboard.
+ static string16 GetClipboardText();
+
virtual ~OmniboxView() {}
};