From c944dee2bd8d2851a070346dada1d42b467f1249 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Mon, 3 Mar 2014 22:52:04 +0100 Subject: [PATCH] Fixed none working 'F' hintmode for webkit2. If vimb is built against webkit2 webkit's sandbox does not allow to open a element via JavaScript into a new window. So, webkit does nothing if the hinting fires a click event on an element that has a none empty target attribute set. This patch enables the setting to allow JavaScript to open windows without user interaction as long as the hinting is active. --- src/hints.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/hints.c b/src/hints.c index 9c254cb..a3e2d87 100644 --- a/src/hints.c +++ b/src/hints.c @@ -39,9 +39,13 @@ static struct { int promptlen; /* lenfth of the hint prompt chars 2 or 3 */ gboolean gmode; /* indicate if the hints g mode is used */ JSContextRef ctx; +#if WEBKIT_CHECK_VERSION(2, 0, 0) + /* holds the setting if JavaScript can open windows automatically that we + * have to change to open windows via hinting */ + gboolean allow_open_win; +#endif } hints; - extern VbCore vb; static gboolean call_hints_function(const char *func, int count, JSValueRef params[]); @@ -128,6 +132,19 @@ void hints_create(const char *input) if (!(vb.mode->flags & FLAG_HINTING)) { vb.mode->flags |= FLAG_HINTING; +#if WEBKIT_CHECK_VERSION(2, 0, 0) + WebKitWebSettings *setting = webkit_web_view_get_settings(vb.gui.webview); + + /* before we enable JavaScript to open new windows, we save the actual + * value to be able restore it after hints where fired */ + g_object_get(G_OBJECT(setting), "javascript-can-open-windows-automatically", &(hints.allow_open_win), NULL); + + /* if window open is already allowed there's no need to allow it again */ + if (!hints.allow_open_win) { + g_object_set(G_OBJECT(setting), "javascript-can-open-windows-automatically", true, NULL); + } +#endif + hints.promptlen = hints.gmode ? 3 : 2; JSValueRef arguments[] = { @@ -252,7 +269,13 @@ static gboolean call_hints_function(const char *func, int count, JSValueRef para g_signal_emit_by_name( vb.gui.webview, "hovering-over-link", NULL, *(value + 5) == '\0' ? NULL : (value + 5) ); - } else if (!strncmp(value, "DONE:", 5)) { + g_free(value); + + return true; + } + + /* following return values mark fired hints */ + if (!strncmp(value, "DONE:", 5)) { if (!hints.gmode) { mode_enter('n'); } @@ -312,5 +335,12 @@ static gboolean call_hints_function(const char *func, int count, JSValueRef para } g_free(value); +#if WEBKIT_CHECK_VERSION(2, 0, 0) + /* if open window was not allowed for JavaScript, restore this */ + if (!hints.allow_open_win) { + WebKitWebSettings *setting = webkit_web_view_get_settings(vb.gui.webview); + g_object_set(G_OBJECT(setting), "javascript-can-open-windows-automatically", hints.allow_open_win, NULL); + } +#endif return true; } -- 2.20.1