Adjust conkeror
authorJoerg Jaspert <joerg@nsb-software.de>
Fri, 15 Aug 2014 10:14:17 +0000 (12:14 +0200)
committerJoerg Jaspert <joerg@nsb-software.de>
Fri, 15 Aug 2014 10:14:17 +0000 (12:14 +0200)
.conkerorrc/001-basics.js [moved from .conkerorrc/basics.js with 97% similarity]
.conkerorrc/005-passwords.js [new file with mode: 0644]
.conkerorrc/020-functions.js [moved from .conkerorrc/functions.js with 97% similarity]
.conkerorrc/025-contentPolicy.js [new file with mode: 0644]
.conkerorrc/030-hide-minibuffer.js [moved from .conkerorrc/hide-minibuffer.js with 100% similarity]
.conkerorrc/040-keybindings.js [moved from .conkerorrc/keybindings.js with 100% similarity]
.conkerorrc/050-reopenclosedtab.js [moved from .conkerorrc/reopenclosedtab.js with 100% similarity]
.conkerorrc/060-webjumps.js [moved from .conkerorrc/webjumps.js with 100% similarity]
.conkerorrc/065-bookmark-manipulate.js [moved from .conkerorrc/bookmark-manipulate.js with 100% similarity]
.conkerorrc/070-theme.js [moved from .conkerorrc/theme.js with 100% similarity]
.conkerorrc/075-themeblack.js [moved from .conkerorrc/themeblack.js with 100% similarity]

similarity index 97%
rename from .conkerorrc/basics.js
rename to .conkerorrc/001-basics.js
index 412065f..cc668bc 100644 (file)
@@ -27,6 +27,13 @@ user_pref('gfx.filter.nearest.force-enabled', true);
 // H264
 user_pref('stagefright.force-enabled', true);
 
+// extensions
+user_pref("extensions.checkCompatibility", false);
+
+// Set to 0 = left mouse, 1 = middle mouse, 2 = right mouse
+clicks_in_new_buffer_button = 2; // Now right mouse follows links in new buffers.
+
+
 // the default page for new buffers.
 homepage = "about:blank";
 
@@ -45,6 +52,9 @@ require("daemon.js");
 require("dom-inspector.js");
 require("suggest-file-name.js");
 
+require("history.js");
+require("permission-manager.js");
+
 // Auto load the auto-save session when conkeror starts
 session_auto_save_auto_load = true;
 
@@ -110,12 +120,6 @@ register_user_stylesheet(make_css_data_uri(
     ["* { image-rendering: -moz-crisp-edges; }"]));
 
 
-// Enable password management service.
-session_pref("signon.rememberSignons", true);
-session_pref("signon.expireMasterPassword", false);
-session_pref("signon.SignonFileName", "signons.txt");
-Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); // init
-
 // what do i care about broken js?
 session_pref("javascript.options.strict", false)
 
diff --git a/.conkerorrc/005-passwords.js b/.conkerorrc/005-passwords.js
new file mode 100644 (file)
index 0000000..ed67e71
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+  Implements new login-manager.
+  See:
+  - http://librelist.com/browser//conkeror/2013/11/28/login-manager-xulrunner-24-0/
+  - https://blog.mozilla.org/dolske/2013/08/21/a-change-in-password-manager/
+  (C) Copyright 2014 thorkill
+  BSD License
+*/
+let Cu = Components.utils;
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this,
+                                  "LoginManagerContent",
+                                  "resource://gre/modules/LoginManagerContent.jsm");
+define_buffer_local_hook("content_buffer_dom_form_has_password_hook");
+define_buffer_local_hook("content_buffer_dom_auto_complete_hook");
+// passwords
+session_pref("signon.rememberSignons", true);
+session_pref("signon.expireMasterPassword", false);
+session_pref("signon.SignonFileName", "signons.txt");
+session_pref("signon.useDOMFormHasPassword", true);
+Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
+/* debugging prefs */
+//session_pref("browser.formfill.debug", false);
+//session_pref("browser.dom.window.dump.enabled", true);
+//session_pref("javascript.options.showInConsole", true);
+//session_pref("javascript.options.strict", true);
+//session_pref("nglayout.debug.disable_xul_cache", true);
+//session_pref("nglayout.debug.disable_xul_fastload", true);
+add_hook("create_buffer_hook", function (buffer) {
+    buffer.browser.addEventListener("DOMFormHasPassword", function(event) {
+        content_buffer_dom_form_has_password_hook.run(buffer, event);
+    }, true /* captrue */);
+    buffer.browser.addEventListener("DOMAutoComplete", function(event) {
+        content_buffer_dom_auto_complete_hook.run(buffer, event);
+    }, true /* captrue */);
+    buffer.browser.addEventListener("blur", function(event) {
+        content_buffer_dom_auto_complete_hook.run(buffer, event);
+    }, true /* captrue */);
+});
+add_hook("content_buffer_dom_form_has_password_hook", function(buffer, event) {
+    // Sometimes onFormPassword is undefined
+    if (LoginManagerContent.onFormPassword) {
+        LoginManagerContent.onFormPassword(event);
+    }
+});
+add_hook("content_buffer_dom_auto_complete_hook", function(buffer, event) {
+    LoginManagerContent.onUsernameInput(event);
+});
similarity index 97%
rename from .conkerorrc/functions.js
rename to .conkerorrc/020-functions.js
index 56cc5f1..a60770e 100644 (file)
@@ -219,3 +219,14 @@ interactive("subscribe-feed", "C-u Subscribes to first encountered feed."
 );
 
 define_key(default_global_keymap, "C-c s", "subscribe-feed");
+
+function jsdump(str) {
+Components.classes['@mozilla.org/consoleservice;1']
+.getService(Components.interfaces.nsIConsoleService)
+.logStringMessage(str);
+}
+function _dump_obj(obj) {
+for (var i in obj) {
+jsdump(i + ' : ' + obj[i]+"\n");
+}
+}
diff --git a/.conkerorrc/025-contentPolicy.js b/.conkerorrc/025-contentPolicy.js
new file mode 100644 (file)
index 0000000..b9a7128
--- /dev/null
@@ -0,0 +1,331 @@
+/*
+  Simple Content-Policy management for Conkeror.
+  It uses mozilla's storage service.
+
+  (C) Copyright 2014 thorkill
+  BSD License
+*/
+
+require("content-policy.js");
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/FileUtils.jsm");
+
+// runtime copy of the db
+// we need it because contentPolicy.shouldLoad can not be blocked
+content_policy_jscript_actions = ({});
+
+// content policy
+function block_sniff (content_type, content_location) {
+    jsdump("block sniff: " + content_type + " : " + content_location.spec);
+    return content_policy_accept;
+}
+
+function block_flash (content_type, content_location) {
+    var Y = content_policy_accept, N = content_policy_reject;
+
+    var action = ({ "homestarrunner.com":Y }
+                  [content_location.host] || N);
+
+    if (action == N)
+        jsdump("blocked content: "+content_type+" : "+content_location.spec);
+
+    return action;
+}
+
+function block_image (content_type, content_location) {
+    var Y = content_policy_accept, N = content_policy_reject;
+
+    var action = ({ "homestarrunner.com" : N }
+                  [content_location.host] || Y);
+
+    if (action == N)
+        jsdump("blocked content: "+content_type+" : "+content_location.spec);
+
+    return action;
+}
+
+// reload permissions on whitelist/blacklist
+function _reload_permissions() {
+    content_policy_jscript_actions = ({});
+    get_permissions(init_permissions);
+}
+
+// callback function which fills the
+// action-list
+function init_permissions(host, value) {
+    jsdump("Adding: "+host +" : " + value);
+    if (value == 't')
+        content_policy_jscript_actions[host] = content_policy_accept;
+    else
+        content_policy_jscript_actions[host] = content_policy_reject;
+}
+
+// here we handle the javascript content filtering
+function block_script (content_type, content_location, request_origin) {
+    var Y = content_policy_accept, N = content_policy_reject;
+
+    var action = (content_policy_jscript_actions[content_location.host] || N);
+    jsdump(content_type + " : " + content_location.host + " : "+ action + " / " + request_origin.host);
+
+    if (action == N)
+        jsdump("blocked JS: "+content_location.spec);
+
+    return action;
+}
+
+// 1
+//content_policy_bytype_table.other = block_sniff;
+// 2
+content_policy_bytype_table.script = block_script;
+// 3
+//content_policy_bytype_table.image = block_image;
+// 4
+//content_policy_bytype_table.stylesheet = block_sniff;
+// 5
+content_policy_bytype_table.object = block_flash;
+// 6
+//content_policy_bytype_table.document = block_sniff;
+// 7
+//content_policy_bytype_table.subdocument = block_sniff;
+// 9
+//content_policy_bytype_table.xbl = block_sniff;
+// 10
+//content_policy_bytype_table.ping = block_sniff;
+// 11
+//content_policy_bytype_table.xmlhttprequest = block_sniff;
+// 12
+//content_policy_bytype_table.object_subrequest = block_sniff;
+// 13
+//content_policy_bytype_table.dtd = block_sniff;
+// 14
+//content_policy_bytype_table.font = block_sniff;
+// 15
+//content_policy_bytype_table.media = block_sniff;
+
+/* ---- start of db-part ---- */
+
+function get_permissions(aCallBack) {
+    jsdump("Load content-policy rules");
+    dbConn = initDB();
+    var r = dbConn.createStatement("SELECT host ,allowjs FROM permissions");
+
+    let tempval = r.executeAsync({
+        handleResult: function(aResultSet) {
+            for(let row = aResultSet.getNextRow();
+                row;
+                row = aResultSet.getNextRow()) {
+                host = row.getResultByName("host");
+                value = row.getResultByName("allowjs");
+                aCallBack(host, value);
+            }
+        },
+
+        handleError: function(aError) {
+            jsdump("Error: " + aError.message);
+            return false;
+        },
+
+        handleCompletion: function(aReason) {
+            if (aReason != Components.interfaces.mozIStorageStatementCallback.REASON_FINISHED)
+                jsdump("Query canceled or aborted!");
+            return false;
+        }
+    });
+    closeDB();
+    return tempval;
+}
+
+function allow_js_host(host) {
+    jsdump("whitelist: " + host);
+    if (host == null)
+        return;
+
+    dbConn = initDB();
+    var r = dbConn.createStatement("INSERT OR REPLACE INTO permissions (host, allowjs) VALUES(:host, 't')");
+    r.params.host=host;
+    r.executeAsync();
+    closeDB();
+}
+
+function deny_js_host(host) {
+    jsdump("blacklist: " + host);
+    if (host == null)
+        return;
+
+    dbConn = initDB();
+    var r = dbConn.createStatement("INSERT OR REPLACE INTO permissions (host, allowjs) VALUES(:host, 'f')");
+    r.params.host=host;
+    r.executeAsync();
+    closeDB();
+}
+
+function initDB() {
+    let file = FileUtils.getFile("ProfD", ["cp_jscript.sqlite"]);
+    let dbConn = Services.storage.openDatabase(file);
+
+    if (!dbConn.tableExists("prefs")) {
+        jsdump("Table pref not found");
+        dbConn.executeSimpleSQL("CREATE TABLE prefs (pref TEXT UNIQUE NOT NULL, value TEXT)");
+        var r = dbConn.createStatement("INSERT INTO prefs (pref, value) VALUES (:pref, :value)");
+        r.params.pref="version";
+        r.params.value="0.1";
+        r.executeAsync();
+    }
+
+    if (!dbConn.tableExists("permissions")) {
+        jsdump("Tables not found");
+        dbConn.executeSimpleSQL("CREATE TABLE permissions (host TEXT UNIQUE NOT NULL, allowjs BOOLEAN)");
+    }
+    return dbConn;
+}
+
+function closeDB(dbConn) {
+    if (dbConn)
+        dbConn.close()
+}
+/* ---- end of db-part ---- */
+
+function uri2basedomain(aURI) {
+    try {
+        var az = make_uri(aURI);
+        return az.host;
+    } catch (e) {
+        return null;
+    }
+    return aURI;
+}
+
+// ContentPolicy JavaScript completer
+// iterates over javascript resources and shows it's permissions
+function cp_js_completer(B) {
+    var completions = B;
+    var get_string = function (x) x;
+    var get_description = function (x) {
+        x = uri2basedomain(x);
+        var n = content_policy_jscript_actions[x];
+        if (n == 1)
+            return x + ": whitelisted";
+        else if (n == -1)
+            return x + ": blacklisted";
+        else
+            return "";
+        };
+
+    var get_value = function (x) "value: " + x;
+    var get_icon = null;
+    var arr;
+
+    var completer = function (input, pos, conservative) {
+        //dumpln("Mine I: " + input + ", P: "+pos+", C:" + conservative);
+        if (input.length == 0 && conservative)
+            return undefined;
+
+        var words = input.toLowerCase().split(" ");
+
+        var data = arr;
+
+        return {count: data.length,
+                index_of:  function (x) data.indexOf(x),
+                get_string: function (i) get_string(data[i]),
+                get_description : function (i) get_description(data[i]),
+                get_input_state: function (i) [get_string(data[i])],
+                get_value: function (i) (get_value ? get_value(data[i]) : data[i]),
+                get_icon: function (i) (get_icon ? get_icon(data[i]) : null)
+               };
+    };
+
+    completer.refresh = function () {
+        var data = [];
+
+        entries = B.document.getElementsByTagName('script');
+        _unique_scripts = {};
+
+        for (i = 0 ; i < entries.length ; i++)
+        {
+            var src = entries[i].src;
+            // this is the case where <script> is embedded into html code
+            if (src == null || src == "")
+                src = B.document.baseURI;
+
+            if (_unique_scripts[src])
+                continue;
+
+            _unique_scripts[src] = true;
+            data.push(src);
+        }
+        arr = data;
+    };
+    completer.refresh();
+    return completer;
+}
+
+function cp_js_show (window, message) {
+    host = uri2basedomain(message);
+    if (host in content_policy_jscript_actions) {
+        if (content_policy_jscript_actions[host] == content_policy_accept)
+           deny_js_host(host);
+        else
+            allow_js_host(host);
+    }  else {
+        // default is to whitelist a host
+        // just because I do not permit JS per default
+        allow_js_host(host);
+    }
+    _reload_permissions();
+}
+
+interactive("cp-js-show",
+            "Show JavaScript content of current buffer with information from content policy DB.",
+            function (I) {
+                cp_js_show(
+                    I.window,
+                    (yield I.minibuffer.read($prompt = "Toggle CP-JS for: ",
+                                             $completer = cp_js_completer(I.window.buffers.current))));
+            });
+
+interactive("blacklist-js", "Blacklists current URI for javascript usage.",
+            function(I) {
+                deny_js_host(I.buffer.current_uri.host);
+                _reload_permissions();
+            });
+
+interactive("whitelist-js", "Whitelists current URI for javascript usage.",
+            function(I) {
+                allow_js_host(I.buffer.current_uri.host);
+                _reload_permissions();
+            });
+
+/**
+ * content_policy_status_widget shows if the content policy is enabled.
+ */
+function content_policy_status_widget (window) {
+    this.class_name = "content-policy-status-widget";
+    text_widget.call(this, window);
+    // Update only if something happens ...
+    this.add_hook("select_buffer_hook");
+    this.add_hook("create_buffer_hook");
+    this.add_hook("kill_buffer_hook");
+    this.add_hook("move_buffer_hook");
+    this.add_hook("current_content_buffer_location_change_hook");
+    this.add_hook("current_content_buffer_focus_change_hook");
+    this.add_hook("current_special_buffer_generated_hook");
+}
+
+content_policy_status_widget.prototype = {
+    constructor: content_policy_status_widget,
+    __proto__: text_widget.prototype,
+    update: function () {
+        if (content_policy_listener.enabled)
+            this.view.text = ("[+]");
+        else
+            this.view.text = ("[-]");
+    }
+};
+
+/**
+ * Define some hooks
+ */
+add_hook("content_policy_hook", content_policy_bytype);
+add_hook("mode_line_hook", mode_line_adder(content_policy_status_widget));
+add_hook("init_hook", get_permissions(init_permissions));