mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 09:17:58 +01:00
Make some attempt to respect "Clear Private Data"
This commit is contained in:
@@ -60,7 +60,7 @@ function Browser() //{{{
|
||||
////////////////////// OPTIONS /////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////{{{
|
||||
|
||||
options.add(["encoding", "enc"],
|
||||
options.add(["enc[oding]"],
|
||||
"Sets the current buffer's character encoding",
|
||||
"string", "UTF-8",
|
||||
{
|
||||
@@ -68,10 +68,13 @@ function Browser() //{{{
|
||||
getter: function () getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset,
|
||||
setter: function (val)
|
||||
{
|
||||
if (options["encoding"] == val)
|
||||
return val;
|
||||
|
||||
// Stolen from browser.jar/content/browser/browser.js, more or less.
|
||||
try
|
||||
{
|
||||
var docCharset = getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset = val;
|
||||
getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset = val;
|
||||
PlacesUtils.history.setCharsetForURI(getWebNavigation().currentURI, val);
|
||||
getWebNavigation().reload(Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
|
||||
}
|
||||
@@ -269,7 +272,8 @@ function Browser() //{{{
|
||||
},
|
||||
{
|
||||
completer: function (context) completion.url(context),
|
||||
literal: 0
|
||||
literal: 0,
|
||||
privateData: true,
|
||||
});
|
||||
|
||||
commands.add(["redr[aw]"],
|
||||
|
||||
@@ -41,14 +41,15 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
||||
* @param {function} action The action invoked by this command when executed.
|
||||
* @param {Object} extraInfo An optional extra configuration hash. The
|
||||
* following properties are supported.
|
||||
* argCount - see {@link Command#argCount}
|
||||
* bang - see {@link Command#bang}
|
||||
* completer - see {@link Command#completer}
|
||||
* count - see {@link Command#count}
|
||||
* heredoc - see {@link Command#heredoc}
|
||||
* literal - see {@link Command#literal}
|
||||
* options - see {@link Command#options}
|
||||
* serial - see {@link Command#serial}
|
||||
* argCount - see {@link Command#argCount}
|
||||
* bang - see {@link Command#bang}
|
||||
* completer - see {@link Command#completer}
|
||||
* count - see {@link Command#count}
|
||||
* heredoc - see {@link Command#heredoc}
|
||||
* literal - see {@link Command#literal}
|
||||
* options - see {@link Command#options}
|
||||
* serial - see {@link Command#serial}
|
||||
* privateData - see {@link Command#privateData}
|
||||
* @optional
|
||||
* @private
|
||||
*/
|
||||
@@ -158,6 +159,12 @@ function Command(specs, description, action, extraInfo) //{{{
|
||||
* startups.
|
||||
*/
|
||||
this.serial = extraInfo.serial;
|
||||
/**
|
||||
* @property {boolean} When true, invocations of this command
|
||||
* may contain private data which should be purged from
|
||||
* saved histories when clearing private data.
|
||||
*/
|
||||
this.privateData = Boolean(extraInfo.privateData);
|
||||
|
||||
/**
|
||||
* @property {boolean} Specifies whether this is a user command. User
|
||||
|
||||
@@ -561,7 +561,8 @@ function Tabs() //{{{
|
||||
{
|
||||
bang: true,
|
||||
completer: function (context) completion.url(context),
|
||||
literal: 0
|
||||
literal: 0,
|
||||
privateData: true
|
||||
});
|
||||
|
||||
commands.add(["tabde[tach]"],
|
||||
|
||||
@@ -45,6 +45,37 @@ function CommandLine() //{{{
|
||||
storage.newArray("history-search", true, { privateData: true });
|
||||
storage.newArray("history-command", true, { privateData: true });
|
||||
|
||||
// Really inideal.
|
||||
let services = modules.services; // Storage objects are global to all windows, 'modules' isn't.
|
||||
storage.newObject("sanitize", function () {
|
||||
({
|
||||
CLEAR: "browser:purge-session-history",
|
||||
init: function ()
|
||||
{
|
||||
services.get("observer").addObserver(this, this.CLEAR, false);
|
||||
services.get("observer").addObserver(this, "quit-application", false);
|
||||
},
|
||||
observe: function (subject, topic, data)
|
||||
{
|
||||
if (topic == this.CLEAR)
|
||||
{
|
||||
["search", "command"].forEach(function (mode) {
|
||||
History(null, mode).sanitize();
|
||||
});
|
||||
}
|
||||
else if (topic == "quit-application")
|
||||
{
|
||||
services.get("observer").removeObserver(this, this.CLEAR);
|
||||
services.get("observer").removeObserver(this, "quit-application");
|
||||
}
|
||||
}
|
||||
}).init();
|
||||
}, false);
|
||||
storage.addObserver("sanitize",
|
||||
function (key, event, value) {
|
||||
autocommands.trigger("Sanitize", {});
|
||||
}, window);
|
||||
|
||||
var messageHistory = { // {{{
|
||||
_messages: [],
|
||||
get messages()
|
||||
@@ -93,6 +124,7 @@ function CommandLine() //{{{
|
||||
if (!(this instanceof arguments.callee))
|
||||
return new arguments.callee(inputField, mode);
|
||||
|
||||
this.mode = mode;
|
||||
this.input = inputField;
|
||||
this.store = storage["history-" + mode];
|
||||
this.reset();
|
||||
@@ -116,10 +148,30 @@ function CommandLine() //{{{
|
||||
let str = this.input.value;
|
||||
if (/^\s*$/.test(str))
|
||||
return;
|
||||
this.store.mutate("filter", function (line) line != str);
|
||||
this.store.push(str);
|
||||
this.store.mutate("filter", function (line) (line.value || line) != str);
|
||||
this.store.push({ value: str, timestamp: Date.now(), privateData: this.checkPrivate(str) });
|
||||
this.store.truncate(options["history"], true);
|
||||
},
|
||||
/**
|
||||
* @property {function} Returns whether a data item should be
|
||||
* considered private.
|
||||
*/
|
||||
checkPrivate: function (str)
|
||||
{
|
||||
// Not really the ideal place for this check.
|
||||
if (this.mode == "command")
|
||||
return (commands.get(str.replace("^[\s:]*", "").split(/[\s!]+/)[0]) || {})
|
||||
.privateData;
|
||||
return false;
|
||||
},
|
||||
/**
|
||||
* Removes any private data from this history.
|
||||
*/
|
||||
sanitize: function ()
|
||||
{
|
||||
// TODO: Respect privacy.item.timeSpan
|
||||
this.store.mutate("filter", function (line) !line.privateData);
|
||||
},
|
||||
/**
|
||||
* Replace the current input field value.
|
||||
*
|
||||
@@ -172,6 +224,7 @@ function CommandLine() //{{{
|
||||
}
|
||||
|
||||
let hist = this.store.get(this.index);
|
||||
hist = (hist.value || hist);
|
||||
|
||||
// user pressed DOWN when there is no newer history item
|
||||
if (hist == null)
|
||||
|
||||
@@ -302,7 +302,8 @@ const config = { //{{{
|
||||
},
|
||||
{
|
||||
completer: function (context) completion.url(context),
|
||||
literal: 0
|
||||
literal: 0,
|
||||
privateData: true
|
||||
});
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
|
||||
@@ -33,6 +33,7 @@ Available {events}:
|
||||
|*PageLoadPre* |Triggered after a page load is initiated
|
||||
|*PageLoad* |Triggered when a page gets (re)loaded/opened
|
||||
|*PrivateMode* |Triggered when private mode is activated or deactivated
|
||||
|*Sanitize* |Triggered when privata data are sanitized
|
||||
|*ShellCmdPost* |Triggered after executing a shell command with [c]:![c]{cmd}
|
||||
|*VimperatorEnter* |Triggered after Firefox starts
|
||||
|*VimperatorLeavePre*|Triggered before exiting Firefox, just before destroying each module
|
||||
|
||||
Reference in New Issue
Block a user