diff options
-rw-r--r-- | doc/dwb.1 | 16 | ||||
-rw-r--r-- | doc/dwb.1.txt | 12 | ||||
-rw-r--r-- | m4/settings.m4 | 1 | ||||
-rw-r--r-- | src/config.h | 2 | ||||
-rw-r--r-- | src/dwb.c | 16 | ||||
-rw-r--r-- | src/dwb.h | 7 | ||||
-rw-r--r-- | src/scripts.c | 68 |
7 files changed, 88 insertions, 34 deletions
@@ -2,12 +2,12 @@ .\" Title: dwb .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/> -.\" Date: 04/25/2013 +.\" Date: 04/27/2013 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "DWB" "1" "04/25/2013" "\ \&" "\ \&" +.TH "DWB" "1" "04/27/2013" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -3463,6 +3463,18 @@ The urls that are saved in the browsing history\&. Specifying a too large value \fI500\fR\&. .RE .PP +\fBjavascript\-api\fR +.RS 4 +Whether to enable the javascript api\&. If set to +\fIdisabled\fR +the javascript context won\(cqt be initialized, meaning that also extensions won\(cqt work\&. If set to +\fIautomatic\fR +the javascript context will automatically be initialized if scripts that use the api are present in $XDG_CONFIG_HOME/dwb/userscripts or extensions are installed\&. If set to +\fIenabled\fR +the javascript context will always be initialized, useful if no scripts are present in $XDG_CONFIG_HOME/dwb/userscripts but the javascript api is used from commandline or in a custom command\&. The javascript context is only initialized on startup, so changing the value needs a restart\&. Default value: +\fIautomatic\fR\&. +.RE +.PP \fBjavascript\-schemes\fR .RS 4 Whether to allow loading javascript snippets with scheme diff --git a/doc/dwb.1.txt b/doc/dwb.1.txt index 70ccd92a..d34345e4 100644 --- a/doc/dwb.1.txt +++ b/doc/dwb.1.txt @@ -1436,6 +1436,18 @@ The urls that are saved in the browsing history. Specifying a too large value can make tab-completion slow. Possible values: number of urls, default value: '500'. +*javascript-api*:: +Whether to enable the javascript api. If set to 'disabled' the javascript +context won't be initialized, meaning that also extensions won't work. If set to +'automatic' the javascript context will automatically be initialized if scripts that use +the api are present in $XDG_CONFIG_HOME/dwb/userscripts or extensions are +installed. If set to 'enabled' the javascript context will always be +initialized, useful if no scripts are present in +$XDG_CONFIG_HOME/dwb/userscripts but the javascript api is used from commandline +or in a custom command. The javascript context is only initialized on startup, +so changing the value needs a restart. Default value: +'automatic'. + *javascript-schemes*:: Whether to allow loading javascript snippets with scheme 'javascript', default value: 'true'. diff --git a/m4/settings.m4 b/m4/settings.m4 index 5d697baa..3284b826 100644 --- a/m4/settings.m4 +++ b/m4/settings.m4 @@ -130,6 +130,7 @@ html_input(enable-scripts, checkbox, Enable embedded scripting languages) ifdef(`WITH_HSTS', html_input(hsts, checkbox, Whether HSTS support should be enabled) ) +html_select(javascript-api, html_options(disabled, automatic, enabled), Whether the javascript api is enabled, needs restart) html_input(javascript-can-access-clipboard, checkbox, Whether javascript can access the clipboard) html_input(javascript-can-open-windows-automatically, checkbox, Whether javascript can open windows) html_input(javascript-schemes, checkbox, Whether to allow loading url with scheme "javascript") diff --git a/src/config.h b/src/config.h index 420fbb54..51b4e98d 100644 --- a/src/config.h +++ b/src/config.h @@ -1206,6 +1206,8 @@ static WebSettings DWB_SETTINGS[] = { SETTING_GLOBAL, BOOLEAN, { .b = true }, NULL, { 0 }, }, { { "maximum-tabs", "Maximum number of tabs", }, SETTING_GLOBAL | SETTING_ONINIT, INTEGER, { .i = 0 }, (S_Func)dwb_set_max_tabs, { 0 }, }, + { { "javascript-api", "Whether to enable the javascript api", }, + SETTING_GLOBAL | SETTING_ONINIT, CHAR, { .p = "automatic" }, (S_Func)dwb_set_javascript_api, { 0 }, }, //{ { "javascript-debugging", "If set will be used for 'Accept-Language' header in all requests", }, // SETTING_GLOBAL | SETTING_ONINIT, BOOLEAN, { .b = false }, (S_Func)dwb_set_javascript_debugging, { 0 }, }, };/*}}}*/ @@ -84,6 +84,7 @@ static DwbStatus dwb_set_do_not_track(GList *gl, WebSettings *s); static DwbStatus dwb_set_show_single_tab(GList *gl, WebSettings *s); static DwbStatus dwb_set_accept_language(GList *gl, WebSettings *s); static DwbStatus dwb_set_passthrough(GList *gl, WebSettings *s); +static DwbStatus dwb_set_javascript_api(GList *gl, WebSettings *s); #if !_HAS_GTK3 static DwbStatus dwb_set_tab_orientation(GList *gl, WebSettings *s); static DwbStatus dwb_set_tab_width(GList *gl, WebSettings *s); @@ -196,6 +197,19 @@ dwb_set_passthrough(GList *gl, WebSettings *s) return STATUS_ERROR; return STATUS_OK; }/*}}}*/ +static DwbStatus +dwb_set_javascript_api(GList *gl, WebSettings *s) +{ + if (!strcmp(s->arg_local.p, "disabled")) + dwb.misc.js_api = JS_API_DISABLED; + else if (!strcmp(s->arg_local.p, "automatic")) + dwb.misc.js_api = JS_API_AUTOMATIC; + else if (!strcmp(s->arg_local.p, "enabled")) + dwb.misc.js_api = JS_API_ENABLED; + else + return STATUS_ERROR; + return STATUS_OK; +}/*}}}*/ #if !_HAS_GTK3 static DwbStatus dwb_set_tab_orientation(GList *gl, WebSettings *s) @@ -3423,7 +3437,7 @@ dwb_get_scripts() path = realpath; } } - if ( (f = fopen(path, "r")) != NULL && (l1 = fgetc(f)) && (l2 = fgetc(f)) ) + if (dwb.misc.js_api != JS_API_DISABLED && (f = fopen(path, "r")) != NULL && (l1 = fgetc(f)) && (l2 = fgetc(f)) ) { if ( (l1 == '#' && l2 == '!') || (l1 == '/' && l2 == '/' && fgetc(f) == '!') ) { @@ -239,6 +239,12 @@ typedef enum { COMP_SCRIPT, } CompletionType; +typedef enum { + JS_API_DISABLED, + JS_API_AUTOMATIC, + JS_API_ENABLED , +} JsApi; + typedef enum { SANITIZE_ERROR = -1, SANITIZE_HISTORY = 1<<0, @@ -815,6 +821,7 @@ struct _Misc { TabOrientation tab_orientation; #endif gint max_tabs; + JsApi js_api; //gboolean javascript_debugging; }; diff --git a/src/scripts.c b/src/scripts.c index 91a34843..d5d1d69e 100644 --- a/src/scripts.c +++ b/src/scripts.c @@ -5489,45 +5489,51 @@ scripts_reapply() gboolean scripts_init(gboolean force) { - dwb.misc.script_signals = 0; - if (s_global_context == NULL) + static gsize init = 0; + if (g_once_init_enter(&init)) { - if (force) - s_global_context = create_global_object(); - else - return false; - } - s_gobject_signals = g_ptr_array_new(); + gsize val = 37; + dwb.misc.script_signals = 0; + if (s_global_context == NULL) + { + if (force || dwb.misc.js_api == JS_API_ENABLED) + s_global_context = create_global_object(); + else + return false; + } + s_gobject_signals = g_ptr_array_new(); - dwb.state.script_completion = NULL; + dwb.state.script_completion = NULL; - char *dir = util_get_data_dir(LIBJS_DIR); - if (dir != NULL) - { - GString *content = g_string_new(NULL); - util_get_directory_content(content, dir, "js"); - if (content != NULL) + char *dir = util_get_data_dir(LIBJS_DIR); + if (dir != NULL) { - JSStringRef js_script = JSStringCreateWithUTF8CString(content->str); - JSEvaluateScript(s_global_context, js_script, NULL, NULL, 0, NULL); - JSStringRelease(js_script); + GString *content = g_string_new(NULL); + util_get_directory_content(content, dir, "js"); + if (content != NULL) + { + JSStringRef js_script = JSStringCreateWithUTF8CString(content->str); + JSEvaluateScript(s_global_context, js_script, NULL, NULL, 0, NULL); + JSStringRelease(js_script); + } + g_string_free(content, true); + g_free(dir); } - g_string_free(content, true); - g_free(dir); - } - UNDEFINED = JSValueMakeUndefined(s_global_context); - JSValueProtect(s_global_context, UNDEFINED); - NIL = JSValueMakeNull(s_global_context); - JSValueProtect(s_global_context, NIL); + UNDEFINED = JSValueMakeUndefined(s_global_context); + JSValueProtect(s_global_context, UNDEFINED); + NIL = JSValueMakeNull(s_global_context); + JSValueProtect(s_global_context, NIL); - s_init_before = get_private(s_global_context, "_initBefore"); - s_init_after = get_private(s_global_context, "_initAfter"); - //s_private = get_private(s_global_context, "_private"); + s_init_before = get_private(s_global_context, "_initBefore"); + s_init_after = get_private(s_global_context, "_initAfter"); + //s_private = get_private(s_global_context, "_private"); - JSObjectRef o = JSObjectMakeArray(s_global_context, 0, NULL, NULL); - s_array_contructor = js_get_object_property(s_global_context, o, "constructor"); - JSValueProtect(s_global_context, s_array_contructor); + JSObjectRef o = JSObjectMakeArray(s_global_context, 0, NULL, NULL); + s_array_contructor = js_get_object_property(s_global_context, o, "constructor"); + JSValueProtect(s_global_context, s_array_contructor); + g_once_init_leave(&init, val); + } return true; }/*}}}*/ |