[epiphany/carlosgc/libsoup3: 9/10] Use GUri instead of SoupURI where possible in preparation for libsoup3
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/carlosgc/libsoup3: 9/10] Use GUri instead of SoupURI where possible in preparation for libsoup3
- Date: Fri, 12 Mar 2021 12:46:59 +0000 (UTC)
commit 2c975884845f88c09881792400d2ea6eb7327d40
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Tue Mar 2 14:35:53 2021 +0100
Use GUri instead of SoupURI where possible in preparation for libsoup3
embed/ephy-embed-shell.c | 6 +-
embed/ephy-embed-utils.c | 14 ++---
embed/ephy-reader-handler.c | 14 ++---
embed/ephy-view-source-handler.c | 65 +++++++++----------
embed/ephy-web-view.c | 49 +++++++--------
.../ephy-web-overview-model.c | 8 +--
lib/ephy-string.c | 15 ++---
lib/ephy-sync-utils.c | 22 +++----
lib/ephy-uri-helpers.c | 42 ++++++++++---
lib/ephy-uri-helpers.h | 1 +
lib/ephy-web-app-utils.c | 40 ++++++------
lib/safe-browsing/ephy-gsb-utils.c | 42 ++++++-------
lib/sync/ephy-sync-crypto.c | 20 +++---
lib/sync/ephy-sync-service.c | 8 +--
lib/widgets/ephy-certificate-dialog.c | 8 +--
lib/widgets/ephy-location-entry.c | 17 +++--
lib/widgets/ephy-security-popover.c | 11 ++--
meson.build | 2 +-
src/ephy-session.c | 15 +++--
src/ephy-suggestion-model.c | 6 +-
src/ephy-window.c | 12 ++--
src/preferences/ephy-search-engine-row.c | 15 ++---
src/window-commands.c | 73 +++++++++++-----------
23 files changed, 240 insertions(+), 265 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 278cdefd8..f930b5c32 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -505,12 +505,12 @@ history_service_host_deleted_cb (EphyHistoryService *service,
EphyEmbedShell *shell)
{
EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
- g_autoptr (SoupURI) deleted_uri = NULL;
+ g_autoptr (GUri) deleted_uri = NULL;
- deleted_uri = soup_uri_new (deleted_url);
+ deleted_uri = g_uri_parse (deleted_url, G_URI_FLAGS_NONE, NULL);
webkit_web_context_send_message_to_all_extensions (priv->web_context,
webkit_user_message_new ("History.DeleteHost",
- g_variant_new ("s",
soup_uri_get_host (deleted_uri))));
+ g_variant_new ("s",
g_uri_get_host (deleted_uri))));
}
static void
diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c
index 59c9e05c8..69534946a 100644
--- a/embed/ephy-embed-utils.c
+++ b/embed/ephy-embed-utils.c
@@ -287,21 +287,21 @@ ephy_embed_utils_normalize_address (const char *address)
return g_strconcat (EPHY_ABOUT_SCHEME, address + strlen ("about"), NULL);
if (!ephy_embed_utils_address_has_web_scheme (address)) {
- g_autoptr (SoupURI) uri = NULL;
+ const char *scheme;
- uri = soup_uri_new (address);
+ scheme = g_uri_peek_scheme (address);
/* Auto-prepend http:// to anything that is not
- * one according to soup, because it probably will be
+ * one according to GLib, because it probably will be
* something like "google.com". Special case localhost(:port)
- * and IP(:port), because SoupURI, correctly, thinks it is a
+ * and IP(:port), because GUri, correctly, thinks it is a
* URI with scheme being localhost/IP and, optionally, path
* being the port. Ideally we should check if we have a
* handler for the scheme, and since we'll fail for localhost
* and IP, we'd fallback to loading it as a domain. */
- if (!uri ||
- !g_strcmp0 (uri->scheme, "localhost") ||
- g_hostname_is_ip_address (uri->scheme) ||
+ if (!scheme ||
+ !g_strcmp0 (scheme, "localhost") ||
+ g_hostname_is_ip_address (scheme) ||
is_host_with_port (address))
effective_address = g_strconcat ("http://", address, NULL);
}
diff --git a/embed/ephy-reader-handler.c b/embed/ephy-reader-handler.c
index ef1422537..707497bdb 100644
--- a/embed/ephy-reader-handler.c
+++ b/embed/ephy-reader-handler.c
@@ -254,14 +254,14 @@ ephy_reader_request_begin_get_source_from_uri (EphyReaderRequest *request,
static void
ephy_reader_request_start (EphyReaderRequest *request)
{
- g_autoptr (SoupURI) soup_uri = NULL;
+ g_autoptr (GUri) uri = NULL;
const char *original_uri;
WebKitWebView *web_view;
original_uri = webkit_uri_scheme_request_get_uri (request->scheme_request);
- soup_uri = soup_uri_new (original_uri);
+ uri = g_uri_parse (original_uri, G_URI_FLAGS_NONE, NULL);
- if (!soup_uri) {
+ if (!uri) {
/* Can't assert because user could theoretically input something weird */
GError *error = g_error_new (WEBKIT_NETWORK_ERROR,
WEBKIT_NETWORK_ERROR_FAILED,
@@ -283,15 +283,11 @@ ephy_reader_request_start (EphyReaderRequest *request)
if (web_view) {
ephy_reader_request_begin_get_source_from_web_view (request, web_view);
} else {
- const char *source_uri;
-
/* Extract URI:
* ephy-reader:https://example.com/whatever?xyz into https://example.com/whatever?xyz
*/
- source_uri = soup_uri_to_string (soup_uri, TRUE);
- g_assert (source_uri);
-
- ephy_reader_request_begin_get_source_from_uri (request, source_uri);
+ g_assert (g_str_has_prefix (original_uri, "ephy-reader:"));
+ ephy_reader_request_begin_get_source_from_uri (request, original_uri + strlen ("ephy-reader:"));
}
request->source_handler->outstanding_requests =
diff --git a/embed/ephy-view-source-handler.c b/embed/ephy-view-source-handler.c
index 52e29519c..9c269490d 100644
--- a/embed/ephy-view-source-handler.c
+++ b/embed/ephy-view-source-handler.c
@@ -186,11 +186,12 @@ ephy_view_source_request_begin_get_source_from_uri (EphyViewSourceRequest *reque
static gint
embed_is_displaying_matching_uri (EphyEmbed *embed,
- SoupURI *uri)
+ GUri *uri)
{
EphyWebView *web_view;
- SoupURI *view_uri;
- gint ret = -1;
+ g_autoptr (GUri) view_uri = NULL;
+ g_autofree char *modified_uri = NULL;
+ g_autofree char *uri_string = NULL;
if (ephy_embed_has_load_pending (embed))
return -1;
@@ -199,20 +200,18 @@ embed_is_displaying_matching_uri (EphyEmbed *embed,
if (ephy_web_view_is_loading (web_view))
return -1;
- view_uri = soup_uri_new (ephy_web_view_get_address (web_view));
+ view_uri = g_uri_parse (ephy_web_view_get_address (web_view),
+ G_URI_FLAGS_NONE, NULL);
if (!view_uri)
return -1;
- soup_uri_set_fragment (view_uri, NULL);
- ret = soup_uri_equal (view_uri, uri) ? 0 : -1;
-
- soup_uri_free (view_uri);
-
- return ret;
+ modified_uri = g_uri_to_string_partial (view_uri, G_URI_HIDE_FRAGMENT);
+ uri_string = g_uri_to_string (uri);
+ return strcmp (modified_uri, uri_string);
}
static WebKitWebView *
-get_web_view_matching_uri (SoupURI *uri)
+get_web_view_matching_uri (GUri *uri)
{
EphyEmbedShell *shell;
GtkWindow *window;
@@ -241,10 +240,8 @@ out:
static void
ephy_view_source_request_start (EphyViewSourceRequest *request)
{
- guint port;
- SoupURI *soup_uri;
- char *modified_uri;
- char *decoded_fragment;
+ g_autoptr (GUri) uri = NULL;
+ g_autoptr (GUri) converted_uri = NULL;
const char *original_uri;
WebKitWebView *web_view;
@@ -252,9 +249,9 @@ ephy_view_source_request_start (EphyViewSourceRequest *request)
g_list_prepend (request->source_handler->outstanding_requests, request);
original_uri = webkit_uri_scheme_request_get_uri (request->scheme_request);
- soup_uri = soup_uri_new (original_uri);
+ uri = g_uri_parse (original_uri, G_URI_FLAGS_ENCODED | G_URI_FLAGS_SCHEME_NORMALIZE, NULL);
- if (!soup_uri || !soup_uri->fragment) {
+ if (!uri || !g_uri_get_fragment (uri)) {
/* Can't assert because user could theoretically input something weird */
GError *error = g_error_new (WEBKIT_NETWORK_ERROR,
WEBKIT_NETWORK_ERROR_FAILED,
@@ -265,26 +262,26 @@ ephy_view_source_request_start (EphyViewSourceRequest *request)
return;
}
- /* Convert e.g. ephy-source://gnome.org#https to https://gnome.org, taking
- * care to prevent soup_uri_set_scheme() from forcing the default port.
- */
- decoded_fragment = soup_uri_decode (soup_uri->fragment);
- port = soup_uri_get_port (soup_uri);
- soup_uri_set_scheme (soup_uri, decoded_fragment);
- soup_uri_set_port (soup_uri, port);
- soup_uri_set_fragment (soup_uri, NULL);
- modified_uri = soup_uri_to_string (soup_uri, FALSE);
- g_assert (modified_uri);
-
- web_view = get_web_view_matching_uri (soup_uri);
+ /* Convert e.g. ephy-source://gnome.org#https to https://gnome.org */
+ converted_uri = g_uri_build (g_uri_get_flags (uri),
+ g_uri_get_fragment (uri),
+ g_uri_get_userinfo (uri),
+ g_uri_get_host (uri),
+ g_uri_get_port (uri),
+ g_uri_get_path (uri),
+ g_uri_get_query (uri),
+ NULL);
+ g_assert (converted_uri);
+
+ web_view = get_web_view_matching_uri (converted_uri);
if (web_view)
ephy_view_source_request_begin_get_source_from_web_view (request, WEBKIT_WEB_VIEW (web_view));
- else
- ephy_view_source_request_begin_get_source_from_uri (request, modified_uri);
+ else {
+ g_autofree char *modified_uri = NULL;
- g_free (decoded_fragment);
- g_free (modified_uri);
- soup_uri_free (soup_uri);
+ modified_uri = g_uri_to_string (converted_uri);
+ ephy_view_source_request_begin_get_source_from_uri (request, modified_uri);
+ }
}
static void
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 4bf68f174..abc66095e 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -54,7 +54,6 @@
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
-#include <libsoup/soup.h>
/**
* SECTION:ephy-web-view
@@ -639,7 +638,7 @@ allow_tls_certificate_cb (EphyEmbedShell *shell,
guint64 page_id,
EphyWebView *view)
{
- SoupURI *uri;
+ g_autoptr (GUri) uri = NULL;
if (webkit_web_view_get_page_id (WEBKIT_WEB_VIEW (view)) != page_id)
return;
@@ -647,12 +646,11 @@ allow_tls_certificate_cb (EphyEmbedShell *shell,
g_assert (G_IS_TLS_CERTIFICATE (view->certificate));
g_assert (view->tls_error_failing_uri != NULL);
- uri = soup_uri_new (view->tls_error_failing_uri);
+ uri = g_uri_parse (view->tls_error_failing_uri, G_URI_FLAGS_NONE, NULL);
webkit_web_context_allow_tls_certificate_for_host (ephy_embed_shell_get_web_context (shell),
view->certificate,
- uri->host);
+ g_uri_get_host (uri));
ephy_web_view_load_url (view, ephy_web_view_get_address (view));
- soup_uri_free (uri);
}
static void
@@ -1375,16 +1373,13 @@ ephy_web_view_set_committed_location (EphyWebView *view,
if (location == NULL || location[0] == '\0') {
ephy_web_view_set_address (view, NULL);
} else if (g_str_has_prefix (location, EPHY_ABOUT_SCHEME ":applications")) {
- SoupURI *uri = soup_uri_new (location);
- char *new_address;
+ g_autoptr (GUri) uri = NULL;
+ g_autofree char *new_address = NULL;
/* Strip the query from the URL for about:applications. */
- soup_uri_set_query (uri, NULL);
- new_address = soup_uri_to_string (uri, FALSE);
- soup_uri_free (uri);
-
+ uri = g_uri_parse (location, G_URI_FLAGS_NONE, NULL);
+ new_address = g_uri_to_string_partial (uri, G_URI_HIDE_QUERY);
ephy_web_view_set_address (view, new_address);
- g_free (new_address);
} else {
/* We do this to get rid of an eventual password in the URL. */
ephy_web_view_set_address (view, location);
@@ -1425,7 +1420,7 @@ update_security_status_for_committed_load (EphyWebView *view,
GtkWidget *toplevel;
WebKitWebContext *web_context;
WebKitSecurityManager *security_manager;
- SoupURI *soup_uri;
+ g_autoptr (GUri) guri = NULL;
g_autofree char *tld = NULL;
if (view->loading_error_page)
@@ -1441,23 +1436,23 @@ update_security_status_for_committed_load (EphyWebView *view,
embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view);
web_context = webkit_web_view_get_context (WEBKIT_WEB_VIEW (view));
security_manager = webkit_web_context_get_security_manager (web_context);
- soup_uri = soup_uri_new (uri);
+ guri = g_uri_parse (uri, G_URI_FLAGS_NONE, NULL);
g_clear_object (&view->certificate);
g_clear_pointer (&view->tls_error_failing_uri, g_free);
- if (soup_uri && soup_uri->host)
- tld = hostname_to_tld (soup_uri->host);
+ if (guri && g_uri_get_host (guri))
+ tld = hostname_to_tld (g_uri_get_host (guri));
- if (!soup_uri ||
- strcmp (soup_uri->scheme, EPHY_VIEW_SOURCE_SCHEME) == 0 ||
- strcmp (soup_uri->scheme, EPHY_READER_SCHEME) == 0 ||
- strcmp (soup_uri->scheme, EPHY_PDF_SCHEME) == 0 ||
+ if (!guri ||
+ strcmp (g_uri_get_scheme (guri), EPHY_VIEW_SOURCE_SCHEME) == 0 ||
+ strcmp (g_uri_get_scheme (guri), EPHY_READER_SCHEME) == 0 ||
+ strcmp (g_uri_get_scheme (guri), EPHY_PDF_SCHEME) == 0 ||
g_strcmp0 (tld, "127.0.0.1") == 0 ||
g_strcmp0 (tld, "::1") == 0 ||
g_strcmp0 (tld, "localhost") == 0 || /* We trust localhost to be local since glib!616. */
- webkit_security_manager_uri_scheme_is_local (security_manager, soup_uri->scheme) ||
- webkit_security_manager_uri_scheme_is_empty_document (security_manager, soup_uri->scheme)) {
+ webkit_security_manager_uri_scheme_is_local (security_manager, g_uri_get_scheme (guri)) ||
+ webkit_security_manager_uri_scheme_is_empty_document (security_manager, g_uri_get_scheme (guri))) {
security_level = EPHY_SECURITY_LEVEL_LOCAL_PAGE;
} else if (webkit_web_view_get_tls_info (WEBKIT_WEB_VIEW (view), &view->certificate, &view->tls_errors)) {
g_object_ref (view->certificate);
@@ -1468,9 +1463,6 @@ update_security_status_for_committed_load (EphyWebView *view,
}
ephy_web_view_set_security_level (view, security_level);
-
- if (soup_uri)
- soup_uri_free (soup_uri);
}
static void
@@ -2791,11 +2783,12 @@ ephy_web_view_load_url (EphyWebView *view,
effective_url = ephy_embed_utils_normalize_address (url);
if (g_str_has_prefix (effective_url, "javascript:")) {
- char *decoded_url;
+ g_autoptr (GUri) uri = NULL;
+ g_autofree char *decoded_url = NULL;
- decoded_url = soup_uri_decode (effective_url);
+ uri = g_uri_parse (effective_url, G_URI_FLAGS_NONE, NULL);
+ decoded_url = g_uri_to_string (uri);
webkit_web_view_run_javascript (WEBKIT_WEB_VIEW (view), decoded_url, NULL, NULL, NULL);
- g_free (decoded_url);
} else
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view), effective_url);
diff --git a/embed/web-process-extension/ephy-web-overview-model.c
b/embed/web-process-extension/ephy-web-overview-model.c
index f85459bcd..59995af29 100644
--- a/embed/web-process-extension/ephy-web-overview-model.c
+++ b/embed/web-process-extension/ephy-web-overview-model.c
@@ -21,8 +21,6 @@
#include "config.h"
#include "ephy-web-overview-model.h"
-#include <libsoup/soup.h>
-
struct _EphyWebOverviewModel {
GObject parent_instance;
@@ -286,17 +284,17 @@ ephy_web_overview_model_delete_host (EphyWebOverviewModel *model,
l = model->items;
while (l) {
EphyWebOverviewModelItem *item = (EphyWebOverviewModelItem *)l->data;
- SoupURI *uri = soup_uri_new (item->url);
+ g_autoptr (GUri) uri = NULL;
GList *next = l->next;
- if (g_strcmp0 (soup_uri_get_host (uri), host) == 0) {
+ uri = g_uri_parse (item->url, G_URI_FLAGS_NONE, NULL);
+ if (g_strcmp0 (g_uri_get_host (uri), host) == 0) {
changed = TRUE;
ephy_web_overview_model_item_free (item);
model->items = g_list_delete_link (model->items, l);
}
- soup_uri_free (uri);
l = next;
}
diff --git a/lib/ephy-string.c b/lib/ephy-string.c
index 5dbf66c9b..dd434e1b8 100644
--- a/lib/ephy-string.c
+++ b/lib/ephy-string.c
@@ -22,8 +22,7 @@
#include "ephy-string.h"
#include <errno.h>
-#include <glib.h>
-#include <libsoup/soup.h>
+#include <gio/gio.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
@@ -175,8 +174,7 @@ ephy_string_collate_key_for_domain (const char *str,
char *
ephy_string_get_host_name (const char *url)
{
- SoupURI *uri;
- char *ret;
+ g_autoptr (GUri) uri = NULL;
if (url == NULL ||
g_str_has_prefix (url, "file://") ||
@@ -184,22 +182,19 @@ ephy_string_get_host_name (const char *url)
g_str_has_prefix (url, "ephy-about:"))
return NULL;
- uri = soup_uri_new (url);
+ uri = g_uri_parse (url, G_URI_FLAGS_NONE, NULL);
/* If uri is NULL it's very possible that we just got
* something without a scheme, let's try to prepend
* 'http://' */
if (uri == NULL) {
char *effective_url = g_strconcat ("http://", url, NULL);
- uri = soup_uri_new (effective_url);
+ uri = g_uri_parse (effective_url, G_URI_FLAGS_NONE, NULL);
g_free (effective_url);
}
if (uri == NULL) return NULL;
- ret = g_strdup (uri->host);
- soup_uri_free (uri);
-
- return ret;
+ return g_strdup (g_uri_get_host (uri));
}
/**
diff --git a/lib/ephy-sync-utils.c b/lib/ephy-sync-utils.c
index c7476fd3e..418853df3 100644
--- a/lib/ephy-sync-utils.c
+++ b/lib/ephy-sync-utils.c
@@ -27,7 +27,6 @@
#include <glib/gi18n.h>
#include <inttypes.h>
#include <json-glib/json-glib.h>
-#include <libsoup/soup.h>
#include <stdio.h>
#include <string.h>
#if defined(__linux__)
@@ -200,28 +199,23 @@ ephy_sync_utils_generate_random_bytes (void *random_ctx,
char *
ephy_sync_utils_get_audience (const char *url)
{
- SoupURI *uri;
+ g_autoptr (GUri) uri = NULL;
const char *scheme;
const char *host;
+ int port;
char *audience;
- char *port;
g_assert (url);
- uri = soup_uri_new (url);
- scheme = soup_uri_get_scheme (uri);
- host = soup_uri_get_host (uri);
- /* soup_uri_get_port returns the default port if URI does not have any port. */
- port = g_strdup_printf (":%u", soup_uri_get_port (uri));
-
- if (g_strstr_len (url, -1, port))
- audience = g_strdup_printf ("%s://%s%s", scheme, host, port);
+ uri = g_uri_parse (url, G_URI_FLAGS_NONE, NULL);
+ scheme = g_uri_get_scheme (uri);
+ host = g_uri_get_host (uri);
+ port = g_uri_get_port (uri);
+ if (port != -1)
+ audience = g_strdup_printf ("%s://%s:%d", scheme, host, port);
else
audience = g_strdup_printf ("%s://%s", scheme, host);
- g_free (port);
- soup_uri_free (uri);
-
return audience;
}
diff --git a/lib/ephy-uri-helpers.c b/lib/ephy-uri-helpers.c
index 2f4e7bab3..9ac8b502e 100644
--- a/lib/ephy-uri-helpers.c
+++ b/lib/ephy-uri-helpers.c
@@ -23,7 +23,6 @@
#include "ephy-uri-helpers.h"
#include <glib.h>
-#include <libsoup/soup.h>
#include <string.h>
#include <webkit2/webkit2.h>
@@ -47,20 +46,16 @@ ephy_uri_decode (const char *uri_string)
char *
ephy_uri_normalize (const char *uri_string)
{
- SoupURI *uri;
- char *encoded_uri;
+ g_autoptr (GUri) uri = NULL;
if (!uri_string || !*uri_string)
return NULL;
- uri = soup_uri_new (uri_string);
+ uri = g_uri_parse (uri_string, G_URI_FLAGS_SCHEME_NORMALIZE, NULL);
if (!uri)
return g_strdup (uri_string);
- encoded_uri = soup_uri_normalize (uri_string, NULL);
- soup_uri_free (uri);
-
- return encoded_uri;
+ return g_uri_to_string (uri);
}
char *
@@ -77,3 +72,34 @@ ephy_uri_to_security_origin (const char *uri_string)
/* May be NULL. */
return result;
}
+
+#define XDIGIT(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10)
+#define HEXCHAR(s) ((XDIGIT (s[1]) << 4) + XDIGIT (s[2]))
+
+char *
+ephy_uri_unescape (const char *uri_string)
+{
+ unsigned char *s, *d;
+ char *decoded;
+
+ g_assert (uri_string);
+
+ decoded = g_strdup (uri_string);
+ s = d = (unsigned char *)decoded;
+ do {
+ if (*s == '%') {
+ if (s[1] == '\0' ||
+ s[2] == '\0' ||
+ !g_ascii_isxdigit (s[1]) ||
+ !g_ascii_isxdigit (s[2])) {
+ *d++ = *s;
+ continue;
+ }
+ *d++ = HEXCHAR (s);
+ s += 2;
+ } else
+ *d++ = *s;
+ } while (*s++);
+
+ return decoded;
+}
diff --git a/lib/ephy-uri-helpers.h b/lib/ephy-uri-helpers.h
index 5b51d240e..f4b6425d6 100644
--- a/lib/ephy-uri-helpers.h
+++ b/lib/ephy-uri-helpers.h
@@ -28,5 +28,6 @@ G_BEGIN_DECLS
char *ephy_uri_decode (const char *uri);
char *ephy_uri_normalize (const char *uri);
char *ephy_uri_to_security_origin (const char *uri);
+char *ephy_uri_unescape (const char *uri);
G_END_DECLS
diff --git a/lib/ephy-web-app-utils.c b/lib/ephy-web-app-utils.c
index 5f80c5db5..a6db43f04 100644
--- a/lib/ephy-web-app-utils.c
+++ b/lib/ephy-web-app-utils.c
@@ -29,7 +29,6 @@
#include <errno.h>
#include <gio/gio.h>
#include <glib/gstdio.h>
-#include <libsoup/soup.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
@@ -817,29 +816,31 @@ static gboolean
urls_have_same_origin (const char *a_url,
const char *b_url)
{
- SoupURI *a_uri, *b_uri;
- gboolean retval = FALSE;
+ g_autoptr (GUri) a_uri = NULL;
+ g_autoptr (GUri) b_uri = NULL;
- a_uri = soup_uri_new (a_url);
- if (!a_uri)
- return retval;
+ a_uri = g_uri_parse (a_url, G_URI_FLAGS_NONE, NULL);
+ if (!a_uri || !g_uri_get_host (a_uri))
+ return FALSE;
- b_uri = soup_uri_new (b_url);
- if (b_uri) {
- retval = a_uri->host && b_uri->host && soup_uri_host_equal (a_uri, b_uri);
- soup_uri_free (b_uri);
- }
+ b_uri = g_uri_parse (b_url, G_URI_FLAGS_NONE, NULL);
+ if (!b_uri || !g_uri_get_host (b_uri))
+ return FALSE;
+
+ if (strcmp (g_uri_get_scheme (a_uri), g_uri_get_scheme (b_uri)) != 0)
+ return FALSE;
- soup_uri_free (a_uri);
+ if (g_uri_get_port (a_uri) != g_uri_get_port (b_uri))
+ return FALSE;
- return retval;
+ return g_ascii_strcasecmp (g_uri_get_host (a_uri), g_uri_get_host (b_uri)) == 0;
}
gboolean
ephy_web_application_is_uri_allowed (const char *uri)
{
EphyWebApplication *webapp = ephy_web_application_for_profile_directory (ephy_profile_dir ());
- SoupURI *request_uri;
+ const char *scheme;
char **urls;
guint i;
gboolean matched = FALSE;
@@ -855,25 +856,24 @@ ephy_web_application_is_uri_allowed (const char *uri)
if (g_strcmp0 (uri, "about:blank") == 0)
return TRUE;
- request_uri = soup_uri_new (uri);
- if (!request_uri)
+ scheme = g_uri_peek_scheme (uri);
+ if (!scheme)
return FALSE;
urls = g_settings_get_strv (EPHY_SETTINGS_WEB_APP, EPHY_PREFS_WEB_APP_ADDITIONAL_URLS);
for (i = 0; urls[i] && !matched; i++) {
if (!strstr (urls[i], "://")) {
- char *url = g_strdup_printf ("%s://%s", request_uri->scheme, urls[i]);
+ g_autofree char *url = NULL;
+
+ url = g_strdup_printf ("%s://%s", scheme, urls[i]);
matched = g_str_has_prefix (uri, url);
- g_free (url);
} else {
matched = g_str_has_prefix (uri, urls[i]);
}
}
g_strfreev (urls);
- soup_uri_free (request_uri);
-
return matched;
}
diff --git a/lib/safe-browsing/ephy-gsb-utils.c b/lib/safe-browsing/ephy-gsb-utils.c
index d3cc81605..cb66f969d 100644
--- a/lib/safe-browsing/ephy-gsb-utils.c
+++ b/lib/safe-browsing/ephy-gsb-utils.c
@@ -23,9 +23,9 @@
#include "ephy-debug.h"
#include "ephy-string.h"
+#include "ephy-uri-helpers.h"
#include <arpa/inet.h>
-#include <libsoup/soup.h>
#include <stdio.h>
#include <string.h>
@@ -520,7 +520,7 @@ ephy_gsb_utils_full_unescape (const char *part)
g_assert (part);
prev = g_strdup (part);
- retval = soup_uri_decode (part);
+ retval = ephy_uri_unescape (part);
/* Iteratively unescape the string until it cannot be unescaped anymore.
* This is useful for strings that have been escaped multiple times.
@@ -528,7 +528,7 @@ ephy_gsb_utils_full_unescape (const char *part)
while (g_strcmp0 (prev, retval) != 0 && attempts++ < MAX_UNESCAPE_STEP) {
prev_prev = prev;
prev = retval;
- retval = soup_uri_decode (retval);
+ retval = ephy_uri_unescape (retval);
g_free (prev_prev);
}
@@ -547,7 +547,7 @@ ephy_gsb_utils_escape (const char *part)
str = g_string_new (NULL);
- /* Use this instead of soup_uri_encode() because that escapes other
+ /* Use this instead of g_uri_escape_string() because that escapes other
* characters that we don't want to be escaped.
*/
while (*s) {
@@ -632,7 +632,8 @@ ephy_gsb_utils_canonicalize (const char *url,
char **path_out,
char **query_out)
{
- SoupURI *uri;
+ g_autoptr (GUri) uri = NULL;
+ g_autoptr (GUri) base = NULL;
char *tmp;
char *host;
char *path;
@@ -653,45 +654,45 @@ ephy_gsb_utils_canonicalize (const char *url,
else
tmp = g_strdup (url);
- /* soup_uri_new() prepares the URL for us:
+ /* GLib only applies the remove_dot_segments algorithm when using g_uri_parse_relative
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/2342
+ */
+ base = g_uri_parse (tmp, G_URI_FLAGS_ENCODED | G_URI_FLAGS_SCHEME_NORMALIZE | G_URI_FLAGS_PARSE_RELAXED |
G_URI_FLAGS_NON_DNS, NULL);
+
+ /* g_uri_parse() prepares the URL for us:
* 1. Strips trailing and leading whitespaces.
* 2. Includes the path component if missing.
* 3. Removes tab (0x09), CR (0x0d), LF (0x0a) characters.
*/
- uri = soup_uri_new (tmp);
+ uri = g_uri_parse_relative (base, tmp, G_URI_FLAGS_ENCODED | G_URI_FLAGS_SCHEME_NORMALIZE |
G_URI_FLAGS_PARSE_RELAXED | G_URI_FLAGS_NON_DNS, NULL);
g_free (tmp);
if (!uri) {
- LOG ("Cannot make SoupURI from URL %s", url);
+ LOG ("Cannot make GUri from URL %s", url);
return NULL;
}
/* Check for e.g. blob or data URIs */
- if (!uri->host) {
- soup_uri_free (uri);
+ if (!g_uri_get_host (uri))
return NULL;
- }
-
- /* Remove fragment. */
- soup_uri_set_fragment (uri, NULL);
/* Canonicalize host. */
- host = ephy_gsb_utils_normalize_escape (soup_uri_get_host (uri));
+ host = ephy_gsb_utils_normalize_escape (g_uri_get_host (uri));
host_canonical = ephy_gsb_utils_canonicalize_host (host);
- /* Canonicalize path. "/../" and "/./" have already been resolved by soup_uri_new(). */
- path = ephy_gsb_utils_normalize_escape (soup_uri_get_path (uri));
+ /* Canonicalize path. "/../" and "/./" have already been resolved by g_uri_parse(). */
+ path = ephy_gsb_utils_normalize_escape (g_uri_get_path (uri));
path_canonical = ephy_string_find_and_replace (path, "//", "/");
/* Combine all parts. */
- query = soup_uri_get_query (uri);
+ query = g_uri_get_query (uri);
if (query) {
retval = g_strdup_printf ("%s://%s%s?%s",
- soup_uri_get_scheme (uri),
+ g_uri_get_scheme (uri),
host_canonical, path_canonical,
query);
} else {
retval = g_strdup_printf ("%s://%s%s",
- soup_uri_get_scheme (uri),
+ g_uri_get_scheme (uri),
host_canonical, path_canonical);
}
@@ -706,7 +707,6 @@ ephy_gsb_utils_canonicalize (const char *url,
g_free (path);
g_free (host_canonical);
g_free (path_canonical);
- soup_uri_free (uri);
return retval;
}
diff --git a/lib/sync/ephy-sync-crypto.c b/lib/sync/ephy-sync-crypto.c
index 717164aa5..6801f6c99 100644
--- a/lib/sync/ephy-sync-crypto.c
+++ b/lib/sync/ephy-sync-crypto.c
@@ -28,7 +28,6 @@
#include <glib/gstdio.h>
#include <inttypes.h>
#include <json-glib/json-glib.h>
-#include <libsoup/soup.h>
#include <nettle/aes.h>
#include <nettle/cbc.h>
#include <nettle/hkdf.h>
@@ -283,7 +282,7 @@ ephy_sync_crypto_hawk_header_new (const char *url,
{
SyncCryptoHawkHeader *hawk_header;
SyncCryptoHawkArtifacts *artifacts;
- SoupURI *uri;
+ g_autoptr (GUri) uri = NULL;
char *resource;
char *hash;
char *header;
@@ -303,12 +302,12 @@ ephy_sync_crypto_hawk_header_new (const char *url,
hash = options ? g_strdup (options->hash) : NULL;
payload = options ? options->payload : NULL;
timestamp = options ? options->timestamp : NULL;
- uri = soup_uri_new (url);
- resource = !soup_uri_get_query (uri) ? g_strdup (soup_uri_get_path (uri))
- : g_strconcat (soup_uri_get_path (uri),
- "?",
- soup_uri_get_query (uri),
- NULL);
+ uri = g_uri_parse (url, G_URI_FLAGS_SCHEME_NORMALIZE, NULL);
+ resource = !g_uri_get_query (uri) ? g_strdup (g_uri_get_path (uri))
+ : g_strconcat (g_uri_get_path (uri),
+ "?",
+ g_uri_get_query (uri),
+ NULL);
if (options && options->nonce) {
nonce = g_strdup (options->nonce);
@@ -340,10 +339,10 @@ ephy_sync_crypto_hawk_header_new (const char *url,
options ? options->dlg : NULL,
options ? options->ext : NULL,
hash,
- soup_uri_get_host (uri),
+ g_uri_get_host (uri),
method,
nonce,
- soup_uri_get_port (uri),
+ g_uri_get_port (uri),
resource,
ts);
@@ -386,7 +385,6 @@ ephy_sync_crypto_hawk_header_new (const char *url,
hawk_header->header = g_strdup (header);
hawk_header->artifacts = artifacts;
- soup_uri_free (uri);
g_free (hash);
g_free (mac);
g_free (nonce);
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index a6ca3de2a..a9eec409d 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -608,7 +608,7 @@ ephy_sync_service_verify_certificate (EphySyncService *self,
JsonObject *json;
JsonObject *principal;
GError *error = NULL;
- SoupURI *uri = NULL;
+ g_autoptr (GUri) uri = NULL;
char **pieces;
char *header;
char *payload;
@@ -668,10 +668,10 @@ ephy_sync_service_verify_certificate (EphySyncService *self,
goto out;
}
accounts_server = ephy_sync_utils_get_accounts_server ();
- uri = soup_uri_new (accounts_server);
+ uri = g_uri_parse (accounts_server, G_URI_FLAGS_NONE, NULL);
expected = g_strdup_printf ("%s@%s",
ephy_sync_service_get_secret (self, secrets[UID]),
- soup_uri_get_host (uri));
+ g_uri_get_host (uri));
retval = g_strcmp0 (email, expected) == 0;
out:
@@ -680,8 +680,6 @@ out:
g_free (payload);
g_free (header);
g_strfreev (pieces);
- if (uri)
- soup_uri_free (uri);
if (error)
g_error_free (error);
diff --git a/lib/widgets/ephy-certificate-dialog.c b/lib/widgets/ephy-certificate-dialog.c
index 9d7db8665..0e79fcc45 100644
--- a/lib/widgets/ephy-certificate-dialog.c
+++ b/lib/widgets/ephy-certificate-dialog.c
@@ -26,7 +26,6 @@
#define GCR_API_SUBJECT_TO_CHANGE
#include <gcr/gcr.h>
#include <glib/gi18n.h>
-#include <libsoup/soup.h>
/**
* SECTION:ephy-certificate-dialog
@@ -63,11 +62,10 @@ static void
ephy_certificate_dialog_set_address (EphyCertificateDialog *dialog,
const char *address)
{
- SoupURI *uri;
+ g_autoptr (GUri) uri = NULL;
- uri = soup_uri_new (address);
- gtk_window_set_title (GTK_WINDOW (dialog), uri->host);
- soup_uri_free (uri);
+ uri = g_uri_parse (address, G_URI_FLAGS_NONE, NULL);
+ gtk_window_set_title (GTK_WINDOW (dialog), g_uri_get_host (uri));
}
static void
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 1141b04ae..341c1402b 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -41,7 +41,6 @@
#include <gdk/gdkkeysyms.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <libsoup/soup.h>
#include <string.h>
#include <webkit2/webkit2.h>
@@ -1130,14 +1129,14 @@ ephy_location_entry_new (void)
}
typedef struct {
- SoupURI *uri;
+ GUri *uri;
EphyLocationEntry *entry;
} PrefetchHelper;
static void
free_prefetch_helper (PrefetchHelper *helper)
{
- soup_uri_free (helper->uri);
+ g_uri_unref (helper->uri);
g_object_unref (helper->entry);
g_free (helper);
}
@@ -1148,7 +1147,7 @@ do_dns_prefetch (PrefetchHelper *helper)
EphyEmbedShell *shell = ephy_embed_shell_get_default ();
if (helper->uri)
- webkit_web_context_prefetch_dns (ephy_embed_shell_get_web_context (shell), helper->uri->host);
+ webkit_web_context_prefetch_dns (ephy_embed_shell_get_web_context (shell), g_uri_get_host (helper->uri));
helper->entry->dns_prefetch_handle_id = 0;
@@ -1196,20 +1195,18 @@ schedule_dns_prefetch (EphyLocationEntry *entry,
{
GProxyResolver *resolver = g_proxy_resolver_get_default ();
PrefetchHelper *helper;
- SoupURI *uri;
+ g_autoptr (GUri) uri = NULL;
if (resolver == NULL)
return;
- uri = soup_uri_new (url);
- if (!uri || !uri->host) {
- soup_uri_free (uri);
+ uri = g_uri_parse (url, G_URI_FLAGS_NONE, NULL);
+ if (!uri || !g_uri_get_host (uri))
return;
- }
helper = g_new0 (PrefetchHelper, 1);
helper->entry = g_object_ref (entry);
- helper->uri = uri;
+ helper->uri = g_steal_pointer (&uri);
g_proxy_resolver_lookup_async (resolver, url, NULL, proxy_resolver_ready_cb, helper);
}
diff --git a/lib/widgets/ephy-security-popover.c b/lib/widgets/ephy-security-popover.c
index 627477755..115261840 100644
--- a/lib/widgets/ephy-security-popover.c
+++ b/lib/widgets/ephy-security-popover.c
@@ -22,7 +22,6 @@
#include "ephy-security-popover.h"
#include <glib/gi18n.h>
-#include <libsoup/soup.h>
#include "ephy-certificate-dialog.h"
#include "ephy-embed-shell.h"
@@ -131,19 +130,17 @@ ephy_security_popover_set_address (EphySecurityPopover *popover,
const char *address)
{
EphyPermissionsManager *permissions_manager;
- SoupURI *uri;
+ g_autoptr (GUri) uri = NULL;
g_autofree gchar *origin = NULL;
g_autofree gchar *uri_text = NULL;
- uri = soup_uri_new (address);
- uri_text = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>", uri->host);
+ uri = g_uri_parse (address, G_URI_FLAGS_NONE, NULL);
+ uri_text = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>", g_uri_get_host (uri));
/* Label when clicking the lock icon on a secure page. %s is the website's hostname. */
gtk_label_set_markup (GTK_LABEL (popover->host_label), uri_text);
popover->address = g_strdup (address);
- popover->hostname = g_strdup (uri->host);
-
- soup_uri_free (uri);
+ popover->hostname = g_strdup (g_uri_get_host (uri));
origin = ephy_uri_to_security_origin (address);
if (!origin)
diff --git a/meson.build b/meson.build
index 42581605f..0adf8f4f2 100644
--- a/meson.build
+++ b/meson.build
@@ -72,7 +72,7 @@ gsb_api_key = get_option('gsb_api_key')
conf.set_quoted('GSB_API_KEY', gsb_api_key)
conf.set10('ENABLE_GSB', gsb_api_key != '')
-glib_requirement = '>= 2.64.0'
+glib_requirement = '>= 2.67.1'
gtk_requirement = '>= 3.24.0'
nettle_requirement = '>= 3.4'
webkitgtk_requirement = '>= 2.31.1'
diff --git a/src/ephy-session.c b/src/ephy-session.c
index 544b4200a..aa74687df 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -857,7 +857,7 @@ session_seems_sane (GList *windows)
for (GList *w = windows; w != NULL; w = w->next) {
for (GList *t = ((SessionWindow *)w->data)->tabs; t != NULL; t = t->next) {
const char *url = ((SessionTab *)t->data)->url;
- SoupURI *uri;
+ g_autoptr (GUri) uri = NULL;
gboolean sane = FALSE;
/* NULL URLs are possible when an invalid URL is opened by JS.
@@ -876,15 +876,14 @@ session_seems_sane (GList *windows)
if (g_str_has_prefix (url, "about:"))
continue;
- uri = soup_uri_new (url);
+ uri = g_uri_parse (url, G_URI_FLAGS_NONE, NULL);
if (uri) {
- if (uri->host != NULL ||
- uri->scheme == SOUP_URI_SCHEME_DATA ||
- uri->scheme == SOUP_URI_SCHEME_FILE ||
- strcmp (uri->scheme, "ephy-reader") == 0 ||
- strcmp (uri->scheme, "ephy-pdf") == 0)
+ if (g_uri_get_host (uri) != NULL ||
+ strcmp (g_uri_get_scheme (uri), "data") == 0 ||
+ strcmp (g_uri_get_scheme (uri), "file") == 0 ||
+ strcmp (g_uri_get_scheme (uri), "ephy-reader") == 0 ||
+ strcmp (g_uri_get_scheme (uri), "ephy-pdf") == 0)
sane = TRUE;
- soup_uri_free (uri);
}
if (!sane) {
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index d8948e7f6..edc465491 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -376,17 +376,17 @@ add_search_engines (EphySuggestionModel *self,
g_autofree char *address = NULL;
g_autofree char *escaped_title = NULL;
g_autofree char *markup = NULL;
- g_autoptr (SoupURI) uri = NULL;
+ g_autoptr (GUri) uri = NULL;
address = ephy_search_engine_manager_build_search_address (manager, engines[i], query);
escaped_title = g_markup_escape_text (engines[i], -1);
markup = dzl_fuzzy_highlight (escaped_title, query, FALSE);
suggestion = ephy_suggestion_new (markup, engines[i], address);
- uri = soup_uri_new (address);
+ uri = g_uri_parse (address, G_URI_FLAGS_NONE, NULL);
if (uri) {
g_free (address);
- address = g_strdup_printf ("%s://%s/", soup_uri_get_scheme (uri), soup_uri_get_host (uri));
+ address = g_strdup_printf ("%s://%s/", g_uri_get_scheme (uri), g_uri_get_host (uri));
}
load_favicon (self, suggestion, address);
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 0531adb15..d954b93d8 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -68,7 +68,6 @@
#include <gio/gio.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <libsoup/soup.h>
#include <stdlib.h>
#include <webkit2/webkit2.h>
@@ -1585,8 +1584,7 @@ populate_context_menu (WebKitWebView *web_view,
parse_context_menu_user_data (context_menu, &selected_text);
if (selected_text) {
- SoupURI *uri = soup_uri_new (selected_text);
- if (uri) {
+ if (g_uri_is_valid (selected_text, G_URI_FLAGS_NONE, NULL)) {
GVariant *value;
value = g_variant_new_string (selected_text);
@@ -1594,8 +1592,6 @@ populate_context_menu (WebKitWebView *web_view,
value);
g_variant_unref (value);
can_open_selection = TRUE;
-
- soup_uri_free (uri);
} else {
GVariant *value;
@@ -2122,10 +2118,10 @@ decide_navigation_policy (WebKitWebView *web_view,
uri = webkit_uri_request_get_uri (request);
if (!ephy_embed_utils_address_has_web_scheme (uri)) {
- g_autoptr (SoupURI) soup_uri = soup_uri_new (uri);
+ const char *scheme = g_uri_peek_scheme (uri);
- if (soup_uri) {
- g_autoptr (GAppInfo) app_info = g_app_info_get_default_for_uri_scheme (soup_uri->scheme);
+ if (scheme) {
+ g_autoptr (GAppInfo) app_info = g_app_info_get_default_for_uri_scheme (scheme);
if (app_info && !g_str_has_prefix (g_app_info_get_id (app_info), "org.gnome.Epiphany")) {
g_autoptr (GError) error = NULL;
diff --git a/src/preferences/ephy-search-engine-row.c b/src/preferences/ephy-search-engine-row.c
index f4432bbce..7ceeac2d1 100644
--- a/src/preferences/ephy-search-engine-row.c
+++ b/src/preferences/ephy-search-engine-row.c
@@ -23,7 +23,6 @@
#include <glib/gi18n.h>
#include <gmodule.h>
-#include <libsoup/soup.h>
#include "ephy-search-engine-listbox.h"
#include "ephy-search-engine-manager.h"
@@ -192,8 +191,7 @@ static gboolean
validate_search_engine_address (const char *address,
const char **error_message)
{
- g_autoptr (SoupURI) soup_uri = NULL;
- g_autofree char *path_and_query = NULL;
+ g_autoptr (GUri) uri = NULL;
if (g_strcmp0 (address, "") == 0) {
*error_message = _("This field is required");
@@ -205,21 +203,18 @@ validate_search_engine_address (const char *address,
return FALSE;
}
- soup_uri = soup_uri_new (address);
- if (!soup_uri) {
+ uri = g_uri_parse (address, G_URI_FLAGS_NONE, NULL);
+ if (!uri) {
*error_message = _("Address is not a valid URI");
return FALSE;
}
- if (!SOUP_URI_VALID_FOR_HTTP (soup_uri) ||
- /* It seems you can dodge the first condition. When we have URI "http:///", without the host part,
libsoup fills the host part with "" but SOUP_URI_VALID_FOR_HTTP checks for non-NULL host, not empty host.
This line fixes it. */
- g_strcmp0 (soup_uri->host, "") == 0) {
+ if (!g_uri_get_host (uri) || g_strcmp0 (g_uri_get_host (uri), "") == 0) {
*error_message = _("Address is not a valid URL. The address should look like
https://www.example.com/search?q=%s");
return FALSE;
}
- path_and_query = soup_uri_to_string (soup_uri, TRUE);
- if (!strstr (path_and_query, "%s")) {
+ if (!g_uri_get_query (uri) || !strstr (g_uri_get_query (uri), "%s")) {
*error_message = _("Address must contain the search term represented by %s");
return FALSE;
}
diff --git a/src/window-commands.c b/src/window-commands.c
index 8353008a9..b552d738d 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -62,7 +62,6 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <libsoup/soup.h>
#include <string.h>
#include <webkit2/webkit2.h>
@@ -1643,11 +1642,11 @@ set_default_application_title (EphyApplicationDialogData *data,
char *title)
{
if (title == NULL || title[0] == '\0') {
- SoupURI *uri;
+ g_autoptr (GUri) uri = NULL;
const char *host;
- uri = soup_uri_new (webkit_web_view_get_uri (WEBKIT_WEB_VIEW (data->view)));
- host = soup_uri_get_host (uri);
+ uri = g_uri_parse (webkit_web_view_get_uri (WEBKIT_WEB_VIEW (data->view)), G_URI_FLAGS_NONE, NULL);
+ host = g_uri_get_host (uri);
if (host != NULL && host[0] != '\0') {
title = get_special_case_application_title_for_host (host);
@@ -1659,8 +1658,6 @@ set_default_application_title (EphyApplicationDialogData *data,
title = g_strdup (host);
}
}
-
- soup_uri_free (uri);
}
if (title == NULL || title[0] == '\0') {
@@ -1957,36 +1954,35 @@ static char *
get_suggested_filename (EphyEmbed *embed)
{
EphyWebView *view;
- char *suggested_filename = NULL;
+ const char *suggested_filename;
const char *mimetype;
WebKitURIResponse *response;
WebKitWebResource *web_resource;
- SoupURI *soup_uri;
+ g_autoptr (GUri) uri = NULL;
view = ephy_embed_get_web_view (embed);
web_resource = webkit_web_view_get_main_resource (WEBKIT_WEB_VIEW (view));
response = webkit_web_resource_get_response (web_resource);
mimetype = webkit_uri_response_get_mime_type (response);
- soup_uri = soup_uri_new (webkit_web_resource_get_uri (web_resource));
+ uri = g_uri_parse (webkit_web_resource_get_uri (web_resource), G_URI_FLAGS_SCHEME_NORMALIZE, NULL);
- if (g_ascii_strncasecmp (mimetype, "text/html", 9) == 0 && g_strcmp0 (soup_uri_get_scheme (soup_uri),
EPHY_VIEW_SOURCE_SCHEME) != 0) {
+ if (g_ascii_strncasecmp (mimetype, "text/html", 9) == 0 && g_strcmp0 (g_uri_get_scheme (uri),
EPHY_VIEW_SOURCE_SCHEME) != 0) {
/* Web Title will be used as suggested filename */
- suggested_filename = g_strconcat (ephy_embed_get_title (embed), ".mhtml", NULL);
- } else {
- suggested_filename = g_strdup (webkit_uri_response_get_suggested_filename (response));
- if (!suggested_filename) {
- char *last_slash = strrchr (soup_uri->path, '/');
- suggested_filename = soup_uri_decode (last_slash ? (last_slash + 1) : soup_uri->path);
-
- if (!strlen (suggested_filename)) {
- g_free (suggested_filename);
- suggested_filename = g_strdup ("index.html");
- }
- }
+ return g_strconcat (ephy_embed_get_title (embed), ".mhtml", NULL);
}
- soup_uri_free (soup_uri);
- return suggested_filename;
+ suggested_filename = webkit_uri_response_get_suggested_filename (response);
+ if (!suggested_filename) {
+ const char *path = g_uri_get_path (uri);
+ char *last_slash = strrchr (path, '/');
+ if (last_slash)
+ path = last_slash + 1;
+
+ if (path[0] != '\0')
+ return g_strdup (path);
+ }
+
+ return suggested_filename ? g_strdup (suggested_filename) : g_strdup ("index.html");
}
@@ -2421,10 +2417,10 @@ window_cmd_page_source (GSimpleAction *action,
EphyWindow *window = user_data;
EphyEmbed *embed;
EphyEmbed *new_embed;
- SoupURI *soup_uri;
+ g_autoptr (GUri) uri = NULL;
+ g_autoptr (GUri) converted_uri = NULL;
char *source_uri;
const char *address;
- guint port;
embed = ephy_embed_container_get_active_child
(EPHY_EMBED_CONTAINER (window));
@@ -2436,20 +2432,22 @@ window_cmd_page_source (GSimpleAction *action,
if (strstr (address, EPHY_VIEW_SOURCE_SCHEME) == address)
return;
- soup_uri = soup_uri_new (address);
- if (!soup_uri) {
- g_critical ("Failed to construct SoupURI for %s", address);
+ uri = g_uri_parse (address, G_URI_FLAGS_ENCODED | G_URI_FLAGS_SCHEME_NORMALIZE, NULL);
+ if (!uri) {
+ g_critical ("Failed to construct GUri for %s", address);
return;
}
- /* Convert e.g. https://gnome.org to ephy-source://gnome.org#https,
- * taking care to prevent soup_uri_set_scheme() from forcing the default port.
- */
- port = soup_uri_get_port (soup_uri);
- soup_uri_set_fragment (soup_uri, soup_uri->scheme);
- soup_uri_set_scheme (soup_uri, EPHY_VIEW_SOURCE_SCHEME);
- soup_uri_set_port (soup_uri, port);
- source_uri = soup_uri_to_string (soup_uri, FALSE);
+ /* Convert e.g. https://gnome.org to ephy-source://gnome.org#https */
+ converted_uri = g_uri_build (g_uri_get_flags (uri),
+ EPHY_VIEW_SOURCE_SCHEME,
+ g_uri_get_userinfo (uri),
+ g_uri_get_host (uri),
+ g_uri_get_port (uri),
+ g_uri_get_path (uri),
+ g_uri_get_query (uri),
+ g_uri_get_scheme (uri));
+ source_uri = g_uri_to_string (converted_uri);
new_embed = ephy_shell_new_tab
(ephy_shell_get_default (),
@@ -2461,7 +2459,6 @@ window_cmd_page_source (GSimpleAction *action,
gtk_widget_grab_focus (GTK_WIDGET (new_embed));
g_free (source_uri);
- soup_uri_free (soup_uri);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]