OLD | NEW |
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 #include "chrome/browser/net/browser_url_util.h" | 5 #include "chrome/browser/net/browser_url_util.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
13 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 13 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
14 | 14 |
15 namespace chrome_browser_net { | 15 namespace chrome_browser_net { |
16 | 16 |
17 void WriteURLToClipboard(const GURL& url, | 17 void WriteURLToClipboard(const GURL& url, |
18 const std::string& languages, | 18 const std::string& languages, |
19 ui::Clipboard *clipboard) { | 19 ui::Clipboard *clipboard) { |
20 if (url.is_empty() || !url.is_valid() || !clipboard) | 20 if (url.is_empty() || !url.is_valid() || !clipboard) |
21 return; | 21 return; |
22 | 22 |
23 // Unescaping path and query is not a good idea because other applications | 23 // Unescaping path and query is not a good idea because other applications |
24 // may not encode non-ASCII characters in UTF-8. See crbug.com/2820. | 24 // may not encode non-ASCII characters in UTF-8. See crbug.com/2820. |
25 string16 text = url.SchemeIs(chrome::kMailToScheme) ? | 25 string16 text = url.SchemeIs(chrome::kMailToScheme) ? |
26 ASCIIToUTF16(url.path()) : | 26 ASCIIToUTF16(url.path()) : |
27 net::FormatUrl(url, languages, net::kFormatUrlOmitNothing, | 27 net::FormatUrl(url, languages, net::kFormatUrlOmitNothing, |
28 net::UnescapeRule::NONE, NULL, NULL, NULL); | 28 net::UnescapeRule::NONE, NULL, NULL, NULL); |
29 | 29 |
30 ui::ScopedClipboardWriter scw(clipboard); | 30 ui::ScopedClipboardWriter scw(clipboard, ui::Clipboard::BUFFER_STANDARD); |
31 scw.WriteURL(text); | 31 scw.WriteURL(text); |
32 } | 32 } |
33 | 33 |
34 GURL AppendQueryParameter(const GURL& url, | 34 GURL AppendQueryParameter(const GURL& url, |
35 const std::string& name, | 35 const std::string& name, |
36 const std::string& value) { | 36 const std::string& value) { |
37 std::string query(url.query()); | 37 std::string query(url.query()); |
38 if (!query.empty()) | 38 if (!query.empty()) |
39 query += "&"; | 39 query += "&"; |
40 query += (net::EscapeQueryParamValue(name, true) + "=" + | 40 query += (net::EscapeQueryParamValue(name, true) + "=" + |
41 net::EscapeQueryParamValue(value, true)); | 41 net::EscapeQueryParamValue(value, true)); |
42 GURL::Replacements replacements; | 42 GURL::Replacements replacements; |
43 replacements.SetQueryStr(query); | 43 replacements.SetQueryStr(query); |
44 return url.ReplaceComponents(replacements); | 44 return url.ReplaceComponents(replacements); |
45 } | 45 } |
46 | 46 |
47 } // namespace chrome_browser_net | 47 } // namespace chrome_browser_net |
OLD | NEW |