From: Sébastien Marie Date: Tue, 28 Oct 2014 13:42:28 +0000 (+0100) Subject: connect `request-queued` signal conditionnally X-Git-Url: https://git.owens.tech///git?a=commitdiff_plain;h=c441ec7aaf4fabc1a32a618bbab3b688d7804628;p=vimb.git connect `request-queued` signal conditionnally - add a new function: vb_update_signals() it manage signal connection/disconnection currently, only `request-queued` is managed. It is connected when autocmd use event AU_REQUEST_QUEUED or when setting "content-security-policy" is in use. - remove the unconditionnally connection of `request-queued` - add a new flag in setting `FLAG_SIGNAL` that inform setting_set_value to refresh signals by calling vb_update_signals() - manage "content-security-policy" setting with `FLAG_SIGNAL` - refresh signals in autocmd_add, at adding or removing. This permit to change the connection/disconnection state of `request-queued` when AU_REQUEST_QUEUED is in use or not. --- diff --git a/src/autocmd.c b/src/autocmd.c index 58698e5..7fa5798 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -222,6 +222,9 @@ gboolean autocmd_add(char *name, gboolean delete) /* if ther was at least one command removed - rebuilt the used bits */ if (removed) { rebuild_used_bits(); + + /* update signals dependants of autocmd */ + vb_update_signals(); } return true; @@ -237,6 +240,9 @@ gboolean autocmd_add(char *name, gboolean delete) /* merge the autocmd bits into the used bits */ usedbits |= cmd->bits; + + /* update signals dependants of autocmd */ + vb_update_signals(); } return true; diff --git a/src/main.c b/src/main.c index ae4009f..3eda51d 100644 --- a/src/main.c +++ b/src/main.c @@ -402,6 +402,43 @@ void vb_update_urlbar(const char *uri) #endif } +void vb_update_signals() +{ + /** + * search the signal handler for signal associated to vb.session + * and matching function session_request_queued_cb + */ + gulong hdl = g_signal_handler_find(vb.session, + G_SIGNAL_MATCH_FUNC, + 0, 0, NULL, session_request_queued_cb, NULL); + + if ((vb.config.contentsecuritypolicy && *vb.config.contentsecuritypolicy != '\0') +#ifdef FEATURE_AUTOCMD + || autocmd_in_use(AU_REQUEST_QUEUED) +#endif + ) { + /** + * content-security-policy OR AU_REQUEST_QUEUED are in used: + * the signal should be connected + */ + if (hdl == 0) { + /* the signal wasn't found: connect it */ + g_signal_connect(vb.session, "request-queued", G_CALLBACK(session_request_queued_cb), NULL); + + PRINT_DEBUG("request-queued connected"); + } + + } else { + /* the signal should not be here */ + if (hdl != 0) { + /* the signal was found: disconnect it */ + g_signal_handler_disconnect(vb.session, hdl); + + PRINT_DEBUG("request-queued disconnected"); + } + } +} + void vb_quit(gboolean force) { /* if not forced quit - don't quit if there are still running downloads */ @@ -962,8 +999,6 @@ static void setup_signals() NULL ); - g_signal_connect(vb.session, "request-queued", G_CALLBACK(session_request_queued_cb), NULL); - #ifdef FEATURE_NO_SCROLLBARS WebKitWebFrame *frame = webkit_web_view_get_main_frame(vb.gui.webview); g_signal_connect(G_OBJECT(frame), "scrollbars-policy-changed", G_CALLBACK(gtk_true), NULL); diff --git a/src/main.h b/src/main.h index ab0dbf6..da28d6b 100644 --- a/src/main.h +++ b/src/main.h @@ -382,6 +382,7 @@ void vb_update_statusbar(void); void vb_update_status_style(void); void vb_update_input_style(void); void vb_update_urlbar(const char *uri); +void vb_update_signals(void); void vb_register_add(char buf, const char *value); const char *vb_register_get(char buf); gboolean vb_download(WebKitWebView *view, WebKitDownload *download, const char *path); diff --git a/src/setting.c b/src/setting.c index ecb13a3..374e60e 100644 --- a/src/setting.c +++ b/src/setting.c @@ -48,8 +48,9 @@ typedef enum { } SettingType; enum { - FLAG_LIST = (1<<1), /* setting contains a ',' separated list of values */ - FLAG_NODUP = (1<<2), /* don't allow duplicate strings within list values */ + FLAG_LIST = (1<<1), /* setting contains a ',' separated list of values */ + FLAG_NODUP = (1<<2), /* don't allow duplicate strings within list values */ + FLAG_SIGNAL = (1<<3), /* changing the setting need call vb_update_signals() */ }; extern VbCore vb; @@ -203,7 +204,7 @@ void setting_init() setting_add("history-max-items", TYPE_INTEGER, &i, internal, 0, &vb.config.history_max); setting_add("editor-command", TYPE_CHAR, &"x-terminal-emulator -e -vi '%s'", NULL, 0, NULL); setting_add("header", TYPE_CHAR, &"", headers, FLAG_LIST|FLAG_NODUP, NULL); - setting_add("content-security-policy", TYPE_CHAR, &"", internal, 0, &vb.config.contentsecuritypolicy); + setting_add("content-security-policy", TYPE_CHAR, &"", internal, FLAG_SIGNAL, &vb.config.contentsecuritypolicy); setting_add("nextpattern", TYPE_CHAR, &"/\\bnext\\b/i,/^(>\\|>>\\|»)$/,/^(>\\|>>\\|»)/,/(>\\|>>\\|»)$/,/\\bmore\\b/i", prevnext, FLAG_LIST|FLAG_NODUP, NULL); setting_add("previouspattern", TYPE_CHAR, &"/\\bprev\\|previous\\b/i,/^(<\\|<<\\|«)$/,/^(<\\|<<\\|«)/,/(<\\|<<\\|«)$/", prevnext, FLAG_LIST|FLAG_NODUP, NULL); setting_add("fullscreen", TYPE_BOOLEAN, &off, fullscreen, 0, NULL); @@ -365,6 +366,11 @@ static int setting_set_value(Setting *prop, void *value, SettingType type) break; } + /* update signals if requested */ + if (prop->flags & FLAG_SIGNAL) { + vb_update_signals(); + } + free: if (free_newvalue) { g_free(newvalue);