X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=d6d644df44ba1744fe2ec6df71a8bc8fd3d7b35f;hb=bb1fc4195f4fa3be5625d0f663e537a22ccf1877;hp=b79438d6d8284153b080a1a541cb309facde6728;hpb=f6a35e5fbfb4a5e9f92a126dae0cca103727d9d4;p=surf.git diff --git a/surf.c b/surf.c index b79438d..d6d644d 100644 --- a/surf.c +++ b/surf.c @@ -103,9 +103,6 @@ static int cookiepolicy; static char *stylefile = NULL; static void addaccelgroup(Client *c); -static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, - WebKitWebResource *r, WebKitNetworkRequest *req, - WebKitNetworkResponse *resp, Client *c); static char *buildfile(const char *path); static char *buildpath(const char *path); static gboolean buttonreleased(GtkWidget *w, GdkEventKey *e, Client *c); @@ -123,8 +120,7 @@ static gboolean decidepolicy(WebKitWebView *v, WebKitPolicyDecision *d, static void decidenavigation(WebKitPolicyDecision *d, Client *c); static void decidenewwindow(WebKitPolicyDecision *d, Client *c); static void decideresource(WebKitPolicyDecision *d, Client *c); -static gboolean deletion_interface(WebKitWebView *view, - WebKitDOMHTMLElement *arg1, Client *c); +static void closeview(WebKitWebView *v, Client *c); static void destroyclient(Client *c); static void destroywin(GtkWidget* w, Client *c); static void die(const char *errstr, ...); @@ -140,7 +136,7 @@ static char *geturi(Client *c); static const gchar *getstyle(const char *uri); static void setstyle(Client *c, const char *style); -static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri); +static void handleplumb(Client *c, const gchar *uri); static void downloadstarted(WebKitWebContext *wc, WebKitDownload *d, Client *c); @@ -165,11 +161,8 @@ static Client *newclient(Client *c); static WebKitWebView *newview(Client *c, WebKitWebView *rv); static void showview(WebKitWebView *v, Client *c); static void newwindow(Client *c, const Arg *arg, gboolean noembed); +static GtkWidget *createwindow(Client *c); static void pasteuri(GtkClipboard *clipboard, const char *text, gpointer d); -static gboolean contextmenu(WebKitWebView *view, GtkWidget *menu, - WebKitHitTestResult *target, gboolean keyboard, - Client *c); -static void menuactivate(GtkMenuItem *item, Client *c); static void print(Client *c, const Arg *arg); static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d); @@ -217,35 +210,6 @@ addaccelgroup(Client *c) gtk_window_add_accel_group(GTK_WINDOW(c->win), group); } -void -beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, - WebKitNetworkRequest *req, WebKitNetworkResponse *resp, - Client *c) -{ - const gchar *uri = webkit_network_request_get_uri(req); - int i, isascii = 1; - - if (g_str_has_suffix(uri, "/favicon.ico")) - webkit_network_request_set_uri(req, "about:blank"); - - if (!g_str_has_prefix(uri, "http://") - && !g_str_has_prefix(uri, "https://") - && !g_str_has_prefix(uri, "about:") - && !g_str_has_prefix(uri, "file://") - && !g_str_has_prefix(uri, "data:") - && !g_str_has_prefix(uri, "blob:") - && strlen(uri) > 0) { - for (i = 0; i < strlen(uri); i++) { - if (!g_ascii_isprint(uri[i])) { - isascii = 0; - break; - } - } - if (isascii) - handleplumb(c, w, uri); - } -} - char * buildfile(const char *path) { @@ -543,34 +507,55 @@ decidenewwindow(WebKitPolicyDecision *d, Client *c) void decideresource(WebKitPolicyDecision *d, Client *c) { + const gchar *uri; + int i, isascii = 1; WebKitResponsePolicyDecision *r = WEBKIT_RESPONSE_POLICY_DECISION(d); WebKitURIResponse *res; + res = webkit_response_policy_decision_get_response(r); + uri = webkit_uri_response_get_uri(res); + + if (g_str_has_suffix(uri, "/favicon.ico")) + webkit_uri_request_set_uri( + webkit_response_policy_decision_get_request(r), + "about:blank"); + + if (!g_str_has_prefix(uri, "http://") + && !g_str_has_prefix(uri, "https://") + && !g_str_has_prefix(uri, "about:") + && !g_str_has_prefix(uri, "file://") + && !g_str_has_prefix(uri, "data:") + && !g_str_has_prefix(uri, "blob:") + && strlen(uri) > 0) { + for (i = 0; i < strlen(uri); i++) { + if (!g_ascii_isprint(uri[i])) { + isascii = 0; + break; + } + } + if (isascii) { + handleplumb(c, uri); + webkit_policy_decision_ignore(d); + } + } + if (webkit_response_policy_decision_is_mime_type_supported(r)) { webkit_policy_decision_use(d); } else { -res = webkit_response_policy_decision_get_response(r); webkit_policy_decision_ignore(d); download(c, res); } } -gboolean -deletion_interface(WebKitWebView *view, WebKitDOMHTMLElement *arg1, Client *c) -{ - return FALSE; -} - void destroyclient(Client *c) { Client *p; webkit_web_view_stop_loading(c->view); - gtk_widget_destroy(GTK_WIDGET(c->view)); - gtk_widget_destroy(c->scroll); - gtk_widget_destroy(c->vbox); + /* Not needed, has already been called gtk_widget_destroy(c->win); + */ for (p = clients; p && p->next != c; p = p->next) ; @@ -579,14 +564,20 @@ destroyclient(Client *c) else clients = c->next; free(c); - if (clients == NULL) - gtk_main_quit(); +} + +void +closeview(WebKitWebView *v, Client *c) +{ + gtk_widget_destroy(c->win); } void destroywin(GtkWidget* w, Client *c) { destroyclient(c); + if (clients == NULL) + gtk_main_quit(); } void @@ -691,12 +682,11 @@ setstyle(Client *c, const char *style) } void -handleplumb(Client *c, WebKitWebView *w, const gchar *uri) +handleplumb(Client *c, const gchar *uri) { Arg arg; - webkit_web_view_stop_loading(w); - arg = (Arg)PLUMB((char *)uri); + arg = (Arg)PLUMB(uri); spawn(c, &arg); } @@ -1015,15 +1005,8 @@ newview(Client *c, WebKitWebView *rv) g_signal_connect(G_OBJECT(v), "button-release-event", G_CALLBACK(buttonreleased), c); - g_signal_connect(G_OBJECT(v), - "context-menu", - G_CALLBACK(contextmenu), c); - g_signal_connect(G_OBJECT(v), - "resource-request-starting", - G_CALLBACK(beforerequest), c); - g_signal_connect(G_OBJECT(v), - "should-show-delete-interface-for-element", - G_CALLBACK(deletion_interface), c); + g_signal_connect(G_OBJECT(v), "close", + G_CALLBACK(closeview), c); return v; } @@ -1035,33 +1018,7 @@ showview(WebKitWebView *v, Client *c) GdkRGBA bgcolor = { 0 }; GdkWindow *gwin; - /* Window */ - if (embed) { - c->win = gtk_plug_new(embed); - } else { - c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - /* TA: 20091214: Despite what the GNOME docs say, the ICCCM - * is always correct, so we should still call this function. - * But when doing so, we *must* differentiate between a - * WM_CLASS and a resource on the window. By convention, the - * window class (WM_CLASS) is capped, while the resource is in - * lowercase. Both these values come as a pair. - */ - gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "Surf"); - - /* TA: 20091214: And set the role here as well -- so that - * sessions can pick this up. - */ - gtk_window_set_role(GTK_WINDOW(c->win), "Surf"); - } - gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600); - g_signal_connect(G_OBJECT(c->win), - "destroy", - G_CALLBACK(destroywin), c); - g_signal_connect(G_OBJECT(c->win), - "leave_notify_event", - G_CALLBACK(titlechangeleave), c); + c->win = createwindow(c); if (!kioskmode) addaccelgroup(c); @@ -1146,51 +1103,39 @@ newwindow(Client *c, const Arg *arg, gboolean noembed) spawn(NULL, &a); } -gboolean -contextmenu(WebKitWebView *view, GtkWidget *menu, WebKitHitTestResult *target, - gboolean keyboard, Client *c) +GtkWidget * +createwindow(Client *c) { - GList *items = gtk_container_get_children(GTK_CONTAINER(GTK_MENU(menu))); + GtkWidget *w; - for (GList *l = items; l; l = l->next) - g_signal_connect(l->data, "activate", G_CALLBACK(menuactivate), c); + if (embed) { + w = gtk_plug_new(embed); + } else { + w = gtk_window_new(GTK_WINDOW_TOPLEVEL); - g_list_free(items); - return FALSE; -} + /* TA: 20091214: Despite what the GNOME docs say, the ICCCM + * is always correct, so we should still call this function. + * But when doing so, we *must* differentiate between a + * WM_CLASS and a resource on the window. By convention, the + * window class (WM_CLASS) is capped, while the resource is in + * lowercase. Both these values come as a pair. + */ + gtk_window_set_wmclass(GTK_WINDOW(w), "surf", "Surf"); -void -menuactivate(GtkMenuItem *item, Client *c) -{ - /* - * context-menu-action-2000 open link - * context-menu-action-1 open link in window - * context-menu-action-2 download linked file - * context-menu-action-3 copy link location - * context-menu-action-7 copy image address - * context-menu-action-13 reload - * context-menu-action-10 back - * context-menu-action-11 forward - * context-menu-action-12 stop - */ + /* TA: 20091214: And set the role here as well -- so that + * sessions can pick this up. + */ + gtk_window_set_role(GTK_WINDOW(w), "Surf"); - const gchar *name, *uri; - GtkClipboard *prisel, *clpbrd; + gtk_window_set_default_size(GTK_WINDOW(w), 800, 600); + } - name = gtk_actionable_get_action_name(GTK_ACTIONABLE(item)); - if (name == NULL) - return; + g_signal_connect(G_OBJECT(w), "destroy", + G_CALLBACK(destroywin), c); + g_signal_connect(G_OBJECT(w), "leave_notify_event", + G_CALLBACK(titlechangeleave), c); - if (!g_strcmp0(name, "context-menu-action-3")) { - prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY); - gtk_clipboard_set_text(prisel, c->linkhover, -1); - } else if (!g_strcmp0(name, "context-menu-action-7")) { - prisel = gtk_clipboard_get(GDK_SELECTION_PRIMARY); - clpbrd = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); - uri = gtk_clipboard_wait_for_text(clpbrd); - if (uri) - gtk_clipboard_set_text(prisel, uri, -1); - } + return w; } void