logo

badwolf

Minimalist and privacy-oriented WebKitGTK+ browser
commit: 31a237b7241c14b919c77c5fb735e7c372cd0780
parent: 208d2976c977f1e81da1907657e496a841ae8662
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 17 May 2019 12:52:18 +0200

When the mime type isn’t supported, download the file

Diffstat:

Mbadwolf.c32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -70,6 +70,10 @@ static WebKitWebView *WebViewCb_create(WebKitWebView *related_web_view, static gboolean WebViewCb_permission_request(WebKitWebView *web_view, WebKitPermissionRequest *request, gpointer user_data); +static gboolean WebViewCb_decide_policy(WebKitWebView *web_view, + WebKitPolicyDecision *decision, + WebKitPolicyDecisionType decision_type, + gpointer user_data); static gboolean locationCb_activate(GtkEntry *location, gpointer user_data); static gboolean javascriptCb_toggled(GtkButton *javascript, gpointer user_data); static gboolean SearchEntryCb_next__match(GtkSearchEntry *search, gpointer user_data); @@ -467,6 +471,33 @@ WebViewCb_permission_request(WebKitWebView *web_view, } static gboolean +WebViewCb_decide_policy(WebKitWebView *web_view, + WebKitPolicyDecision *decision, + WebKitPolicyDecisionType decision_type, + gpointer user_data) +{ + WebKitResponsePolicyDecision *r; + (void)web_view; + (void)user_data; + + switch(decision_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; +} + +static gboolean locationCb_activate(GtkEntry *location, gpointer user_data) { char *target_url; @@ -648,6 +679,7 @@ new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web g_signal_connect(browser->webView, "scroll-event", G_CALLBACK(WebViewCb_scroll_event), browser); g_signal_connect( browser->webView, "permission-request", G_CALLBACK(WebViewCb_permission_request), NULL); + g_signal_connect(browser->webView, "decide-policy", G_CALLBACK(WebViewCb_decide_policy), NULL); /* signals for search widget */ g_signal_connect(browser->search, "next-match", G_CALLBACK(SearchEntryCb_next__match), browser);