diff options
author | portix <none@none> | 2012-05-17 23:09:27 +0200 |
---|---|---|
committer | portix <none@none> | 2012-05-17 23:09:27 +0200 |
commit | 6096a98157490ca7fa6ac71960c592c3ea1400fe (patch) | |
tree | 6c810a9ebed943f67a83069c632da51e56a2845c /scripts | |
parent | d4f4a7faea6799346a6ccc1448f4750e4304be97 (diff) | |
parent | 86e9256be77d62324fc82e2bd1474fc96d1efd97 (diff) | |
download | dwb-6096a98157490ca7fa6ac71960c592c3ea1400fe.zip |
Merging branch scripts into default
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/data.js | 35 | ||||
-rw-r--r-- | scripts/lib/enums.js | 73 | ||||
-rw-r--r-- | scripts/lib/extensions.js | 130 | ||||
-rw-r--r-- | scripts/lib/signals.js | 92 |
4 files changed, 330 insertions, 0 deletions
diff --git a/scripts/lib/data.js b/scripts/lib/data.js new file mode 100644 index 00000000..80e2eff5 --- /dev/null +++ b/scripts/lib/data.js @@ -0,0 +1,35 @@ +(function () { + var configDir = data.configDir; + var profile = data.profile; + Object.defineProperties(data, { + "bookmarks" : { value : configDir + "/" + profile + "/bookmarks", enumerable : true }, + "history" : { value : configDir + "/" + profile + "/history", enumerable : true }, + "cookies" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "quickmarks" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "cookies" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "cookiesWhitelist" : { value : configDir + "/" + profile + "/cookies.allow", enumerable : true }, + "sessionCookiesWhitelist" : { value : configDir + "/" + profile + "/cookies_session.allow", enumerable : true }, + "sessionCookiesWhitelist" : { value : configDir + "/" + profile + "/cookies_session.allow", enumerable : true }, + "pluginsWhitelist" : { value : configDir + "/" + profile + "/plugins.allow", enumerable : true }, + "scriptWhitelist" : { value : configDir + "/" + profile + "/scripts.allow", enumerable : true }, + "session" : { value : configDir + "/" + profile + "/session", enumerable : true }, + "customKeys" : { value : configDir + "/" + profile + "/custom_keys", enumerable : true }, + "keys" : { value : configDir + "/keys", enumerable : true }, + "settings" : { value : configDir + "/settings", enumerable : true }, + "searchEngines" : { value : configDir + "/searchengines", enumerable : true }, + "cookies" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "quickmarks" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "cookies" : { value : configDir + "/" + profile + "/cookies", enumerable : true }, + "cookiesWhitelist" : { value : configDir + "/" + profile + "/cookies.allow", enumerable : true }, + "sessionCookiesWhitelist" : { value : configDir + "/" + profile + "/cookies_session.allow", enumerable : true }, + "sessionCookiesWhitelist" : { value : configDir + "/" + profile + "/cookies_session.allow", enumerable : true }, + "pluginsWhitelist" : { value : configDir + "/" + profile + "/plugins.allow", enumerable : true }, + "scriptWhitelist" : { value : configDir + "/" + profile + "/scripts.allow", enumerable : true }, + "session" : { value : configDir + "/" + profile + "/session", enumerable : true }, + "customKeys" : { value : configDir + "/" + profile + "/custom_keys", 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/enums.js b/scripts/lib/enums.js new file mode 100644 index 00000000..f59a7409 --- /dev/null +++ b/scripts/lib/enums.js @@ -0,0 +1,73 @@ +const LoadStatus = { + provisional : 0, + committed : 1, + finished : 2, + firstVisualLayout : 3, + failed : 4 +}; +const Modifier = { + Shift : 1 << 0, + Lock : 1 << 1, + Control : 1 << 2, + Mod1 : 1 << 3, + Mod2 : 1 << 4, + Mod3 : 1 << 5, + Mod4 : 1 << 6, + Mod5 : 1 << 7, + Button1 : 1 << 8, + Button2 : 1 << 9, + Button3 : 1 << 10, + Button4 : 1 << 11, + Button5 : 1 << 12, + Super : 1 << 26, + Hyper : 1 << 27, + Meta : 1 << 28, + Release : 1 << 30, + Modifier : 0x5c001fff +}; +const ButtonContext = { + document : 1 << 1, + link : 1 << 2, + image : 1 << 3, + media : 1 << 4, + selection : 1 << 5, + editable : 1 << 6 +}; +const ClickType = { + click : 4, + doubleClick : 5, + tripleClick : 6 +}; +const NavigationReason = { + linkClicked : 0, + formSubmitted : 1, + backForward : 2, + reload : 3, + formResubmitted : 4, + other : 5 +}; +const DownloadStatus = { + error : -1, + created : 0, + started : 1, + cancelled : 2, + finished : 3 +}; +const SpawnError = { + success : 0, + spawnFailed : 1<<0, + stdoutFailed : 1<<1, + stderrFailed : 1<<2 +}; +const ChecksumType = { + md5 : 0, + sha1 : 1, + sha256 : 2 +}; +const FileTest = { + regular : 1 << 0, + symlink : 1 << 1, + dir : 1 << 2, + executable : 1 << 3, + exists : 1 << 4 +}; diff --git a/scripts/lib/extensions.js b/scripts/lib/extensions.js new file mode 100644 index 00000000..a1f40d7a --- /dev/null +++ b/scripts/lib/extensions.js @@ -0,0 +1,130 @@ +(function () { + var _config = undefined; + var _debug = false; + function getPlugin(name, filename) { + var ret = null; + try { + if (system.fileTest(filename, FileTest.exists)) { + ret = include(filename); + } + } + catch(e) { + extensions.error(name, "Error in line " + e.line + " parsing " + filename); + } + return ret; + } + function getStack(offset) { + if (arguments.length === 0) { + offset = 0; + } + try { + throw Error (message); + } + catch (e) { + var stack = e.stack.match(/[^\n]+/g); + return "STACK: [" + stack.slice(offset+1).join("] [")+"]"; + } + } + Object.defineProperties(extensions, { + "warning" : { + value : function (name, message) { + io.print("\033[1mDWB EXTENSION WARNING: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr"); + } + }, + "enableDebugging" : { + set : function (value) { + if (typeof value == "boolean") + _debug = value; + } + }, + "debug" : { + value : function (name, message) { + if (_debug) { + io.print("\033[1mDWB EXTENSION DEBUG: \033[0mextension \033[1m" + name + "\033[0m\n" + getStack(1), "stderr"); + } + } + }, + "error" : { + value : function (name, a, b) { + var message = ""; + if (a instanceof Error) { + if (a.message) { + message = a.message; + } + else if (arguments.length > 2) + message = b; + else + b = ""; + io.print("\033[31mDWB EXTENSION ERROR: \033[0mextension \033[1m" + name + "\033[0m in line " + a.line + ": " + + message + "\nSTACK: [" + a.stack.match(/[^\n]+/g).join("] [") + "]", "stderr"); + } + else { + io.print("\033[31mDWB EXTENSION ERROR: \033[0mextension \033[1m" + name + "\033[0m: " + a + "\n" + getStack(1), "stderr"); + } + } + }, + "message" : { + value : function (name, message) { + io.print("\033[1mDWB EXTENSION: \033[0mextension \033[1m" + name + "\033[0m: " + message, "stderr"); + } + }, + "load" : { + value : function(name, c) { + var boldname = "\033[1m" + name + "\033[0m"; + + var config, dataBase, pluginPath, plugin = null; + var extConfig = null; + + /* Get default config if the config hasn't been read yet */ + if (arguments.length == 2) { + extConfig = c; + } + else { + if (_config === undefined) { + try { + config = include(data.configDir + "/extensionrc"); + } + catch (e) { + extensions.error(name, "loading config failed : " + e); + } + if (config === null) { + extensions.warning(name, "Could not load config."); + } + else { + _config = config; + } + } + if (_config) { + extConfig = _config[name] || null; + } + } + + /* Load extension */ + var filename = data.userDataDir + "/extensions/" + name; + plugin = getPlugin(name, data.userDataDir + "/extensions/" + name); + if (plugin === null) { + plugin = getPlugin(name, data.systemDataDir + "/extensions/" + name); + if (plugin === null) { + extensions.error(name, "Couldn't find extension."); + return false; + } + } + try { + if (plugin.init(extConfig)) { + extensions.message(name, "Successfully loaded and initialized."); + return true; + } + else { + extensions.error(name, "Initialization failed."); + return false; + } + } + catch (e) { + extensions.error(name, "Initialization failed: " + e); + return false; + } + } + } + }); +})(); +Object.freeze(extensions); diff --git a/scripts/lib/signals.js b/scripts/lib/signals.js new file mode 100644 index 00000000..f254aea9 --- /dev/null +++ b/scripts/lib/signals.js @@ -0,0 +1,92 @@ +(function () { + var _registered = {}; + Object.defineProperties(signals, { + "emit" : { + value : function(sig, args) { + var sigs = _registered[sig]; + var ret = false; + var i = 0; + do { + if (sigs[i].connected) { + ret = sigs[i].callback.apply(this, args) || ret; + i++; + } + else { + sigs.splice(i, 1); + } + } while (i<sigs.length); + if (_registered[sig].length === 0) { + signals[sig] = null; + } + return ret; + } + }, + "connect" : { + value : (function () { + var id = 0; + return function(sig, func) { + ++id; + if (_registered[sig] === undefined || _registered[sig] === null) { + _registered[sig] = []; + signals[sig] = function () { return signals.emit(sig, arguments); }; + } + if (func === null || typeof func !== "function") { + return -1; + } + _registered[sig].push({callback : func, id : id, connected : true }); + return id; + }; + })() + }, + "disconnect" : { + value : function(id) { + var sig, i, sigs; + for (sig in _registered) { + sigs = _registered[sig]; + for (i = 0; i<sigs.length; i++) { + if (sigs[i].id == id) { + if (_registered[sig].length === 1) { + signals[sig] = null; + } + else { + sigs[i].connected = false; + } + return true; + } + } + } + return false; + } + }, + "disconnectByFunction" : { + value : function(func) { + var sig, i, sigs, ret = false; + for (sig in _registered) { + sigs = _registered[sig]; + for (i = 0; i<sigs.length; i++) { + if (sigs[i].callback == func) { + if (_registered[sig].length === 1) { + signals[sig] = null; + } + else { + sigs[i].connected = false; + } + ret = true; + } + } + } + return ret; + } + }, + "disconnectByName" : { + value : function (name) { + io.print(name); + if (signals[name] !== null && signals[name] !== undefined) { + signals[name] = null; + return true; + } + return false; + } + } + }); +})(); |