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);
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));

View file

@ -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)

View file

@ -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;

View file

@ -18,6 +18,7 @@
#endif
#include "katze-net.h"
#include "midori-core.h"
#include <glib/gstdio.h>
#include <libsoup/soup.h>
@ -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)

View file

@ -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;

View file

@ -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 */

View file

@ -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)
{

View file

@ -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)
{