summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <none@none>2013-03-15 04:13:20 +0100
committerportix <none@none>2013-03-15 04:13:20 +0100
commitfa00d93c8ddd539617b8257cc7542578ce1818f1 (patch)
treebbdab6ccc32f432b6f80f4033e4b53c89c5f4e2b
parent5792415c791c941915deea0205babf6c1429845f (diff)
downloaddwb-fa00d93c8ddd539617b8257cc7542578ce1818f1.zip
Inline documentation of javascript api; clean up api: new namespaces net and
timer; this refers to connected object in GObject.connect, moving prototype declarations from util.js to dwb.js; moving some functions from global namespace to util
-rw-r--r--Makefile4
-rw-r--r--config.mk2
-rw-r--r--doc/dwb-js.74
-rw-r--r--extensions/perdomainsettings2
-rw-r--r--extensions/requestpolicy10
-rw-r--r--extensions/userscripts2
-rw-r--r--scripts/lib/data.js94
-rw-r--r--scripts/lib/dwb.js721
-rw-r--r--scripts/lib/enums.js189
-rw-r--r--scripts/lib/extensions.js202
-rw-r--r--scripts/lib/io.js232
-rw-r--r--scripts/lib/signals.js181
-rw-r--r--scripts/lib/util.js65
-rw-r--r--src/callback.c58
-rw-r--r--src/download.c47
-rw-r--r--src/dwb.c95
-rw-r--r--src/scripts.c1604
-rw-r--r--src/view.c346
18 files changed, 3414 insertions, 444 deletions
diff --git a/Makefile b/Makefile
index 3cea5bdb..f1f37cde 100644
--- a/Makefile
+++ b/Makefile
@@ -92,6 +92,10 @@ endif
distclean: clean
+apidoc: $(wildcard src/*.c) $(wildcard scripts/lib/*.js)
+ @echo generating doc
+ jsdoc -d=jsdoc -x=c,js $(wildcard src/*.c) $(wildcard scripts/lib/*.js)
+ #@/home/stefan/tmp/jsdoc-master/jsdoc -x=c,js $(wildcard src/*.c) $(wildcard scripts/lib/*.js)
snapshot:
@$(MAKE) dist DISTDIR=$(REAL_NAME)-$(BUILDDATE)
diff --git a/config.mk b/config.mk
index 73dc326f..7478822f 100644
--- a/config.mk
+++ b/config.mk
@@ -13,7 +13,7 @@ JSDIR=scripts
HTMLDIR=html
LIBDIR=lib
LIBJSDIR=$(JSDIR)/$(LIBDIR)
-LIBJSFILES=$(LIBJSDIR)/signals.js $(LIBJSDIR)/enums.js $(LIBJSDIR)/data.js
+LIBJSFILES=$(wildcard $(LIBJSDIR)/*.js)
SHAREDIR=share
M4DIR=m4
UTILDIR=$(SRCDIR)/util
diff --git a/doc/dwb-js.7 b/doc/dwb-js.7
index 26ffd2ec..aeb01dcb 100644
--- a/doc/dwb-js.7
+++ b/doc/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: 03/11/2013
+.\" Date: 03/13/2013
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "DWB\-JS" "7" "03/11/2013" "\ \&" "\ \&"
+.TH "DWB\-JS" "7" "03/13/2013" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
diff --git a/extensions/perdomainsettings b/extensions/perdomainsettings
index 91b7e4cc..df2645ca 100644
--- a/extensions/perdomainsettings
+++ b/extensions/perdomainsettings
@@ -174,7 +174,7 @@ function onNavigation(wv, frame, request, action)
o.set = {};
var uri = request.uri;
var host = request.message.uri.host;
- var domain = util.domainFromHost(host);
+ var domain = net.domainFromHost(host);
var rTld = new RegExp(domain.substring(domain.indexOf(".") + 1) + "$");
var domainTld = domain.replace(rTld, "tld");
var hostTld = host.replace(rTld, "tld");
diff --git a/extensions/requestpolicy b/extensions/requestpolicy
index 4d0a66f3..9af23275 100644
--- a/extensions/requestpolicy
+++ b/extensions/requestpolicy
@@ -275,7 +275,7 @@ function showMenu()
});
}
- tabComplete("Requestpolicy:", labels, function (response) {
+ util.tabComplete("Requestpolicy:", labels, function (response) {
var i, l, len;
for (i=0, len = labels.length; i<len; ++i)
{
@@ -307,7 +307,7 @@ function unblockCurrent()
}
if (labels.length > 0)
{
- tabComplete("Unblock:", labels, function(response) {
+ util.tabComplete("Unblock:", labels, function(response) {
listRemove(persistentList, "_alwaysBlock", response, true);
if (config.autoreload)
tabs.current.reload();
@@ -331,7 +331,7 @@ function unblockAll()
if (labels.length > 0)
{
- tabComplete("Unblock:", labels, function(response) {
+ util.tabComplete("Unblock:", labels, function(response) {
listRemove(persistentList, "_alwaysBlock", response, true);
if (config.autoreload)
tabs.current.reload();
@@ -362,10 +362,10 @@ var resourceCB = (function ()
return false;
if (message.firstParty)
- firstParty = util.domainFromHost(message.firstParty.host);
+ firstParty = net.domainFromHost(message.firstParty.host);
else
firstParty = wv.mainFrame.domain;
- domain = util.domainFromHost(message.uri.host);
+ domain = net.domainFromHost(message.uri.host);
if (firstParty == domain)
return false;
diff --git a/extensions/userscripts b/extensions/userscripts
index 82a15eb3..e8fd71ee 100644
--- a/extensions/userscripts
+++ b/extensions/userscripts
@@ -232,7 +232,7 @@ function doInject(frame, item)
{
if (item.delay > 0)
{
- timerStart(item.delay, function() {
+ timer.start(item.delay, function() {
frame.inject(item.script, null, item.offset, item.unwrap);
return false;
});
diff --git a/scripts/lib/data.js b/scripts/lib/data.js
index 3a3b76e1..0f49e5aa 100644
--- a/scripts/lib/data.js
+++ b/scripts/lib/data.js
@@ -2,22 +2,110 @@
var configDir = data.configDir;
var profile = data.profile;
Object.defineProperties(data, {
+ /**
+ * The bookmark file
+ * @name bookmarks
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"bookmarks" : { value : configDir + "/" + profile + "/bookmarks", enumerable : true },
+ /**
+ * The history file
+ * @name history
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"history" : { value : configDir + "/" + profile + "/history", enumerable : true },
+ /**
+ * The cookie file
+ * @name cookies
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"cookies" : { value : configDir + "/" + profile + "/cookies", enumerable : true },
+ /**
+ * The quickmarks file
+ * @name quickmarks
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"quickmarks" : { value : configDir + "/" + profile + "/quickmarks", enumerable : true },
+ /**
+ * The whitelist for persistent cookies
+ * @name cookiesWhitelist
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"cookiesWhitelist" : { value : configDir + "/" + profile + "/cookies.allow", enumerable : true },
+ /**
+ * The whitelist for session cookies
+ * @name sessionCookiesWhitelist
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"sessionCookiesWhitelist" : { value : configDir + "/" + profile + "/cookies_session.allow", enumerable : true },
+ /**
+ * The whitelist for plugins
+ * @name pluginsWhitelist
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"pluginsWhitelist" : { value : configDir + "/" + profile + "/plugins.allow", enumerable : true },
+ /**
+ * The whitelist for scripts
+ * @name scriptWhitelist
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"scriptWhitelist" : { value : configDir + "/" + profile + "/scripts.allow", enumerable : true },
+ /**
+ * The session file
+ * @name session
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"session" : { value : configDir + "/" + profile + "/session", enumerable : true },
+ /**
+ * The custom keys file
+ * @name customKeys
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"customKeys" : { value : configDir + "/" + profile + "/custom_keys", enumerable : true },
+ /**
+ * The keyboard configuration file
+ * @name keys
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"keys" : { value : configDir + "/keys", enumerable : true },
+ /**
+ * The settings configuration file
+ * @name settings
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"settings" : { value : configDir + "/settings", enumerable : true },
+ /**
+ * The searchengines file
+ * @name searchengines
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
"searchEngines" : { value : configDir + "/searchengines", enumerable : true },
- "keys" : { value : configDir + "/keys", enumerable : true },
- "settings" : { value : configDir + "/settings", enumerable : true },
- "searchEngines" : { value : configDir + "/searchengines", enumerable : true }
});
})();
Object.freeze(data);
diff --git a/scripts/lib/dwb.js b/scripts/lib/dwb.js
index 06dde8a4..832fa0a8 100644
--- a/scripts/lib/dwb.js
+++ b/scripts/lib/dwb.js
@@ -23,194 +23,489 @@
}
modules.push(_modules[name]);
}
+ /**
+ * Callback that will be called when all provided modules have been
+ * loaded
+ *
+ * @callback requireCallback
+ *
+ * @param {...varargs|Object} arguments
+ * Variable number of modules, for each module one argument, if
+ * <i>null</i> was passed to require the callback will only
+ * have on parameter that contains all modules.
+ *
+ * @example
+ * require(["foo", "bar"], function(foo, bar) {
+ * ...
+ * });
+ * require(null, function(modules) {
+ * var foo = modules.foo;
+ * var bar = modules.bar;
+ * });
+ *
+ *
+ * */
if (callback)
callback.apply(callback, modules);
}
};
var _contexts = {};
Object.defineProperties(this, {
- "Glob" :
- {
- value : (function() {
- var esc = new RegExp("[-\/\\^$+.()|[\]{}]", "g");
- var matcher = new RegExp("(\\\\)?([*?])", "g");
- var cnstr = function (m, f, s) {
- return f ? m : s == "?" ? "." : ".*";
- };
- return function(p) {
- var regex = new RegExp("^" + p.replace(esc, '\\$&').replace(matcher, cnstr) + "$");
- return Object.create(Object.prototype, {
- match : { value : function(string) { return regex.test(string); } },
- toString : { value : function() { return p; } }
- });
- };
- })()
- },
- "provide" :
- {
- value : function(name, module)
+ "Glob" :
+ {
+ value : (function() {
+ var esc = new RegExp("[-\/\\^$+.()|[\]{}]", "g");
+ var matcher = new RegExp("(\\\\)?([*?])", "g");
+ var cnstr = function (m, f, s) {
+ return f ? m : s == "?" ? "." : ".*";
+ };
+ /**
+ * Constructs a new Glob
+ *
+ * @name Glob
+ * @class Globs are similar to regular expressions but much
+ * simpler, can be used for pattern matching. They
+ * only match against wildcard <b>*</b> and joker
+ * <b>?</b> where the wildcard character matches
+ * any number of unknown characters and the joker
+ * matches exactly one unkown character
+ * @constructs Glob
+ *
+ * @param {String} pattern The pattern to match against
+ *
+ * @example
+ * var g = new Glob("foo*ba?baz");
+ * */
+ return function(p) {
+ var regex = new RegExp("^" + p.replace(esc, '\\$&').replace(matcher, cnstr) + "$");
+ return Object.create(Object.prototype, {
+ /**
+ * Match against a text
+ * @name match
+ * @memberOf Glob.prototype
+ * @function
+ * @example
+ * var glob = new Glob("foo*ba?");
+ * glob.match("foobarbaz"); // true
+ * glob.match("foobaz"); // true
+ * glob.match("foobarbazx"); // false
+ * glob.match("fooba"); // false
+ *
+ * @param {String} text The text to match
+ * against
+ * @returns {Boolean}
+ * Whether the text matches the globs pattern
+ * */
+ match : { value : function(string) { return regex.test(string); } },
+ /**
+ * Converts a glob to string
+ * @name toString
+ * @memberOf Glob.prototype
+ * @function
+ *
+ * @returns {String}
+ * The original pattern passed to the constructor
+ * */
+ toString : { value : function() { return p; } }
+ });
+ };
+ })()
+ },
+ /**
+ * Define a module that can be retrieved with require in other scripts
+ * @name provide
+ * @function
+ *
+ * @param {String} name The name of the module
+ * @param {Object} module The module
+ * @example
+ * provide("foo", {
+ * baz : 37,
+ * bar : function() { ... }
+ * });
+ *
+ * */
+ "provide" :
+ {
+ value : function(name, module)
+ {
+ if (_modules[name])
{
- if (_modules[name])
- {
- io.debug({
- offset : 1, arguments : arguments,
- error : new Error("provide: Module " +
- name + " is already defined!")
- });
- }
- else
- _modules[name] = module;
+ io.debug({
+ offset : 1, arguments : arguments,
+ error : new Error("provide: Module " +
+ name + " is already defined!")
+ });
}
- },
- "replace" :
+ else
+ _modules[name] = module;
+ }
+ },
+ /**
+ * Same as provide but replaces modules if they are already defined
+ * @name replace
+ * @function
+ *
+ * @param {String} name The name of the module
+ * @param {Object} module The module
+ *
+ * */
+ "replace" :
+ {
+ value : function(name, module)
{
- value : function(name, module)
+ if (! module && _modules[name] )
{
- if (! module && _modules[name] )
- {
- for (var key in _modules[name])
- delete _modules[name][key];
+ for (var key in _modules[name])
+ delete _modules[name][key];
- delete _modules[name];
- }
- else
- _modules[name] = module;
+ delete _modules[name];
}
- },
- "require" :
+ else
+ _modules[name] = module;
+ }
+ },
+ /**
+ * Load modules asynchronously
+ * @name require
+ * @function
+ *
+ * @param {Array} names Array of module names or null, passing null
+ * will require all defined modules
+ * @param {requireCallback} callback
+ * A callback function, the modules are passed as parameters to
+ * the callback
+ * @example
+ * require(["foo", "bar"], function(foo, bar) {
+ * io.print(foo.baz);
+ * });
+ * */
+ "require" :
+ {
+ value : function(names, callback)
{
- value : function(names, callback)
+ if (names !== null && ! (names instanceof Array))
{
- if (names !== null && ! (names instanceof Array))
- {
- io.debug({
- error : new Error("require : invalid argument (" +
- JSON.stringify(names) + ")"),
- offset : 1,
- arguments : arguments
- });
- return;
- }
-
- if (!_initialized)
- _callbacks.push({callback : callback, names : names});
- else
- _applyRequired(names, callback);
+ io.debug({
+ error : new Error("require : invalid argument (" +
+ JSON.stringify(names) + ")"),
+ offset : 1,
+ arguments : arguments
+ });
+ return;
}
- },
- "_initNewContext" :
- {
- value : (function() {
- return function(self, arguments, path) {
- var generateId = (function() {
- var id = 0;
- var timeStamp = new Date().getTime();
- return function() {
- id++;
- return checksum(timeStamp + (id) + path, ChecksumType.sha1);
- };
- })();
- var id = "_" + generateId();
- _contexts[id] = self;
- Object.defineProperties(self, {
- "path" : { value : path },
- "debug" : { value : io.debug.bind(self) },
- "_arguments" : { value : arguments },
- "generateId" : { value : generateId },
- "setPrivate" :
- {
- value : function(id, object, key, value)
+
+ if (!_initialized)
+ _callbacks.push({callback : callback, names : names});
+ else
+ _applyRequired(names, callback);
+ }
+ },
+ "_initNewContext" :
+ {
+ value : (function() {
+ return function(self, arguments, path) {
+ var generateId = (function() {
+ var id = 0;
+ var timeStamp = new Date().getTime();
+ return function() {
+ id++;
+ return util.checksum(timeStamp + (id) + path, ChecksumType.sha1);
+ };
+ })();
+ var id = "_" + generateId();
+ _contexts[id] = self;
+ /**
+ * In every script the variable <i>script</i>
+ * refers to the encapsulating function.
+ *
+ * @namespace
+ * @name script
+ *
+ * */
+ Object.defineProperties(self, {
+ /**
+ * The path of the script
+ *
+ * @name path
+ * @memberOf script
+ * @constant
+ * */
+ "path" : { value : path },
+ /**
+ * Print debug messages. Basically the same as
+ * {@link io.debug} but prints some additional
+ * information.
+ *
+ * @name debug
+ * @memberOf script
+ * @function
+ * @param {Object|Function} params|Function
+ * Parameters passed to {@link io.debug} or a function to debug, see also {@link Function}
+ *
+ * @example
+ * script.debug({ message : "foobar" });
+ *
+ * var myFunction = function() {
+ * ...
+ * };
+ *
+ * bind("xx", script.debug(myFunction));
+ *
+ * // Equivalent to
+ * bind("xx", myFunction.debug(script));
+ *
+ * */
+ "debug" : { value : io.debug.bind(self) },
+ "_arguments" : { value : arguments },
+ /**
+ * Generates a unique id. Successive calls will
+ * generate new ids.
+ *
+ * @name generateId
+ * @memberOf script
+ * @function
+ *
+ * @returns {String}
+ * A unique id
+ * */
+ "generateId" : { value : generateId },
+ /**
+ *
+ * Convenience function to set a private property on an object that doesn’t conflict
+ * with properties set in other scripts. It uses a random unique id to set the property, so
+ * the property can most likely only be retrieved with {@link script.getPrivate|getPrivate}. This is
+ * mostly useful for objects derived from GObject since GObjects are shared between all
+ * scripts.
+ *
+ * @name setPrivate
+ * @memberOf script
+ * @function
+ *
+ * @param {Object} object The object on which the value was set
+ * @param {String} key The property name
+ * @param {Object} value The value to set
+ * @example
+ * signals.connect("loadFinished", function(wv) {
+ * // would conflict if another script also sets foo on the same webview
+ * wv.foo = "bar"
+ * // secure, won't conflict with other scripts
+ * script.setPrivate(wv, "foo", "bar");
+ * });
+ * */
+ "setPrivate" :
+ {
+ value : function(id, object, key, value)
+ {
+ var realKey = key + id;
+ if (object[realKey])
+ object[realKey] = value;
+ else
{
- var realKey = key + id;
- if (object[realKey])
- object[realKey] = value;
- else
- {
- Object.defineProperty(object, realKey, {
- value : value, writable : true
- });
- }
- }.bind(self, id)
- },
- "getPrivate" :
+ Object.defineProperty(object, realKey, {
+ value : value, writable : true
+ });
+ }
+ }.bind(self, id)
+ },
+ /**
+ * Gets a private property of an object previously set with {@link script.setPrivate|setPrivate}
+ *
+ * @name getPrivate
+ * @memberOf script
+ * @function
+ *
+ * @param {Object} object The object on which the value was set
+ * @param {String} key The property name
+ *
+ * @returns {Object}
+ * The private value
+ * */
+ "getPrivate" :
+ {
+ value : function(id, object, key)
{
- value : function(id, object, key)
- {
- return object[key + id];
- }.bind(self, id)
- }
- });
- Object.freeze(self);
+ return object[key + id];
+ }.bind(self, id)
+ }
+ });
+ Object.freeze(self);
- };
- })()
- },
- // Called after all scripts have been loaded and executed
- // Immediately deleted from the global object, so it is not callable
- // from other scripts
- "_initAfter" :
- {
- value : function()
+ };
+ })()
+ },
+ // Called after all scripts have been loaded and executed
+ // Immediately deleted from the global object, so it is not callable
+ // from other scripts
+ "_initAfter" :
+ {
+ value : function()
+ {
+ var i, l;
+ _initialized = true;
+ for (i=0, l=_callbacks.length; i<l; i++)
{
- var i, l;
- _initialized = true;
- for (i=0, l=_callbacks.length; i<l; i++)
- {
- _applyRequired(_callbacks[i].names, _callbacks[i].callback);
- }
- },
- configurable : true
+ _applyRequired(_callbacks[i].names, _callbacks[i].callback);
+ }
},
- "_initBefore" :
+ configurable : true
+ },
+ "_initBefore" :
+ {
+ value : function(contexts)
{
- value : function(contexts)
- {
- //_contexts = contexts;
- Object.freeze(this);
- },
- configurable : true
- }
+ //_contexts = contexts;
+ Object.freeze(this);
+ },
+ configurable : true
+ }
});
Object.defineProperties(GObject.prototype, {
+ /**
+ * Connects to a property change notification
+ *
+ * @memberOf GObject.prototype
+ * @name notify
+ * @function
+ *
+ * @param {String} name
+ * The property name, can also be in camelcase.
+ * @param {GObject~notifyCallback} callback
+ * Callback that will be called when the property changes
+ * @param {Boolean} [after]
+ * Whether to connect after the default handler.
+ *
+ * @returns {Number}
+ * The signal id of this signal
+ * */
"notify" :
{
value : function(name, callback, after)
{
- return this.connect("notify::" + util.uncamelize(name), callback, after || false);
+ return this.connect.call(this, "notify::" + util.uncamelize(name), callback, after || false);
}
},
+ /**
+ * Connect to a gobject-signal but block the emission of the own
+ * callback during execution of the callback. Useful if the object
+ * is connected to a notify event and the the property is changed in
+ * the callback function.
+ * @memberOf GObject.prototype
+ * @name connectBlocked
+ * @function
+ *
+ * @param {String} name The signal name.
+ * @param {Function} callback Callback that will be called when the signal is emitted.
+ * @param {Boolean} [after] Whether to connect after the default signal handler.
+ *
+ * @returns {Number}
+ * The signal id of this signal
+ * */
"connectBlocked" :
{
value : function(name, callback, after)
{
+ io.print(this.label);
var sig = this.connect(name, (function() {
this.blockSignal(sig);
- var result = callback.apply(callback, arguments);
+ var result = callback.apply(this, arguments);
this.unblockSignal(sig);
return result;
}).bind(this));
return sig;
}
},
+ /**
+ * Connects to a property change notification but with signal
+ * blocking. Must be used if the property is modified in the
+ * callback function.
+ *
+ * @memberOf GObject.prototype
+ * @name notifyBlocked
+ * @function
+ *
+ * @param {String} name
+ * The property name, can also be in camelcase.
+ * @param {GObject~notifyCallback} callback
+ * Callback that will be called when the property changes
+ * @param {Boolean} [after]
+ * Whether to connect after the default handler.
+ *
+ * @returns {Number}
+ * The signal id of this signal
+ *
+ * @example
+ * gui.statusLabel.notifyBlocked("label", function() {
+ * this.label += "foo";
+ * });
+ *
+ * */
"notifyBlocked" :
{
value : function(name, callback, after)
{
- return this.connectBlocked("notify::" + util.uncamelize(name), callback, after || false);
+ return this.connectBlocked.call(this, "notify::" + util.uncamelize(name), callback, after || false);
}
}
});
Object.defineProperties(Deferred.prototype, {
+ /**
+ * Registers a function for the done-chain
+ *
+ * @name done
+ * @memberOf Deferred.prototype
+ * @function
+ *
+ * @param {Deferred~resolveCallback} callback
+ * A callback function that will be called when the Deferred is
+ * resolved. If the function returns a deferred the original
+ * deferred will be replaced with the new deferred.
+ *
+ * @returns {Deferred}
+ * A new Deferred that can be used to chain callbacks
+ * */
"done" : {
- value : function(method) {
+ value : function(method)
+ {
return this.then(method);
}
},
+ /**
+ * Registers a function for the fail-chain
+ *
+ * @name fail
+ * @memberOf Deferred.prototype
+ * @function
+ *
+ * @param {Deferred~rejectCallback} callback
+ * A callback function that will be called when the Deferred is
+ * rejected. If the function returns a deferred the original
+ * deferred will be replaced with the new deferred.
+ *
+ * @returns {Deferred}
+ * A new Deferred that can be used to chain callbacks
+ * */
"fail" : {
- value : function(method) {
+ value : function(method)
+ {
return this.then(null, method);
}
},
+ /**
+ * Registers a function for the done- and fail-chain
+ *
+ * @name always
+ * @memberOf Deferred.prototype
+ * @function
+ *
+ * @param {Deferred~resolveCallback|Deferred~rejectCallback} callback
+ * A callback function that will be called when the Deferred is
+ * resolved or rejected. If the function returns a deferred the
+ * original deferred will be replaced with the new deferred.
+ *
+ * @returns {Deferred}
+ * A new Deferred that can be used to chain callbacks
+ * */
"always" : {
value : function(method)
{
@@ -218,6 +513,49 @@
}
}
});
+ /**
+ * Static method that can be used for synchronous and asynchronous
+ * operations.
+ * If the first parameter is a Deferred ondone is called when the Deferred is
+ * resolved and onfail is called if the Deferred is rejected, otherwise
+ * ondone is called and value is the first parameter of the callback.
+ *
+ * @name when
+ * @memberOf Deferred
+ * @function
+ *
+ * @param {Value|Deferred} value
+ * A Deferred or an arbitrary value
+ * @param {Deferred~resolveCallback} ondone
+ * Callback function for the done chain
+ * @param {Deferred~rejectCallback} onFail
+ * Callback function for the fail chain
+ *
+ * @returns {Any value}
+ * The value
+ *
+ * @example
+ * function sync() {
+ * return "sync";
+ * }
+ * function async() {
+ * var stdout;
+ * var d = new Deferred();
+ * timer.start(1000, function() {
+ * d.resolve("async");
+ * return false;
+ * });
+ * return d;
+ * }
+ * Deferred.when(sync(), function(response) {
+ * // sync
+ * io.print(response);
+ * });
+ * Deferred.when(async(), function(response) {
+ * // async
+ * io.print(response);
+ * });
+ * */
Object.defineProperty(Deferred, "when", {
value : function(value, callback, errback)
{
@@ -227,6 +565,41 @@
return callback(value);
}
});
+ /**
+ * Standard javascript Function object with additional methods
+ * @name Function
+ * @class
+ * */
+ /**
+ * Convenience method to print debug messages, wraps the function into a
+ * try/catch statement
+ *
+ * @name debug
+ * @memberOf Function.prototype
+ * @function
+ *
+ * @param {Object} [info]
+ * Arguments passed to io.debug, the recommended argument is {@link script}
+ *
+ * @example
+ * //!javascript
+ *
+ * function onNavigation() {
+ * var x = y;
+ * };
+ * signals.connect("navigation", onNavigation.debug(script));
+ *
+ * // Debug message:
+ * ==> DEBUG [FILE] : /path/to/script.js
+ * ==> DEBUG [ERROR] : Error in line 4: Can't find variable: y
+ * ==> DEBUG [STACK] : [onNavigation] [[native code]] [value] [[native code]]
+ * ==> DEBUG [SOURCE]
+ * ...
+ * 4 > function onNavigation( {
+ * --> 5 > var x = y;
+ * 6 > }
+ * ...
+ * */
if (!Function.prototype.debug)
{
Object.defineProperty(Function.prototype, "debug", {
@@ -249,5 +622,91 @@
}
});
}
+ /**
+ * Standard javascript array with additional methods
+ * @name Array
+ * @class
+ * */
+ /**
+ * Basically the same as Array.indexOf but without typechecking
+ * @name fastIndexOf
+ * @memberOf Array.prototype
+ * @function
+ *
+ * @param {Object} object Object to search for
+ *
+ * @returns {Number}
+ * The index of the object or -1 if the array doesn't contain the
+ * object
+ * */
+ if (Array.prototype.fastIndexOf === undefined)
+ {
+ Object.defineProperty(Array.prototype, "fastIndexOf",
+ {
+ value : function (v)
+ {
+ for (var i=0, l=this.length; i<l; ++i) {
+ if (this[i] == v)
+ return i;
+ }
+ return -1;
+ }
+ });
+ }
+ /**
+ * Basically the same as Array.lastIndexOf but without typechecking
+ * @name fastLastIndexOf
+ * @memberOf Array.prototype
+ * @function
+ *
+ * @param {Object} object Object to search for
+ *
+ * @returns {Number}
+ * The index of the object or -1 if the array doesn't contain the
+ * object
+ * */
+ if (Array.prototype.fastLastIndexOf === undefined)
+ {
+ Object.defineProperty(Array.prototype, "fastLastIndexOf",
+ {
+ value : function (v)
+ {
+ for (var i=this.length-1; i>=0; --i) {
+ if (this[i] == v)
+ return i;
+ }
+ return -1;
+ }
+ });
+ }
+ /**
+ * Standard RegExp object with additional methods
+ * @name RegExp
+ * @class
+ * */
+ /**
+ * Escapes special characters that are used in regular expressions
+ * @name escape
+ * @memberOf RegExp
+ * @function
+ *
+ * @param {String} string String to escape
+ *
+ * @returns {String}
+ * The escaped string
+ * @example
+ * // /.*foo\.bar\[\].*$/
+ * var r = new RegExp(".*" + RegExp.escape("foo.bar[]") + ".*$");
+ * */
+ if (! RegExp.escape)
+ {
+ Object.defineProperty(RegExp, "escape",
+ {
+ value : function(string)
+ {
+ return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
+ }
+ });
+ }
})();
Object.preventExtensions(this);
diff --git a/scripts/lib/enums.js b/scripts/lib/enums.js
index 7dedf800..8d2f2bfb 100644
--- a/scripts/lib/enums.js
+++ b/scripts/lib/enums.js
@@ -1,10 +1,71 @@
-const LoadStatus = {
- provisional : 0,
- committed : 1,
- finished : 2,
- firstVisualLayout : 3,
- failed : 4
+/**
+ * All enums and flags are global, the type <i>Enum</i> just
+ * means that it is a number, the type <i>Flag</i> means that it is a number
+ * that can be used in a bitmask.
+ * @namespace
+ * @name Enums and Flags
+ * @static
+ * @example
+ * signals.connect("loadStatus", function(wv) {
+ * if (wv.loadStatus == LoadStatus.finished)
+ * {
+ * ...
+ * }
+ * });
+ * signals.connect("keyPress", function(wv, event) {
+ * // Check if Control and Mod1 is pressed
+ * if (event.state & (Modifier.Control | Modifier.Mod1))
+ * {
+ * ...
+ * }
+ * });
+ * */
+/**
+ * Loadstatus of a WebKitWebView or WebKitWebFrame
+ * @constant
+ * @name LoadStatus
+ * @memberOf Enums and Flags
+ * @type Object
+ * @property {Enum} provisional
+ * @property {Enum} committed
+ * @property {Enum} finished
+ * @property {Enum} firstVisualLayout
+ * @property {Enum} failed
+ * */
+const LoadStatus =
+{
+ provisional : 0,
+ committed : 1,
+ finished : 2,
+ firstVisualLayout : 3,
+ failed : 4
};
+Object.freeze(LoadStatus);
+/**
+ * Gdk modifier flag
+ * @constant
+ * @name Modifier
+ * @memberOf Enums and Flags
+ * @type Object
+ * @property {Flag} Shift
+ * @property {Flag} Lock
+ * @property {Flag} Control
+ * @property {Flag} Mod1
+ * @property {Flag} Mod2
+ * @property {Flag} Mod3
+ * @property {Flag} Mod4
+ * @property {Flag} Mod5
+ * @property {Flag} Button1
+ * @property {Flag} Button2
+ * @property {Flag} Button3
+ * @property {Flag} Button4
+ * @property {Flag} Button5
+ * @property {Flag} Super
+ * @property {Flag} Hyper
+ * @property {Flag} Meta
+ * @property {Flag} Release
+ * @property {Flag} Modifier
+ * */
const Modifier = {
Shift : 1 << 0,
Lock : 1 << 1,
@@ -25,6 +86,20 @@ const Modifier = {
Release : 1 << 30,
Modifier : 0x5c001fff
};
+Object.freeze(Modifier);
+/**
+ * ButtonContext flag
+ * @constant
+ * @name ButtonContext
+ * @memberOf Enums and Flags
+ * @type Object
+ * @property {Flag} document
+ * @property {Flag} link
+ * @property {Flag} image
+ * @property {Flag} media
+ * @property {Flag} selection
+ * @property {Flag} editable
+ * */
const ButtonContext = {
document : 1 << 1,
link : 1 << 2,
@@ -33,11 +108,36 @@ const ButtonContext = {
selection : 1 << 5,
editable : 1 << 6
};
+Object.freeze(ButtonContext);
+/**
+ * ClickType
+ * @constant
+ * @name ClickType
+ * @memberOf Enums and Flags
+ * @type Object
+ * @property {Enum} click
+ * @property {Enum} doubleClick
+ * @property {Enum} tripleClick
+ * */
const ClickType = {
click : 4,
doubleClick : 5,
tripleClick : 6
};
+Object.freeze(ClickType);
+/**
+ * NavigationReason
+ * @constant
+ * @name NavigationReason
+ * @memberOf Enums and Flags
+ * @type Object
+ * @property {Enum} linkClicked
+ * @property {Enum} formSubmitted
+ * @property {Enum} backForward
+ * @property {Enum} reload
+ * @property {Enum} formResubmitted
+ * @property {Enum} other
+ * */
const NavigationReason = {
linkClicked : 0,
formSubmitted : 1,
@@ -46,6 +146,19 @@ const NavigationReason = {
formResubmitted : 4,
other : 5
};
+Object.freeze(NavigationReason);
+/**
+ * Status of a download
+ * @constant
+ * @name DownloadStatus
+ * @memberOf Enums and Flags
+ * @type Object
+ * @property {Enum} error
+ * @property {Enum} created
+ * @property {Enum} started
+ * @property {Enum} cancelled
+ * @property {Enum} finished
+ * */
const DownloadStatus = {
error : -1,
created : 0,
@@ -53,11 +166,36 @@ const DownloadStatus = {
cancelled : 2,
finished : 3
};
+Object.freeze(DownloadStatus);
+/**
+ * Type of checksum
+ * @constant
+ * @name ChecksumType
+ * @memberOf Enums and Flags
+ * @type Object
+ * @property {Enum} md5
+ * @property {Enum} sha1
+ * @property {Enum} sha256
+ * */
const ChecksumType = {
md5 : 0,
sha1 : 1,
sha256 : 2
};
+Object.freeze(ChecksumType);
+/**
+ * Filetest flag, multiple flags can be set on a file
+ * @constant
+ * @name FileTest
+ * @memberOf Enums and Flags
+ * @type Object
+ *
+ * @property {Flag} regular regular file
+ * @property {Flag} symlink symbolic link
+ * @property {Flag} dir directory
+ * @property {Flag} executable executable File
+ * @property {Flag} exists Whether the file exists
+ * */
const FileTest = {
regular : 1 << 0,
symlink : 1 << 1,
@@ -65,18 +203,57 @@ const FileTest = {
executable : 1 << 3,
exists : 1 << 4
};
+Object.freeze(FileTest);
+/**
+ * A mode
+ * @constant
+ * @name Modes
+ * @memberOf Enums and Flags
+ * @type Object
+ *
+ * @property {Flag} NormalMode normal mode
+ * @property {Flag} InsertMode insert mode
+ * @property {Flag} CommandMode command mode
+ * @property {Flag} HintMode hint mode
+ * */
const Modes = {
NormalMode : 1<<0,
InsertMode : 1<<1,
CommandMode : 1<<2,
HintMode : 1<<3
};
+Object.freeze(Modes);
+/**
+ * Clipboard selection
+ * @constant
+ * @name Selection
+ * @memberOf Enums and Flags
+ * @type {Object}
+ *
+ * @property {Enum} primary The primary selection
+ * @property {Enum} clipboard The clipboard
+ * */
const Selection = {
primary : 1,
clipboard : 2
};
+Object.freeze(Selection);
+/**
+ * Override certain conditions when binding a shortcut with bind
+ * @constant
+ * @name OverrideKey
+ * @memberOf Enums and Flags
+ * @type {Object}
+ * @property {Flag} insertMode
+ * Executes a shortcut also in insertmode
+ * @property {Flag} entryFocus
+ * Executes a shortcut also when the entry has focus
+ * @property {Flag} all
+ * Always executes a shortcut
+ * */
const OverrideKey = {
insertMode : 1<<5,
entryFocus : 1<<6,
all : 1<<7
};
+Object.freeze(OverrideKey);
diff --git a/scripts/lib/extensions.js b/scripts/lib/extensions.js
index 7d1a2356..d7b8de64 100644
--- a/scripts/lib/extensions.js
+++ b/scripts/lib/extensions.js
@@ -1,3 +1,91 @@
+/**
+ * Handles extensions. If scripts should be managed by <b>dwbem</b> they must
+ * be implemented as an extension. In contrast to regular scripts extensions can
+ * be enabled/disabled on the fly without reloading all userscripts. Every extension must contain two special tags,
+ * <b>/*&lt;INFO ... INFO&gt;*<span><span>/</b> that will be used by dwbem to find information
+ * about the extension and <b>//&lt;DEFAULT_CONFIG ... //&gt;DEFAULT_CONFIG</b> that
+ * will be used by dwbem to find the default configuration
+ * Every extension must also return an object that can have up to four properties.
+ *
+ *
+ * @namespace
+ * Static object that handles extensions
+ * @name extensions
+ * @static
+ *
+
+ * @property {Object} [defaultConfig]
+ * The default configuration, will be passed to extensions.getConfig
+ * @property {extensions~onEnd} end
+ * A function that will be called when the extension is unloaded, can be
+ * used to disconnect from signals/unbind shortcuts, ...
+ * @property {Object} [exports]
+ * An object that exports some functionality or the configuration, the
+ * object can retrieved in other scripts with {@link require}
+ * @property {extensions~onInit} init
+ * A function that will be called when an extension is loaded
+ *
+ * @example
+ * // ext:set ft=javascript:
+ *
+ * /*&lt;INFO
+ * Extension that does some awesome things
+ * INFO&gt;*<span></span>/
+ *
+ * var defaultConfig = {
+ * //&lt;DEFAULT_CONFIG
+ * // Foo
+ * foo : 37,
+ * // Shortcut to do some action
+ * shortcut : "foo"
+ * //&gt;DEFAULT_CONFIG
+ * };
+ *
+ * var myConfig = {};
+ *
+ * function action() {
+ * ...
+ * }
+ * function onNavigation() {
+ * ...
+ * }
+ * var myExtension = {
+ * defaultConfig : defaultConfig,
+ * exports : {
+ * action : action
+ * },
+ * init : function(config) {
+ * myConfig = config;
+ * bind(config.shortcut, "action");
+ * signals.connect("navigation", onNavigation);
+ * return true;
+ * },
+ * end : function() {
+ * signals.disconnect(onNavigation);
+ * unbind(action);
+ * return true;
+ * }
+ * };
+ * return myExtension;
+ *
+ * */
+/**
+ * Called when an extension is unloaded
+ * @callback extensions~onEnd
+ *
+ * @returns {Boolean}
+ * Return true if the extension was successfully unloaded
+ * */
+/**
+ * Called when an extension is loaded
+ * @callback extensions~onInit
+ *
+ * @param {Object} configuration
+ * The configuration passed to {@link extensions.load}
+ * @returns {Boolean}
+ * Return true if the extension was successfully initialized
+ * */
+
(function () {
var _config = {};
var _registered = {};
@@ -54,6 +142,17 @@
};
Object.defineProperties(extensions,
{
+ /**
+ * Print a warning message to stderr
+ *
+ * @memberOf extensions
+ * @function
+ *
+ * @param {String} name
+ * Name of the extension
+ * @param {String} message
+ * The message to print
+ * */
"warning" :
{
value : function (name, message)
@@ -61,6 +160,17 @@
io.print("\033[1mDWB EXTENSION WARNING: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
}
},
+ /**
+ * Print an error message to stderr
+ *
+ * @memberOf extensions
+ * @function
+ *
+ * @param {String} name
+ * Name of the extension
+ * @param {String} message
+ * The message to print
+ * */
"error" :
{
value : function (name, a, b) {
@@ -81,6 +191,17 @@
}
}
},
+ /**
+ * Print message to stderr
+ *
+ * @memberOf extensions
+ * @function
+ *
+ * @param {String} name
+ * Name of the extension
+ * @param {String} message
+ * The message to print
+ * */
"message" :
{
value : function (name, message)
@@ -88,6 +209,18 @@
io.print("\033[1mDWB EXTENSION: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr");
}
},
+ /**
+ * Merges the default configuration with the configuration passed to
+ * {@link extensions.load}
+ *
+ * @memberOf extensions
+ * @function
+ *
+ * @param {Object} config
+ * The configuration was passed to {@link extensions.load|load}
+ * @param {Object} defaultConfig
+ * The default configuration
+ * */
"getConfig" :
{
value : function(c, dc)
@@ -103,6 +236,19 @@
return config;
}
},
+ /**
+ * Loads an extension, the default path for an extension is
+ * <i>{@link data.userDataDir}/extensions/name_of_extension</i> or
+ * <i>{@link data.systemDataDir}/extensions/name_of_extension</i>
+ *
+ * @memberOf extensions
+ * @function
+ *
+ * @param {String} name
+ * The name of the extension
+ * @param {Object} configuration
+ * The configuration that will be used for the extension
+ * */
"load" :
{
value : function(name, c)
@@ -160,7 +306,7 @@
if (plugin === null)
{
extensions.error(name, "Couldn't find extension.");
- return false;
+ return null;
}
}
try
@@ -193,6 +339,18 @@
}
}
},
+ /**
+ * Unloads an extension, calls extension.end when the extensions
+ *
+ * @memberOf extensions
+ * @function
+ *
+ * @param {String} name
+ * The name of the extension
+ *
+ * @returns {Boolean}
+ * true if the extension was found and unloaded
+ * */
"unload" :
{
value : function(name)
@@ -200,6 +358,14 @@
return _unload(name, true);
}
},
+ /**
+ * Disables all extensions, calls {@link extensions.unload} for every
+ * extension
+ *
+ * @memberOf extensions
+ * @function
+ *
+ * */
"disableAll" :
{
value : function()
@@ -208,6 +374,21 @@
_unload(key, true);
}
},
+ /**
+ * Toggles an extensions, if it is loaded toggle will unload it, otherwise
+ * it will load it.
+ *
+ * @memberOf extensions
+ * @function
+ *
+ * @param {String} name
+ * Name of the extension
+ * @param {Object} configuration
+ * Configuration that will be passed to {@link extensions.load}
+ *
+ * @returns {Boolean}
+ * true if the extension was loaded, false if it was unloaded
+ * */
"toggle" :
{
value : function(name, c)
@@ -224,6 +405,25 @@
}
}
},
+ /**
+ * Binds an extension to a shortcut
+ *
+ * @memberOf extensions
+ * @function
+ *
+ * @param {String} name
+ * Name of the extension
+ * @param {String} shortcut
+ * The shortcut that will be used to toggle the extension
+ * @param {Object} options
+ * @param {Boolean} options.load
+ * Whether to initially load the extension
+ * @param {Boolean} options.config
+ * The configuration passed to {@link extensions.load}
+ * @param {String} options.command
+ * Command that can be used from dwb's command line to toggle the
+ * extension
+ * */
"bind" :
{
value : function(name, shortcut, options)
diff --git a/scripts/lib/io.js b/scripts/lib/io.js
index 92170b14..6ebdac80 100644
--- a/scripts/lib/io.js
+++ b/scripts/lib/io.js
@@ -1,136 +1,150 @@
(function () {
- var prefixMessage = "\n==> DEBUG [MESSAGE] : ";
- var prefixFile = "\n==> DEBUG [FILE] : ";
- var prefixError = "\n==> DEBUG [ERROR] : ";
- var prefixStack = "\n==> DEBUG [STACK] : ";
- var prefixArguments = "\n==> DEBUG [ARGUMENTS] : ";
- var prefixCaller = "\n==> DEBUG [CALLER]";
- var prefixSource = "\n==> DEBUG [SOURCE]\n";
- var prefixFunction = "\n------>";
- var regHasDwb = new RegExp("[^]*/\\*<dwb\\*/([^]*)/\\*dwb>\\*/[^]*");
- var prefixEditor = " ";
- var prefixHighlight = "--> ";
- var _formatLine = function(max, line)
- {
- var size = max - Math.ceil(Math.log(line+1)/Math.log(10)) + 1;
- return Array(size).join(" ") + line + " > ";
- };
+ var prefixMessage = "\n==> DEBUG [MESSAGE] : ";
+ var prefixFile = "\n==> DEBUG [FILE] : ";
+ var prefixError = "\n==> DEBUG [ERROR] : ";
+ var prefixStack = "\n==> DEBUG [STACK] : ";
+ var prefixArguments = "\n==> DEBUG [ARGUMENTS] : ";
+ var prefixCaller = "\n==> DEBUG [CALLER]";
+ var prefixSource = "\n==> DEBUG [SOURCE]\n";
+ var prefixFunction = "\n------>";
+ var regHasDwb = new RegExp("[^]*/\\*<dwb\\*/([^]*)/\\*dwb>\\*/[^]*");
+ var prefixEditor = " ";
+ var prefixHighlight = "--> ";
+ var _formatLine = function(max, line)
+ {
+ var size = max - Math.ceil(Math.log(line+1)/Math.log(10)) + 1;
+ return Array(size).join(" ") + line + " > ";
+ };
- Object.defineProperties(io, {
- "debug" :
+ /**
+ * Prints a debug messsage and the callstack to stderr
+ *
+ * @name debug
+ * @memberOf io
+ * @function
+ * @type void
+ *
+ * @param {Object} detail Message details
+ * @param {String} detail.message A message
+ * @param {Error} detail.error A javascript Error object
+ * @param {Error} detail.arguments Arguments, only useful for the
+ * internal api
+ * */
+ Object.defineProperties(io, {
+ "debug" :
+ {
+ value : function (params)
{
- value : function (params)
- {
- if (typeof params == "function" && this._arguments)
- return params.bind(this);
- var outMessage = new String();
- params = params || {};
- var offset = params.offset || 0;
- var error, message;
- var line = -1;
- var showLine;
- var caller, source;
- var stack;
+ if (typeof params == "function" && this._arguments)
+ return params.bind(this);
+ var outMessage = new String();
+ params = params || {};
+ var offset = params.offset || 0;
+ var error, message;
+ var line = -1;
+ var showLine;
+ var caller, source;
+ var stack;
- if (typeof params == "string")
- message = params;
- else if (params instanceof Error)
- error = params;
- else
- {
- if (params.message)
- message = params.message;
- if (params.error instanceof Error)
- error = params.error;
- }
+ if (typeof params == "string")
+ message = params;
+ else if (params instanceof Error)
+ error = params;
+ else
+ {
+ if (params.message)
+ message = params.message;
+ if (params.error instanceof Error)
+ error = params.error;
+ }
- if (this.path)
- outMessage += prefixFile + this.path;
- if (message)
- outMessage += prefixMessage + message;
+ if (this.path)
+ outMessage += prefixFile + this.path;
+ if (message)
+ outMessage += prefixMessage + message;
- if (error)
- {
- if (error.line || error.line === 0)
- line = showLine = error.line;
- else
- showLine = "?";
- if (!error.stack)
- {
- try
- {
- throw new Error(error.message);
- }
- catch(e)
- {
- error = e;
- }
- offset += 1;
- }
- outMessage += prefixError + "Error in line " + showLine + ": " + error.message;
- stack = "[" + error.stack.match(/[^\n]+/g).slice(offset).join("] [")+"]";
- }
+ if (error)
+ {
+ if (error.line || error.line === 0)
+ line = showLine = error.line;
else
+ showLine = "?";
+ if (!error.stack)
{
try
{
- throw new Error();
+ throw new Error(error.message);
}
catch(e)
- {
- stack = "[" + e.stack.match(/[^\n]+/g).slice(offset + 2).join("] [")+"]";
+ {
+ error = e;
}
+ offset += 1;
}
- if (stack)
+ outMessage += prefixError + "Error in line " + showLine + ": " + error.message;
+ stack = "[" + error.stack.match(/[^\n]+/g).slice(offset).join("] [")+"]";
+ }
+ else
+ {
+ try
{
- outMessage += prefixStack + stack;
+ throw new Error();
}
-
- if (this._arguments && line >= 0)
+ catch(e)
{
- caller = String(this._arguments.callee).replace(regHasDwb, "$1", "");
- source = caller.split("\n");
- var length = source.length;
- var formatLine = _formatLine.bind(null, Math.ceil(Math.log(source.length+1)/Math.log(10)));
+ stack = "[" + e.stack.match(/[^\n]+/g).slice(offset + 2).join("] [")+"]";
+ }
+ }
+ if (stack)
+ {
+ outMessage += prefixStack + stack;
+ }
- outMessage += prefixSource;
- if (length >= line-2 && line-2 >= 0)
- {
- if (line > 2)
- outMessage += prefixEditor + "...\n";
- else
- outMessage += prefixEditor + "BOF\n";
- outMessage += prefixEditor + formatLine(line-1) + source[line-2] + "\n";
- }
+ if (this._arguments && line >= 0)
+ {
+ caller = String(this._arguments.callee).replace(regHasDwb, "$1", "");
+ source = caller.split("\n");
+ var length = source.length;
+ var formatLine = _formatLine.bind(null, Math.ceil(Math.log(source.length+1)/Math.log(10)));
+
+ outMessage += prefixSource;
+ if (length >= line-2 && line-2 >= 0)
+ {
+ if (line > 2)
+ outMessage += prefixEditor + "...\n";
else
outMessage += prefixEditor + "BOF\n";
- if (length > line-1)
- outMessage += prefixHighlight + formatLine(line) + source[line-1] + "\n";
- if (length > line && length != line+1)
- {
- outMessage += prefixEditor + formatLine(line+1) + source[line];
- if (length > line + 2)
- outMessage += "\n" + prefixEditor + "...";
- else
- outMessage += "\n" + prefixEditor + "EOF";
- }
- else
- outMessage += prefixEditor + "EOF";
+ outMessage += prefixEditor + formatLine(line-1) + source[line-2] + "\n";
}
- else if (params.arguments)
+ else
+ outMessage += prefixEditor + "BOF\n";
+ if (length > line-1)
+ outMessage += prefixHighlight + formatLine(line) + source[line-1] + "\n";
+ if (length > line && length != line+1)
{
- outMessage += prefixArguments + JSON.stringify(params.arguments);
- caller = String(params.arguments.callee.caller);
- outMessage += prefixCaller;
- outMessage += prefixFunction + "\n";
- outMessage += caller.replace(regHasDwb, "$1").replace(/\n/gm, "\n ");
- outMessage += prefixFunction;
+ outMessage += prefixEditor + formatLine(line+1) + source[line];
+ if (length > line + 2)
+ outMessage += "\n" + prefixEditor + "...";
+ else
+ outMessage += "\n" + prefixEditor + "EOF";
}
- io.print(outMessage + "\n", "stderr");
- return undefined;
+ else
+ outMessage += prefixEditor + "EOF";
}
-
+ else if (params.arguments)
+ {
+ outMessage += prefixArguments + JSON.stringify(params.arguments);
+ caller = String(params.arguments.callee.caller);
+ outMessage += prefixCaller;
+ outMessage += prefixFunction + "\n";
+ outMessage += caller.replace(regHasDwb, "$1").replace(/\n/gm, "\n ");
+ outMessage += prefixFunction;
+ }
+ io.print(outMessage + "\n", "stderr");
+ return undefined;
}
- });
+
+ }
+ });
})();
//Object.freeze(io);
diff --git a/scripts/lib/signals.js b/scripts/lib/signals.js
index 25eebede..aa867be9 100644
--- a/scripts/lib/signals.js
+++ b/scripts/lib/signals.js
@@ -36,8 +36,40 @@
}
}
};
+ var _connect = function(id, sig, func, pre)
+ {
+ pre = pre || 0;
+ if (func === null || typeof func !== "function")
+ {
+ return -1;
+ }
+ if (_registered[sig] === undefined || _registered[sig] === null)
+ {
+ _registered[sig] = [];
+ signals[sig] = function () { return signals.emit(sig, arguments); };
+ }
+ _registered[sig].push({ callback : func, id : id, pre : pre });
+ _registered[sig].sort(function(a, b) { return b.pre - a.pre; });
+ return id;
+ };
Object.defineProperties(signals,
{
+ /**
+ * Emits a signal, can be used to implement custom signals.
+ *
+ * @name emit
+ * @memberOf signals
+ * @function
+ *
+ * @param {String} signal The signal name
+ * @param {varargs} args Arguments passed to the callback function of
+ * {@link signals.connect}
+ *
+ * @returns {Boolean}
+ * The overall return value of all callback function, if one
+ * callback function returns <i>true</i> the overall return value
+ * will be <i>true</i>
+ * */
"emit" :
{
value : function(sig, args)
@@ -65,28 +97,66 @@
return ret;
}
},
+ /**
+ * Connects to a signal. Use this function to connect to a signal,
+ * setting a callback function directly on an event will overwrite
+ * all existing callbacks. The callbacks are executed in order they are
+ * connected except precedence is set for some signals.
+ *
+ * @example
+ * signals.connect("navigation", function(webview, frame, request, action) {
+ * ...
+ * });
+ *
+ * @name connect
+ * @memberOf signals
+ * @function
+ *
+ * @param {String} event
+ * The event name, see Events for details
+ * @param {Function} callback
+ * A callback function the will be called when the signal is
+ * emitted, see Type Definitions for details
+ * @param {Number} [precedence]
+ * A number indicating the precedence of executing the callback,
+ * the higher the number the earlier the function will be executed
+ * in the callback queue, note that all callbacks connected from
+ * scripts will be executed regardless of precedence. The default
+ * precedence is 0.
+ *
+ * @returns {Number}
+ * A unique signal id
+ * */
"connect" :
{
value : (function ()
{
var id = 0;
- return function(sig, func)
+ return function(sig, func, pre)
{
- if (func === null || typeof func !== "function")
- {
- return -1;
- }
- ++id;
- if (_registered[sig] === undefined || _registered[sig] === null)
- {
- _registered[sig] = [];
- signals[sig] = function () { return signals.emit(sig, arguments); };
- }
- _registered[sig].push({ callback : func, id : id });
+ id++;
+ _connect(id, sig, func, pre);
return id;
};
})()
},
+ /**
+ * Connects all webviews to a GObject signal.
+ *
+ * @name connectWebView
+ * @memberOf signals
+ * @function
+ *
+ * @param {String} signal The signal name
+ * @param {GObject~connectCallback} callback
+ * A callback function the will be called when the signal is
+ * emitted, the arguments of the callback correspond to the GObject
+ * callback
+ * @example
+ * signals.connectWebView("hovering-over-link", function(title, uri) {
+ * io.write("/tmp/hovered_sites", "a", uri + " " + title);
+ * });
+ * */
"connectWebView" :
{
value : function(name, callback)
@@ -96,6 +166,28 @@
});
}
},
+ /**
+ * Disconnect from a signal
+ *
+ * @name disconnect
+ * @memberOf signals
+ * @function
+ *
+ * @param {Number|Function} id|callback
+ * The id returned from {@link connect} or the callback
+ * function passed to connect. Note that if the same callback
+ * is used more than once the signal must be disconnected by
+ * id, otherwise the behaviour is undefined.
+ * @example
+ * signals.connect("loadFinished", function(wv) {
+ * ...
+ * signals.disconnect(this);
+ * });
+ * var id = signals.connect("loadCommitted", function(wv) {
+ * ...
+ * signals.disconnect(id);
+ * });
+ * */
"disconnect" :
{
value : function(obj) {
@@ -106,16 +198,75 @@
}
},
- "disconnectByName" :
+ /**
+ * Disconnect from all signals with matching name. Use with care, it
+ * will stop the emission of the signal in <b>all scripts</b>. Can be used to
+ * temporarily disable the emission of the signal.
+ * To reconnect to all signals pass the returned object to
+ * {@link signals.connectAll}.
+ *
+ * @name disconnectAll
+ * @memberOf signals
+ * @function
+ *
+ * @param {String} signal
+ * The signal name
+ *
+ * @returns {Object}
+ * An object that can be passed to {@link signals.connectAll} or
+ * <i>null</i>.
+ * */
+ "disconnectAll" :
{
value : function (name)
{
+ var sigs = null;
if (signals[name] !== null && signals[name] !== undefined)
{
+ var ret = [];
+ for (var i=0; i<_registered[name].length; i++)
+ ret.push(_registered[name][i]);
_disconnect(name);
- return true;
+
+ return { name : name, signals : ret };
+ }
+ return null;
+ }
+ },
+ /**
+ * Reconnect to a signal previously disconnected with
+ * {@link signals.disconnectAll}.
+ *
+ * @name connectAll
+ * @memberOf signals
+ * @function
+ *
+ * @param {Object} detail
+ * Object retrieved from {@link signals.disconnectAll}
+ * @param {String} detail.name
+ * Name of the signal
+ * @param {Array[Object]} detail.signals[]
+ * Array of signal data
+ * @param {Number} detail.signals[].id
+ * The id of the signal
+ * @param {Function} detail.signals[].callback
+ * The callback passed to {@link signals.connect}
+ * @param {Number} detail.signals[].pre
+ * The precedence
+ *
+ * */
+ "connectAll" :
+ {
+ value : function(sigs)
+ {
+ var sig, i, l;
+ var name = sigs.name;
+ var s = sigs.signals;
+ for (i=0, l=s.length; i<l; i++)
+ {
+ sig = s[i];
+ _connect(sig.id, name, sig.callback, sig.pre);
}
- return false;
}
}
});
diff --git a/scripts/lib/util.js b/scripts/lib/util.js
index e99d7a35..908c94a8 100644
--- a/scripts/lib/util.js
+++ b/scripts/lib/util.js
@@ -1,6 +1,14 @@
(function () {
Object.defineProperties(util,
{
+ /**
+ * Get the selected text in a webview
+ * @name getSelection
+ * @memberOf util
+ * @function
+ *
+ * @returns {String} The selected text or null if no text was selected
+ * */
"getSelection" :
{
value : function()
@@ -15,6 +23,15 @@
return null;
}
},
+ /**
+ * Converts camel-case string for usage with GObject properties to a
+ * non-camel-case String
+ * @name uncamelize
+ * @memberOf util
+ * @function
+ *
+ * @returns {String} The uncamelized String
+ * */
"uncamelize" :
{
value : function(text)
@@ -26,6 +43,16 @@
});
}
},
+ /**
+ * Converts non-camel-case string to a camel-case string
+ * non-camel-case String
+ *
+ * @name camelize
+ * @memberOf util
+ * @function
+ *
+ * @returns {String} A camelcase String
+ * */
"camelize" :
{
value : function(text)
@@ -55,42 +82,4 @@
}
});
}
- if (Array.prototype.fastIndexOf === undefined)
- {
- Object.defineProperty(Array.prototype, "fastIndexOf",
- {
- value : function (v)
- {
- for (var i=0, l=this.length; i<l; ++i) {
- if (this[i] == v)
- return i;
- }
- return -1;
- }
- });
- }
- if (Array.prototype.fastLastIndexOf === undefined)
- {
- Object.defineProperty(Array.prototype, "fastLastIndexOf",
- {
- value : function (v)
- {
- for (var i=this.length-1; i>=0; --i) {
- if (this[i] == v)
- return i;
- }
- return -1;
- }
- });
- }
- if (! RegExp.escape)
- {
- Object.defineProperty(RegExp, "escape",
- {
- value : function(string)
- {
- return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
- }
- });
- }
})();
diff --git a/src/callback.c b/src/callback.c
index 657632af..0e1a8f87 100644
--- a/src/callback.c
+++ b/src/callback.c
@@ -147,6 +147,38 @@ callback_key_press(GtkWidget *w, GdkEventKey *e)
if (EMIT_SCRIPT(KEY_PRESS))
{
+ /**
+ * Emitted when a key was pressed
+ * @event keyPress
+ * @memberOf signals
+ * @param {signals~onKeyPress} callback
+ * Callback function that will be called when the signal is emitted
+ *
+ * */
+ /**
+ * Callback called whenever a key is pressed
+ * @memberOf signals
+ * @callback signals~onKeyPress
+ *
+ * @param {WebKitWebView} webview The currently focused webview
+ * @param {Object} event
+ * The event
+ * @param {Boolean} event.isModifier
+ * Whether the key is a modifier
+ * @param {Number} event.keyCode
+ * The hardware keycode
+ * @param {Number} event.keyVal
+ * The keycode as listed in gdkkeysyms.h
+ * @param {String} event.name
+ * A string representation of the key
+ * @param {Modifier} event.state
+ * A bitmask of {@link Enums and Flags.Modifier|Modifier} pressed
+ *
+ * @returns {Boolean}
+ * Return true to stop emission of the signal, will also prevent
+ * dwb from handling the signal.
+ *
+ * */
char *json = util_create_json(5, UINTEGER, "state", e->state,
UINTEGER, "keyVal", e->keyval, UINTEGER, "keyCode", e->hardware_keycode,
BOOLEAN, "isModifier", e->is_modifier, CHAR, "name", gdk_keyval_name(e->keyval));
@@ -203,6 +235,32 @@ callback_key_release(GtkWidget *w, GdkEventKey *e)
{
if (EMIT_SCRIPT(KEY_RELEASE))
{
+ /**
+ * Emitted when a key was released
+ * @event keyRelease
+ * @memberOf signals
+ * @param {signals~onKeyRelease} callback
+ * Callback function that will be called when the signal is emitted
+ *
+ * */
+ /**
+ * Callback called whenever a key is pressed
+ * @callback signals~onKeyRelease
+ *
+ * @param {WebKitWebView} webview The currently focused webview
+ * @param {Object} event The event
+ * @param {Boolean} event.isModifier Whether the key is a modifier
+ * @param {Number} event.keyCode The hardware keycode
+ * @param {Number} event.keyVal The keycode as listed in gdkkeysyms.h
+ * @param {String} event.name A string representation of the
+ * key
+ * @param {Modifier} event.state
+ * A bitmask of {@link Enums and Flags.Modifier|Modifier} pressed
+ * @returns {Boolean}
+ * Return true to stop emission of the signal, will also prevent
+ * dwb from handling the signal.
+ *
+ * */
char *json = util_create_json(5, UINTEGER, "state", e->state,
UINTEGER, "keyVal", e->keyval, UINTEGER, "keyCode", e->hardware_keycode,
BOOLEAN, "isModifier", e->is_modifier, CHAR, "name", gdk_keyval_name(e->keyval));
diff --git a/src/download.c b/src/download.c
index 1b2fb24c..b2d2debd 100644
--- a/src/download.c
+++ b/src/download.c
@@ -303,6 +303,24 @@ download_status_cb(WebKitDownload *download, GParamSpec *p, DwbDownloadStatus *d
gboolean script_handled = false;
if (EMIT_SCRIPT(DOWNLOAD_STATUS))
{
+ /**
+ * Emitted when the status of a download handled by dwb changes.
+ * @event downloadStatus
+ * @memberOf signals
+ * @param {signals~onDownloadStatus} callback
+ * Callback function that will be called when the signal is emitted
+ *
+ * */
+ /**
+ * Callback called when the download status changes
+ * @callback signals~onDownloadStatus
+ *
+ * @param {WebKitDownload} download The download
+ *
+ * @returns {Boolean}
+ * Return true to stop dwb from handling the download when the
+ * download has finished
+ * */
ScriptSignal signal = { .jsobj = NULL, { G_OBJECT(download) }, SCRIPTS_SIG_META(NULL, DOWNLOAD_STATUS, 1) };
script_handled = scripts_emit(&signal);
}
@@ -450,6 +468,35 @@ download_start(const char *path)
if (EMIT_SCRIPT(DOWNLOAD_START))
{
+ /**
+ * Emitted before a download starts, after the user has chosen a path or
+ * application
+ * @event downloadStart
+ * @memberOf signals
+ * @param {signals~onDownloadStart} callback
+ * Callback function that will be called when the signal is emitted
+ *
+ * */
+ /**
+ * Callback called when the download status changes
+ * @callback signals~onDownloadStart
+ *
+ * @param {WebKitDownload} download The download
+ * @param {Object} data
+ * @param {String} data.application
+ * The application that will be spawned when the download has
+ * finished or <i>null</i> if no application will be spawned.
+ * @param {String} data.destinationUri
+ * The destination uri of the download or <i>null</i> if an
+ * application is spawned when the download has finished
+ * @param {String} data.mimeType
+ * The mimetype of the download
+ * @param {String} data.referer
+ * The referer
+ *
+ * @returns {Boolean}
+ * Return true to stop dwb from handling the download
+ * */
if (dwb.state.dl_action == DL_ACTION_EXECUTE)
{
json = util_create_json(4,
diff --git a/src/dwb.c b/src/dwb.c
index 1ec8f013..74417a3a 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -691,6 +691,45 @@ dwb_emit_status_signal(GList *gl, const char *type)
View *v = VIEW(gl);
if (EMIT_SCRIPT(STATUS_BAR))
{
+ /**
+ * Emitted before the status bar is updated.
+ * @event statusBarChange
+ * @memberOf signals
+ * @param {signals~onStatusBarChange} callback
+ * Callback called when the signal is emitted
+ * */
+ /**
+ * Callback called before dwb updates the status bar
+ * If the callback returns true dwb will not update the statusbar so it
+ * is possible to set the statusbar from the script.
+ *
+ * @callback signals~onStatusBarChange
+ *
+ * @param {WebKitWebView} webview The focused webview
+ * @param {Object} data Data
+ * @param {boolean} data.canGoBack
+ * Whether it is possible to navigate back in the webview
+ * @param {Boolean} data.canGoForward
+ * Whether it is possible to navigate forward in the webview
+ * @param {Boolean} data.isBookmarked
+ * Whether the site is bookmarked
+ * @param {Boolean} data.isQuickmarked
+ * Whether the site is quickmarked
+ * @param {Boolean} data.pluginsBlocked
+ * Whether plugins are blocked
+ * @param {Boolean} data.scriptsBlocked
+ * Whether scripts are blocked
+ * @param {String} data.ssl
+ * SSL-State of the page, can either be <i>"trusted"</i>, <i>"untrusted"</i>
+ * or <i>"none"</i>
+ * @param {String} data.type
+ * The type of the update, can be <i>"status</i> and </>uri<i>, status means
+ * that statusLabel und uriLabel need to be updated, uri means
+ * that only the uriLabel needs to be updated.
+ *
+ * @returns {Boolean}
+ * Return true to prevent dwb to update the statusbar
+ * */
gboolean back = webkit_web_view_can_go_back(WEBKIT_WEB_VIEW(v->web));
gboolean forward = webkit_web_view_can_go_forward(WEBKIT_WEB_VIEW(v->web));
const char *uri = webkit_web_view_get_uri(WEBVIEW(gl));
@@ -1453,6 +1492,29 @@ dwb_focus_view(GList *gl, const char *event)
{
if (EMIT_SCRIPT(TAB_FOCUS))
{
+ /**
+ * Emitted before a tab gets focus
+ * @event tabFocus
+ * @memberOf signals
+ * @param {signals~onTabFocus} callback
+ * Callback function that will be called when the signal is emitted
+ *
+ * */
+ /**
+ * Callback called before a tab gets focus
+ * @callback signals~onTabFocus
+ *
+ * @param {WebKitWebView} new The webview that will get focus
+ * @param {WebKitWebView} last The webview that has focus
+ * @param {Object} data
+ * @param {String} data.event
+ * The event either a command name <i>button_press</i>,
+ * <i>tab_button_press</i>, <i>close_tab</i> or <i>new_tab</i>
+ *
+ * @returns {Boolean}
+ * Return true to prevent the focus
+ * */
+
char *json = util_create_json(1, CHAR, "event", event);
//ScriptSignal signal = { SCRIPTS_WV(gl), .objects = { SCRIPTS_WV(dwb.state.fview) }, SCRIPTS_SIG_META(NULL, TAB_FOCUS, 1) };
ScriptSignal signal = { SCRIPTS_WV(gl), .objects = { G_OBJECT(VIEW(dwb.state.fview)->web) }, SCRIPTS_SIG_META(json, TAB_FOCUS, 1) };
@@ -2940,6 +3002,27 @@ dwb_change_mode(Mode mode, ...)
completion_clean_autocompletion();
if (EMIT_SCRIPT(CHANGE_MODE))
{
+ /**
+ * Emitted before the mode changes
+ * @event changeMode
+ * @memberOf signals
+ * @param {signals~onChangeMode} callback
+ * Callback function that will be called when the signal is emitted
+ *
+ * */
+ /**
+ * Callback called before the mode changes
+ * @callback signals~onChangeMode
+ *
+ * @param {WebKitWebView} new
+ * The webview that currently has focus
+ * @param {Modes} mode
+ * A {@link Enums and Flags|Mode}
+ *
+ * @returns {Boolean}
+ * Return true to prevent changing mode
+ * */
+
char buffer[] = { BASIC_MODES(mode) + 48, 0 };
ScriptSignal sig = { SCRIPTS_WV(dwb.state.fview), SCRIPTS_SIG_META(buffer, CHANGE_MODE, 0) };
if (scripts_emit(&sig))
@@ -3560,6 +3643,18 @@ dwb_end()
}
if (EMIT_SCRIPT(CLOSE))
{
+ /**
+ * Emitted when dwb is closed
+ * @event close
+ * @memberOf signals
+ * @param {signals~onClose} callback
+ * Callback function that will be called when the signal is emitted
+ *
+ * */
+ /**
+ * Callback called when dwb is closed
+ * @callback signals~onClose
+ * */
ScriptSignal s = { .jsobj = NULL, SCRIPTS_SIG_META(NULL, CLOSE, 0) };
scripts_emit(&s);
}
diff --git a/src/scripts.c b/src/scripts.c
index f225dfc4..34791ceb 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -134,6 +134,7 @@ enum {
CONSTRUCTOR_WIDGET,
CONSTRUCTOR_FRAME,
CONSTRUCTOR_SOUP_MESSAGE,
+ CONSTRUCTOR_HISTORY_LIST,
CONSTRUCTOR_DEFERRED,
CONSTRUCTOR_HIDDEN_WEB_VIEW,
CONSTRUCTOR_LAST,
@@ -395,6 +396,38 @@ deferred_new(JSContextRef ctx)
return ret;
}
+/**
+ * Registers functions for the done and fail chain
+ *
+ * @name then
+ * @memberOf Deferred.prototype
+ * @function
+ *
+ *
+ * @param {Deferred~resolveCallback} ondone
+ * A callback function that will be called when the deferred is resolved.
+ * If the function returns a deferred the original deferred will be
+ * replaced with the new deferred.
+
+ * @param {Deferred~rejectCallback} onfail
+ * A callback function that will be called when the deferred is rejected.
+ * If the function returns a deferred the original deferred will be
+ * replaced with the new deferred.
+ * @returns {Deferred}
+ * A new deferred that can be used to chain callbacks.
+ * */
+/**
+ * Called when a Deferred is resolved
+ * @callback Deferred~resolveCallback
+ * @param {...Object} arguments
+ * Variable number of arguments passed to Deferred.resolve
+ * */
+/**
+ * Called when a Deferred is rejected
+ * @callback Deferred~rejectCallback
+ * @param {...Object} arguments
+ * Variable number of arguments passed to Deferred.reject
+ * */
static JSValueRef
deferred_then(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -424,6 +457,15 @@ deferred_transition(JSContextRef ctx, JSObjectRef old, JSObjectRef new)
deferred_destroy(ctx, old, opriv);
return npriv;
}
+/**
+ * Resolves a deferred, the done-chain is called when a deferred is resolved
+ *
+ * @name resolve
+ * @memberOf Deferred.prototype
+ * @function
+ *
+ * @param {...Object} arguments Arguments passed to the <i>done</i> callbacks
+ */
static JSValueRef
deferred_resolve(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -451,6 +493,15 @@ deferred_resolve(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc,
}
return UNDEFINED;
}
+/**
+ * Rejects a deferred, the fail-chain is called when a deferred is resolved
+ *
+ * @name reject
+ * @memberOf Deferred.prototype
+ * @function
+ *
+ * @param {...Object} arguments Arguments passed to the <i>fail</i> callbacks
+ */
static JSValueRef
deferred_reject(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -606,6 +657,11 @@ make_callback(JSContextRef ctx, JSObjectRef this, GObject *gobject, const char *
}/*}}}*/
/* callback {{{*/
+/**
+ * @callback WebKitDownload~statusCallback
+ * @param {WebKitDownload} download
+ * The download
+ * */
static void
callback(CallbackData *c)
{
@@ -630,6 +686,13 @@ callback(CallbackData *c)
/* TABS {{{*/
/* tabs_current {{{*/
+/**
+ * The currently focused webview
+ *
+ * @name current
+ * @memberOf tabs
+ * @type WebKitWebView
+ * */
static JSValueRef
tabs_current(JSContextRef ctx, JSObjectRef this, JSStringRef name, JSValueRef* exc)
{
@@ -640,6 +703,13 @@ tabs_current(JSContextRef ctx, JSObjectRef this, JSStringRef name, JSValueRef* e
}/*}}}*/
/* tabs_number {{{*/
+/**
+ * The number of the currently focused webview
+ *
+ * @name number
+ * @memberOf tabs
+ * @type Number
+ * */
static JSValueRef
tabs_number(JSContextRef ctx, JSObjectRef this, JSStringRef name, JSValueRef* exc)
{
@@ -647,6 +717,13 @@ tabs_number(JSContextRef ctx, JSObjectRef this, JSStringRef name, JSValueRef* ex
}/*}}}*/
/* tabs_length {{{*/
+/**
+ * Total number of tabs
+ *
+ * @name length
+ * @memberOf tabs
+ * @type Number
+ * */
static JSValueRef
tabs_length(JSContextRef ctx, JSObjectRef this, JSStringRef name, JSValueRef* exc)
{
@@ -654,6 +731,17 @@ tabs_length(JSContextRef ctx, JSObjectRef this, JSStringRef name, JSValueRef* ex
}/*}}}*/
/* tabs_get_nth {{{*/
+/**
+ * Gets the WebKitWebView of the nth tab, counting at 0
+ * @name nth
+ * @memberOf tabs
+ * @function
+ *
+ * @param {Number} number Number of the tab
+ *
+ * @returns {WebKitWebView}
+ * The corresponding {@link WebKitWebView}
+ * */
static JSValueRef
tabs_get_nth(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -684,6 +772,13 @@ find_webview(JSObjectRef o)
return NULL;
}
/* wv_status_cb {{{*/
+/**
+ * Callback that will be called if the load-status changes, return true to stop
+ * the emission
+ *
+ * @callback WebKitWebView#loadUriCallback
+ * @param {WebKitWebView} wv The webview which loaded the uri
+ * */
static gboolean
wv_status_cb(CallbackData *c)
{
@@ -694,6 +789,21 @@ wv_status_cb(CallbackData *c)
}/*}}}*/
/* wv_load_uri {{{*/
+/**
+ * Load an uri in a webview
+ * @name loadUri
+ * @memberOf WebKitWebView.prototype
+ * @function
+ *
+ * @param {String} uri
+ * The uri to load
+ * @param {WebKitWebView#loadUriCallback} [callback]
+ * A callback function that will be called when the load status changes,
+ * return true to stop the emission
+ *
+ * @returns {Boolean}
+ * true if the uri was loaded
+ * */
static JSValueRef
wv_load_uri(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -716,6 +826,14 @@ wv_load_uri(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t arg
return JSValueMakeBoolean(ctx, false);
}/*}}}*/
+/**
+ * Stops any ongoing loading
+ *
+ * @name stopLoading
+ * @memberOf WebKitWebView.prototype
+ * @function
+ *
+ * */
static JSValueRef
wv_stop_loading(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -725,6 +843,16 @@ wv_stop_loading(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t
return UNDEFINED;
}
+/**
+ * Loads a history item, can be used to navigate forward/backwards in history
+ *
+ * @name history
+ * @memberOf WebKitWebView.prototype
+ * @function
+ *
+ * @param {Number} steps
+ * Number of steps, pass a negative value to go back in history
+ * */
/* wv_history {{{*/
static JSValueRef
wv_history(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -743,6 +871,14 @@ wv_history(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc
return UNDEFINED;
}/*}}}*/
+/**
+ * Reloads the current site
+ *
+ * @name reload
+ * @memberOf WebKitWebView.prototype
+ * @function
+ *
+ * */
/* wv_reload {{{*/
static JSValueRef
wv_reload(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -766,6 +902,28 @@ wv_inject(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc,
return NIL;
}/*}}}*/
#if WEBKIT_CHECK_VERSION(1, 10, 0)
+
+/**
+ * Renders a webview to a png file
+ *
+ * @name toPng
+ * @memberOf WebKitWebView.prototype
+ * @function
+ * @type Number
+ * @requires webkitgtk >= 1.10
+ *
+ *
+ * @param {String} filename
+ * The filename for the png.
+ * @param {Number} width
+ * The width of the png, if width is < 0 and height is > 0 the image will have the same aspect ratio as the original webview, optional.
+ * @param {Number} height
+ * The height of the png, if height is < 0 and width is > 0 the image will have the same aspect ratio as the original webview, optional, mandatory if width is set.
+ * @param {Boolean} keepAspect
+ * Whether to keep the ascpect ratio, if set to true the new image will have the same aspect ratio as the original webview, width and height are taken as maximum sizes and must both be > 0, optional.
+ *
+ * @returns A cairo_status_t, 0 on success, -1 if an error occured
+ * */
static JSValueRef
wv_to_png(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -855,6 +1013,13 @@ wv_to_png(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc,
}
#endif
/* wv_get_main_frame {{{*/
+/**
+ * The main frame
+ *
+ * @name mainFrame
+ * @memberOf WebKitWebView.prototype
+ * @type WebKitWebFrame
+ * */
static JSValueRef
wv_get_main_frame(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -867,6 +1032,13 @@ wv_get_main_frame(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSV
return NIL;
}/*}}}*/
+/**
+ * The focused frame
+ *
+ * @name focusedFrame
+ * @memberOf WebKitWebView.prototype
+ * @type WebKitWebFrame
+ * */
/* wv_get_focused_frame {{{*/
static JSValueRef
wv_get_focused_frame(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
@@ -881,6 +1053,13 @@ wv_get_focused_frame(JSContextRef ctx, JSObjectRef object, JSStringRef js_name,
}/*}}}*/
/* wv_get_all_frames {{{*/
+/**
+ * All frames of a webview, including the main frame
+ *
+ * @name allFrames
+ * @memberOf WebKitWebView.prototype
+ * @type Array[WebKitWebFrame]
+ * */
static JSValueRef
wv_get_all_frames(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -899,6 +1078,14 @@ wv_get_all_frames(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSV
return JSObjectMakeArray(ctx, argc, argv, exception);
}/*}}}*/
+/**
+ * The tabnumber of the webview, starting at 0
+ *
+ * @name number
+ * @memberOf WebKitWebView.prototype
+ * @type Number
+ *
+ * */
/* wv_get_number {{{*/
static JSValueRef
wv_get_number(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
@@ -912,6 +1099,13 @@ wv_get_number(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValue
return JSValueMakeNumber(ctx, -1);
}/*}}}*/
+/**
+ * The main widget for tab labels, used for coloring tabs, child of gui.tabBox.
+ *
+ * @name tabWidget
+ * @memberOf WebKitWebView.prototype
+ * @type GtkEventBox
+ * */
static JSValueRef
wv_get_tab_widget(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -920,6 +1114,13 @@ wv_get_tab_widget(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSV
return NIL;
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(VIEW(gl)->tabevent), true);
}
+/**
+ * Horizontal box, child of wv.tabWidget.
+ *
+ * @name tabBox
+ * @memberOf WebKitWebView.prototype
+ * @type GtkBox
+ * */
static JSValueRef
wv_get_tab_box(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -928,6 +1129,13 @@ wv_get_tab_box(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValu
return NIL;
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(VIEW(gl)->tabbox), true);
}
+/**
+ * Text label of a tab, child of wv.tabBox.
+ *
+ * @name tabLabel
+ * @memberOf WebKitWebView.prototype
+ * @type GtkLabel
+ * */
static JSValueRef
wv_get_tab_label(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -936,6 +1144,13 @@ wv_get_tab_label(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSVa
return NIL;
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(VIEW(gl)->tablabel), true);
}
+/**
+ * Favicon widget, child of wv.tabBox
+ *
+ * @name tabIcon
+ * @memberOf WebKitWebView.prototype
+ * @type GtkImage
+ * */
static JSValueRef
wv_get_tab_icon(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -945,6 +1160,13 @@ wv_get_tab_icon(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSVal
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(VIEW(gl)->tabicon), true);
}
+/**
+ * The parent widget of every webview, it is used for scrolling the webview
+ *
+ * @name scrolledWindow
+ * @memberOf WebKitWebView.prototype
+ * @type GtkScrolledWindow
+ * */
static JSValueRef
wv_get_scrolled_window(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -953,6 +1175,13 @@ wv_get_scrolled_window(JSContextRef ctx, JSObjectRef object, JSStringRef js_name
return NIL;
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(VIEW(gl)->scroll), true);
}
+/**
+ * The history of the webview
+ *
+ * @name historyList
+ * @memberOf WebKitWebView.prototype
+ * @type WebKitWebBackForwardList
+ * */
static JSValueRef
wv_get_history_list(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -966,6 +1195,68 @@ wv_get_history_list(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, J
/*}}}*/
/* SOUP_MESSAGE {{{*/
+/**
+ * A SoupUri
+ *
+ * @class
+ * @name SoupUri
+ * */
+ /**
+ * The scheme part of the uri
+ * @name scheme
+ * @memberOf SoupUri.prototype
+ * @type String
+ * @readonly
+ * */
+ /**
+ * The user part of the uri
+ * @name user
+ * @memberOf SoupUri.prototype
+ * @type String
+ * @readonly
+ * */
+ /**
+ * The password part of the uri
+ * @name password
+ * @memberOf SoupUri.prototype
+ * @type String
+ * @readonly
+ * */
+ /**
+ * The host part of the uri
+ * @name host
+ * @memberOf SoupUri.prototype
+ * @type String
+ * @readonly
+ * */
+ /**
+ * The port of the uri
+ * @name port
+ * @memberOf SoupUri.prototype
+ * @type Number
+ * @readonly
+ * */
+ /**
+ * The path part of the uri
+ * @name path
+ * @memberOf SoupUri.prototype
+ * @type String
+ * @readonly
+ * */
+ /**
+ * The query part of the uri
+ * @name query
+ * @memberOf SoupUri.prototype
+ * @type String
+ * @readonly
+ * */
+ /**
+ * The fragment part of the uri
+ * @name fragment
+ * @memberOf SoupUri.prototype
+ * @type String
+ * @readonly
+ * */
static JSValueRef
get_soup_uri(JSContextRef ctx, JSObjectRef object, SoupURI * (*func)(SoupMessage *), JSValueRef *exception)
{
@@ -990,6 +1281,13 @@ get_soup_uri(JSContextRef ctx, JSObjectRef object, SoupURI * (*func)(SoupMessage
}
/* message_get_uri {{{*/
+/**
+ * The uri of a message
+ *
+ * @name uri
+ * @memberOf SoupMessage.prototype
+ * @type SoupUri
+ * */
static JSValueRef
message_get_uri(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -997,6 +1295,13 @@ message_get_uri(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSVal
}/*}}}*/
/* message_get_first_party {{{*/
+/**
+ * The first party uri of a message
+ *
+ * @name firstParty
+ * @memberOf SoupMessage.prototype
+ * @type SoupUri
+ * */
static JSValueRef
message_get_first_party(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1006,6 +1311,14 @@ message_get_first_party(JSContextRef ctx, JSObjectRef object, JSStringRef js_nam
/* FRAMES {{{*/
/* frame_get_domain {{{*/
+/**
+ * The domain name of the frame which is the effective second level domain
+ *
+ * @name domain
+ * @memberOf WebKitWebFrame.prototype
+ * @type String
+ *
+ * */
static JSValueRef
frame_get_domain(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1024,6 +1337,14 @@ frame_get_domain(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSVa
}/*}}}*/
/* frame_get_host {{{*/
+/**
+ * The host name of the frame
+ *
+ * @name host
+ * @memberOf WebKitWebFrame.prototype
+ * @type String
+ *
+ * */
static JSValueRef
frame_get_host(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1040,6 +1361,41 @@ frame_get_host(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValu
}/*}}}*/
/* frame_inject {{{*/
+
+/**
+ * Injects javascript code into a frame or webview
+ *
+ * @name inject
+ * @memberOf WebKitWebFrame.prototype
+ * @function
+ * @example
+ * //!javascript
+ * function injectable() {
+ * var text = arguments[0];
+ * document.body.innerHTML = text;
+ * }
+ * signals.connect("documentLoaded", function(wv) {
+ * wv.inject(injectable, "foo", 3);
+ * });
+ *
+ * @param {String|Function} code
+ * The script to inject, either a string or a function. If it is a function
+ * the body will be wrapped inside a new function.
+ * @param {Object} arg
+ * If the script isn’t injected into the global scope the script is wrapped
+ * inside a function. arg then is accesible via arguments in the injected
+ * script, optional
+ * @param {Number} [line]
+ * Starting line number, useful for debugging. If linenumber is greater
+ * than 0 error messages will be printed to stderr, optional.
+ * @param {Boolean} [global]
+ * true to inject it into the global scope, false to encapsulate it in a
+ * function, default false
+ * @returns {String}
+ * The return value of the script. If the script is injected globally
+ * inject always returns null. The return value is always converted to a
+ * string. To return objects call JSON.parse on the return value.
+ * */
static JSValueRef
frame_inject(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1054,42 +1410,19 @@ frame_inject(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t ar
/*}}}*/
/* GLOBAL {{{*/
-/* global_checksum {{{*/
-static JSValueRef
-global_checksum(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
-{
- char *checksum = NULL;
- guchar *original = NULL;
- JSValueRef ret;
-
- if (argc < 1)
- return NIL;
-
- original = (guchar*)js_value_to_char(ctx, argv[0], -1, exc);
- if (original == NULL)
- return NIL;
-
- GChecksumType type = G_CHECKSUM_SHA256;
- if (argc > 1)
- {
- type = JSValueToNumber(ctx, argv[1], exc);
- if (isnan(type))
- {
- ret = NIL;
- goto error_out;
- }
- type = MIN(MAX(type, G_CHECKSUM_MD5), G_CHECKSUM_SHA256);
- }
- checksum = g_compute_checksum_for_data(type, original, -1);
-
- ret = js_char_to_value(ctx, checksum);
-
-error_out:
- g_free(original);
- g_free(checksum);
- return ret;
-}/*}}}*/
-
+/**
+ * Callback that will be called when a shortcut or command was invoked that was
+ * bound with {@link bind}
+ *
+ * @callback bindCallback
+ *
+ * @param {Object} arguments
+ * @param {Number} arguments.nummod
+ * Numerical modifier that was used or -1 if no modifier was used.
+ * @param {Number} [arguments.arg]
+ * Argument if the callback was invoked from commandline and an argument
+ * was used on commanline
+ * */
/* scripts_eval_key {{{*/
DwbStatus
scripts_eval_key(KeyMap *m, Arg *arg)
@@ -1130,6 +1463,17 @@ unbind_free_keymap(JSContextRef ctx, GList *l)
dwb.keymap = g_list_delete_link(dwb.keymap, l);
}
/* global_unbind{{{*/
+/**
+ * Unbind a shortcut previously bound with <b>bind</b>
+ * @name unbind
+ * @function
+ *
+ * @param {String|bindCallback} command|callback Either the function or the command
+ * passed to {@link bind}
+ * @returns {Boolean}
+ * Whether the shortcut was unbound
+ *
+ * */
static JSValueRef
global_unbind(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1165,6 +1509,29 @@ global_unbind(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, si
return JSValueMakeBoolean(ctx, false);
}/*}}}*/
/* global_bind {{{*/
+/**
+ * Bind a function to a shortcut or commandline command
+ * @name bind
+ * @function
+ *
+ * @param {String} shortcut
+ * A shortcut, the syntax is the same as in dwb:keys, pass <i>null</i> if
+ * only a commandline command should be bound
+ * @param {bindCallback} callback
+ * A callback function that will be called if the shortcut is pressed or
+ * the command was executed from commandline
+ * @param {String|OverrideKey} [command|override]
+ * A command the can be used on dwb's commandline or an
+ * {@link Enums and Flags.OverrideKey|OverrideKey} flag
+ *
+ * @returns {Boolean}
+ * true if the shortcut/command was bound
+ * @example
+ * bind("Control U", function () {
+ * execute("tabopen " + tabs.current.uri);
+ * }, "tabopen_current");
+ *
+ * */
static JSValueRef
global_bind(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1232,17 +1599,42 @@ error_out:
return JSValueMakeBoolean(ctx, ret);
}/*}}}*/
+/**
+ * Refers to the global object
+ * @name global
+ *
+ * */
static JSValueRef
global_get(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
return JSContextGetGlobalObject(ctx);
}
+/**
+ * The webkit session
+ *
+ * @name session
+ * @type SoupSession
+ *
+ * */
static JSValueRef
global_get_webkit_session(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
return s_soup_session;
}
/* global_execute {{{*/
+/**
+ * Executes a command
+ * @name execute
+ * @function
+ *
+ * @param {String} name
+ * A command, the command syntax is the same as the syntax on dwb's
+ * commandline
+ *
+ * @returns {Boolean}
+ * true if execution was successful
+ *
+ * */
static JSValueRef
global_execute(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1259,6 +1651,12 @@ global_execute(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, s
return JSValueMakeBoolean(ctx, status == STATUS_OK);
}/*}}}*/
+/**
+ * Exit dwb
+ * @name exit
+ * @function
+ *
+ * */
/* global_exit {{{*/
static JSValueRef
global_exit(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -1391,6 +1789,18 @@ get_message_data(SoupMessage *msg)
return ret;
}
+/**
+ * Callback called when a response from a request was retrieved
+ *
+ * @callback net~onResponse
+ *
+ * @param {Object} data
+ * @param {String} data.body
+ * The message body
+ * @param {Object} data.he
+ * An object that contains all response headers
+ * @param {SoupMessage} message The soup message
+ * */
static void
request_callback(SoupSession *session, SoupMessage *message, JSObjectRef function)
{
@@ -1427,11 +1837,28 @@ set_request(JSContextRef ctx, SoupMessage *msg, JSValueRef val, JSValueRef *exc)
g_free(content_type);
g_free(body);
}
-
+/**
+ * Sends a http-request
+ * @name sendRequest
+ * @memberOf net
+ * @function
+ *
+ * @param {String} uri
+ * The uri the request will be sent to.
+ * @param {net~onResponse} callback
+ * A callback that will be called when the request is finished
+ * @param {String} [method] The http request method, default GET
+ * @param {Object} [data] An object if method is POST
+ * @param {String} data.contentType The content type
+ * @param {String} data.data The data that will be sent with the request
+ *
+ * @returns {Boolean}
+ * true if the request was sent
+ * */
static JSValueRef
-global_send_request(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
+net_send_request(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
- gint ret = -1;
+ gboolean success = false;
char *method = NULL, *uri = NULL;
SoupMessage *msg;
JSObjectRef function;
@@ -1457,16 +1884,29 @@ global_send_request(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, siz
JSValueProtect(ctx, function);
soup_session_queue_message(webkit_get_default_session(), msg, (SoupSessionCallback)request_callback, function);
- ret = 0;
+ success = true;
error_out:
g_free(uri);
g_free(method);
- return JSValueMakeNumber(ctx, ret);
+ return JSValueMakeBoolean(ctx, success);
}/*}}}*/
+/**
+ * Sends a http-request synchronously
+ * @name sendRequestSync
+ * @memberOf net
+ * @function
+ *
+ * @param {String} uri The uri the request will be sent to.
+ * @param {String} [method] The http request method, default GET
+ *
+ * @returns {Object}
+ * Object that contains the response body, the response headers and the
+ * http status code of the request.
+ * */
static JSValueRef
-global_send_request_sync(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
+net_send_request_sync(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
char *method = NULL, *uri = NULL;
SoupMessage *msg;
@@ -1518,67 +1958,12 @@ scripts_completion_activate(void)
}
CONTEXT_UNLOCK;
}
-static JSValueRef
-global_tab_complete(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
-{
- if (argc < 3 || !JSValueIsInstanceOfConstructor(ctx, argv[1], s_array_contructor, exc))
- {
- js_make_exception(ctx, exc, EXCEPTION("tabComplete: invalid argument."));
- return UNDEFINED;
- }
- s_completion_callback = js_value_to_function(ctx, argv[2], exc);
- if (s_completion_callback == NULL)
- return UNDEFINED;
-
- dwb.state.script_comp_readonly = false;
- if (argc > 3 && JSValueIsBoolean(ctx, argv[3]))
- {
- dwb.state.script_comp_readonly = JSValueToBoolean(ctx, argv[3]);
- }
-
- char *left, *right, *label;
- js_array_iterator iter;
- JSValueRef val;
- JSObjectRef cur = NULL;
- Navigation *n;
-
- label = js_value_to_char(ctx, argv[0], JS_STRING_MAX, exc);
- JSObjectRef o = JSValueToObject(ctx, argv[1], exc);
- js_array_iterator_init(ctx, &iter, o);
- while((val = js_array_iterator_next(&iter, exc)))
- {
- cur = JSValueToObject(ctx, val, exc);
- if (cur == NULL)
- goto error_out;
- left = js_get_string_property(ctx, cur, "left");
- right = js_get_string_property(ctx, cur, "right");
- n = g_malloc(sizeof(Navigation));
- n->first = left;
- n->second = right;
- dwb.state.script_completion = g_list_prepend(dwb.state.script_completion, n);
- }
- dwb.state.script_completion = g_list_reverse(dwb.state.script_completion);
- dwb_set_status_bar_text(dwb.gui.lstatus, label, NULL, NULL, true);
-
- entry_focus();
- completion_complete(COMP_SCRIPT, false);
-
-error_out:
- js_array_iterator_finish(&iter);
-
- for (GList *l = dwb.state.script_completion; l; l=l->next)
- {
- n = l->data;
- g_free(n->first);
- g_free(n->second);
- g_free(n);
- }
- g_free(label);
- g_list_free(dwb.state.script_completion);
- dwb.state.script_completion = NULL;
- return UNDEFINED;
-}
/* timeout_callback {{{*/
+/**
+ * @callback timer~startCallback
+ * @returns {Boolean}
+ * Return true to stop the timer
+ * */
static gboolean
timeout_callback(JSObjectRef obj)
{
@@ -1600,8 +1985,19 @@ timeout_callback(JSObjectRef obj)
}/*}}}*/
/* global_timer_stop {{{*/
+/**
+ * Stops a timer started by {@link timerStart}
+ * @name stop
+ * @memberOf timer
+ * @function
+ *
+ * @param {Number} id A timer id retrieved from {@link timer.start|start}
+ *
+ * @returns {Boolean}
+ * true if the timer was stopped
+ * */
static JSValueRef
-global_timer_stop(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
+timer_stop(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
gdouble sigid;
if (argc < 1)
@@ -1631,10 +2027,36 @@ timer_stopped_cb(JSObjectRef func)
JSValueUnprotect(s_global_context, func);
CONTEXT_UNLOCK;
}
+/**
+ * Calls a function reqeatedly or after a timeout, similar to window.setInterval
+ * or window.setTimeout that are available in the webcontext.
+ * @name start
+ * @memberOf timer
+ * @function
+ * @example
+ * // equivalent to window.setInterval
+ * timer.start(1000, function() {
+ * ...
+ * });
+ * // equivalent to window.setTimeout
+ * timer.start(1000, function() {
+ * ...
+ * return false;
+ * });
+ *
+ * @param {Number} interval The interval in milliseconds, the minimum interval
+ * is 10 milliseconds
+ * @param {timer~startCallback} callback
+ * The callback that will be called, if the callback returns <i>false</i>
+ * the timer will be stopped
+ *
+ * @returns {Number}
+ * A timer id that can be passed to {@link timer.stop|stop}
+ * */
/* global_timer_start {{{*/
static JSValueRef
-global_timer_start(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
+timer_start(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
if (argc < 2)
{
@@ -1659,8 +2081,23 @@ global_timer_start(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size
/* UTIL {{{*/
/* util_domain_from_host {{{*/
+/**
+ * Gets the base domain name from a hostname where the base domain name is the
+ * effective second level domain name, e.g. for www.example.com it will be
+ * example.com, for www.example.co.uk it will be example.co.uk.
+ *
+ * @name domainFromHost
+ * @memberOf net
+ * @function
+ * @type String
+ *
+ * @param {String} hostname A hostname
+ *
+ * @returns The effective second level domain
+ *
+ * */
static JSValueRef
-sutil_domain_from_host(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
+net_domain_from_host(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
if (argc < 1)
{
@@ -1676,6 +2113,92 @@ sutil_domain_from_host(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject,
g_free(host);
return ret;
}/*}}}*//*}}}*/
+/**
+ * Initializes tab completion.
+ * @name tabComplete
+ * @memberOf util
+ * @function
+ *
+ * @param {String} label The command line label
+ * @param {Object} items An array of objects, each object can have 2 properties,
+ * left which will be the left completion label and right
+ * which will be the right completion label.
+ * @param {Function} callback Callback function, the first argument will be the
+ * returned string from the url bar.
+ * @param {Boolean} [readonly] Whether the items are readonly, default false
+ *
+ * */
+static JSValueRef
+sutil_tab_complete(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
+{
+ if (argc < 3 || !JSValueIsInstanceOfConstructor(ctx, argv[1], s_array_contructor, exc))
+ {
+ js_make_exception(ctx, exc, EXCEPTION("tabComplete: invalid argument."));
+ return UNDEFINED;
+ }
+ s_completion_callback = js_value_to_function(ctx, argv[2], exc);
+ if (s_completion_callback == NULL)
+ return UNDEFINED;
+
+ dwb.state.script_comp_readonly = false;
+ if (argc > 3 && JSValueIsBoolean(ctx, argv[3]))
+ {
+ dwb.state.script_comp_readonly = JSValueToBoolean(ctx, argv[3]);
+ }
+
+ char *left, *right, *label;
+ js_array_iterator iter;
+ JSValueRef val;
+ JSObjectRef cur = NULL;
+ Navigation *n;
+
+ label = js_value_to_char(ctx, argv[0], JS_STRING_MAX, exc);
+ JSObjectRef o = JSValueToObject(ctx, argv[1], exc);
+ js_array_iterator_init(ctx, &iter, o);
+ while((val = js_array_iterator_next(&iter, exc)))
+ {
+ cur = JSValueToObject(ctx, val, exc);
+ if (cur == NULL)
+ goto error_out;
+ left = js_get_string_property(ctx, cur, "left");
+ right = js_get_string_property(ctx, cur, "right");
+ n = g_malloc(sizeof(Navigation));
+ n->first = left;
+ n->second = right;
+ dwb.state.script_completion = g_list_prepend(dwb.state.script_completion, n);
+ }
+ dwb.state.script_completion = g_list_reverse(dwb.state.script_completion);
+ dwb_set_status_bar_text(dwb.gui.lstatus, label, NULL, NULL, true);
+
+ entry_focus();
+ completion_complete(COMP_SCRIPT, false);
+
+error_out:
+ js_array_iterator_finish(&iter);
+
+ for (GList *l = dwb.state.script_completion; l; l=l->next)
+ {
+ n = l->data;
+ g_free(n->first);
+ g_free(n->second);
+ g_free(n);
+ }
+ g_free(label);
+ g_list_free(dwb.state.script_completion);
+ dwb.state.script_completion = NULL;
+ return UNDEFINED;
+}
+/**
+ * Escapes text for usage with pango markup
+ *
+ * @name markupEscape
+ * @memberOf util
+ * @function
+ * @type String
+ *
+ * @returns The escaped text or null
+ *
+ * */
static JSValueRef
sutil_markup_escape(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1697,12 +2220,82 @@ sutil_markup_escape(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, siz
}
return NIL;
}
+/* global_checksum {{{*/
+/**
+ * Computes a checksum of a string
+ * @name checksum
+ * @memberOf util
+ * @function
+ * @type Boolean
+ *
+ * @param {String} data The data
+ * @param {ChecksumType} [type] The {@link Enums and Flags.ChecksumType|ChecksumType}, defaults to sha256
+ * @returns Whether the shortcut was unbound
+ *
+ * */
+static JSValueRef
+sutil_checksum(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
+{
+ char *checksum = NULL;
+ guchar *original = NULL;
+ JSValueRef ret;
+
+ if (argc < 1)
+ return NIL;
+
+ original = (guchar*)js_value_to_char(ctx, argv[0], -1, exc);
+ if (original == NULL)
+ return NIL;
+
+ GChecksumType type = G_CHECKSUM_SHA256;
+ if (argc > 1)
+ {
+ type = JSValueToNumber(ctx, argv[1], exc);
+ if (isnan(type))
+ {
+ ret = NIL;
+ goto error_out;
+ }
+ type = MIN(MAX(type, G_CHECKSUM_MD5), G_CHECKSUM_SHA256);
+ }
+ checksum = g_compute_checksum_for_data(type, original, -1);
+
+ ret = js_char_to_value(ctx, checksum);
+
+error_out:
+ g_free(original);
+ g_free(checksum);
+ return ret;
+}/*}}}*/
+
+/**
+ * Gets the current mode
+ *
+ * @name getMode
+ * @memberOf util
+ * @function
+ * @type Modes
+ *
+ * @returns The current mode
+ * */
static JSValueRef
sutil_get_mode(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
return JSValueMakeNumber(ctx, BASIC_MODES(dwb.state.mode));
}
+/**
+ * Gets the body of a function, useful for injecting scripts
+ *
+ * @name getBody
+ * @memberOf util
+ * @function
+ * @type String
+ *
+ * @param {Function} function A function
+ *
+ * @returns The body of the function
+ * */
static JSValueRef
sutil_get_body(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1718,6 +2311,20 @@ sutil_get_body(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t a
}
return ret;
}
+/**
+ * Dispatches a keyboard event
+ *
+ * @name dispatchEvent
+ * @memberOf util
+ * @function
+ * @type Boolean
+ *
+ * @param {KeyEvent} event
+ * @param {Modifier} modifier Modifier state bitmask
+ * @param {Keyval} keyval The key that was pressed
+ *
+ * @returns Whether the key was dispatched
+ * */
static JSValueRef
sutil_dispatch_event(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1756,6 +2363,7 @@ atom_from_jsvalue(JSContextRef ctx, JSValueRef val, JSValueRef *exc)
double type = JSValueToNumber(ctx, val, exc);
if (isnan(type))
return NULL;
+ printf("%f %d\n", type, (int)type);
if ((int)type == SELECTION_PRIMARY)
return GDK_SELECTION_PRIMARY;
else if ((int)type == SELECTION_CLIPBOARD)
@@ -1763,6 +2371,16 @@ atom_from_jsvalue(JSContextRef ctx, JSValueRef val, JSValueRef *exc)
else
return NULL;
}
+/**
+ * Sets content of the system clipboard
+ * @name set
+ * @memberOf clipboard
+ * @function
+ *
+ * @param {Selection} selection The {@link Enums and Flags.Selection|Selection} to set
+ * @param {String} text The text to set
+ *
+ * */
static JSValueRef
clipboard_set(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1780,6 +2398,13 @@ clipboard_set(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t ar
}
return UNDEFINED;
}
+/**
+ * Callback called when the clipboard was received
+ * @callback clipboard~onGotClipboard
+ *
+ * @param {String} text
+ * The text content of the clipboard
+ * */
static void
got_clipboard(GtkClipboard *cb, const char *text, JSObjectRef callback)
{
@@ -1794,6 +2419,22 @@ got_clipboard(GtkClipboard *cb, const char *text, JSObjectRef callback)
}
CONTEXT_UNLOCK;
}
+/**
+ * Gets content of the system clipboard
+ * @name get
+ * @memberOf clipboard
+ * @function
+ *
+ * @param {Selection} selection
+ * The {@Link Enums and Flags.Selection|Selection} to get
+ * @param {clipboard~onGotClipboard} [callback]
+ * A callback function that is called when the clipboard content was
+ * retrieved, if a callback function is used the clipboard will be fetched
+ * asynchronously, otherwise it will be fetched synchronously
+ *
+ * @returns {String|undefined}
+ * The content of the clipboard or undefined if a callback function is used
+ * */
static JSValueRef
clipboard_get(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1826,6 +2467,18 @@ clipboard_get(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t ar
return NIL;
}
+/**
+ * Get a history item
+ *
+ * @name getItem
+ * @memberOf WebKitWebBackForwardList.prototype
+ * @function
+ *
+ * @param {Number} position Position of the history item
+ *
+ * @return {WebKitWebHistoryItem}
+ * The history item
+ * */
static JSValueRef
history_get_item(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -1839,6 +2492,13 @@ history_get_item(JSContextRef ctx, JSObjectRef f, JSObjectRef this, size_t argc,
}
return NIL;
}
+/**
+ * Number of items that precede the current item
+ *
+ * @name backLength
+ * @memberOf WebKitWebBackForwardList.prototype
+ * @type Number
+ * */
static JSValueRef
history_back_length(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1846,6 +2506,13 @@ history_back_length(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, J
g_return_val_if_fail(list != NULL, NIL);
return JSValueMakeNumber(ctx, webkit_web_back_forward_list_get_back_length(list));
}
+/**
+ * Number of items that succeed the current item
+ *
+ * @name forwardLength
+ * @memberOf WebKitWebBackForwardList.prototype
+ * @type Number
+ * */
static JSValueRef
history_forward_length(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1856,6 +2523,14 @@ history_forward_length(JSContextRef ctx, JSObjectRef object, JSStringRef js_name
/* DATA {{{*/
/* data_get_profile {{{*/
+/**
+ * Profile which will be <i>default</i> unless another profile is specified on command line
+ *
+ * @name profile
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
static JSValueRef
data_get_profile(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1863,6 +2538,14 @@ data_get_profile(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSVa
}/*}}}*/
/* data_get_cache_dir {{{*/
+/**
+ * The cache directory used by dwb
+ *
+ * @name cacheDir
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
static JSValueRef
data_get_cache_dir(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1870,6 +2553,14 @@ data_get_cache_dir(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JS
}/*}}}*/
/* data_get_config_dir {{{*/
+/**
+ * The configuration diretory
+ *
+ * @name configDir
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
static JSValueRef
data_get_config_dir(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1883,6 +2574,14 @@ data_get_config_dir(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, J
}/*}}}*/
/* data_get_system_data_dir {{{*/
+/**
+ * The system data dir, for a default installation it is /usr/share/dwb
+ *
+ * @name systemDataDir
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
static JSValueRef
data_get_system_data_dir(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1896,6 +2595,14 @@ data_get_system_data_dir(JSContextRef ctx, JSObjectRef object, JSStringRef js_na
}/*}}}*/
/* data_get_user_data_dir {{{*/
+/**
+ * The user data dir, in most cases it will be ~/.local/share/dwb
+ *
+ * @name userDataDir
+ * @memberOf data
+ * @readonly
+ * @type String
+ * */
static JSValueRef
data_get_user_data_dir(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception)
{
@@ -1911,6 +2618,18 @@ data_get_user_data_dir(JSContextRef ctx, JSObjectRef object, JSStringRef js_name
/* SYSTEM {{{*/
/* system_get_env {{{*/
+/**
+ * Get a environment variable
+ *
+ * @name getEnv
+ * @memberOf system
+ * @function
+ *
+ * @param {String} name The name of the environment variable
+ *
+ * @returns {String}
+ * The environment variable or <i>null</i> if the variable wasn't found
+ * */
static JSValueRef
system_get_env(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2013,6 +2732,23 @@ get_environment(JSContextRef ctx, JSValueRef v, JSValueRef *exc)
}
/* {{{*/
+
+/**
+ * Spawn a process synchronously. This function should be used with care. The
+ * execution is single threaded so longer running processes will block the whole
+ * execution
+ *
+ * @name spawnSync
+ * @memberOf system
+ * @function
+ *
+ * @param {String} command The command to execute
+ * @param {Object} [environ] Object that can be used to add environment
+ * variables to the childs environment
+ *
+ * @returns {Object}
+ * An object that contains <i>stdout</i>, <i>stderr</i> and the <i>status</i> code.
+ * */
static JSValueRef
system_spawn_sync(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2077,6 +2813,39 @@ watch_spawn(GPid pid, gint status, JSObjectRef deferred)
}
/* system_spawn {{{*/
+/**
+ * Spawn a process asynchronously
+ *
+ * @name spawn
+ * @memberOf system
+ * @function
+ * @example
+ * system.spawn("foo" function (stdin) {
+ * io.print(stdin);
+ * }, function(stderr) {
+ * io.print(stderr, "stderr");
+ * }, { foo : "bar"});
+ *
+ * @param {String} command The command to execute
+ * @param {Function} [stdout] A callback function that is called when a line from
+ * stdout was read, if the function returns a
+ * string the string is passed to stdin of the
+ * spawned process, pass <i>null</i> if only stderr
+ * is needed or only environment variables should be
+ * set
+ * @param {Function} [stderr] A callback function that is called when a line from
+ * stderr was read, if the function returns a
+ * string the string is passed to stdin of the
+ * spawned process, pass <i>null</i> if stderr is not
+ * needed and environment variables should be set
+ * @param {Object} [environ] Object that can be used to add environment
+ * variables to the childs environment
+ *
+ * @returns {Deferred}
+ * A deferred, it will be resolved if the child exits normally, it will be
+ * rejected if the child process exits abnormally, the first parameter of
+ * the reject function will be the status code of the child process.
+ * */
static JSValueRef
system_spawn(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2155,6 +2924,20 @@ error_out:
}/*}}}*/
/* system_file_test {{{*/
+/**
+ * Checks for existence of a file or directory
+ *
+ * @name fileTest
+ * @memberOf system
+ * @function
+ *
+ * @param {String} path Path to a file to check
+ * @param {FileTest} flags
+ * Bitmask of {@link Enums and Flags.FileTest|FileTest} flags
+ *
+ * @returns {Boolean}
+ * <i>true</i> if any of the flags is set
+ * */
static JSValueRef
system_file_test(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2176,6 +2959,20 @@ system_file_test(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
return JSValueMakeBoolean(ctx, ret);
}/*}}}*/
+/**
+ * Creates a directory and all parent directories
+ *
+ * @name mkdir
+ * @memberOf system
+ * @function
+ *
+ * @param {Path} path Path to create
+ * @param {Number} mode The permissions the directory will get
+ *
+ * @returns {Boolean}
+ * <i>true</i> if creation was successful or if the diretory already
+ * existed
+ * */
/* system_mkdir {{{*/
static JSValueRef
system_mkdir(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -2201,6 +2998,21 @@ system_mkdir(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, siz
/* IO {{{*/
/* io_prompt {{{*/
+/**
+ * Gets user input synchronously
+ *
+ * @name prompt
+ * @memberOf io
+ * @function
+ *
+ * @param {String} prompt The prompt message
+ * @param {Boolean} [visible] Whether the chars should be visible, pass false
+ * for a password prompt, default true.
+ *
+ * @returns {String}
+ * The user response
+ * */
+
static JSValueRef
io_prompt(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2225,6 +3037,18 @@ io_prompt(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t
return result;
}/*}}}*/
+/**
+ * Read from a file
+ *
+ * @name read
+ * @memberOf io
+ * @function
+ *
+ * @param {String} path A path to a file
+ *
+ * @returns {String}
+ * The file content
+ * */
/* io_read {{{*/
static JSValueRef
io_read(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -2254,6 +3078,15 @@ error_out:
}/*}}}*/
/* io_notify {{{*/
+/**
+ * Show a notification in the browser window
+ *
+ * @name notify
+ * @memberOf io
+ * @function
+ *
+ * @param {String} message The message
+ * */
static JSValueRef
io_notify(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2269,6 +3102,15 @@ io_notify(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t
return UNDEFINED;
}/*}}}*/
+/**
+ * Show an error message in the browser window
+ *
+ * @name error
+ * @memberOf io
+ * @function
+ *
+ * @param {String} message The error message
+ * */
/* io_error {{{*/
static JSValueRef
io_error(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -2285,6 +3127,18 @@ io_error(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t
return UNDEFINED;
}/*}}}*/
+/**
+ * Get directory entries
+ *
+ * @name dirnames
+ * @memberOf io
+ * @function
+ *
+ * @param {String} path A path to a directory
+ *
+ * @returns {Arrayp[String]}
+ * An array of file names
+ * */
static JSValueRef
io_dir_names(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2324,6 +3178,20 @@ io_dir_names(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, siz
return ret;
}
/* io_write {{{*/
+/**
+ * Write to a file
+ *
+ * @name write
+ * @memberOf io
+ * @function
+ *
+ * @param {String} path Path to a file to write to
+ * @param {String} mode Either <i>"a"</i> to append or <i>"w"</i> to strip the file
+ * @param {String} text The text that should be written to the file
+ *
+ * @returns {Boolean}
+ * true if writing was successful
+ * */
static JSValueRef
io_write(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2367,6 +3235,16 @@ error_out:
}/*}}}*/
/* io_print {{{*/
+/**
+ * Print messages to stdout or stderr
+ *
+ * @name print
+ * @memberOf io
+ * @function
+ *
+ * @param {String} text The text to print
+ * @param {String} [stream] The stream, either <i>"stdout"</i> or <i>"stderr"</i>, default <i>"stdout"</i>
+ * */
static JSValueRef
io_print(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2436,6 +3314,18 @@ hwv_constructor_cb(JSContextRef ctx, JSObjectRef constructor, size_t argc, const
return make_object_for_class(ctx, s_webview_class, wv, false);
}
+/**
+ * Moves a widget in a GtkBox to a new Position
+ *
+ * @name reorderChild
+ * @memberOf GtkWidget.prototype
+ * @function
+ *
+ * @param {GtkWidget} child
+ * The child widget
+ * @param {Number} position
+ * Whether to expand the widget
+ * */
static JSValueRef
widget_reorder_child(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2463,6 +3353,40 @@ widget_reorder_child(JSContextRef ctx, JSObjectRef function, JSObjectRef this, s
return UNDEFINED;
}
+/**
+ * Adds a widget to a GtkBox
+ *
+ * @name packEnd
+ * @memberOf GtkWidget.prototype
+ * @function
+ *
+ * @param {GtkWidget} child
+ * The child widget
+ * @param {Boolean} expand
+ * Whether to expand the widget
+ * @param {Boolean} fill
+ * Whether to fill the remaining space
+ * @param {Number} padding
+ * Padding in the box
+ *
+ * */
+/**
+ * Adds a widget to a GtkBox
+ *
+ * @name packStart
+ * @memberOf GtkWidget.prototype
+ * @function
+ *
+ * @param {GtkWidget} child
+ * The child widget
+ * @param {Boolean} expand
+ * Whether to expand the widget
+ * @param {Boolean} fill
+ * Whether to fill the remaining space
+ * @param {Number} padding
+ * Padding in the box
+ *
+ * */
static JSValueRef
widget_pack(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2527,6 +3451,13 @@ widget_container_add(JSContextRef ctx, JSObjectRef function, JSObjectRef this, s
return UNDEFINED;
}
+/**
+ * Destroys a widget
+ *
+ * @name destroy
+ * @memberOf GtkWidget.prototype
+ * @function
+ * */
static JSValueRef
widget_destroy(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2560,6 +3491,13 @@ widget_constructor_cb(JSContextRef ctx, JSObjectRef constructor, size_t argc, co
/* DOWNLOAD {{{*/
/* download_constructor_cb {{{*/
+/**
+ * Constructs a new download
+ *
+ * @memberOf WebKitDownload.prototype
+ * @constructor
+ * @param {String} uri The uri of the download
+ * */
static JSObjectRef
download_constructor_cb(JSContextRef ctx, JSObjectRef constructor, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
@@ -2584,6 +3522,11 @@ download_constructor_cb(JSContextRef ctx, JSObjectRef constructor, size_t argc,
WebKitDownload *download = webkit_download_new(request);
return JSObjectMake(ctx, s_download_class, download);
}/*}}}*/
+/**
+ * Constructs a new Deferred.
+ * @memberOf Deferred.prototype
+ * @constructor
+ */
static JSObjectRef
deferred_constructor_cb(JSContextRef ctx, JSObjectRef constructor, size_t argc, const JSValueRef argv[], JSValueRef* exception)
{
@@ -2602,6 +3545,20 @@ stop_download_notify(CallbackData *c)
}/*}}}*/
/* download_start {{{*/
+/**
+ * Starts a download
+ *
+ * @name start
+ * @memberOf WebKitDownload.prototype
+ * @function
+ *
+ * @param {WebKitDownload~statusCallback} callback
+ * Callback function that will be executed whenever the
+ * {@link Enums and Flags.DownloadStatus|DownloadStatus} changes
+ *
+ * @returns {Boolean}
+ * true if the download was started
+ * */
static JSValueRef
download_start(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -2623,6 +3580,13 @@ download_start(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t
}/*}}}*/
+/**
+ * Cancels a download
+ *
+ * @name cancel
+ * @memberOf WebKitDownload.prototype
+ * @function
+ * */
/* download_cancel {{{*/
static JSValueRef
download_cancel(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -2636,56 +3600,122 @@ download_cancel(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t
/*}}}*/
/* gui {{{*/
+/**
+ * The main window
+ * @name window
+ * @memberOf gui
+ * @type GtkWindow
+ * */
static JSValueRef
gui_get_window(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.window), true);
}
+/**
+ * The main container. Child of window
+ * @name mainBox
+ * @memberOf gui
+ * @type GtkBox
+ * */
static JSValueRef
gui_get_main_box(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.vbox), true);
}
+/**
+ * The box used for tab labels. Child of mainBox
+ * @name tabBox
+ * @memberOf gui
+ * @type GtkBox
+ * */
static JSValueRef
gui_get_tab_box(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.topbox), true);
}
+/**
+ * The box used for the main content. Child of mainBox
+ * @name contentBox
+ * @memberOf gui
+ * @type GtkBox
+ * */
static JSValueRef
gui_get_content_box(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.mainbox), true);
}
+/**
+ * The outmost statusbar widget, used for setting the statusbars colors, child of mainBox.
+ * @name statusWidget
+ * @memberOf gui
+ * @type GtkEventBox
+ * */
static JSValueRef
gui_get_status_widget(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.statusbox), true);
}
+/**
+ * Used for the statusbar alignment, child of statusWidget.
+ * @name statusAlignment
+ * @memberOf gui
+ * @type GtkAlignment
+ * */
static JSValueRef
gui_get_status_alignment(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.alignment), true);
}
+/**
+ * The box that contains the statusbar widgets, grandchild of statusAlignment
+ * @name statusBox
+ * @memberOf gui
+ * @type GtkBox
+ * */
static JSValueRef
gui_get_status_box(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.status_hbox), true);
}
- static JSValueRef
+/**
+ * Label used for notifications, first child of statusBox
+ * @name messageLabel
+ * @memberOf gui
+ * @type GtkLabel
+ * */
+static JSValueRef
gui_get_message_label(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.lstatus), true);
}
+/**
+ * The entry, second child of statusBox
+ * @name entry
+ * @memberOf gui
+ * @type GtkEntry
+ * */
static JSValueRef
gui_get_entry(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.entry), true);
}
+/**
+ * The uri label, third child of statusBox
+ * @name uriLabel
+ * @memberOf gui
+ * @type GtkLabel
+ * */
static JSValueRef
gui_get_uri_label(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
return make_object_for_class(ctx, s_secure_widget_class, G_OBJECT(dwb.gui.urilabel), true);
}
+/**
+ * Label used for status information, fourth child of statusBox
+ * @name statusLabel
+ * @memberOf gui
+ * @type GtkLabel
+ * */
static JSValueRef
gui_get_status_label(JSContextRef ctx, JSObjectRef object, JSStringRef property, JSValueRef* exception)
{
@@ -2831,12 +3861,29 @@ make_object(JSContextRef ctx, GObject *o)
return make_object_for_class(ctx, class, o, true);
}/*}}}*/
+/**
+ * Callback called for GObject signals, <b>this</b> will refer to the object
+ * that connected to the signal
+ * @callback GObject~connectCallback
+ *
+ * @param {...Object} varargs
+ * Variable number of additional arguments, see the correspondent
+ * gtk/glib/webkit documentation. Note that only arguments of basic type
+ * and arguments derived from GObject are converted to the corresponding
+ * javascript object, otherwise the argument will be undefined (e.g.
+ * GBoxed types and structs).
+ *
+ * @returns {Boolean}
+ * Return true to stop the emission. Note that this signal handler is
+ * connected after dwb's default handler so it will not prevent dwb's
+ * handlers to be executed
+ * */
static gboolean
connect_callback(SSignal *sig, ...)
{
va_list args;
JSValueRef cur;
- JSValueRef argv[sig->query->n_params + 1];
+ JSValueRef argv[sig->query->n_params];
gboolean result = false;
if (!TRY_CONTEXT_LOCK)
@@ -2888,11 +3935,10 @@ connect_callback(SSignal *sig, ...)
}
apply:
- argv[i+1] = cur;
+ argv[i] = cur;
}
#undef CHECK_NUMBER
- argv[0] = sig->object;
- JSValueRef ret = call_as_function_debug(s_global_context, sig->func, sig->func, sig->query->n_params+1, argv);
+ JSValueRef ret = call_as_function_debug(s_global_context, sig->func, sig->object, sig->query->n_params, argv);
if (JSValueIsBoolean(s_global_context, ret))
{
result = JSValueToBoolean(s_global_context, ret);
@@ -2916,6 +3962,12 @@ on_disconnect_notify(JSObjectRef func, GClosure *closure)
JSValueUnprotect(s_global_context, func);
CONTEXT_UNLOCK;
}
+/**
+ * Called when a property of an object changes, <b>this</b> will refer to the object
+ * that connected to the signal.
+ * @callback GObject~notifyCallback
+ *
+ * */
static void
notify_callback(GObject *o, GParamSpec *param, JSObjectRef func)
{
@@ -2923,11 +3975,29 @@ notify_callback(GObject *o, GParamSpec *param, JSObjectRef func)
return;
if (s_global_context != NULL)
{
- JSValueRef argv[] = { make_object(s_global_context, o) };
- call_as_function_debug(s_global_context, func, func, 1, argv);
+ //JSValueRef argv[] = { make_object(s_global_context, o) };
+ call_as_function_debug(s_global_context, func, make_object(s_global_context, o), 0, NULL);
}
CONTEXT_UNLOCK;
}
+/**
+ * Connect to a GObject-signal. Note that all signals are connected using the
+ * signal::- or with notify::-prefix. If connecting to a signal the
+ * signal::-prefix must be omitted. The callback function will have the same
+ * parameters as the GObject signal callback, however some parameters may be
+ * undefined if they cannot be converted to javascript objects. All signal
+ * handlers are executed after dwb’s default handler.
+ *
+ * @memberOf GObject.prototype
+ * @name connect
+ * @function
+ *
+ * @param {String} name The signal name.
+ * @param {GObject~connectCallback} callback Callback that will be called when the signal is emitted.
+ * @param {Boolean} [after] Whether to connect after the default signal handler.
+ *
+ * @returns {Number} The signal id of this signal
+ * */
static JSValueRef
gobject_connect(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -3000,6 +4070,15 @@ error_out:
g_free(name);
return JSValueMakeNumber(ctx, id);
}
+/**
+ * Blocks emission of a signal
+ *
+ * @name blockSignal
+ * @memberOf GObject.prototype
+ * @function
+ *
+ * @param {Number} id The signal id retrieved from GObject#connect
+ * */
static JSValueRef
gobject_block_signal(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
@@ -3013,6 +4092,15 @@ gobject_block_signal(JSContextRef ctx, JSObjectRef function, JSObjectRef this, s
}
return UNDEFINED;
}
+/**
+ * Unblocks a signal that was blocked with GObject#blockSignal
+ *
+ * @name unblockSignal
+ * @memberOf GObject.prototype
+ * @function
+ *
+ * @param {Number} id The signal id retrieved from GObject#connect
+ * */
static JSValueRef
gobject_unblock_signal(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -3025,6 +4113,18 @@ gobject_unblock_signal(JSContextRef ctx, JSObjectRef function, JSObjectRef this,
}
return UNDEFINED;
}
+/**
+ * Disconnects from a signal
+ *
+ * @name disconnect
+ * @memberOf GObject.prototype
+ * @function
+ *
+ * @param {Number} id The signal id retrieved from {@link GObject.connect}
+ *
+ * @returns {Boolean}
+ * Whether a signal was found and disconnected
+ * */
static JSValueRef
gobject_disconnect(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef* exc)
{
@@ -3244,7 +4344,7 @@ create_global_object()
s_ref_quark = g_quark_from_static_string("dwb_js_ref");
JSStaticValue global_values[] = {
- { "global", global_get, NULL, kJSDefaultAttributes },
+ { "global", global_get, NULL, kJSDefaultAttributes },
{ "session", global_get_webkit_session, NULL, kJSDefaultAttributes },
{ 0, 0, 0, 0 },
};
@@ -3254,13 +4354,7 @@ create_global_object()
{ "exit", global_exit, kJSDefaultAttributes },
{ "bind", global_bind, kJSDefaultAttributes },
{ "unbind", global_unbind, kJSDefaultAttributes },
- { "checksum", global_checksum, kJSDefaultAttributes },
{ "include", global_include, kJSDefaultAttributes },
- { "timerStart", global_timer_start, kJSDefaultAttributes },
- { "timerStop", global_timer_stop, kJSDefaultAttributes },
- { "sendRequest", global_send_request, kJSDefaultAttributes },
- { "sendRequestSync", global_send_request_sync, kJSDefaultAttributes },
- { "tabComplete", global_tab_complete, kJSDefaultAttributes },
{ 0, 0, 0 },
};
@@ -3269,6 +4363,14 @@ create_global_object()
JSClassRelease(class);
+ /**
+ * Get internally used data like configuration files
+ *
+ * @namespace
+ * Get internally used data like configuration files
+ * @name data
+ * @static
+ * */
JSObjectRef global_object = JSContextGetGlobalObject(s_global_context);
JSStaticValue data_values[] = {
@@ -3283,6 +4385,46 @@ create_global_object()
create_object(s_global_context, class, global_object, kJSDefaultAttributes, "data", NULL);
JSClassRelease(class);
+ /**
+ * Static object for timed execution
+ * @namespace
+ * Static object for timed execution
+ * @name timer
+ * @static
+ * */
+ JSStaticFunction timer_functions[] = {
+ { "start", timer_start, kJSDefaultAttributes },
+ { "stop", timer_stop, kJSDefaultAttributes },
+ { 0, 0, 0 },
+ };
+ class = create_class("timer", timer_functions, NULL);
+ create_object(s_global_context, class, global_object, kJSDefaultAttributes, "timer", NULL);
+ JSClassRelease(class);
+ /**
+ * @namespace
+ * Static object for network related tasks
+ * @name net
+ * @static
+ * */
+ JSStaticFunction net_functions[] = {
+ { "sendRequest", net_send_request, kJSDefaultAttributes },
+ { "sendRequestSync", net_send_request_sync, kJSDefaultAttributes },
+ { "domainFromHost", net_domain_from_host, kJSDefaultAttributes },
+ { 0, 0, 0 },
+ };
+ class = create_class("net", net_functions, NULL);
+ create_object(s_global_context, class, global_object, kJSDefaultAttributes, "net", NULL);
+ JSClassRelease(class);
+
+
+ /**
+ * Static object for input and output
+ *
+ * @namespace
+ * Static object for input and output and file operations
+ * @name io
+ * @static
+ * */
cd = kJSClassDefinitionEmpty;
cd.getProperty = settings_get;
cd.setProperty = set_property_cb;
@@ -3304,6 +4446,15 @@ create_global_object()
create_object(s_global_context, class, global_object, kJSPropertyAttributeDontDelete, "io", NULL);
JSClassRelease(class);
+ /**
+ * Static object for system functions
+ *
+ * @namespace
+ * Static object for system functions such as spawning processes,
+ * getting environment variables
+ * @name system
+ * @static
+ * */
JSStaticFunction system_functions[] = {
{ "spawn", system_spawn, kJSDefaultAttributes },
{ "spawnSync", system_spawn_sync, kJSDefaultAttributes },
@@ -3326,10 +4477,31 @@ create_global_object()
{ "length", tabs_length, NULL, kJSDefaultAttributes },
{ 0, 0, 0, 0 },
};
+
+ /**
+ * Getting webviews
+ *
+ * @namespace
+ * Static object that can be used to get webviews
+ * @name tabs
+ * @static
+ * */
class = create_class("tabs", tab_functions, tab_values);
create_object(s_global_context, class, global_object, kJSDefaultAttributes, "tabs", NULL);
JSClassRelease(class);
+ /**
+ * Execute code on certain events. dwb emits some signals, e.g. before a new
+ * site is loaded, the signals object can be used to handle these signals.
+ * All events are emitted on the signals object itself, for example
+ * "signals.keyPress = function() { ... };" would connect to the keyPress
+ * signal but it is <b>strongly discouraged</b> to use this pattern since it will
+ * only allow to connect one callback to a certain signal, so {@link signals.connect}
+ * which manages all signals should be used instead.
+ *
+ * @namespace
+ * @name signals
+ * */
cd = kJSClassDefinitionEmpty;
cd.className = "signals";
cd.setProperty = signal_set;
@@ -3342,18 +4514,35 @@ create_global_object()
create_object(s_global_context, class, global_object, kJSDefaultAttributes, "extensions", NULL);
JSClassRelease(class);
+ /**
+ * Utility functions
+ *
+ * @namespace
+ * Miscellaneous utility functions
+ * @name util
+ * @static
+ * */
JSStaticFunction util_functions[] = {
- { "domainFromHost", sutil_domain_from_host, kJSDefaultAttributes },
{ "markupEscape", sutil_markup_escape, kJSDefaultAttributes },
{ "getMode", sutil_get_mode, kJSDefaultAttributes },
{ "getBody", sutil_get_body, kJSDefaultAttributes },
- { "dispatchEvent", sutil_dispatch_event, kJSDefaultAttributes },
+ { "dispatchEvent", sutil_dispatch_event, kJSDefaultAttributes },
+ { "tabComplete", sutil_tab_complete, kJSDefaultAttributes },
+ { "checksum", sutil_checksum, kJSDefaultAttributes },
{ 0, 0, 0 },
};
class = create_class("util", util_functions, NULL);
create_object(s_global_context, class, global_object, kJSDefaultAttributes, "util", NULL);
JSClassRelease(class);
+ /**
+ * Access to the system clipboard
+ * @namespace
+ * Accessing the system clipboard
+ * @name clipboard
+ * @static
+ *
+ * */
JSStaticFunction clipboard_functions[] = {
{ "get", clipboard_get, kJSDefaultAttributes },
{ "set", clipboard_set, kJSDefaultAttributes },
@@ -3363,7 +4552,28 @@ create_global_object()
create_object(s_global_context, class, global_object, kJSDefaultAttributes, "clipboard", NULL);
JSClassRelease(class);
- /* Default gobject class */
+ /**
+ * Base class for webkit/gtk objects
+ *
+ * @name GObject
+ * @property {Object} ...
+ * Variable number of properties, See the corresponding
+ * gtk/webkitgtk/libsoup documentation for a list of properties, All
+ * properties can be used in camelcase.
+ *
+ * @class
+ * Base class for webkit/gtk objects, all objects derived from GObject
+ * correspond to the original GObjects. They have the same properties,
+ * but javascript properties can also be used in camelcase.
+ * It is discouraged from settting own properties directly on objects derived
+ * from GObject since these objects are shared between all scripts, use
+ * {@link script.setPrivate} and {@link script.getPrivate} instead
+ * @example
+ * tabs.current["zoom-level"] = 2;
+ * // is equivalent to
+ * tabs.current.zoomLevel = 2;
+ *
+ * */
JSStaticFunction default_functions[] = {
{ "connect", gobject_connect, kJSDefaultAttributes },
{ "blockSignal", gobject_block_signal, kJSDefaultAttributes },
@@ -3382,6 +4592,14 @@ create_global_object()
s_constructors[CONSTRUCTOR_DEFAULT] = create_constructor(s_global_context, "GObject", s_gobject_class, NULL, NULL);
/* Webview */
+ /**
+ * A GtkWidget that shows the webcontent
+ *
+ * @name WebKitWebView
+ * @augments GObject
+ * @class GtkWidget that shows webcontent
+ * @borrows WebKitWebFrame#inject as prototype.inject
+ * */
JSStaticFunction wv_functions[] = {
{ "loadUri", wv_load_uri, kJSDefaultAttributes },
{ "stopLoading", wv_stop_loading, kJSDefaultAttributes },
@@ -3425,6 +4643,16 @@ create_global_object()
/* Frame */
+ /**
+ * Represents a frame or an iframe
+ *
+ * @name WebKitWebFrame
+ * @augments GObject
+ * @class
+ * Represents a frame or iframe. Due to same origin policy it
+ * is not possible to inject scripts from a WebKitWebView into iframes with a
+ * different domain. For this purpose the frame object can be used.
+ * */
JSStaticFunction frame_functions[] = {
{ "inject", frame_inject, kJSDefaultAttributes },
{ 0, 0, 0 },
@@ -3445,6 +4673,17 @@ create_global_object()
s_constructors[CONSTRUCTOR_FRAME] = create_constructor(s_global_context, "WebKitWebFrame", s_frame_class, NULL, NULL);
/* SoupMessage */
+ /**
+ * Represents a SoupMessage
+ *
+ * @name SoupMessage
+ * @augments GObject
+ * @class
+ * Represents a SoupMessage. Can be used to inspect information about a
+ * request
+ *
+ * @returns undefined
+ * */
JSStaticValue message_values[] = {
{ "uri", message_get_uri, NULL, kJSDefaultAttributes },
{ "firstParty", message_get_first_party, NULL, kJSDefaultAttributes },
@@ -3457,8 +4696,17 @@ create_global_object()
cd.parentClass = s_gobject_class;
s_message_class = JSClassCreate(&cd);
- s_constructors[CONSTRUCTOR_SOUP_MESSAGE] = create_constructor(s_global_context, "SoupMessage", s_message_class, NULL, NULL);
-
+ s_constructors[CONSTRUCTOR_HISTORY_LIST] = create_constructor(s_global_context, "SoupMessage", s_message_class, NULL, NULL);
+
+ /**
+ * The history of a webview
+ *
+ * @class
+ * The history of a webview.
+ * @augments GObject
+ * @name WebKitWebBackForwardList
+ *
+ * */
JSStaticFunction history_functions[] = {
{ "getItem", history_get_item, kJSDefaultAttributes },
{ 0, 0, 0 },
@@ -3474,8 +4722,49 @@ create_global_object()
cd.parentClass = s_gobject_class;
s_history_class = JSClassCreate(&cd);
- s_constructors[CONSTRUCTOR_SOUP_MESSAGE] = create_constructor(s_global_context, "SoupMessage", s_message_class, NULL, NULL);
-
+ s_constructors[CONSTRUCTOR_SOUP_MESSAGE] = create_constructor(s_global_context, "WebKitWebBackForwardList", s_history_class, NULL, NULL);
+
+ /**
+ * Constructs a new Deferred
+ *
+ * @class
+ * Deferred objects can be used to manage asynchronous operations. It
+ * can trigger a callback function when an asynchrounous operation has
+ * finished, and allows chaining of callbacks. Deferred basically has 2
+ * callback chains, a done-chain and a fail-chain. If a asynchronous
+ * operation is successful the deferred should be resolved and the done
+ * callback chain of the deferred is called. If a asynchronous
+ * operation fails the deferred should be rejected and the fail
+ * callback chain of the deferred is called.
+ * @name Deferred
+ * @constructs Deferred
+ * @example
+ * system.spawn("command").then(
+ * function() {
+ * // called when execution was successful
+ * },
+ * function(errorcode) {
+ * // called when execution wasn't successful
+ * }
+ * );
+ *
+ * function foo() {
+ * var d = new Deferred();
+ * timerStart(2000, function() {
+ * d.reject("rejected");
+ * });
+ * return d;
+ * }
+ * function onResponse(response) {
+ * io.print(response);
+ * }
+ *
+ * // Will print "rejected" after 2 and 4 seconds
+ * foo().fail(onResponse).fail(onResponse);
+ *
+ * @returns A Deferred
+ *
+ * */
JSStaticFunction deferred_functions[] = {
{ "then", deferred_then, kJSDefaultAttributes },
{ "resolve", deferred_resolve, kJSDefaultAttributes },
@@ -3488,11 +4777,28 @@ create_global_object()
s_deferred_class = JSClassCreate(&cd);
s_constructors[CONSTRUCTOR_DEFERRED] = create_constructor(s_global_context, "Deferred", s_deferred_class, deferred_constructor_cb, NULL);
+ /**
+ * Constructs a new GtkWidget
+ *
+ * @class
+ * It is possible to create new widgets but only widgets that are currently
+ * used by dwb can be created. The widgets used by dwb can be found under
+ * {@see http://portix.bitbucket.org/dwb/resources/layout.html}
+ * @augments GObject
+ * @name GtkWidget
+ *
+ * @constructs GtkWidget
+ * @param {String} name Name of the Widget, e.g. "GtkLabel"
+ *
+ * @returns A GtkWidget
+ * @example
+ * var myLabel = new GtkWidget("GtkLabel");
+ * */
JSStaticFunction secure_widget_functions[] = {
{ "packStart", widget_pack, kJSDefaultAttributes },
{ "packEnd", widget_pack, kJSDefaultAttributes },
{ "reorderChild", widget_reorder_child, kJSDefaultAttributes },
- { "add", widget_container_add, kJSDefaultAttributes },
+ { "add", widget_container_add, kJSDefaultAttributes },
{ 0, 0, 0 },
};
cd = kJSClassDefinitionEmpty;
@@ -3513,6 +4819,18 @@ create_global_object()
s_constructors[CONSTRUCTOR_WIDGET] = create_constructor(s_global_context, "GtkWidget", s_widget_class, widget_constructor_cb, NULL);
+ /**
+ * Static object that holds dwb's GtkWidgets
+ *
+ * @namespace
+ * Static object that holds dwb's GtkWidgets. Most widgets can be accessed
+ * directly from scripts
+ * see <a>http://portix.bitbucket.org/dwb/resources/layout.html</a> for an
+ * overview of all widgets.
+ * @name gui
+ * @static
+ *
+ * */
JSStaticValue gui_values[] = {
{ "window", gui_get_window, NULL, kJSDefaultAttributes },
{ "mainBox", gui_get_main_box, NULL, kJSDefaultAttributes },
@@ -3534,6 +4852,20 @@ create_global_object()
create_object(s_global_context, class, global_object, kJSDefaultAttributes, "gui", NULL);
JSClassRelease(class);
+ /**
+ * Constructs a new download
+ *
+ * @class
+ * Object that can be used for downloads
+ * @name WebKitDownload
+ * @augments GObject
+ *
+ * @constructs WebKitDownload
+ *
+ * @param {String} url The url of the download
+ *
+ * @returns WebKitDownLoad
+ * */
/* download */
JSStaticFunction download_functions[] = {
{ "start", download_start, kJSDefaultAttributes },
@@ -3541,13 +4873,13 @@ create_global_object()
{ 0, 0, 0 },
};
- cd.className = "Download";
+ cd.className = "WebKitDownload";
cd.staticFunctions = download_functions;
cd.staticValues = NULL;
cd.parentClass = s_gobject_class;
s_download_class = JSClassCreate(&cd);
- s_constructors[CONSTRUCTOR_DOWNLOAD] = create_constructor(s_global_context, "Download", s_download_class, download_constructor_cb, NULL);
+ s_constructors[CONSTRUCTOR_DOWNLOAD] = create_constructor(s_global_context, "WebKitDownload", s_download_class, download_constructor_cb, NULL);
s_soup_session = make_object_for_class(s_global_context, s_gobject_class, G_OBJECT(webkit_get_default_session()), false);
@@ -3624,6 +4956,20 @@ scripts_remove_tab(JSObjectRef obj)
{
if (EMIT_SCRIPT(CLOSE_TAB))
{
+ /**
+ * Emitted when a tab is closed
+ * @event closeTab
+ * @memberOf signals
+ * @param {signals~onCloseTab} callback
+ * Callback function that will be called when the signal is emitted
+ *
+ * */
+ /**
+ * Callback called when a tab is closed
+ * @callback signals~onCloseTab
+ *
+ * @param {WebKitWebView} webview The corresponding WebKitWebView
+ * */
ScriptSignal signal = { obj, SCRIPTS_SIG_META(NULL, CLOSE_TAB, 0) };
scripts_emit(&signal);
}
diff --git a/src/view.c b/src/view.c
index 4c9345f5..c02ca874 100644
--- a/src/view.c
+++ b/src/view.c
@@ -80,6 +80,27 @@ view_resource_request_cb(WebKitWebView *wv, WebKitWebFrame *frame, WebKitWebReso
{
if (EMIT_SCRIPT(RESOURCE))
{
+ /**
+ * Emitted before a resource is loaded
+ * @event resource
+ * @memberOf signals
+ * @param {signals~onResource} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called before a resource is loaded
+ * @callback signals~onResource
+ * @param {WebKitWebView} webview
+ * The webview that contains the requesting frame
+ * @param {WebKitWebFrame} frame
+ * The frame that requested the resource
+ * @param {WebKitNetworkRequest} request
+ * The request, setting request.uri to "about:blank" will prevent
+ * the request from being loaded.
+ * @param {WebKitNetworkResponse} response
+ * The response, note that response will always be null unless the
+ * request comes from a redirect
+ * */
ScriptSignal signal = {
SCRIPTS_WV(gl), .objects = { G_OBJECT(frame), G_OBJECT(request), G_OBJECT(response) }, SCRIPTS_SIG_META(NULL, RESOURCE, 3) };
scripts_emit(&signal);
@@ -97,6 +118,22 @@ view_document_finished(WebKitWebView *wv, WebKitWebFrame *frame, GList *gl)
{
if (EMIT_SCRIPT(DOCUMENT_LOADED))
{
+ /**
+ * Emitted when a document of a frame has been loaded. Use this
+ * event to inject scripts that need a fully populated DOM-tree
+ * @event documentLoaded
+ * @memberOf signals
+ * @param {signals~onDocumentLoaded} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when the document of a frame has been loaded.
+ * @callback signals~onDocumentLoaded
+ * @param {WebKitWebView} webview
+ * The webview that contains the frame
+ * @param {WebKitWebFrame} frame
+ * The frame that emitted the signal
+ * */
ScriptSignal signal = { SCRIPTS_WV(gl), { G_OBJECT(frame) }, SCRIPTS_SIG_META(NULL, DOCUMENT_LOADED, 1) };
scripts_emit(&signal);
}
@@ -163,6 +200,44 @@ view_button_press_cb(WebKitWebView *web, GdkEventButton *e, GList *gl)
s_click_time = e->time;
if (EMIT_SCRIPT(BUTTON_PRESS))
{
+ /**
+ * Emitted when a mouse button was pressed
+ *
+ * @event buttonPress
+ * @memberOf signals
+ * @param {signals~onButtonPress} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when a mouse button was pressed on a webview
+ * @callback signals~onButtonPress
+ * @param {WebKitWebView} webview
+ * The webview that emitted the signal
+ * @param {WebKitHitTestResult} result
+ * A hit test result
+ * @param {GtkEventBox} tabwidget
+ * The tabwidget
+ * @param {Object} event
+ * @param {Number} event.button
+ * The button that was pressed, usually a value between 1 and 5
+ * @param {Modifier} event.state
+ * A bitmask of {@link Enums and Flags.Modifier|Modifiers} pressed
+ * @param {Number} event.time
+ * The time in milliseconds when the button was pressed
+ * @param {ClickType} event.type
+ * A {@link Enums and Flags.ClickType|ClickType}
+ * @param {Number} event.x
+ * x-position relative to the window
+ * @param {Number} event.xRoot
+ * x-position relative to the screen
+ * @param {Number} event.y
+ * y-position relative to the window
+ * @param {Number} event.yRoot
+ * y-position relative to the screen
+ *
+ * @returns {Boolean}
+ * Return true to prevent the default action
+ * */
char *json = util_create_json(8,
UINTEGER, "time", e->time, UINTEGER, "type", e->type,
DOUBLE, "x", e->x, DOUBLE, "y", e->y,
@@ -246,6 +321,40 @@ view_button_release_cb(WebKitWebView *web, GdkEventButton *e, GList *gl)
if (EMIT_SCRIPT(BUTTON_RELEASE))
{
+ /**
+ * Emitted when a mouse button was released
+ *
+ * @event buttonRelease
+ * @memberOf signals
+ * @param {signals~onButtonRelease} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when the load-status of a WebKitWebView changes
+ * @callback signals~onButtonRelease
+ * @param {WebKitWebView} webview
+ * The webview that emitted the signal
+ * @param {WebKitHitTestResult} result
+ * The hit test result
+ * @param {Object} event
+ * @param {Number} event.button
+ * The button that was pressed, usually a value between 1 and 5
+ * @param {Modifier} event.state
+ * A bitmask of {@link Enums and Flags.Modifier|Modifiers} pressed
+ * @param {Number} event.time
+ * The time in milliseconds when the button was pressed
+ * @param {Number} event.x
+ * x-position relative to the window
+ * @param {Number} event.xRoot
+ * x-position relative to the screen
+ * @param {Number} event.y
+ * y-position relative to the window
+ * @param {Number} event.yRoot
+ * y-position relative to the screen
+ *
+ * @returns {Boolean}
+ * Return true to prevent the default action
+ * */
char *json = util_create_json(7,
UINTEGER, "time", e->time,
DOUBLE, "x", e->x, DOUBLE, "y", e->y,
@@ -287,6 +396,22 @@ view_frame_committed_cb(WebKitWebFrame *frame, GList *gl)
{
if (EMIT_SCRIPT(FRAME_STATUS))
{
+ /**
+ * Emitted when the load status of a frame changes
+ *
+ * @event frameStatus
+ * @memberOf signals
+ * @param {signals~onFrameStatus} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when the load-status of a WebKitWebFrame changes
+ * @callback signals~onFrameStatus
+ * @param {WebKitWebView} webview
+ * The webview that contains the frame
+ * @param {WebKitWebFrame} frame
+ * The frame that emitted the signal
+ * */
ScriptSignal signal = { SCRIPTS_WV(gl),
.objects = { G_OBJECT(frame) }, SCRIPTS_SIG_META(NULL, FRAME_STATUS, 1) };
scripts_emit(&signal);
@@ -297,7 +422,24 @@ view_frame_committed_cb(WebKitWebFrame *frame, GList *gl)
static void
view_frame_created_cb(WebKitWebView *wv, WebKitWebFrame *frame, GList *gl)
{
- if (EMIT_SCRIPT(FRAME_CREATED)) {
+ if (EMIT_SCRIPT(FRAME_CREATED))
+ {
+ /**
+ * Emitted when a frame is created
+ *
+ * @event frameCreated
+ * @memberOf signals
+ * @param {signals~onFrameCreated} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when a WebKitWebFrame is created
+ * @callback signals~onFrameCreated
+ * @param {WebKitWebView} webview
+ * The webview that contains the frame
+ * @param {WebKitWebFrame} frame
+ * The created frame
+ * */
ScriptSignal signal = { SCRIPTS_WV(gl), .objects = { G_OBJECT(frame) }, SCRIPTS_SIG_META(NULL, FRAME_CREATED, 1) };
scripts_emit(&signal);
}
@@ -346,6 +488,28 @@ view_download_requested_cb(WebKitWebView *web, WebKitDownload *download, GList *
{
if (EMIT_SCRIPT(DOWNLOAD))
{
+ /**
+ * Emitted before a download starts
+ *
+ * @event download
+ * @memberOf signals
+ * @param {signals~onDownload} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called before a download starts, will be called before the
+ * a path/application was chosen
+ * @callback signals~onDownload
+ * @param {WebKitWebView} webview
+ * The webview emitted the signal
+ * @param {WebKitDownload} frame
+ * The download
+ * @param {Object} data
+ * @param {String} data.referer
+ * The referer
+ * @param {String} data.mimeType
+ * The mime type of the download
+ * */
char *json = util_create_json(2,
CHAR, "referer", soup_get_header_from_request(webkit_download_get_network_request(download), "Referer"),
CHAR, "mimeType", dwb.state.mimetype_request);
@@ -437,7 +601,32 @@ view_mime_type_policy_cb(WebKitWebView *web, WebKitWebFrame *frame, WebKitNetwor
if (EMIT_SCRIPT(MIME_TYPE))
{
- char *json = util_create_json(1, CHAR, "mimeType", mimetype);
+ /**
+ * Emitted when a mime type decision is requested
+ * @event mimeType
+ * @memberOf signals
+ * @param {signals~onMimeType} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when a mimetype decision has to be made
+ * @callback signals~onMimeType
+ * @param {WebKitWebView} webview
+ * The webview that contains the frame
+ * @param {WebKitWebFrame} frame
+ * The frame that emitted the signal
+ * @param {WebKitNetworkRequest} request
+ * The network request
+ * @param {Object} data
+ * @param {Boolean} data.canShowMimeType
+ * Whether the webview can show the mimetype
+ * @param {String} data.mimeType
+ * The mime type
+ *
+ * @returns {Boolean}
+ * Return true to ignore the request
+ * */
+ char *json = util_create_json(2, CHAR, "mimeType", mimetype, BOOLEAN, "canShowMimeType", webkit_web_view_can_show_mime_type(web, mimetype));
ScriptSignal signal = { SCRIPTS_WV(gl), { G_OBJECT(frame), G_OBJECT(request) }, SCRIPTS_SIG_META(json, MIME_TYPE, 2) };
if (scripts_emit(&signal))
{
@@ -469,6 +658,30 @@ view_navigation_policy_cb(WebKitWebView *web, WebKitWebFrame *frame, WebKitNetwo
if (EMIT_SCRIPT(NAVIGATION))
{
+ /**
+ * Emitted before a new site or a new frame is loaded
+ * @event navigation
+ * @memberOf signals
+ * @param {signals~onNavigation} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called before a new navigation starts
+ * @callback signals~onNavigation
+ * @param {WebKitWebView} webview
+ * The webview that contains the frame, to check if a new site will
+ * be loaded check if {@linkcode webview.mainFrame == frame}
+ * @param {WebKitWebFrame} frame
+ * The frame that emitted the signal
+ * @param {WebKitNetworkRequest} request
+ * The network request
+ * @param {WebKitWebNavigationAction} action
+ * A navigation action that started the request
+ *
+ * @returns {Boolean}
+ * Return true to stop the emission and prevent the site from being
+ * loaded
+ * */
ScriptSignal signal = { SCRIPTS_WV(gl), { G_OBJECT(frame), G_OBJECT(request), G_OBJECT(action) }, SCRIPTS_SIG_META(NULL, NAVIGATION, 3) };
if (scripts_emit(&signal))
{
@@ -804,6 +1017,22 @@ view_load_status_cb(WebKitWebView *web, GParamSpec *pspec, GList *gl)
{
plugins_disconnect(gl);
}
+ /**
+ * Emitted when the load has just been commited, no data has been loaded
+ * when this signal is emitted. This is the preferred signal for
+ * injected scripts that do not manipulate the DOM.
+ *
+ * @event loadCommitted
+ * @memberOf signals
+ * @param {signals~onLoadCommitted} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when the load of a site has just been committed.
+ * @callback signals~onLoadCommitted
+ * @param {WebKitWebView} webview
+ * The webview that emitted the signal
+ * */
if (EMIT_SCRIPT(LOAD_COMMITTED))
{
ScriptSignal signal = { SCRIPTS_WV(gl), SCRIPTS_SIG_META(NULL, LOAD_COMMITTED, 0) };
@@ -826,6 +1055,20 @@ view_load_status_cb(WebKitWebView *web, GParamSpec *pspec, GList *gl)
if (dwb.state.auto_insert_mode)
dwb_check_auto_insert(gl);
+ /**
+ * Emitted when the site has completely loaded.
+ *
+ * @event loadFinished
+ * @memberOf signals
+ * @param {signals~onLoadFinished} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when a site has completely loaded
+ * @callback signals~onLoadFinished
+ * @param {WebKitWebView} webview
+ * The webview that emitted the signal
+ * */
if (EMIT_SCRIPT(LOAD_FINISHED))
{
ScriptSignal signal = { SCRIPTS_WV(gl), SCRIPTS_SIG_META(NULL, LOAD_FINISHED, 0) };
@@ -839,6 +1082,20 @@ view_load_status_cb(WebKitWebView *web, GParamSpec *pspec, GList *gl)
}
if (EMIT_SCRIPT(LOAD_STATUS))
{
+ /**
+ * Emitted whenever the loadstatus changes
+ *
+ * @event loadStatus
+ * @memberOf signals
+ * @param {signals~onLoadStatus} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when the load-status of a WebKitWebView changes
+ * @callback signals~onLoadStatus
+ * @param {WebKitWebView} webview
+ * The webview that emitted the signal
+ * */
ScriptSignal signal = { SCRIPTS_WV(gl), SCRIPTS_SIG_META(NULL, LOAD_STATUS, 0) };
scripts_emit(&signal);
}
@@ -889,6 +1146,38 @@ static gboolean
view_motion_notify_cb(WebKitWebView *web, GdkEventButton *e, GList *gl)
{
if (EMIT_SCRIPT(MOUSE_MOVE)) {
+ /**
+ * Emitted when the mouse was moved
+ *
+ * @event mouseMove
+ * @memberOf signals
+ * @param {signals~onMouseMove} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when the mouse was moved
+ * @callback signals~onMouseMove
+ * @param {WebKitWebView} webview
+ * The webview that emitted the signal
+ * @param {Object} event
+ * @param {Number} event.button
+ * The button that was pressed, usually a value between 1 and 5
+ * @param {Modifier} event.state
+ * A bitmask of {@link Enums and Flags.Modifier|Modifiers} pressed
+ * @param {Number} event.time
+ * The time in milliseconds when the button was pressed
+ * @param {Number} event.x
+ * x-position relative to the window
+ * @param {Number} event.xRoot
+ * x-position relative to the screen
+ * @param {Number} event.y
+ * y-position relative to the window
+ * @param {Number} event.yRoot
+ * y-position relative to the screen
+ *
+ * @returns {Boolean}
+ * Return true to prevent the movement
+ * */
char *json = util_create_json(7,
UINTEGER, "time", e->time,
DOUBLE, "x", e->x, DOUBLE, "y", e->y,
@@ -911,6 +1200,42 @@ view_tab_button_press_cb(GtkWidget *tabevent, GdkEventButton *e, GList *gl)
{
if (EMIT_SCRIPT(TAB_BUTTON_PRESS))
{
+ /**
+ * Emitted when the mouse was pressed on a tab label
+ *
+ * @event tabButtonPress
+ * @memberOf signals
+ * @param {signals~onTabButtonPress} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when a button was pressed on a tablabel
+ * @callback signals~onTabButtonPress
+ * @param {WebKitWebView} webview
+ * The webview that emitted the signal
+ * @param {GtkEventBox} tabwidget
+ * The tabwidget
+ * @param {Object} event
+ * @param {Number} event.button
+ * The button that was pressed, usually a value between 1 and 5
+ * @param {Modifier} event.state
+ * A bitmask of {@link Enums and Flags.Modifier|Modifiers} pressed
+ * @param {Number} event.time
+ * The time in milliseconds when the button was pressed
+ * @param {ClickType} event.type
+ * A {@link Enums and Flags.ClickType|ClickType}
+ * @param {Number} event.x
+ * x-position relative to the window
+ * @param {Number} event.xRoot
+ * x-position relative to the screen
+ * @param {Number} event.y
+ * y-position relative to the window
+ * @param {Number} event.yRoot
+ * y-position relative to the screen
+ *
+ * @returns {Boolean}
+ * Return true to prevent the default action
+ * */
char *json = util_create_json(8,
UINTEGER, "time", e->time, UINTEGER, "type", e->type,
DOUBLE, "x", e->x, DOUBLE, "y", e->y,
@@ -1413,6 +1738,23 @@ view_add(const char *uri, gboolean background)
}
if (EMIT_SCRIPT(CREATE_TAB))
{
+ /**
+ * Emitted when a tab is created
+ * @event createTab
+ * @memberOf signals
+ * @param {signals~onCreateTab} callback
+ * Callback function that will be called when the signal is emitted
+ * */
+ /**
+ * Callback called when a tab is created
+ * @callback signals~onCreateTab
+ * @param {WebKitWebView} webview
+ * The webview that was created
+ * @param {Object} data
+ * @param {Object} data.uri
+ * The uri that will be loaded or <i>null</i> if an empty tab or
+ * the startpage will be loaded
+ * */
char *json = util_create_json(1, CHAR, "uri", uri);
ScriptSignal signal = { VIEW(ret)->script_wv, SCRIPTS_SIG_META(json, CREATE_TAB, 0) };
scripts_emit(&signal);