Bug 552828 - update Form History to work with Electrolysis: don't use preference branches [r=dolske]
authorBenjamin Stover <bstover@mozilla.com>
Mon, 16 Aug 2010 21:10:39 -0700
changeset 50716 116f2046b9efa7d6cbf7de100165a4a601512e43
parent 50715 39171f12fd3987bd2317f979fd1034816e8cf6e6
child 50717 51e296a1db95dd0ece4e288874e71f85eaad0b99
child 51333 0f96e7356ba364b923733b65594aafe6dccde7fc
push idunknown
push userunknown
push dateunknown
reviewersdolske
bugs552828
milestone2.0b4pre
Bug 552828 - update Form History to work with Electrolysis: don't use preference branches [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
@@ -48,31 +48,25 @@ var satchelFormListener = {
                                             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, false);
-
+        Services.prefs.addObserver("browser.formfill.", 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");
+        this.debug          = Services.prefs.getBoolPref("browser.formfill.debug");
+        this.enabled        = Services.prefs.getBoolPref("browser.formfill.enable");
+        this.saveHttpsForms = Services.prefs.getBoolPref("browser.formfill.saveHttpsForms");
     },
 
     // Implements the Luhn checksum algorithm as described at
     // http://wikipedia.org/wiki/Luhn_algorithm
     isValidCCNumber : function (ccNumber) {
         // Remove dashes and whitespace
         ccNumber = ccNumber.replace(/[\-\s]/g, '');
 
@@ -105,22 +99,19 @@ var satchelFormListener = {
     },
 
     /* ---- dom event handler ---- */
 
     handleEvent: function(e) {
         switch (e.type) {
             case "unload":
                 Services.obs.removeObserver(this, "earlyformsubmit");
+                Services.prefs.removeObserver("browser.formfill.", this);
+                break;
 
-                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 ---- */
 
--- a/toolkit/components/satchel/src/nsFormHistory.js
+++ b/toolkit/components/satchel/src/nsFormHistory.js
@@ -122,19 +122,17 @@ FormHistory.prototype = {
         dump("FormHistory: " + message + "\n");
         Services.console.logStringMessage("FormHistory: " + message);
     },
 
 
     init : function() {
         let self = this;
 
-        let prefBranch = Services.prefs.getBranch("browser.formfill.");
-        prefBranch = prefBranch.QueryInterface(Ci.nsIPrefBranch2);
-        prefBranch.addObserver("", this, false);
+        Services.prefs.addObserver("browser.formfill.", 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);
@@ -506,18 +504,17 @@ FormHistory.prototype = {
 
 
     expireOldEntries : function () {
         this.log("expireOldEntries");
 
         // Determine how many days of history we're supposed to keep.
         let expireDays = 180;
         try {
-            let prefBranch = Services.prefs.getBranch("browser.formfill.");
-            expireDays = prefBranch.getIntPref("expire_days");
+            expireDays = Services.prefs.getIntPref("browser.formfill.expire_days");
         } catch (e) { /* ignore */ }
 
         let expireTime = Date.now() - expireDays * DAY_IN_MS;
         expireTime *= 1000; // switch to microseconds
 
         this.sendIntNotification("before-expireOldEntries", expireTime);
 
         let beginningCount = this.countAllEntries();
@@ -546,20 +543,19 @@ FormHistory.prototype = {
         if (beginningCount - endingCount > 500)
             this.dbConnection.executeSimpleSQL("VACUUM");
 
         this.sendIntNotification("expireOldEntries", expireTime);
     },
 
 
     updatePrefs : function () {
-        let prefBranch = Services.prefs.getBranch("browser.formfill.");
-        this.debug          = prefBranch.getBoolPref("debug");
-        this.enabled        = prefBranch.getBoolPref("enable");
-        this.saveHttpsForms = prefBranch.getBoolPref("saveHttpsForms");
+        this.debug          = Services.prefs.getBoolPref("browser.formfill.debug");
+        this.enabled        = Services.prefs.getBoolPref("browser.formfill.enable");
+        this.saveHttpsForms = Services.prefs.getBoolPref("browser.formfill.saveHttpsForms");
     },
 
 //**************************************************************************//
     // Database Creation & Access
 
     /*
      * dbCreateStatement
      *