Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / common / net / url_util.cc
blob9a62afdab6855fbe6bd705db2e0ea7f05101f602
1 // Copyright (c) 2012 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/common/net/url_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "net/base/escape.h"
9 #include "net/base/net_util.h"
10 #include "ui/base/clipboard/scoped_clipboard_writer.h"
11 #include "url/gurl.h"
12 #include "url/url_constants.h"
14 namespace chrome_common_net {
16 void WriteURLToClipboard(const GURL& url, const std::string& languages) {
17 if (url.is_empty() || !url.is_valid())
18 return;
20 // Unescaping path and query is not a good idea because other applications
21 // may not encode non-ASCII characters in UTF-8. See crbug.com/2820.
22 base::string16 text = url.SchemeIs(url::kMailToScheme) ?
23 base::ASCIIToUTF16(url.path()) :
24 net::FormatUrl(url, languages, net::kFormatUrlOmitNothing,
25 net::UnescapeRule::NONE, NULL, NULL, NULL);
27 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE);
28 scw.WriteURL(text);
31 } // namespace chrome_common_net