Bug 960903 - Listen for subframe loads and clear observers r=yoric
authorTim Taubert <ttaubert@mozilla.com>
Wed, 22 Jan 2014 13:10:58 +0100
changeset 181129 4c85a2007510f24b938b124bb9fd35bbf14b8f4d
parent 181128 c99d792be115612fa33f955fb1ce6634fdf9c1b4
child 181130 c7c63c6c2433a437312066c0f1419a87c9688f5a
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyoric
bugs960903
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 960903 - Listen for subframe loads and clear observers r=yoric
browser/components/sessionstore/content/content-sessionStore.js
--- 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.
 });