From: Daniel Carl Date: Fri, 13 Oct 2017 21:22:18 +0000 (+0200) Subject: Switch to input mode on authentication request #444. X-Git-Url: https://git.owens.tech/about.html/about.html/git?a=commitdiff_plain;h=2d67f7984deeda4cf715c4ec57d9438b4c1efbf7;p=vimb.git Switch to input mode on authentication request #444. Webkit shows an default embedded authentication dialog in case of HTTP-Authentication. But this dialog is neither a GTK dialog nor part of the DOM. So we are not informed about the any focus changes and vimb keeps in normal mode and the user cant use all the chars for the authentication. This patch listen to the webview authentication signal to force switching to input mode. On the other had a new flag is set to avoid switching vimb back to normal mode because of focus changes in the underlaying DOM (previous opened page). --- diff --git a/src/main.c b/src/main.c index c440902..09d2af9 100644 --- a/src/main.c +++ b/src/main.c @@ -82,6 +82,8 @@ static void on_webview_notify_uri(WebKitWebView *webview, GParamSpec *pspec, Client *c); static void on_webview_ready_to_show(WebKitWebView *webview, Client *c); static gboolean on_webview_web_process_crashed(WebKitWebView *webview, Client *c); +static gboolean on_webview_authenticate(WebKitWebView *webview, + WebKitAuthenticationRequest *request, Client *c); static gboolean on_window_delete_event(GtkWidget *window, GdkEvent *event, Client *c); static void on_window_destroy(GtkWidget *window, Client *c); static gboolean quit(Client *c); @@ -1259,6 +1261,12 @@ static void on_webview_load_changed(WebKitWebView *webview, break; case WEBKIT_LOAD_COMMITTED: + /* In case of HTTP authentication request we ignore the focus + * changes so that the input mode can be set for the + * authentication request. If the authentication dialog is filled + * or aborted the load will be commited. So this seems to be the + * right place to remove the flag. */ + c->mode->flags &= ~FLAG_IGNORE_FOCUS; uri = webkit_web_view_get_uri(webview); #ifdef FEATURE_AUTOCMD autocmd_run(c, AU_LOAD_COMMITTED, uri, NULL); @@ -1388,6 +1396,22 @@ static gboolean on_webview_web_process_crashed(WebKitWebView *webview, Client *c return TRUE; } +/** + * Callback in case HTTP authentication is requested by the server. + */ +static gboolean on_webview_authenticate(WebKitWebView *webview, + WebKitAuthenticationRequest *request, Client *c) +{ + /* Don't change the mode if we are in pass through mode. */ + if (c->mode->id == 'n') { + vb_enter(c, 'i'); + /* Make sure we do not switch back to normal mode in case a previos + * page is open and looses the focus. */ + c->mode->flags |= FLAG_IGNORE_FOCUS; + } + return FALSE; +} + /** * Callback for window ::delete-event signal which is emitted if a user * requests that a toplevel window is closed. The default handler for this @@ -1741,6 +1765,7 @@ static WebKitWebView *webview_new(Client *c, WebKitWebView *webview) "signal::notify::uri", G_CALLBACK(on_webview_notify_uri), c, "signal::ready-to-show", G_CALLBACK(on_webview_ready_to_show), c, "signal::web-process-crashed", G_CALLBACK(on_webview_web_process_crashed), c, + "signal::authenticate", G_CALLBACK(on_webview_authenticate), c, NULL ); @@ -1771,7 +1796,7 @@ static void on_script_message_focus(WebKitUserContentManager *manager, g_variant_unref(variant); c = vb_get_client_for_page_id(pageid); - if (!c) { + if (!c || c->mode->flags & FLAG_IGNORE_FOCUS) { return; } diff --git a/src/main.h b/src/main.h index de66fc5..afe6ddd 100644 --- a/src/main.h +++ b/src/main.h @@ -194,11 +194,12 @@ struct Mode { ModeTransitionFunc leave; /* is called if the mode is left */ ModeKeyFunc keypress; /* receives key to process */ ModeInputChangedFunc input_changed; /* is triggered if input textbuffer is changed */ -#define FLAG_NOMAP 0x0001 /* disables mapping for key strokes */ -#define FLAG_HINTING 0x0002 /* marks active hinting submode */ -#define FLAG_COMPLETION 0x0004 /* marks active completion submode */ -#define FLAG_PASSTHROUGH 0x0008 /* don't handle any other keybind than */ -#define FLAG_NEW_WIN 0x0010 /* enforce opening of pages into new window */ +#define FLAG_NOMAP 0x0001 /* disables mapping for key strokes */ +#define FLAG_HINTING 0x0002 /* marks active hinting submode */ +#define FLAG_COMPLETION 0x0004 /* marks active completion submode */ +#define FLAG_PASSTHROUGH 0x0008 /* don't handle any other keybind than */ +#define FLAG_NEW_WIN 0x0010 /* enforce opening of pages into new window */ +#define FLAG_IGNORE_FOCUS 0x0012 /* do not listen for focus change messages */ unsigned int flags; };