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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file defines helper functions shared by the various implementations 5 // This file defines helper functions shared by the various implementations
6 // of OmniboxView. 6 // of OmniboxView.
7 7
8 #include "chrome/browser/ui/omnibox/omnibox_view.h" 8 #include "chrome/browser/ui/omnibox/omnibox_view.h"
9 9
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h"
14 #include "ui/base/clipboard/clipboard.h"
13 15
14 string16 OmniboxView::StripJavascriptSchemas(const string16& text) { 16 string16 OmniboxView::StripJavascriptSchemas(const string16& text) {
15 const string16 kJsPrefix(ASCIIToUTF16(chrome::kJavaScriptScheme) + 17 const string16 kJsPrefix(ASCIIToUTF16(chrome::kJavaScriptScheme) +
16 ASCIIToUTF16(":")); 18 ASCIIToUTF16(":"));
17 string16 out(text); 19 string16 out(text);
18 while (StartsWith(out, kJsPrefix, false)) 20 while (StartsWith(out, kJsPrefix, false))
19 TrimWhitespace(out.substr(kJsPrefix.length()), TRIM_LEADING, &out); 21 TrimWhitespace(out.substr(kJsPrefix.length()), TRIM_LEADING, &out);
20 return out; 22 return out;
21 } 23 }
22 24
25 // static
26 string16 OmniboxView::GetClipboardText() {
27 // Try text format.
28 ui::Clipboard* clipboard = g_browser_process->clipboard();
29 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
30 ui::Clipboard::BUFFER_STANDARD)) {
31 string16 text;
32 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &text);
33 // Note: Unlike in the find popup and textfield view, here we completely
34 // remove whitespace strings containing newlines. We assume users are
35 // most likely pasting in URLs that may have been split into multiple
36 // lines in terminals, email programs, etc., and so linebreaks indicate
37 // completely bogus whitespace that would just cause the input to be
38 // invalid.
39 return StripJavascriptSchemas(CollapseWhitespace(text, true));
40 }
41
42 // Try bookmark format.
43 //
44 // It is tempting to try bookmark format first, but the URL we get out of a
45 // bookmark has been cannonicalized via GURL. This means if a user copies
46 // and pastes from the URL bar to itself, the text will get fixed up and
47 // cannonicalized, which is not what the user expects. By pasting in this
48 // order, we are sure to paste what the user copied.
49 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(),
50 ui::Clipboard::BUFFER_STANDARD)) {
51 std::string url_str;
52 clipboard->ReadBookmark(NULL, &url_str);
53 // pass resulting url string through GURL to normalize
54 GURL url(url_str);
55 if (url.is_valid())
56 return StripJavascriptSchemas(UTF8ToUTF16(url.spec()));
57 }
58
59 return string16();
60 }
OLDNEW
« 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