Bug 552828 - update Form History to work with Electrolysis: use frame script unload event [r=dolske]
authorBenjamin Stover <bstover@mozilla.com>
Mon, 16 Aug 2010 21:10:37 -0700
changeset 50715 39171f12fd3987bd2317f979fd1034816e8cf6e6
parent 50714 3e1fc0dcf7c8be3abcaa0d4244aedfe375d09410
child 50716 116f2046b9efa7d6cbf7de100165a4a601512e43
push idunknown
push userunknown
push dateunknown
reviewersdolske
bugs552828
milestone2.0b4pre
Bug 552828 - update Form History to work with Electrolysis: use frame script unload event [r=dolske]
toolkit/components/satchel/src/formSubmitListener.js
toolkit/components/satchel/src/nsFormHistory.js
--- a/toolkit/components/satchel/src/formSubmitListener.js
+++ b/toolkit/components/satchel/src/formSubmitListener.js
@@ -30,39 +30,42 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-const Cc = Components.classes;
-const Ci = Components.interfaces;
+var Cc = Components.classes;
+var Ci = Components.interfaces;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
-const satchelFormListener = {
+var satchelFormListener = {
     QueryInterface : XPCOMUtils.generateQI([Ci.nsIFormSubmitObserver,
+                                            Ci.nsIDOMEventListener,
                                             Ci.nsObserver,
                                             Ci.nsISupportsWeakReference]),
 
     debug          : true,
     enabled        : true,
     saveHttpsForms : true,
 
     init : function() {
         Services.obs.addObserver(this, "earlyformsubmit", false);
 
         let prefBranch = Services.prefs.getBranch("browser.formfill.");
         prefBranch.QueryInterface(Ci.nsIPrefBranch2);
-        prefBranch.addObserver("", this, true);
+        prefBranch.addObserver("", this, false);
 
         this.updatePrefs();
+
+        addEventListener("unload", this, false);
     },
 
     updatePrefs : function () {
         let prefBranch = Services.prefs.getBranch("browser.formfill.");
         this.debug          = prefBranch.getBoolPref("debug");
         this.enabled        = prefBranch.getBoolPref("enable");
         this.saveHttpsForms = prefBranch.getBoolPref("saveHttpsForms");
     },
@@ -96,16 +99,34 @@ const satchelFormListener = {
 
     log : function (message) {
         if (!this.debug)
             return;
         dump("satchelFormListener: " + message + "\n");
         Services.console.logStringMessage("satchelFormListener: " + message);
     },
 
+    /* ---- dom event handler ---- */
+
+    handleEvent: function(e) {
+        switch (e.type) {
+            case "unload":
+                Services.obs.removeObserver(this, "earlyformsubmit");
+
+                let prefBranch = Services.prefs.getBranch("browser.formfill.");
+                prefBranch.QueryInterface(Ci.nsIPrefBranch2);
+                prefBranch.removeObserver("", this);
+
+                break;
+            default:
+                this.log("Oops! Unexpected event: " + e.type);
+                break;
+        }
+    },
+
     /* ---- nsIObserver interface ---- */
 
     observe : function (subject, topic, data) {
         if (topic == "nsPref:changed")
             this.updatePrefs();
         else
             this.log("Oops! Unexpected notification: " + topic);
     },
--- a/toolkit/components/satchel/src/nsFormHistory.js
+++ b/toolkit/components/satchel/src/nsFormHistory.js
@@ -50,17 +50,17 @@ function FormHistory() {
     this.init();
 }
 
 FormHistory.prototype = {
     classID          : Components.ID("{0c1bb408-71a2-403f-854a-3a0659829ded}"),
     QueryInterface   : XPCOMUtils.generateQI([Ci.nsIFormHistory2,
                                               Ci.nsIObserver,
                                               Ci.nsIFrameMessageListener,
-                                              Ci.nsISupportsWeakReference]),
+                                              ]),
 
     debug          : true,
     enabled        : true,
     saveHttpsForms : true,
 
     // The current database schema.
     dbSchema : {
         tables : {
@@ -124,17 +124,17 @@ FormHistory.prototype = {
     },
 
 
     init : function() {
         let self = this;
 
         let prefBranch = Services.prefs.getBranch("browser.formfill.");
         prefBranch = prefBranch.QueryInterface(Ci.nsIPrefBranch2);
-        prefBranch.addObserver("", this, true);
+        prefBranch.addObserver("", this, false);
 
         this.updatePrefs();
 
         this.dbStmts = {};
 
         this.messageManager = Cc["@mozilla.org/globalmessagemanager;1"].
                               getService(Ci.nsIChromeFrameMessageManager);
         this.messageManager.loadFrameScript("chrome://satchel/content/formSubmitListener.js", true);