mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 23:57:59 +01:00
Make some attempt to respect "Clear Private Data"
This commit is contained in:
@@ -60,7 +60,7 @@ function Browser() //{{{
|
|||||||
////////////////////// OPTIONS /////////////////////////////////////////////////
|
////////////////////// OPTIONS /////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
options.add(["encoding", "enc"],
|
options.add(["enc[oding]"],
|
||||||
"Sets the current buffer's character encoding",
|
"Sets the current buffer's character encoding",
|
||||||
"string", "UTF-8",
|
"string", "UTF-8",
|
||||||
{
|
{
|
||||||
@@ -68,10 +68,13 @@ function Browser() //{{{
|
|||||||
getter: function () getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset,
|
getter: function () getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset,
|
||||||
setter: function (val)
|
setter: function (val)
|
||||||
{
|
{
|
||||||
|
if (options["encoding"] == val)
|
||||||
|
return val;
|
||||||
|
|
||||||
// Stolen from browser.jar/content/browser/browser.js, more or less.
|
// Stolen from browser.jar/content/browser/browser.js, more or less.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var docCharset = getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset = val;
|
getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset = val;
|
||||||
PlacesUtils.history.setCharsetForURI(getWebNavigation().currentURI, val);
|
PlacesUtils.history.setCharsetForURI(getWebNavigation().currentURI, val);
|
||||||
getWebNavigation().reload(Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
|
getWebNavigation().reload(Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
|
||||||
}
|
}
|
||||||
@@ -269,7 +272,8 @@ function Browser() //{{{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (context) completion.url(context),
|
completer: function (context) completion.url(context),
|
||||||
literal: 0
|
literal: 0,
|
||||||
|
privateData: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
commands.add(["redr[aw]"],
|
commands.add(["redr[aw]"],
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
|||||||
* literal - see {@link Command#literal}
|
* literal - see {@link Command#literal}
|
||||||
* options - see {@link Command#options}
|
* options - see {@link Command#options}
|
||||||
* serial - see {@link Command#serial}
|
* serial - see {@link Command#serial}
|
||||||
|
* privateData - see {@link Command#privateData}
|
||||||
* @optional
|
* @optional
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@@ -158,6 +159,12 @@ function Command(specs, description, action, extraInfo) //{{{
|
|||||||
* startups.
|
* startups.
|
||||||
*/
|
*/
|
||||||
this.serial = extraInfo.serial;
|
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
|
* @property {boolean} Specifies whether this is a user command. User
|
||||||
|
|||||||
@@ -561,7 +561,8 @@ function Tabs() //{{{
|
|||||||
{
|
{
|
||||||
bang: true,
|
bang: true,
|
||||||
completer: function (context) completion.url(context),
|
completer: function (context) completion.url(context),
|
||||||
literal: 0
|
literal: 0,
|
||||||
|
privateData: true
|
||||||
});
|
});
|
||||||
|
|
||||||
commands.add(["tabde[tach]"],
|
commands.add(["tabde[tach]"],
|
||||||
|
|||||||
@@ -45,6 +45,37 @@ function CommandLine() //{{{
|
|||||||
storage.newArray("history-search", true, { privateData: true });
|
storage.newArray("history-search", true, { privateData: true });
|
||||||
storage.newArray("history-command", 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 = { // {{{
|
var messageHistory = { // {{{
|
||||||
_messages: [],
|
_messages: [],
|
||||||
get messages()
|
get messages()
|
||||||
@@ -93,6 +124,7 @@ function CommandLine() //{{{
|
|||||||
if (!(this instanceof arguments.callee))
|
if (!(this instanceof arguments.callee))
|
||||||
return new arguments.callee(inputField, mode);
|
return new arguments.callee(inputField, mode);
|
||||||
|
|
||||||
|
this.mode = mode;
|
||||||
this.input = inputField;
|
this.input = inputField;
|
||||||
this.store = storage["history-" + mode];
|
this.store = storage["history-" + mode];
|
||||||
this.reset();
|
this.reset();
|
||||||
@@ -116,10 +148,30 @@ function CommandLine() //{{{
|
|||||||
let str = this.input.value;
|
let str = this.input.value;
|
||||||
if (/^\s*$/.test(str))
|
if (/^\s*$/.test(str))
|
||||||
return;
|
return;
|
||||||
this.store.mutate("filter", function (line) line != str);
|
this.store.mutate("filter", function (line) (line.value || line) != str);
|
||||||
this.store.push(str);
|
this.store.push({ value: str, timestamp: Date.now(), privateData: this.checkPrivate(str) });
|
||||||
this.store.truncate(options["history"], true);
|
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.
|
* Replace the current input field value.
|
||||||
*
|
*
|
||||||
@@ -172,6 +224,7 @@ function CommandLine() //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
let hist = this.store.get(this.index);
|
let hist = this.store.get(this.index);
|
||||||
|
hist = (hist.value || hist);
|
||||||
|
|
||||||
// user pressed DOWN when there is no newer history item
|
// user pressed DOWN when there is no newer history item
|
||||||
if (hist == null)
|
if (hist == null)
|
||||||
|
|||||||
@@ -302,7 +302,8 @@ const config = { //{{{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (context) completion.url(context),
|
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
|
|*PageLoadPre* |Triggered after a page load is initiated
|
||||||
|*PageLoad* |Triggered when a page gets (re)loaded/opened
|
|*PageLoad* |Triggered when a page gets (re)loaded/opened
|
||||||
|*PrivateMode* |Triggered when private mode is activated or deactivated
|
|*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}
|
|*ShellCmdPost* |Triggered after executing a shell command with [c]:![c]{cmd}
|
||||||
|*VimperatorEnter* |Triggered after Firefox starts
|
|*VimperatorEnter* |Triggered after Firefox starts
|
||||||
|*VimperatorLeavePre*|Triggered before exiting Firefox, just before destroying each module
|
|*VimperatorLeavePre*|Triggered before exiting Firefox, just before destroying each module
|
||||||
|
|||||||
Reference in New Issue
Block a user