Closed
Bug 828780
Opened 12 years ago
Closed 12 years ago
"last-pb-context-exiting" doesn't fire when private window is closed
Categories
(Firefox :: Private Browsing, defect)
Tracking
()
RESOLVED
FIXED
Firefox 21
Tracking | Status | |
---|---|---|
firefox19 | --- | unaffected |
firefox20 | + | fixed |
firefox21 | + | fixed |
People
(Reporter: evold, Assigned: ehsan.akhgari)
References
Details
Attachments
(2 files)
1.72 KB,
patch
|
Gavin
:
review+
lsblakk
:
approval-mozilla-aurora+
|
Details | Diff | Splinter Review |
3.25 KB,
patch
|
jdm
:
review+
|
Details | Diff | Splinter Review |
I tired the code below in Scratchpad and the event is not observed when the last private browsing window is closed as I would expect from what I read here https://developer.mozilla.org/en-US/docs/Supporting_per-window_private_browsing#Preventing_a_private_session_from_ending
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"].
getService(Components.interfaces.nsIConsoleService);
os.addObserver({observe: function (aSubject, aTopic, aData) {
aConsoleService.logStringMessage("got here2");
aSubject.QueryInterface(Components.interfaces.nsISupportsPRBool);
// if another extension has not already canceled entering the private mode
if (!aSubject.data) {
if (aData == "exit") { // if we are leaving the private mode
/* you should display some user interface here */
aSubject.data = true; // cancel the operation
}
}
}}, "last-pb-context-exiting", false);
Updated•12 years ago
|
Assignee: nobody → josh
Comment 1•12 years ago
|
||
Fortunately, this is just a documentation error that I've now corrected. There's no aData any longer, and it worked fine for me when I got rid of that check.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → WORKSFORME
Reporter | ||
Comment 2•12 years ago
|
||
I still have this issue even with the following simplified example:
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"].
getService(Components.interfaces.nsIConsoleService);
os.addObserver({observe: function (aSubject, aTopic, aData) {
aConsoleService.logStringMessage("got here: " + aTopic);
}}, "last-pb-context-exiting", false);
os.addObserver({observe: function (aSubject, aTopic, aData) {
aConsoleService.logStringMessage("got here: " + aTopic);
}}, "last-pb-context-exited", false);
I do get the "last-pb-context-exited" notification though.
Status: RESOLVED → REOPENED
Resolution: WORKSFORME → ---
Assignee | ||
Comment 3•12 years ago
|
||
Perhaps you're seeing a variant of bug 818224? Can you log some other way not using the console service?
Reporter | ||
Comment 4•12 years ago
|
||
Same problem with:
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"].
getService(Components.interfaces.nsIConsoleService);
os.addObserver({observe: function (aSubject, aTopic, aData) {
window.alert("got here: " + aTopic);
}}, "last-pb-context-exiting", false);
os.addObserver({observe: function (aSubject, aTopic, aData) {
window.alert("got here: " + aTopic);
}}, "last-pb-context-exited", false);
Assignee | ||
Comment 5•12 years ago
|
||
Ah shoot, of course. The global service used to dispatch this, and now that the service doesn't exist anymore, no wonder this is no longer being dispatched: <http://mxr.mozilla.org/mozilla-central/source/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js#343> Sorry about the confusion.
I'll write a patch.
Assignee: josh → ehsan
Assignee | ||
Comment 6•12 years ago
|
||
I was wrong, browser.js does dispatch the notification. <http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser.js#6199> But the code path for closing the window by closing the last tab conveniently bypasses calling warnAboutClosingWindow, so that code (and the rest of the checks there) never gets called.
I cannot believe nobody has caught this before. :(
Assignee | ||
Comment 7•12 years ago
|
||
Attachment #701389 -
Flags: review?(gavin.sharp)
Assignee | ||
Updated•12 years ago
|
tracking-firefox20:
--- → ?
tracking-firefox21:
--- → ?
Updated•12 years ago
|
status-firefox19:
--- → unaffected
status-firefox20:
--- → affected
status-firefox21:
--- → affected
Assignee | ||
Comment 8•12 years ago
|
||
So the existing notification mentioned in comment 6 relies on closeWindow being called with warnAboutClosingWindow as its argument, so that it can perform the checks necessary to dispatch this notification. However turns out that the tabbrowser code calls closeWindow on a couple of occasions without using warnAboutClosingWindow, therefore bypassing that code altogether. As a result, if you close the last PB window using the window close button which does go through the warnAboutClosingWindow code path, the notification is dispatched, and it you close it by closing the last remaining tab (such as when pressing Cmd+W), then it won't get dispatched.
In builds with the global PB service, the service was responsible for dispatching this notification as it was the central place where PB mode could be turned off, but in Firefox 20+ that code doesn't exist any more, which is why this bug has been noticed on those builds.
Comment 9•12 years ago
|
||
Comment on attachment 701389 [details] [diff] [review]
Patch (v1)
AIUI both of these closeWindow callers only occur when there are <=1 tabs left in the window, so warnAboutClosingTabs when called via warnAboutClosingWindow is a no-op, and so the only effect warnAboutClosingWindow has is notifying the observers it notifies. This code is so hard to follow :(
Attachment #701389 -
Flags: review?(gavin.sharp) → review+
Comment 10•12 years ago
|
||
It also makes me nervous to be changing this on Aurora, FWIW. I guess we don't have much other choice at this point.
Assignee | ||
Comment 11•12 years ago
|
||
We should of course watch closely for regressions... :/
Assignee | ||
Comment 12•12 years ago
|
||
Comment on attachment 701389 [details] [diff] [review]
Patch (v1)
[Approval Request Comment]
Bug caused by (feature/regressing bug #): No specific bug... The original code has had this bug for a long time but it was first uncovered with per-window PB.
User impact if declined: See comment 0. Prompting to cancel private downloads when closing the last private window depends on this, so depending on whether you close the window by pressing Cmd+W, the prompt might be suppressed. This also breaks the last-pb-context-exiting API that add-ons may rely on for similar cleanup.
Testing completed (on m-c, etc.): Locally.
Risk to taking this patch (and alternatives if risky): This can be fairly risky, but the bug that this fixes can be fairly bad (dataloss is possible, see above), so I recommend we take it on Aurora ASAP and watch for regressions.
String or UUID changes made by this patch: None.
Attachment #701389 -
Flags: approval-mozilla-aurora?
Assignee | ||
Comment 13•12 years ago
|
||
Reporter | ||
Comment 14•12 years ago
|
||
No test?
Comment 15•12 years ago
|
||
Status: REOPENED → RESOLVED
Closed: 12 years ago → 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 21
Assignee | ||
Comment 16•12 years ago
|
||
Assignee | ||
Updated•12 years ago
|
Attachment #702673 -
Flags: review?(josh)
Updated•12 years ago
|
Attachment #702673 -
Flags: review?(josh) → review+
Assignee | ||
Comment 17•12 years ago
|
||
Test case: hg.mozilla.org/integration/mozilla-inbound/rev/e6ab6c9b5885
Comment 18•12 years ago
|
||
Comment 19•12 years ago
|
||
Comment on attachment 701389 [details] [diff] [review]
Patch (v1)
Will approve for Aurora, and please watch for reqressions.
Attachment #701389 -
Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Assignee | ||
Comment 20•12 years ago
|
||
You need to log in
before you can comment on or make changes to this bug.
Description
•