Introduce and use Midori.URI.is_http

Also make further uses of Midori.URI.parse.
This commit is contained in:
Christian Dywan 2011-10-28 22:47:17 +02:00
parent 8f540b3d86
commit be04be8303
8 changed files with 20 additions and 17 deletions

View file

@ -248,7 +248,7 @@ adblock_preferences_renderer_toggle_toggled_cb (GtkCellRendererToggle* renderer,
ADBLOCK_FILTER_SET (filter, TRUE); ADBLOCK_FILTER_SET (filter, TRUE);
if (gtk_cell_renderer_toggle_get_active (renderer)) 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); gchar* filename = adblock_get_filename_for_uri (filter);
g_unlink (filename); g_unlink (filename);
@ -757,7 +757,7 @@ adblock_resource_request_starting_cb (WebKitWebView* web_view,
page_uri = webkit_web_view_get_uri (web_view); page_uri = webkit_web_view_get_uri (web_view);
/* Skip checks on about: pages */ /* Skip checks on about: pages */
if (!(page_uri && *page_uri) || !strncmp (page_uri, "about:", 6)) if (midori_uri_is_blank (page_uri))
return; return;
/* Never filter the main page itself */ /* 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); page_uri = webkit_web_view_get_uri (web_view);
/* Don't add adblock css into speeddial and about: pages */ /* 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; return;
g_free (sokoke_js_script_eval (js_context, blockscript, NULL)); g_free (sokoke_js_script_eval (js_context, blockscript, NULL));

View file

@ -38,7 +38,7 @@ colorful_tabs_view_notify_uri_cb (MidoriView* view,
MidoriExtension* extension) MidoriExtension* extension)
{ {
GtkWidget* label; GtkWidget* label;
SoupURI* uri; gchar* hostname;
gchar* colorstr; gchar* colorstr;
GdkColor color; GdkColor color;
GdkColor fgcolor; GdkColor fgcolor;
@ -46,8 +46,8 @@ colorful_tabs_view_notify_uri_cb (MidoriView* view,
label = midori_view_get_proxy_tab_label (view); label = midori_view_get_proxy_tab_label (view);
if ((uri = soup_uri_new (midori_view_get_display_uri (view))) if ((hostname = midori_uri_parse (midori_view_get_display_uri (view), NULL))
&& uri->host && (katze_object_get_enum (view, "load-status") == MIDORI_LOAD_FINISHED)) && katze_object_get_enum (view, "load-status") == MIDORI_LOAD_FINISHED)
{ {
icon = midori_view_get_icon (view); icon = midori_view_get_icon (view);
@ -65,13 +65,13 @@ colorful_tabs_view_notify_uri_cb (MidoriView* view,
} }
else 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); colorstr = g_strndup (hash, 6 + 1);
g_free (hash); g_free (hash);
colorstr[0] = '#'; colorstr[0] = '#';
gdk_color_parse (colorstr, &color); gdk_color_parse (colorstr, &color);
} }
soup_uri_free (uri); g_free (hostname);
if ((color.red < 35000) if ((color.red < 35000)
&& (color.green < 35000) && (color.green < 35000)

View file

@ -354,7 +354,7 @@ web_cache_session_request_queued_cb (SoupSession* session,
SoupURI* soup_uri = soup_message_get_uri (msg); SoupURI* soup_uri = soup_message_get_uri (msg);
gchar* uri = soup_uri_to_string (soup_uri, FALSE); 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); gchar* filename = web_cache_get_cached_path (extension, uri);
GHashTable* cache_headers; GHashTable* cache_headers;

View file

@ -18,6 +18,7 @@
#endif #endif
#include "katze-net.h" #include "katze-net.h"
#include "midori-core.h"
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <libsoup/soup.h> #include <libsoup/soup.h>
@ -283,7 +284,7 @@ katze_net_load_uri (KatzeNet* net,
priv->user_data = user_data; priv->user_data = user_data;
priv->request = request; 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); msg = soup_message_new ("GET", uri);
if (status_cb) if (status_cb)

View file

@ -1472,7 +1472,7 @@ katze_load_cached_icon (const gchar* uri,
g_return_val_if_fail (uri != NULL, NULL); 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; guint i;
gchar* icon_uri; gchar* icon_uri;

View file

@ -88,11 +88,14 @@ namespace Midori {
public static bool is_blank (string? uri) { public static bool is_blank (string? uri) {
return !(uri != null && uri != "" && !uri.has_prefix ("about:")); 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) { public static bool is_resource (string? uri) {
return uri != null return uri != null
&& (uri.has_prefix ("http://") && (is_http (uri)
|| (uri.has_prefix ("data:") && uri.chr (-1, ';') != null) || (uri.has_prefix ("data:") && uri.chr (-1, ';') != null));
|| uri.has_prefix ("https://"));
} }
public static bool is_location (string? uri) { public static bool is_location (string? uri) {
/* file:// is not considered a location for security reasons */ /* file:// is not considered a location for security reasons */

View file

@ -870,7 +870,7 @@ midori_soup_session_set_proxy_uri (SoupSession* session,
SoupURI* proxy_uri; SoupURI* proxy_uri;
/* soup_uri_new expects a non-NULL string with a protocol */ /* 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); proxy_uri = soup_uri_new (uri);
else if (uri && *uri) else if (uri && *uri)
{ {

View file

@ -894,8 +894,7 @@ _midori_web_view_load_icon (MidoriView* view)
pixbuf = NULL; pixbuf = NULL;
icon_uri = g_strdup (view->icon_uri); icon_uri = g_strdup (view->icon_uri);
if ((icon_uri && g_str_has_prefix (icon_uri, "http")) if (midori_uri_is_http (icon_uri) || midori_uri_is_http (view->uri))
|| (view->uri && g_str_has_prefix (view->uri, "http")))
{ {
if (!icon_uri) if (!icon_uri)
{ {