1 | /* |
2 | * Copyright (C) 2018 Igalia S.L. |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Library General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Library General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Library General Public License |
15 | * along with this library; see the file COPYING.LIB. If not, write to |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "config.h" |
21 | #include "WebKitURIUtilities.h" |
22 | |
23 | #include <wtf/URLHelpers.h> |
24 | #include <wtf/text/CString.h> |
25 | #include <wtf/text/WTFString.h> |
26 | |
27 | /** |
28 | * SECTION: WebKitURIUtilities |
29 | * @Short_description: Utility functions to manipulate URIs |
30 | * @Title: WebKitURIUtilities |
31 | */ |
32 | |
33 | /** |
34 | * webkit_uri_for_display: |
35 | * @uri: the URI to be converted |
36 | * |
37 | * Use this function to format a URI for display. The URIs used internally by |
38 | * WebKit may contain percent-encoded characters or Punycode, which are not |
39 | * generally suitable to display to users. This function provides protection |
40 | * against IDN homograph attacks, so in some cases the host part of the returned |
41 | * URI may be in Punycode if the safety check fails. |
42 | * |
43 | * Returns: (nullable) (transfer full): @uri suitable for display, or %NULL in |
44 | * case of error. |
45 | * |
46 | * Since: 2.24 |
47 | */ |
48 | gchar* webkit_uri_for_display(const gchar* uri) |
49 | { |
50 | g_return_val_if_fail(uri, nullptr); |
51 | |
52 | String result = WTF::URLHelpers::userVisibleURL(uri); |
53 | if (!result) |
54 | return nullptr; |
55 | |
56 | return g_strdup(result.utf8().data()); |
57 | } |
58 | |