]> git.armaanb.net Git - chorizo.git/commitdiff
Auto-add "http://" when typed in location bar
authorPeter Hofmann <scm@uninformativ.de>
Sun, 15 Jun 2014 10:14:08 +0000 (12:14 +0200)
committerPeter Hofmann <scm@uninformativ.de>
Sun, 15 Jun 2014 10:15:12 +0000 (12:15 +0200)
browser.c

index 094fe65a2a2c96d472c289d15d69e7f4b608db07..2eacb55649209b212a8d05b4082d6ce3f5e5c1b6 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -34,6 +34,7 @@ static gboolean download_request(WebKitWebView *, WebKitWebFrame *,
                                  WebKitNetworkRequest *, gchar *,
                                  WebKitWebPolicyDecision *, gpointer);
 static gboolean download_wget(WebKitWebView *, WebKitDownload *, gpointer);
+static gchar *ensure_http_prefix(const gchar *);
 static void hover_web_view(WebKitWebView *, gchar *, gchar *, gpointer);
 static gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
 static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
@@ -419,6 +420,23 @@ download_wget(WebKitWebView *web_view, WebKitDownload *download, gpointer data)
        return FALSE;
 }
 
+gchar *
+ensure_http_prefix(const gchar *t)
+{
+       gchar *f;
+
+       f = g_ascii_strdown(t, -1);
+       if (!g_str_has_prefix(f, "http://") &&
+               !g_str_has_prefix(f, "https://"))
+       {
+               g_free(f);
+               f = g_strdup_printf("http://%s", t);
+               return f;
+       }
+       else
+               return g_strdup(t);
+}
+
 void
 hover_web_view(WebKitWebView *web_view, gchar *title, gchar *uri,
                    gpointer data)
@@ -438,6 +456,7 @@ key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
        struct Client *c = (struct Client *)data;
        const gchar *t;
+       gchar *f;
 
        (void)widget;
 
@@ -456,7 +475,11 @@ key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
                                        search(c, 1);
                                }
                                else
-                                       webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), t);
+                               {
+                                       f = ensure_http_prefix(t);
+                                       webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
+                                       g_free(f);
+                               }
                                return TRUE;
                        case GDK_KEY_Escape:
                                t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));