From be04be83034e0ac0125f75b7122a2d57430b053d Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Fri, 28 Oct 2011 22:47:17 +0200 Subject: [PATCH] Introduce and use Midori.URI.is_http Also make further uses of Midori.URI.parse. --- extensions/adblock.c | 6 +++--- extensions/colorful-tabs.c | 10 +++++----- extensions/web-cache.c | 2 +- katze/katze-net.c | 3 ++- katze/katze-utils.c | 2 +- katze/midori-uri.vala | 9 ++++++--- midori/main.c | 2 +- midori/midori-view.c | 3 +-- 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/extensions/adblock.c b/extensions/adblock.c index 6e8b3f7f..c76ddba7 100644 --- a/extensions/adblock.c +++ b/extensions/adblock.c @@ -248,7 +248,7 @@ adblock_preferences_renderer_toggle_toggled_cb (GtkCellRendererToggle* renderer, ADBLOCK_FILTER_SET (filter, TRUE); if (gtk_cell_renderer_toggle_get_active (renderer)) { - if (!strncmp (filter, "http", 4)) + if (midori_uri_is_http (filter)) { gchar* filename = adblock_get_filename_for_uri (filter); g_unlink (filename); @@ -757,7 +757,7 @@ adblock_resource_request_starting_cb (WebKitWebView* web_view, page_uri = webkit_web_view_get_uri (web_view); /* Skip checks on about: pages */ - if (!(page_uri && *page_uri) || !strncmp (page_uri, "about:", 6)) + if (midori_uri_is_blank (page_uri)) return; /* Never filter the main page itself */ @@ -935,7 +935,7 @@ adblock_window_object_cleared_cb (WebKitWebView* web_view, page_uri = webkit_web_view_get_uri (web_view); /* Don't add adblock css into speeddial and about: pages */ - if (!(page_uri && *page_uri) || !strncmp (page_uri, "about:", 6)) + if (midori_uri_is_blank (page_uri)) return; g_free (sokoke_js_script_eval (js_context, blockscript, NULL)); diff --git a/extensions/colorful-tabs.c b/extensions/colorful-tabs.c index f8a47fb1..672797e6 100644 --- a/extensions/colorful-tabs.c +++ b/extensions/colorful-tabs.c @@ -38,7 +38,7 @@ colorful_tabs_view_notify_uri_cb (MidoriView* view, MidoriExtension* extension) { GtkWidget* label; - SoupURI* uri; + gchar* hostname; gchar* colorstr; GdkColor color; GdkColor fgcolor; @@ -46,8 +46,8 @@ colorful_tabs_view_notify_uri_cb (MidoriView* view, label = midori_view_get_proxy_tab_label (view); - if ((uri = soup_uri_new (midori_view_get_display_uri (view))) - && uri->host && (katze_object_get_enum (view, "load-status") == MIDORI_LOAD_FINISHED)) + if ((hostname = midori_uri_parse (midori_view_get_display_uri (view), NULL)) + && katze_object_get_enum (view, "load-status") == MIDORI_LOAD_FINISHED) { icon = midori_view_get_icon (view); @@ -65,13 +65,13 @@ colorful_tabs_view_notify_uri_cb (MidoriView* view, } else { - gchar* hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri->host, 1); + gchar* hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, hostname, 1); colorstr = g_strndup (hash, 6 + 1); g_free (hash); colorstr[0] = '#'; gdk_color_parse (colorstr, &color); } - soup_uri_free (uri); + g_free (hostname); if ((color.red < 35000) && (color.green < 35000) diff --git a/extensions/web-cache.c b/extensions/web-cache.c index b038db8f..1980d53d 100644 --- a/extensions/web-cache.c +++ b/extensions/web-cache.c @@ -354,7 +354,7 @@ web_cache_session_request_queued_cb (SoupSession* session, SoupURI* soup_uri = soup_message_get_uri (msg); gchar* uri = soup_uri_to_string (soup_uri, FALSE); - if (uri && g_str_has_prefix (uri, "http") && !g_strcmp0 (msg->method, "GET")) + if (midori_uri_is_http (uri) && !g_strcmp0 (msg->method, "GET")) { gchar* filename = web_cache_get_cached_path (extension, uri); GHashTable* cache_headers; diff --git a/katze/katze-net.c b/katze/katze-net.c index 6bb457eb..f873d08c 100644 --- a/katze/katze-net.c +++ b/katze/katze-net.c @@ -18,6 +18,7 @@ #endif #include "katze-net.h" +#include "midori-core.h" #include #include @@ -283,7 +284,7 @@ katze_net_load_uri (KatzeNet* net, priv->user_data = user_data; priv->request = request; - if (g_str_has_prefix (uri, "http://") || g_str_has_prefix (uri, "https://")) + if (midori_uri_is_http (uri)) { msg = soup_message_new ("GET", uri); if (status_cb) diff --git a/katze/katze-utils.c b/katze/katze-utils.c index 687b728c..27b2e471 100644 --- a/katze/katze-utils.c +++ b/katze/katze-utils.c @@ -1472,7 +1472,7 @@ katze_load_cached_icon (const gchar* uri, g_return_val_if_fail (uri != NULL, NULL); - if (g_str_has_prefix (uri, "http://") || g_str_has_prefix (uri,"https://")) + if (midori_uri_is_http (uri)) { guint i; gchar* icon_uri; diff --git a/katze/midori-uri.vala b/katze/midori-uri.vala index 2653fbc5..b8cfc626 100644 --- a/katze/midori-uri.vala +++ b/katze/midori-uri.vala @@ -88,11 +88,14 @@ namespace Midori { public static bool is_blank (string? uri) { return !(uri != null && uri != "" && !uri.has_prefix ("about:")); } + public static bool is_http (string? uri) { + return uri != null + && (uri.has_prefix ("http://") || uri.has_prefix ("https://")); + } public static bool is_resource (string? uri) { return uri != null - && (uri.has_prefix ("http://") - || (uri.has_prefix ("data:") && uri.chr (-1, ';') != null) - || uri.has_prefix ("https://")); + && (is_http (uri) + || (uri.has_prefix ("data:") && uri.chr (-1, ';') != null)); } public static bool is_location (string? uri) { /* file:// is not considered a location for security reasons */ diff --git a/midori/main.c b/midori/main.c index 615b324b..81dabd2e 100644 --- a/midori/main.c +++ b/midori/main.c @@ -870,7 +870,7 @@ midori_soup_session_set_proxy_uri (SoupSession* session, SoupURI* proxy_uri; /* soup_uri_new expects a non-NULL string with a protocol */ - if (uri && g_str_has_prefix (uri, "http://")) + if (midori_uri_is_http (uri)) proxy_uri = soup_uri_new (uri); else if (uri && *uri) { diff --git a/midori/midori-view.c b/midori/midori-view.c index ae3c727d..413fdf53 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -894,8 +894,7 @@ _midori_web_view_load_icon (MidoriView* view) pixbuf = NULL; icon_uri = g_strdup (view->icon_uri); - if ((icon_uri && g_str_has_prefix (icon_uri, "http")) - || (view->uri && g_str_has_prefix (view->uri, "http"))) + if (midori_uri_is_http (icon_uri) || midori_uri_is_http (view->uri)) { if (!icon_uri) { -- 2.39.5