Skip to content

Commit 8526863

Browse files
committed
Merge pull request #138 from zklinger/private-browsing
Fix command history and search history in 'per-window private mode'
2 parents 9e519de + 41cbd08 commit 8526863

File tree

11 files changed

+52
-89
lines changed

11 files changed

+52
-89
lines changed

common/content/browser.js

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,47 +52,6 @@ const Browser = Module("browser", {
5252
completer: function (context) completion.charset(context)
5353
});
5454

55-
// only available in FF 3.5-19
56-
// TODO: remove when FF ESR's version is over 20. privateBrowsing will be per-window from FF 20+
57-
// XXX: on Fx20, nsIPrivateBrowsingService exists yet but has no properties
58-
let pb = services.get("privateBrowsing");
59-
if (pb && "privateBrowsingEnabled" in pb) {
60-
options.add(["private", "pornmode"],
61-
"Set the 'private browsing' option",
62-
"boolean", false,
63-
{
64-
setter: function (value) services.get("privateBrowsing").privateBrowsingEnabled = value,
65-
getter: function () services.get("privateBrowsing").privateBrowsingEnabled
66-
});
67-
let services = modules.services; // Storage objects are global to all windows, 'modules' isn't.
68-
storage.newObject("private-mode", function () {
69-
({
70-
init: function () {
71-
services.get("obs").addObserver(this, "private-browsing", false);
72-
services.get("obs").addObserver(this, "quit-application", false);
73-
this.private = services.get("privateBrowsing").privateBrowsingEnabled;
74-
},
75-
observe: function (subject, topic, data) {
76-
if (topic == "private-browsing") {
77-
if (data == "enter")
78-
storage.privateMode = true;
79-
else if (data == "exit")
80-
storage.privateMode = false;
81-
storage.fireEvent("private-mode", "change", storage.privateMode);
82-
}
83-
else if (topic == "quit-application") {
84-
services.get("obs").removeObserver(this, "quit-application");
85-
services.get("obs").removeObserver(this, "private-browsing");
86-
}
87-
}
88-
}).init();
89-
}, { store: false });
90-
storage.addObserver("private-mode",
91-
function (key, event, value) {
92-
autocommands.trigger("PrivateMode", { state: value });
93-
}, window);
94-
}
95-
9655
options.add(["urlseparator"],
9756
"Set the separator regex used to separate multiple URL args",
9857
"string", ",\\s");

common/content/commandline.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,42 @@ const CommandLine = Module("commandline", {
1919

2020
this._callbacks = {};
2121

22-
storage.newArray("history-search", { store: true, privateData: true });
23-
storage.newArray("history-command", { store: true, privateData: true });
22+
["search", "command"].forEach(function (mode) {
23+
let isPrivate = liberator.isPrivateWindow();
24+
storage.newArray(liberator.storeName(mode, isPrivate), { store: !isPrivate});
25+
}, this);
2426

2527
// Really inideal.
2628
let services = modules.services; // Storage objects are global to all windows, 'modules' isn't.
2729
storage.newObject("sanitize", function () {
2830
({
2931
CLEAR: "browser:purge-session-history",
3032
QUIT: "quit-application",
33+
PRIVATE_END: "last-pb-context-exited",
34+
3135
init: function () {
3236
services.get("obs").addObserver(this, this.CLEAR, false);
3337
services.get("obs").addObserver(this, this.QUIT, false);
38+
services.get("obs").addObserver(this, this.PRIVATE_END, false);
3439
},
3540
observe: function (subject, topic, data) {
3641
switch (topic) {
3742
case this.CLEAR:
3843
["search", "command"].forEach(function (mode) {
39-
CommandLine.History(null, mode).sanitize();
40-
});
44+
CommandLine.History(null, mode, liberator.isPrivateWindow()).sanitize();
45+
}, this);
46+
break;
47+
case this.PRIVATE_END:
48+
for (let [key, obj] in Iterator(storage)) {
49+
if (key.match(/^private-[0-9]/)) {
50+
delete storage[key];
51+
}
52+
}
4153
break;
4254
case this.QUIT:
4355
services.get("obs").removeObserver(this, this.CLEAR);
4456
services.get("obs").removeObserver(this, this.QUIT);
57+
services.get("obs").removeObserver(this, this.PRIVATE_END);
4558
break;
4659
}
4760
}
@@ -471,7 +484,9 @@ const CommandLine = Module("commandline", {
471484

472485
this.show();
473486

474-
this._history = CommandLine.History(this._commandWidget.inputField, (modes.extended == modes.EX) ? "command" : "search");
487+
this._history = CommandLine.History(this._commandWidget.inputField,
488+
(modes.extended == modes.EX) ? "command" : "search",
489+
liberator.isPrivateWindow());
475490
this._completions = CommandLine.Completions(this._commandWidget.inputField);
476491

477492
// open the completion list automatically if wanted
@@ -662,7 +677,9 @@ const CommandLine = Module("commandline", {
662677
this.show();
663678
this._commandWidget.focus();
664679

665-
this._history = CommandLine.History(this._commandWidget.inputField, (modes.extended == modes.EX) ? "command" : "search");
680+
this._history = CommandLine.History(this._commandWidget.inputField,
681+
(modes.extended == modes.EX) ? "command" : "search",
682+
liberator.isPrivateWindow());
666683
this._completions = CommandLine.Completions(this._commandWidget.inputField);
667684
},
668685

@@ -1032,10 +1049,11 @@ const CommandLine = Module("commandline", {
10321049
* @param {string} mode The mode for which we need history.
10331050
*/
10341051
History: Class("History", {
1035-
init: function (inputField, mode) {
1052+
init: function (inputField, mode, privateBrowsing) {
10361053
this.mode = mode;
10371054
this.input = inputField;
1038-
this.store = storage["history-" + mode];
1055+
this.storeName = liberator.storeName(mode, privateBrowsing);
1056+
this.store = storage[this.storeName];
10391057
this.reset();
10401058
},
10411059
/**

common/content/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const Events = Module("events", {
2424

2525
this.sessionListeners = [];
2626

27-
this._macros = storage.newMap("macros", { store: true, privateData: true });
27+
this._macros = storage.newMap("macros", { store: true });
2828

2929
// NOTE: the order of ["Esc", "Escape"] or ["Escape", "Esc"]
3030
// matters, so use that string as the first item, that you

common/content/liberator.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,25 @@ const Liberator = Module("liberator", {
254254
window.dump(msg.replace(/^./gm, ("config" in modules && config.name.toLowerCase()) + ": $&"));
255255
},
256256

257+
isPrivateWindow: function () {
258+
return window.QueryInterface(Ci.nsIInterfaceRequestor)
259+
.getInterface(Ci.nsIWebNavigation)
260+
.QueryInterface(Ci.nsILoadContext)
261+
.usePrivateBrowsing;
262+
},
263+
264+
windowID: function() {
265+
return window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
266+
.getInterface(Components.interfaces.nsIDOMWindowUtils)
267+
.outerWindowID;
268+
269+
},
270+
271+
storeName: function(mode, isPrivate) {
272+
let prefix = isPrivate ? "private-" + this.windowID() + "-" : "";
273+
return prefix + "history-" + mode ;
274+
},
275+
257276
/**
258277
* Outputs a plain message to the command line.
259278
*
@@ -1171,10 +1190,7 @@ const Liberator = Module("liberator", {
11711190
win.setAttribute("titlemodifier_normal", value);
11721191
win.setAttribute("titlemodifier_privatebrowsing", value + suffix);
11731192

1174-
if (window.QueryInterface(Ci.nsIInterfaceRequestor)
1175-
.getInterface(Ci.nsIWebNavigation)
1176-
.QueryInterface(Ci.nsILoadContext)
1177-
.usePrivateBrowsing) {
1193+
if (liberator.isPrivateWindow()) {
11781194
win.setAttribute("titlemodifier", value + suffix);
11791195
}
11801196
else

common/content/marks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const Marks = Module("marks", {
1111
requires: ["config", "storage"],
1212

1313
init: function init() {
14-
this._localMarks = storage.newMap("local-marks", { store: true, privateData: true });
15-
this._urlMarks = storage.newMap("url-marks", { store: false, privateData: true });
14+
this._localMarks = storage.newMap("local-marks", { store: true });
15+
this._urlMarks = storage.newMap("url-marks", { store: false });
1616

1717
this._pendingJumps = [];
1818
},

common/content/quickmarks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const QuickMarks = Module("quickmarks", {
1212
requires: ["config", "storage"],
1313

1414
init: function () {
15-
this._qmarks = storage.newMap("quickmarks", { store: true, privateData: true });
15+
this._qmarks = storage.newMap("quickmarks", { store: true });
1616
},
1717

1818
/**

common/content/sanitizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const Sanitizer = Module("sanitizer", {
7474
commands.add(["sa[nitize]"],
7575
"Clear private data",
7676
function (args) {
77-
liberator.assert(!options['private'], "Cannot sanitize items in private mode");
77+
liberator.assert(!liberator.isPrivateWindow(), "Cannot sanitize items in private mode");
7878

7979
let timespan = args["-timespan"] == undefined ? options["sanitizetimespan"] : args["-timespan"];
8080

common/content/services.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ const Services = Module("services", {
4242
class_: "@mozilla.org/browser/nav-history-service;1",
4343
iface: [Ci.nsINavHistoryService, Ci.nsIBrowserHistory]
4444
},
45-
"privateBrowsing": {
46-
class_: "@mozilla.org/privatebrowsing;1",
47-
iface: Ci.nsIPrivateBrowsingService
48-
},
4945
"profile": {
5046
class_: "@mozilla.org/toolkit/profile-service;1",
5147
iface: Ci.nsIToolkitProfileService

common/locale/en-US/options.xml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -640,23 +640,6 @@
640640
</item>
641641

642642

643-
<item>
644-
<tags>'noprivate' 'private'</tags>
645-
<spec>'private'</spec>
646-
<type>boolean</type>
647-
<default>off</default>
648-
<description>
649-
<p>
650-
Set the <str>private browsing</str> option. In private browsing mode
651-
history, cache files, cookies, form data, passwords, download list
652-
entries, local and URL marks, command-line history and macros are
653-
available only for the duration of the private browsing session and
654-
deleted when returning to normal browsing mode.
655-
</p>
656-
</description>
657-
</item>
658-
659-
660643
<item>
661644
<tags>'nohls' 'nohlsearch'</tags>
662645
<tags>'hls' 'hlsearch'</tags>

common/modules/storage.jsm

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ function loadPref(name, store, type) {
151151
}
152152

153153
function savePref(obj) {
154-
if (obj.privateData && storage.privateMode)
155-
return;
156154
if (obj.store && storage.infoPath)
157155
writeFile(getFile(obj.name), obj.serial);
158156
}
@@ -357,14 +355,6 @@ var storage = {
357355
savePref(obj);
358356
},
359357

360-
_privateMode: false,
361-
get privateMode() this._privateMode,
362-
set privateMode(val) {
363-
if (!val && this._privateMode)
364-
for (let key in keys)
365-
this.load(key);
366-
return this._privateMode = Boolean(val);
367-
}
368358
};
369359

370360
// vim: set fdm=marker sw=4 sts=4 et ft=javascript:

0 commit comments

Comments
 (0)