Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Unified Diff: chrome/browser/ui/omnibox/omnibox_view.cc

Issue 10386085: Support 'Paste and Go' action in omnibox Aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view.h ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/omnibox/omnibox_view.cc
diff --git a/chrome/browser/ui/omnibox/omnibox_view.cc b/chrome/browser/ui/omnibox/omnibox_view.cc
index 533e4e4bfd871fe3ca5e5199ba965bc014c15a7f..2884a786e458bdca4264a74e1175695edaef7694 100644
--- a/chrome/browser/ui/omnibox/omnibox_view.cc
+++ b/chrome/browser/ui/omnibox/omnibox_view.cc
@@ -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();
+}
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view.h ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698