Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / omnibox / clipboard_utils.cc
blob239c7f4c94f60cb25f5490826654a0e4fb9ead4a
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/omnibox/clipboard_utils.h"
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "components/omnibox/browser/omnibox_view.h"
10 #include "ui/base/clipboard/clipboard.h"
12 base::string16 GetClipboardText() {
13 // Try text format.
14 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
15 if (clipboard->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(),
16 ui::CLIPBOARD_TYPE_COPY_PASTE)) {
17 base::string16 text;
18 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &text);
19 return OmniboxView::SanitizeTextForPaste(text);
22 // Try bookmark format.
24 // It is tempting to try bookmark format first, but the URL we get out of a
25 // bookmark has been cannonicalized via GURL. This means if a user copies
26 // and pastes from the URL bar to itself, the text will get fixed up and
27 // cannonicalized, which is not what the user expects. By pasting in this
28 // order, we are sure to paste what the user copied.
29 if (clipboard->IsFormatAvailable(ui::Clipboard::GetUrlWFormatType(),
30 ui::CLIPBOARD_TYPE_COPY_PASTE)) {
31 std::string url_str;
32 clipboard->ReadBookmark(NULL, &url_str);
33 // pass resulting url string through GURL to normalize
34 GURL url(url_str);
35 if (url.is_valid())
36 return OmniboxView::StripJavascriptSchemas(base::UTF8ToUTF16(url.spec()));
39 return base::string16();