summaryrefslogtreecommitdiff
path: root/surf.c
diff options
context:
space:
mode:
authorQuentin Rameau <quinq@fifth.space>2015-11-18 18:16:06 +0100
committerQuentin Rameau <quinq@fifth.space>2015-11-20 00:34:20 +0100
commit1f99df029c5c190941a20ed87344aeef56f76418 (patch)
treec9583b15941159992348d584c9749c97a25e7136 /surf.c
parent92d7ba7ed8cf4cb7ffa839596fca58032e2c4dd3 (diff)
downloadsurf-1f99df029c5c190941a20ed87344aeef56f76418.tar.gz
surf-1f99df029c5c190941a20ed87344aeef56f76418.tar.bz2
surf-1f99df029c5c190941a20ed87344aeef56f76418.zip
Replace createwindow() with createview()
We can now perform some filtering before opening a new view (window) when requested by JavaScript (either random or by a click).
Diffstat (limited to 'surf.c')
-rw-r--r--surf.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/surf.c b/surf.c
index c9a036a..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);
@@ -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
@@ -890,8 +913,8 @@ newview(Client *c, WebKitWebView *rv)
"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),