]> git.armaanb.net Git - chorizo.git/blobdiff - browser.c
Completely remove adblock for now
[chorizo.git] / browser.c
index 4d6ea04b82e92205e0c99f89ba08410a405e15d2..b625bac8a781fed4d472db89894c98cce116f31d 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -6,35 +6,30 @@
 #include <string.h>
 
 #include <gtk/gtk.h>
-#include <gdk/gdkx.h>
+#include <gtk/gtkx.h>
 #include <gdk/gdkkeysyms.h>
 #include <gio/gio.h>
-#include <webkit/webkit.h>
+#include <webkit2/webkit2.h>
 
 
-static void adblock(WebKitWebView *, WebKitWebFrame *, WebKitWebResource *,
-                    WebKitNetworkRequest *, WebKitNetworkResponse *, gpointer);
-static void adblock_load(void);
-static void client_destroy(GtkWidget *obj, gpointer data);
+static void client_destroy(GtkWidget *, gpointer);
 static gboolean client_destroy_request(WebKitWebView *, gpointer);
-static WebKitWebView *client_new(const gchar *uri);
-static WebKitWebView *client_new_request(WebKitWebView *, WebKitWebFrame *,
+static WebKitWebView *client_new(const gchar *);
+static WebKitWebView *client_new_request(WebKitWebView *, WebKitNavigationAction *,
                                          gpointer);
 static void cooperation_setup(void);
-static void changed_load_progress(GObject *obj, GParamSpec *pspec,
-                                  gpointer data);
+static void changed_download_progress(GObject *, GParamSpec *, gpointer);
+static void changed_load_progress(GObject *, GParamSpec *, gpointer);
 static void changed_title(GObject *, GParamSpec *, gpointer);
 static void changed_uri(GObject *, GParamSpec *, gpointer);
-static gboolean download_handle(WebKitWebView *, WebKitDownload *, gpointer);
+static gboolean decide_policy(WebKitWebView *, WebKitPolicyDecision *,
+                              WebKitPolicyDecisionType, gpointer);
+static gboolean download_handle(WebKitDownload *, gchar *, gpointer);
+static void download_handle_start(WebKitWebView *, WebKitDownload *, gpointer);
 static gboolean download_reset_indicator(gpointer);
-static gboolean download_request(WebKitWebView *, WebKitWebFrame *,
-                                 WebKitNetworkRequest *, gchar *,
-                                 WebKitWebPolicyDecision *, gpointer);
 static void downloadmanager_cancel(GtkToolButton *, gpointer data);
-static void downloadmanager_progress(GObject *obj, GParamSpec *pspec,
-                                     gpointer data);
 static void downloadmanager_setup(void);
-static gchar *ensure_url_scheme(const gchar *);
+static gchar *ensure_uri_scheme(const gchar *);
 static void grab_environment_configuration(void);
 static void hover_web_view(WebKitWebView *, gchar *, gchar *, gpointer);
 static gboolean key_downloadmanager(GtkWidget *, GdkEvent *, gpointer);
@@ -69,7 +64,6 @@ struct DownloadManager
 
 
 static gchar *accepted_language = "en-US";
-static GSList *adblock_patterns = NULL;
 static gint clients = 0;
 static gboolean cooperative_alone = TRUE;
 static gboolean cooperative_instances = TRUE;
@@ -77,88 +71,27 @@ static int cooperative_pipe_fp = 0;
 static gchar *download_dir = "/tmp";
 static gint downloads_indicated = 0;
 static Window embed = 0;
-static gchar *first_uri = NULL;
+static gchar *fifo_suffix = "main";
 static gdouble global_zoom = 1.0;
+static gchar *home_uri = "about:blank";
 static GHashTable *keywords = NULL;
 static gboolean language_is_set = FALSE;
 static gchar *search_text = NULL;
 static gboolean show_all_requests = FALSE;
 static gboolean tabbed_automagic = TRUE;
+static gchar *user_agent = "Mozilla/5.0 (X11; U; Unix; en-US) "
+                           "AppleWebKit/537.15 (KHTML, like Gecko) "
+                           "Chrome/24.0.1295.0 "
+                           "Safari/537.15 "__NAME_CAPITALIZED__"/git";
 
 
-void
-adblock(WebKitWebView *web_view, WebKitWebFrame *frame,
-        WebKitWebResource *resource, WebKitNetworkRequest *request,
-        WebKitNetworkResponse *response, gpointer data)
-{
-       GSList *it = adblock_patterns;
-       const gchar *uri;
-
-       (void)web_view;
-       (void)frame;
-       (void)resource;
-       (void)response;
-       (void)data;
-
-       uri = webkit_network_request_get_uri(request);
-       if (show_all_requests)
-               fprintf(stderr, "   -> %s\n", uri);
-
-       while (it)
-       {
-               if (g_regex_match((GRegex *)(it->data), uri, 0, NULL))
-               {
-                       webkit_network_request_set_uri(request, "about:blank");
-                       if (show_all_requests)
-                               fprintf(stderr, "            BLOCKED!\n");
-                       return;
-               }
-               it = g_slist_next(it);
-       }
-}
-
-void
-adblock_load(void)
-{
-       GRegex *re = NULL;
-       GError *err = NULL;
-       GIOChannel *channel = NULL;
-       gchar *path = NULL, *buf = NULL;
-
-       path = g_build_filename(g_get_user_config_dir(), __NAME__, "adblock.black",
-                               NULL);
-       channel = g_io_channel_new_file(path, "r", &err);
-       if (channel != NULL)
-       {
-               while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
-                      == G_IO_STATUS_NORMAL)
-               {
-                       g_strstrip(buf);
-                       re = g_regex_new(buf,
-                                        G_REGEX_CASELESS | G_REGEX_OPTIMIZE,
-                                        G_REGEX_MATCH_PARTIAL, &err);
-                       if (err != NULL)
-                       {
-                               fprintf(stderr, __NAME__": Could not compile regex: %s\n", buf);
-                               g_error_free(err);
-                               err = NULL;
-                       }
-                       adblock_patterns = g_slist_append(adblock_patterns, re);
-
-                       g_free(buf);
-               }
-       }
-       g_io_channel_shutdown(channel, FALSE, NULL);
-       g_free(path);
-}
-
 void
 client_destroy(GtkWidget *obj, gpointer data)
 {
        struct Client *c = (struct Client *)data;
 
-       (void)obj;
-       (void)data;
+       g_signal_handlers_disconnect_by_func(G_OBJECT(c->web_view),
+                                            changed_load_progress, c);
 
        free(c);
        clients--;
@@ -172,8 +105,6 @@ client_destroy_request(WebKitWebView *web_view, gpointer data)
 {
        struct Client *c = (struct Client *)data;
 
-       (void)web_view;
-
        gtk_widget_destroy(c->win);
 
        return TRUE;
@@ -183,6 +114,7 @@ WebKitWebView *
 client_new(const gchar *uri)
 {
        struct Client *c;
+       WebKitWebContext *wc;
        gchar *f;
 
        if (uri != NULL && cooperative_instances && !cooperative_alone)
@@ -218,18 +150,14 @@ client_new(const gchar *uri)
                gtk_window_set_wmclass(GTK_WINDOW(c->win), __NAME__, __NAME_CAPITALIZED__);
        }
 
-       /* When using Gtk2, it only shows a white area when run in suckless'
-        * tabbed. It appears we need to set a default window size for this
-        * to work. This is not needed when using Gtk3. */
-       gtk_window_set_default_size(GTK_WINDOW(c->win), 1024, 768);
-
        g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(client_destroy), c);
        gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
 
        c->web_view = webkit_web_view_new();
+       wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
 
        /* XXX I really do want to enable this option. However, I get
-        * reproducable crashes with it enabled. I've seen bug reports from
+        * reproducible crashes with it enabled. I've seen bug reports from
         * 2010 about this... WebKit crashes in libpixman, so maybe it's not
         * a WebKit issue.
         * Yeah, well. I'll turn it off for now. */
@@ -240,17 +168,16 @@ client_new(const gchar *uri)
                         G_CALLBACK(changed_title), c);
        g_signal_connect(G_OBJECT(c->web_view), "notify::uri",
                         G_CALLBACK(changed_uri), c);
-       g_signal_connect(G_OBJECT(c->web_view), "notify::progress",
+       g_signal_connect(G_OBJECT(c->web_view), "notify::estimated-load-progress",
                         G_CALLBACK(changed_load_progress), c);
-       g_signal_connect(G_OBJECT(c->web_view), "create-web-view",
+       g_signal_connect(G_OBJECT(c->web_view), "create",
                         G_CALLBACK(client_new_request), NULL);
-       g_signal_connect(G_OBJECT(c->web_view), "close-web-view",
+       g_signal_connect(G_OBJECT(c->web_view), "close",
                         G_CALLBACK(client_destroy_request), c);
-       g_signal_connect(G_OBJECT(c->web_view),
-                        "mime-type-policy-decision-requested",
-                        G_CALLBACK(download_request), NULL);
-       g_signal_connect(G_OBJECT(c->web_view), "download-requested",
-                        G_CALLBACK(download_handle), c);
+       g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
+                        G_CALLBACK(decide_policy), NULL);
+       g_signal_connect(G_OBJECT(wc), "download-started",
+                        G_CALLBACK(download_handle_start), c);
        g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
                         G_CALLBACK(key_web_view), c);
        g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
@@ -259,16 +186,22 @@ client_new(const gchar *uri)
                         G_CALLBACK(key_web_view), c);
        g_signal_connect(G_OBJECT(c->web_view), "hovering-over-link",
                         G_CALLBACK(hover_web_view), c);
-       g_signal_connect(G_OBJECT(c->web_view), "resource-request-starting",
-                        G_CALLBACK(adblock), NULL);
 
        if (!language_is_set)
        {
-               g_object_set(webkit_get_default_session(), "accept-language",
-                            accepted_language, NULL);
+               /* XXX make this pretty */
+               const gchar *languages[2];
+               languages[0] = accepted_language;
+               languages[1] = NULL;
+               webkit_web_context_set_preferred_languages(wc, languages);
                language_is_set = TRUE;
        }
 
+       /*
+       g_object_set(G_OBJECT(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view))),
+                    "user-agent", user_agent, NULL);
+                                */
+
        c->scroll = gtk_scrolled_window_new(NULL, NULL);
 
        gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
@@ -277,21 +210,24 @@ client_new(const gchar *uri)
        g_signal_connect(G_OBJECT(c->location), "key-press-event",
                         G_CALLBACK(key_location), c);
 
-       c->progress = gtk_progress_bar_new();
-       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), 0);
+       /* XXX Progress bars don't work/look as intended anymore. Level bars
+        * are a dirty workaround (kind of). */
+       c->progress = gtk_level_bar_new();
+       gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
+       gtk_widget_set_size_request(c->progress, 100, -1);
 
-       c->status = gtk_progress_bar_new();
-       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 0);
+       c->status = gtk_level_bar_new();
+       gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 0);
        gtk_widget_set_size_request(c->status, 20, -1);
 
-       c->top_box = gtk_hbox_new(FALSE, 0);
+       c->top_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
        gtk_box_pack_start(GTK_BOX(c->top_box), c->status, FALSE, FALSE, 2);
        gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 0);
-       gtk_box_pack_end(GTK_BOX(c->top_box), c->progress, FALSE, TRUE, 2);
+       gtk_box_pack_start(GTK_BOX(c->top_box), c->progress, FALSE, FALSE, 2);
 
-       c->vbox = gtk_vbox_new(FALSE, 0);
+       c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
        gtk_box_pack_start(GTK_BOX(c->vbox), c->top_box, FALSE, FALSE, 2);
-       gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
+       gtk_box_pack_start(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 2);
 
        gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
 
@@ -300,7 +236,7 @@ client_new(const gchar *uri)
 
        if (uri != NULL)
        {
-               f = ensure_url_scheme(uri);
+               f = ensure_uri_scheme(uri);
                if (show_all_requests)
                        fprintf(stderr, "====> %s\n", uri);
                webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
@@ -313,12 +249,9 @@ client_new(const gchar *uri)
 }
 
 WebKitWebView *
-client_new_request(WebKitWebView *web_view, WebKitWebFrame *frame, gpointer data)
+client_new_request(WebKitWebView *web_view,
+                   WebKitNavigationAction *navigation_action, gpointer data)
 {
-       (void)web_view;
-       (void)frame;
-       (void)data;
-
        return client_new(NULL);
 }
 
@@ -326,14 +259,9 @@ void
 cooperation_setup(void)
 {
        GIOChannel *towatch;
-       const gchar *e;
        gchar *fifofilename, *fifopath;
 
-       e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
-       if (e != NULL)
-               fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", e);
-       else
-               fifofilename = g_strdup(__NAME__".fifo");
+       fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", fifo_suffix);
        fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
        g_free(fifofilename);
 
@@ -362,17 +290,49 @@ cooperation_setup(void)
        g_free(fifopath);
 }
 
+void
+changed_download_progress(GObject *obj, GParamSpec *pspec, gpointer data)
+{
+       WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
+       WebKitURIResponse *resp;
+       GtkToolItem *tb = GTK_TOOL_ITEM(data);
+       gdouble p, size_mb;
+       const gchar *uri;
+       gchar *t, *filename, *base;
+
+       p = webkit_download_get_estimated_progress(download) * 100;
+       resp = webkit_download_get_response(download);
+       size_mb = webkit_uri_response_get_content_length(resp) / 1e6;
+
+       uri = webkit_download_get_destination(download);
+       filename = g_filename_from_uri(uri, NULL, NULL);
+       if (filename == NULL)
+       {
+               /* This really should not happen because WebKit uses that URI to
+                * write to a file... */
+               fprintf(stderr, __NAME__": Could not construct file name from URI!\n");
+               t = g_strdup_printf("%s (%.0f%% of %.1f MB)",
+                                   webkit_uri_response_get_uri(resp), p, size_mb);
+       }
+       else
+       {
+               base = g_path_get_basename(filename);
+               t = g_strdup_printf("%s (%.0f%% of %.1f MB)", base, p, size_mb);
+               g_free(filename);
+               g_free(base);
+       }
+       gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
+       g_free(t);
+}
+
 void
 changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
 {
        struct Client *c = (struct Client *)data;
        gdouble p;
 
-       (void)obj;
-       (void)pspec;
-
-       p = webkit_web_view_get_progress(WEBKIT_WEB_VIEW(c->web_view));
-       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), p);
+       p = webkit_web_view_get_estimated_load_progress(WEBKIT_WEB_VIEW(c->web_view));
+       gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), p);
 }
 
 void
@@ -381,9 +341,6 @@ changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
        const gchar *t;
        struct Client *c = (struct Client *)data;
 
-       (void)obj;
-       (void)pspec;
-
        t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
        gtk_window_set_title(GTK_WINDOW(c->win), (t == NULL ? __NAME__ : t));
 }
@@ -394,28 +351,49 @@ changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
        const gchar *t;
        struct Client *c = (struct Client *)data;
 
-       (void)obj;
-       (void)pspec;
-
        t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
        gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
 }
 
 gboolean
-download_handle(WebKitWebView *web_view, WebKitDownload *download, gpointer data)
+decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
+              WebKitPolicyDecisionType type, gpointer data)
+{
+       WebKitResponsePolicyDecision *r;
+
+       switch (type)
+       {
+               case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
+                       r = WEBKIT_RESPONSE_POLICY_DECISION(decision);
+                       if (!webkit_response_policy_decision_is_mime_type_supported(r))
+                               webkit_policy_decision_download(decision);
+                       else
+                               webkit_policy_decision_use(decision);
+                       break;
+               default:
+                       /* Use whatever default there is. */
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+void
+download_handle_start(WebKitWebView *web_view, WebKitDownload *download,
+                      gpointer data)
+{
+       g_signal_connect(G_OBJECT(download), "decide-destination",
+                        G_CALLBACK(download_handle), data);
+}
+
+gboolean
+download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer data)
 {
        struct Client *c = (struct Client *)data;
        gchar *path, *path2 = NULL, *uri;
        GtkToolItem *tb;
-       gboolean ret;
        int suffix = 1;
 
-       (void)web_view;
-       (void)data;
-
-       path = g_build_filename(download_dir,
-                               webkit_download_get_suggested_filename(download),
-                               NULL);
+       path = g_build_filename(download_dir, suggested_filename, NULL);
        path2 = g_strdup(path);
        while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000)
        {
@@ -428,27 +406,25 @@ download_handle(WebKitWebView *web_view, WebKitDownload *download, gpointer data
        if (suffix == 1000)
        {
                fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
-               ret = FALSE;
+               webkit_download_cancel(download);
        }
        else
        {
                uri = g_filename_to_uri(path2, NULL, NULL);
-               webkit_download_set_destination_uri(download, uri);
-               ret = TRUE;
+               webkit_download_set_destination(download, uri);
                g_free(uri);
 
-               gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 1);
+               gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 1);
                downloads_indicated++;
                g_timeout_add(500, download_reset_indicator, c);
 
                tb = gtk_tool_button_new_from_stock(GTK_STOCK_DELETE);
-               gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb),
-                                         webkit_download_get_suggested_filename(download));
+               gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), suggested_filename);
                gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
                gtk_widget_show_all(dm.toolbar);
 
-               g_signal_connect(G_OBJECT(download), "notify::progress",
-                                G_CALLBACK(downloadmanager_progress), tb);
+               g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
+                                G_CALLBACK(changed_download_progress), tb);
 
                g_object_ref(download);
                g_signal_connect(G_OBJECT(tb), "clicked",
@@ -458,7 +434,8 @@ download_handle(WebKitWebView *web_view, WebKitDownload *download, gpointer data
        g_free(path);
        g_free(path2);
 
-       return ret;
+       /* Propagate -- to whom it may concern. */
+       return FALSE;
 }
 
 gboolean
@@ -468,28 +445,11 @@ download_reset_indicator(gpointer data)
 
        downloads_indicated--;
        if (downloads_indicated == 0)
-               gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 0);
+               gtk_level_bar_set_value(GTK_LEVEL_BAR(c->status), 0);
 
        return FALSE;
 }
 
-gboolean
-download_request(WebKitWebView *web_view, WebKitWebFrame *frame,
-                 WebKitNetworkRequest *request, gchar *mime_type,
-                 WebKitWebPolicyDecision *policy_decision, gpointer data)
-{
-       (void)frame;
-       (void)request;
-       (void)data;
-
-       if (!webkit_web_view_can_show_mime_type(web_view, mime_type))
-       {
-               webkit_web_policy_decision_download(policy_decision);
-               return TRUE;
-       }
-       return FALSE;
-}
-
 void
 downloadmanager_cancel(GtkToolButton *tb, gpointer data)
 {
@@ -501,24 +461,6 @@ downloadmanager_cancel(GtkToolButton *tb, gpointer data)
        gtk_widget_destroy(GTK_WIDGET(tb));
 }
 
-void
-downloadmanager_progress(GObject *obj, GParamSpec *pspec, gpointer data)
-{
-       WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
-       GtkToolItem *tb = GTK_TOOL_ITEM(data);
-       gdouble p;
-       gchar *t;
-
-       (void)pspec;
-
-       p = webkit_download_get_progress(download) * 100;
-       t = g_strdup_printf("%s (%.0f%%)",
-                           webkit_download_get_suggested_filename(download),
-                                               p);
-       gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
-       g_free(t);
-}
-
 void
 downloadmanager_setup(void)
 {
@@ -547,7 +489,7 @@ downloadmanager_setup(void)
 }
 
 gchar *
-ensure_url_scheme(const gchar *t)
+ensure_uri_scheme(const gchar *t)
 {
        gchar *f;
 
@@ -578,6 +520,18 @@ grab_environment_configuration(void)
        if (e != NULL)
                download_dir = g_strdup(e);
 
+       e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
+       if (e != NULL)
+               fifo_suffix = g_strdup(e);
+
+       e = g_getenv(__NAME_UPPERCASE__"_HOME_URI");
+       if (e != NULL)
+               home_uri = g_strdup(e);
+
+       e = g_getenv(__NAME_UPPERCASE__"_USER_AGENT");
+       if (e != NULL)
+               user_agent = g_strdup(e);
+
        e = g_getenv(__NAME_UPPERCASE__"_ZOOM");
        if (e != NULL)
                global_zoom = atof(e);
@@ -588,9 +542,6 @@ hover_web_view(WebKitWebView *web_view, gchar *title, gchar *uri, gpointer data)
 {
        struct Client *c = (struct Client *)data;
 
-       (void)web_view;
-       (void)title;
-
        if (!gtk_widget_is_focus(c->location))
        {
                if (uri == NULL)
@@ -604,16 +555,13 @@ hover_web_view(WebKitWebView *web_view, gchar *title, gchar *uri, gpointer data)
 gboolean
 key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
-       (void)widget;
-       (void)data;
-
        if (event->type == GDK_KEY_PRESS)
        {
                if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
                {
                        switch (((GdkEventKey *)event)->keyval)
                        {
-                               case GDK_KEY_q:  /* close window (left hand) */
+                               case GDK_KEY_d:  /* close window (left hand) */
                                        gtk_widget_hide(dm.win);
                                        return TRUE;
                        }
@@ -630,8 +578,6 @@ key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
        const gchar *t;
        gchar *f;
 
-       (void)widget;
-
        if (event->type == GDK_KEY_PRESS)
        {
                if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
@@ -670,7 +616,7 @@ key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
                                        }
                                        else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
                                        {
-                                               f = ensure_url_scheme(t);
+                                               f = ensure_uri_scheme(t);
                                                if (show_all_requests)
                                                        fprintf(stderr, "====> %s\n", f);
                                                webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
@@ -697,8 +643,7 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
        WebKitHitTestResult *ht_result = NULL;
        gchar *ht_uri = NULL, *f;
        gfloat z;
-
-       (void)widget;
+       gboolean b;
 
        if (event->type == GDK_KEY_PRESS)
        {
@@ -710,14 +655,14 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
                                        gtk_widget_destroy(c->win);
                                        return TRUE;
                                case GDK_KEY_w:  /* home (left hand) */
-                                       f = ensure_url_scheme(first_uri);
+                                       f = ensure_uri_scheme(home_uri);
                                        if (show_all_requests)
                                                fprintf(stderr, "====> %s\n", f);
                                        webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
                                        g_free(f);
                                        return TRUE;
                                case GDK_KEY_e:  /* new tab (left hand) */
-                                       f = ensure_url_scheme(first_uri);
+                                       f = ensure_uri_scheme(home_uri);
                                        if (show_all_requests)
                                                fprintf(stderr, "====> %s\n", f);
                                        client_new(f);
@@ -727,6 +672,16 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
                                        webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
                                                                            c->web_view));
                                        return TRUE;
+#if 0
+                               case GDK_KEY_s:  /* toggle source view (left hand) */
+                                       b = webkit_web_view_get_view_source_mode(WEBKIT_WEB_VIEW(
+                                                                                c->web_view));
+                                       b = !b;
+                                       webkit_web_view_set_view_source_mode(WEBKIT_WEB_VIEW(
+                                                                            c->web_view), b);
+                                       webkit_web_view_reload(WEBKIT_WEB_VIEW(c->web_view));
+                                       return TRUE;
+#endif
                                case GDK_KEY_d:  /* download manager (left hand) */
                                        gtk_widget_show_all(dm.win);
                                        return TRUE;
@@ -750,13 +705,14 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
                else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
                {
                        webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
-                       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), 0);
+                       gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
                }
        }
        else if (event->type == GDK_BUTTON_PRESS)
        {
                switch (((GdkEventButton *)event)->button)
                {
+#if 0
                        case 2:
                                ht_result = webkit_web_view_get_hit_test_result(
                                                                   WEBKIT_WEB_VIEW(c->web_view),
@@ -771,6 +727,7 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
                                }
                                g_object_unref(ht_result);
                                break;
+#endif
                        case 8:
                                webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
                                return TRUE;
@@ -787,18 +744,14 @@ key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
                        switch (((GdkEventScroll *)event)->direction)
                        {
                                case GDK_SCROLL_UP:
-                                       z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(
-                                                                                    c->web_view));
+                                       z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
                                        z += 0.1;
-                                       webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
-                                                                      z);
+                                       webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
                                        return TRUE;
                                case GDK_SCROLL_DOWN:
-                                       z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(
-                                                                                    c->web_view));
+                                       z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
                                        z -= 0.1;
-                                       webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
-                                                                      z);
+                                       webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
                                        return TRUE;
                                default:
                                        break;
@@ -832,14 +785,14 @@ keywords_load(void)
                        {
                                tokens = g_strsplit(buf, " ", 2);
                                if (tokens[0] != NULL && tokens[1] != NULL)
-                                       g_hash_table_insert(keywords, tokens[0], tokens[1]);
-                               else
-                                       g_strfreev(tokens);
+                                       g_hash_table_insert(keywords, g_strdup(tokens[0]),
+                                                           g_strdup(tokens[1]));
+                               g_strfreev(tokens);
                        }
                        g_free(buf);
                }
+               g_io_channel_shutdown(channel, FALSE, NULL);
        }
-       g_io_channel_shutdown(channel, FALSE, NULL);
        g_free(path);
 }
 
@@ -874,9 +827,6 @@ remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
 {
        gchar *uri = NULL;
 
-       (void)condition;
-       (void)data;
-
        g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
        if (uri)
        {
@@ -895,8 +845,10 @@ search(gpointer data, gint direction)
        if (search_text == NULL)
                return;
 
+       /*
        webkit_web_view_search_text(WEBKIT_WEB_VIEW(c->web_view), search_text,
                                    FALSE, direction == 1, TRUE);
+                                                               */
 }
 
 Window
@@ -919,25 +871,30 @@ tabbed_launch(void)
        }
 
        tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
+       if (tabbed_stdout_channel == NULL)
+       {
+               fprintf(stderr, __NAME__": Could open tabbed's stdout\n");
+               return 0;
+       }
        g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
+       g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
        if (output == NULL)
        {
                fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
                return 0;
        }
-
-       g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
-
        g_strstrip(output);
        plug_into = strtol(output, NULL, 16);
        g_free(output);
+       if (plug_into == 0)
+               fprintf(stderr, __NAME__": The XID from tabbed is 0\n");
        return plug_into;
 }
 
 void
 usage(void)
 {
-       fprintf(stderr, "Usage: "__NAME__" [OPTION]... <URI>...\n");
+       fprintf(stderr, "Usage: "__NAME__" [OPTION]... [URI]...\n");
        exit(EXIT_FAILURE);
 }
 
@@ -973,10 +930,6 @@ main(int argc, char **argv)
                }
        }
 
-       if (optind >= argc)
-               usage();
-
-       adblock_load();
        keywords_load();
        cooperation_setup();
        downloadmanager_setup();
@@ -984,9 +937,14 @@ main(int argc, char **argv)
        if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
                embed = tabbed_launch();
 
-       first_uri = g_strdup(argv[optind]);
-       for (i = optind; i < argc; i++)
-               client_new(argv[i]);
+       if (optind >= argc)
+               client_new(home_uri);
+       else
+       {
+               for (i = optind; i < argc; i++)
+                       client_new(argv[i]);
+       }
+
        if (!cooperative_instances || cooperative_alone)
                gtk_main();
        exit(EXIT_SUCCESS);