X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=surf.c;h=23ea087744bd9f2efa2a96b5f4efe04cfb7b136f;hb=1f99df029c5c190941a20ed87344aeef56f76418;hp=af994bb6ab77d5abdc546ae591ccee52bc2b410b;hpb=42c6c90366b7ce7708b13037a6ba819b08fbb20e;p=surf.git diff --git a/surf.c b/surf.c index af994bb..23ea087 100644 --- a/surf.c +++ b/surf.c @@ -114,8 +114,8 @@ static WebKitCookieAcceptPolicy cookiepolicy_get(void); static char cookiepolicy_set(const WebKitCookieAcceptPolicy p); static char *copystr(char **str, const char *src); -static WebKitWebView *createwindow(WebKitWebView *v, WebKitWebFrame *f, - Client *c); +static GtkWidget *createview(WebKitWebView *v, WebKitNavigationAction *a, + Client *c); static gboolean decidedownload(WebKitWebView *v, WebKitWebFrame *f, WebKitNetworkRequest *r, gchar *m, WebKitWebPolicyDecision *p, Client *c); @@ -130,8 +130,8 @@ static void die(const char *errstr, ...); static void eval(Client *c, const Arg *arg); static void find(Client *c, const Arg *arg); static void fullscreen(Client *c, const Arg *arg); -static void geopolicyrequested(WebKitWebView *v, WebKitWebFrame *f, - WebKitGeolocationPolicyDecision *d, Client *c); +static gboolean permissionrequested(WebKitWebView *v, + WebKitPermissionRequest *r, Client *c); static const char *getatom(Client *c, int a); static void gettogglestat(Client *c); static void getpagestat(Client *c); @@ -427,11 +427,34 @@ copystr(char **str, const char *src) return tmp; } -WebKitWebView * -createwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c) +GtkWidget * +createview(WebKitWebView *v, WebKitNavigationAction *a, Client *c) { - Client *n = newclient(); - return n->view; + Client *n; + + switch (webkit_navigation_action_get_navigation_type(a)) { + case WEBKIT_NAVIGATION_TYPE_OTHER: /* fallthrough */ + /* + * popup windows of type “other” are almost always triggered + * by user gesture, so inverse the logic here + */ + if (webkit_navigation_action_is_user_gesture(a)) { + return NULL; + break; + } + case WEBKIT_NAVIGATION_TYPE_LINK_CLICKED: /* fallthrough */ + case WEBKIT_NAVIGATION_TYPE_FORM_SUBMITTED: /* fallthrough */ + case WEBKIT_NAVIGATION_TYPE_BACK_FORWARD: /* fallthrough */ + case WEBKIT_NAVIGATION_TYPE_RELOAD: /* fallthrough */ + case WEBKIT_NAVIGATION_TYPE_FORM_RESUBMITTED: + n = newclient(c); + break; + default: + return NULL; + break; + } + + return GTK_WIDGET(n->view); } gboolean @@ -527,14 +550,18 @@ fullscreen(Client *c, const Arg *arg) c->fullscreen = !c->fullscreen; } -void -geopolicyrequested(WebKitWebView *v, WebKitWebFrame *f, - WebKitGeolocationPolicyDecision *d, Client *c) +gboolean +permissionrequested(WebKitWebView *v, WebKitPermissionRequest *r, Client *c) { - if (allowgeolocation) - webkit_geolocation_policy_allow(d); - else - webkit_geolocation_policy_deny(d); + if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(r)) { + if (allowgeolocation) + webkit_permission_request_allow(r); + else + webkit_permission_request_deny(r); + return TRUE; + } + + return FALSE; } const char * @@ -883,11 +910,11 @@ newview(Client *c, WebKitWebView *rv) "mouse-target-changed", G_CALLBACK(mousetargetchanged), c); g_signal_connect(G_OBJECT(v), - "geolocation-policy-decision-requested", - G_CALLBACK(geopolicyrequested), c); + "permission-request", + G_CALLBACK(permissionrequested), c); g_signal_connect(G_OBJECT(v), - "create-web-view", - G_CALLBACK(createwindow), c); + "create", + G_CALLBACK(createview), c); g_signal_connect(G_OBJECT(v), "ready-to-show", G_CALLBACK(showview), c); g_signal_connect(G_OBJECT(v),