Bug 909093 Update SeaMonkey to use nsIContentPrefService2 r=Ratty SEA_2_26_1_RELBRANCH
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Tue, 15 Apr 2014 11:31:17 +0100
branchSEA_2_26_1_RELBRANCH
changeset 31061 91519486358d840cdeb1694f7994343372b9a405
parent 31060 cfda76589359a95ab5057d5573fc1ada33630a39
child 31062 ff1ec742d4c028d4687c83253ce0a4a940aee98c
push id1
push userclokep@gmail.com
push dateMon, 07 May 2018 22:45:56 +0000
treeherdercomm-esr60@57eacde5ef40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersRatty
bugs909093
Bug 909093 Update SeaMonkey to use nsIContentPrefService2 r=Ratty
suite/common/viewZoomOverlay.js
--- a/suite/common/viewZoomOverlay.js
+++ b/suite/common/viewZoomOverlay.js
@@ -7,29 +7,25 @@
 // One of the possible values for the mousewheel.* preferences.
 // From nsEventStateManager.cpp.
 const MOUSE_SCROLL_ZOOM = 3;
 
 /**
  * Controls the "full zoom" setting and its site-specific preferences.
  */
 var FullZoom = {
+  contentPrefs: Services.contentPrefs.QueryInterface(Components.interfaces.nsIContentPrefService2),
+
   // Identifies the setting in the content prefs database.
   name: "browser.content.full-zoom",
 
-  // The global value (if any) for the setting.  Lazily loaded from the service
-  // when first requested, then updated by the pref change listener as it changes.
-  // If there is no global value, then this should be undefined.
-  get globalValue() {
-    var globalValue = Services.contentPrefs.getPref(null, this.name, null);
-    if (typeof globalValue != "undefined")
-      globalValue = this._ensureValid(globalValue);
-    delete this.globalValue;
-    return this.globalValue = globalValue;
-  },
+  // The global value (if any) for the setting. Asynchronously loaded from the
+  // service when first requested, then updated by the pref change listener as
+  // it changes. If there is no global value, then this should be undefined.
+  globalValue: undefined,
 
   // browser.zoom.siteSpecific preference cache
   _siteSpecificPref: undefined,
 
   // browser.zoom.updateBackgroundTabs preference cache
   updateBackgroundTabs: undefined,
 
   get siteSpecific() {
@@ -38,41 +34,45 @@ var FullZoom = {
 
   //**************************************************************************//
   // nsISupports
 
   QueryInterface:
   XPCOMUtils.generateQI([Components.interfaces.nsIDOMEventListener,
                          Components.interfaces.nsIObserver,
                          Components.interfaces.nsIContentPrefObserver,
+                         Components.interfaces.nsIContentPrefCallback2,
                          Components.interfaces.nsISupportsWeakReference,
                          Components.interfaces.nsISupports]),
 
   //**************************************************************************//
   // Initialization & Destruction
 
   init: function FullZoom_init() {
     // Listen for scrollwheel events so we can save scrollwheel-based changes.
     window.addEventListener("wheel", this, true);
 
+    // Fetch the initial global value.
+    this.contentPrefs.getGlobal(this.name, null, this);
+
     // Register ourselves with the service so we know when our pref changes.
-    Services.contentPrefs.addObserver(this.name, this);
+    this.contentPrefs.addObserverForName(this.name, this);
 
     this._siteSpecificPref =
       Services.prefs.getBoolPref("browser.zoom.siteSpecific");
     this.updateBackgroundTabs =
       Services.prefs.getBoolPref("browser.zoom.updateBackgroundTabs");
     // Listen for changes to the browser.zoom branch so we can enable/disable
     // updating background tabs and per-site saving and restoring of zoom levels.
     Services.prefs.addObserver("browser.zoom.", this, true);
   },
 
   destroy: function FullZoom_destroy() {
     Services.prefs.removeObserver("browser.zoom.", this);
-    Services.contentPrefs.removeObserver(this.name, this);
+    this.contentPrefs.removeObserverForName(this.name, this);
     window.removeEventListener("wheel", this, true);
   },
 
 
   //**************************************************************************//
   // Event Handlers
 
   // nsIDOMEventListener
@@ -135,43 +135,53 @@ var FullZoom = {
         }
         break;
     }
   },
 
   // nsIContentPrefObserver
 
   onContentPrefSet: function FullZoom_onContentPrefSet(aGroup, aName, aValue) {
-    if (aGroup == Services.contentPrefs.grouper.group(getBrowser().currentURI))
+    if (aGroup == this.contentPrefs.extractDomain(getBrowser().currentURI.spec))
       this._applyPrefToSetting(aValue);
     else if (aGroup == null) {
       this.globalValue = this._ensureValid(aValue);
 
       // If the current page doesn't have a site-specific preference,
       // then its zoom should be set to the new global preference now that
       // the global preference has changed.
-      if (!Services.contentPrefs.hasPref(getBrowser().currentURI, this.name, getBrowser().docShell))
+      var zoomValue = this.contentPrefs.getCachedByDomainAndName(getBrowser().currentURI.spec, this.name, getBrowser().docShell);
+      if (zoomValue && !zoomValue.value)
         this._applyPrefToSetting();
     }
   },
 
   onContentPrefRemoved: function FullZoom_onContentPrefRemoved(aGroup, aName) {
-    if (aGroup == Services.contentPrefs.grouper.group(getBrowser().currentURI))
+    if (aGroup == this.contentPrefs.extractDomain(getBrowser().currentURI.spec))
       this._applyPrefToSetting();
     else if (aGroup == null) {
       this.globalValue = undefined;
 
       // If the current page doesn't have a site-specific preference,
       // then its zoom should be set to the default preference now that
       // the global preference has changed.
-      if (!Services.contentPrefs.hasPref(getBrowser().currentURI, this.name, getBrowser().docShell))
+      var zoomValue = this.contentPrefs.getCachedByDomainAndName(getBrowser().currentURI.spec, this.name, getBrowser().docShell);
+      if (zoomValue && !zoomValue.value)
         this._applyPrefToSetting();
     }
   },
 
+  // nsIContentPrefCallback2
+
+  handleCompletion: function(aReason) {},
+  handleError: function(aResult) {},
+  handleResult: function(aPref) {
+    this.onContentPrefSet(null, this.name, aPref.value);
+  },
+
   // location change observer
 
   /**
    * Called when the location of a tab changes.
    * When that happens, we need to update the current zoom level if appropriate.
    *
    * @param aURI
    *        A URI object representing the new location.
@@ -192,27 +202,34 @@ var FullZoom = {
 
     // Image documents should always start at 1, and are not affected by prefs.
     if (!aIsTabSwitch && aBrowser.contentDocument.mozSyntheticDocument) {
       ZoomManager.setZoomForBrowser(aBrowser, this._ensureValid(1));
       return;
     }
 
     var loadContext = aBrowser.docShell;
-    if (Services.contentPrefs.hasCachedPref(aURI, this.name, loadContext)) {
-      let zoomValue = Services.contentPrefs.getPref(aURI, this.name, loadContext);
-      this._applyPrefToSetting(zoomValue, aBrowser);
+    var zoomValue = this.contentPrefs.getCachedByDomainAndName(aURI.spec, this.name, loadContext);
+    if (zoomValue) {
+      this._applyPrefToSetting(zoomValue.value, aBrowser);
     } else {
-      var self = this;
-      Services.contentPrefs.getPref(aURI, this.name, loadContext, function (aResult) {
-        // Check that we're still where we expect to be in case this took a while.
-        // Null check currentURI, since the window may have been destroyed before
-        // we were called.
-        if (aBrowser.currentURI && aURI.equals(aBrowser.currentURI))
-          self._applyPrefToSetting(aResult, aBrowser);
+      this.contentPrefs.getByDomainAndName(aURI.spec, this.name, loadContext, {
+        self: this,
+        value: undefined,
+        handleCompletion: function(aReason) {
+          // Check that we're still where we expect to be in case this took a
+          // while. Null check currentURI, since the window may have been
+          // destroyed before we were called.
+          if (aBrowser.currentURI && aURI.equals(aBrowser.currentURI))
+            this.self._applyPrefToSetting(this.value, aBrowser);
+        },
+        handleError: function(aResult) {},
+        handleResult: function(aPref) {
+          this.value = aPref.value;
+        }
       });
     }
   },
 
   // update state of zoom type menu item
 
   updateMenu: function FullZoom_updateMenu() {
     var menuItem = document.getElementById("toggle_zoom");
@@ -300,22 +317,22 @@ var FullZoom = {
   },
 
   _applySettingToPref: function FullZoom_applySettingToPref() {
     if (!this.siteSpecific || window.gInPrintPreviewMode ||
         content.document.mozSyntheticDocument)
       return;
 
     var zoomLevel = ZoomManager.zoom;
-    Services.contentPrefs.setPref(getBrowser().currentURI, this.name, zoomLevel, getBrowser().docShell);
+    this.contentPrefs.set(getBrowser().currentURI.spec, this.name, zoomLevel, getBrowser().docShell);
   },
 
   _removePref: function FullZoom_removePref() {
     if (!content.document.mozSyntheticDocument)
-      Services.contentPrefs.removePref(getBrowser().currentURI, this.name, getBrowser().docShell);
+      this.contentPrefs.removeByDomainAndName(getBrowser().currentURI.spec, this.name, getBrowser().docShell);
   },
 
 
   //**************************************************************************//
   // Utilities
 
   _ensureValid: function FullZoom_ensureValid(aValue) {
     if (isNaN(aValue))