summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/dwb-js.718
-rw-r--r--api/jsapi.7.txt13
-rw-r--r--api/jsapi.txt16
-rw-r--r--src/scripts.c36
4 files changed, 80 insertions, 3 deletions
diff --git a/api/dwb-js.7 b/api/dwb-js.7
index 2283e2d5..48da24da 100644
--- a/api/dwb-js.7
+++ b/api/dwb-js.7
@@ -2,12 +2,12 @@
.\" Title: dwb-js
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.78.0 <http://docbook.sf.net/>
-.\" Date: 02/23/2013
+.\" Date: 02/24/2013
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "DWB\-JS" "7" "02/23/2013" "\ \&" "\ \&"
+.TH "DWB\-JS" "7" "02/24/2013" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -1507,6 +1507,20 @@ Deferred\&.when(syncOperation(), function() {\&.\&.\&.});
.RE
.\}
.RE
+.SS "settings"
+.sp
+Readonly object that can be used to query dwb\(cqs current settings, all settings can also be used in camelcase, to modify settings \fBexecute\fR can be used\&.
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+if (settings\&.enablePrivateBrowsing == true)
+ execute("set enable\-private\-browsing false");
+.fi
+.if n \{\
+.RE
+.\}
.SH "WEBKIT OBJECTS"
.sp
All webkit objects correspond to gobject objects, i\&.e\&. they have the same properties, but the javascript properties are all camelcase\&. For example, a WebKitWebView has the property \fBzoom\-level\fR, the corresponding javascript property is \fBzoomLevel\fR:
diff --git a/api/jsapi.7.txt b/api/jsapi.7.txt
index dc0a417d..76cc98d7 100644
--- a/api/jsapi.7.txt
+++ b/api/jsapi.7.txt
@@ -761,6 +761,19 @@ Deferred.when(asyncOperation(), function() {...});
Deferred.when(syncOperation(), function() {...});
---------------------------------
+=== settings ===
+
+Readonly object that can be used to query dwb's current settings, all settings
+can also be used in camelcase, to modify settings *execute* can be used.
+
+====
+[source,javascript]
+---------------------------------
+if (settings.enablePrivateBrowsing == true)
+ execute("set enable-private-browsing false");
+---------------------------------
+====
+
== WEBKIT OBJECTS ==
diff --git a/api/jsapi.txt b/api/jsapi.txt
index 918f7650..25eddd9f 100644
--- a/api/jsapi.txt
+++ b/api/jsapi.txt
@@ -1403,6 +1403,22 @@ Deferred.when(asyncOperation(), function() {...});
Deferred.when(syncOperation(), function() {...});
---------------------------------
+[[settings]]
+=== settings ===
+
+Readonly object that can be used to query dwb's current settings, all settings
+can also be used in camelcase, to modify settings *execute* can be used.
+
+.Example
+
+====
+[source,javascript]
+---------------------------------
+if (settings.enablePrivateBrowsing == true)
+ execute("set enable-private-browsing false");
+---------------------------------
+====
+
[[Webkitobjects]]
== Webkit objects ==
diff --git a/src/scripts.c b/src/scripts.c
index e8e591ae..b1b8c2ee 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -1154,6 +1154,32 @@ global_exit(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size
return UNDEFINED;
}/*}}}*/
+/*{{{*/
+static JSValueRef
+settings_get(JSContextRef ctx, JSObjectRef jsobj, JSStringRef js_name, JSValueRef *exc)
+{
+ char buffer[PROP_LENGTH];
+ char *name = js_string_to_char(ctx, js_name, PROP_LENGTH);
+ if (name != NULL)
+ {
+ uncamelize(buffer, name, '-', PROP_LENGTH);
+ WebSettings *s = g_hash_table_lookup(dwb.settings, buffer);
+ g_free(name);
+ if (s == NULL)
+ return NIL;
+ switch (s->type)
+ {
+ case INTEGER : return JSValueMakeNumber(ctx, s->arg_local.i);
+ case DOUBLE : return JSValueMakeNumber(ctx, s->arg_local.d);
+ case BOOLEAN : return JSValueMakeBoolean(ctx, s->arg_local.b);
+ case CHAR : return js_char_to_value(ctx, s->arg_local.p);
+ default : return NIL;
+ }
+ }
+ return NIL;
+}
+/*}}}*/
+
/* global_include {{{*/
static JSValueRef
global_include(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -2980,6 +3006,7 @@ static void
create_global_object()
{
pthread_rwlock_wrlock(&s_context_lock);
+ JSClassDefinition cd;
s_ref_quark = g_quark_from_static_string("dwb_js_ref");
JSStaticValue global_values[] = {
@@ -3022,6 +3049,13 @@ create_global_object()
create_object(s_global_context, class, global_object, kJSDefaultAttributes, "data", NULL);
JSClassRelease(class);
+ cd = kJSClassDefinitionEmpty;
+ cd.getProperty = settings_get;
+ cd.setProperty = set_property_cb;
+ class = JSClassCreate(&cd);
+ create_object(s_global_context, class, global_object, kJSDefaultAttributes, "settings", NULL);
+ JSClassRelease(class);
+
JSStaticFunction io_functions[] = {
{ "print", io_print, kJSDefaultAttributes },
{ "prompt", io_prompt, kJSDefaultAttributes },
@@ -3062,7 +3096,7 @@ create_global_object()
create_object(s_global_context, class, global_object, kJSDefaultAttributes, "tabs", NULL);
JSClassRelease(class);
- JSClassDefinition cd = kJSClassDefinitionEmpty;
+ cd = kJSClassDefinitionEmpty;
cd.className = "signals";
cd.setProperty = signal_set;
class = JSClassCreate(&cd);