Bug 960903 - Listen for subframe loads and clear observers r=yoric
--- a/browser/components/sessionstore/content/content-sessionStore.js
+++ b/browser/components/sessionstore/content/content-sessionStore.js
@@ -212,49 +212,54 @@ let SyncHandler = {
* session history.
*
* Example:
* {entries: [{url: "about:mozilla", ...}, ...], index: 1}
*/
let SessionHistoryListener = {
init: function () {
gFrameTree.addObserver(this);
+ addEventListener("load", this, true);
addEventListener("hashchange", this, true);
- Services.obs.addObserver(this, "browser:purge-session-history", true);
+ Services.obs.addObserver(this, "browser:purge-session-history", false);
+ },
+
+ uninit: function () {
+ Services.obs.removeObserver(this, "browser:purge-session-history");
},
observe: function () {
// We need to use setTimeout() here because we listen for
// "browser:purge-session-history". When that is fired all observers are
// expected to purge their data. We can't expect to be called *after* the
// observer in browser.xml that clears session history so we need to wait
// a tick before actually collecting data.
setTimeout(() => this.collect(), 0);
},
- handleEvent: function () {
- this.collect();
+ handleEvent: function (event) {
+ // We are only interested in "load" events from subframes.
+ if (event.type == "hashchange" || event.target != content.document) {
+ this.collect();
+ }
},
collect: function () {
if (docShell) {
MessageQueue.push("history", () => SessionHistory.collect(docShell));
}
},
onFrameTreeCollected: function () {
this.collect();
},
onFrameTreeReset: function () {
this.collect();
- },
-
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
- Ci.nsISupportsWeakReference])
+ }
};
/**
* Listens for scroll position changes. Whenever the user scrolls the top-most
* frame we update the scroll position and will restore it when requested.
*
* Causes a SessionStore:update message to be sent that contains the current
* scroll positions as a tree of strings. If no frame of the whole frame tree
@@ -668,13 +673,14 @@ SessionStorageListener.init();
ScrollPositionListener.init();
DocShellCapabilitiesListener.init();
PrivacyListener.init();
addEventListener("unload", () => {
// Remove all registered nsIObservers.
PageStyleListener.uninit();
SessionStorageListener.uninit();
+ SessionHistoryListener.uninit();
// We don't need to take care of any gFrameTree observers as the gFrameTree
// will die with the content script. The same goes for the privacy transition
// observer that will die with the docShell when the tab is closed.
});