Bug 1588876 - Part 1: Use Services obs and prefs if possible in SeaMonkey. r=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Sun, 20 Oct 2019 17:40:58 +0200
changeset 37188 dcdf7978e8310a2cbfb74b6e5a9ecbfba8d42e37
parent 37187 01dcc0cc8f07406220436186fd13c22d56380916
child 37189 b7054ece21742ae4ae0f6e85aff2ff7eb02c5b4f
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersIanN
bugs1588876
Bug 1588876 - Part 1: Use Services obs and prefs if possible in SeaMonkey. r=IanN
suite/browser/nsTypeAheadFind.js
suite/browser/tabbrowser.xml
suite/components/bindings/notification.xml
suite/components/downloads/tests/chrome/test_basic_functionality.xul
suite/components/downloads/tests/chrome/test_delete_key_cancels.xul
suite/components/downloads/tests/chrome/test_delete_key_removes.xul
suite/components/downloads/tests/chrome/test_drag.xul
suite/components/downloads/tests/chrome/test_removeDownload_updates_ui.xul
suite/components/downloads/tests/chrome/test_search_keys.xul
suite/components/downloads/tests/chrome/test_space_key_pauses_resumes.xul
suite/components/downloads/tests/chrome/test_space_key_retries.xul
suite/components/downloads/tests/chrome/test_ui_stays_open_on_alert_clickback.xul
suite/components/places/nsPlacesAutoComplete.js
suite/components/places/tests/unit/test_browserGlue_prefs.js
suite/components/places/tests/unit/test_browserGlue_shutdown.js
suite/modules/Sanitizer.jsm
--- a/suite/browser/nsTypeAheadFind.js
+++ b/suite/browser/nsTypeAheadFind.js
@@ -76,19 +76,17 @@ typeAheadFind.prototype = {
   /* nsIObserver */
   observe: function(aSubject, aTopic, aData) {
     if (aTopic == "app-startup") {
       // It's now safe to get our pref branch.
       this.mPrefs = Services.prefs.getBranch("accessibility.typeaheadfind.");
       // We need to add our event listeners to all windows.
       Services.ww.registerNotification(this);
       // We also need to listen for find again commands
-      Cc["@mozilla.org/observer-service;1"]
-        .getService(Ci.nsIObserverService)
-        .addObserver(this, "nsWebBrowserFind_FindAgain", true);
+      Services.obs.addObserver(this, "nsWebBrowserFind_FindAgain", true);
     }
     if (aTopic == "domwindowopened") {
       // Add our listeners. They get automatically removed on window teardown.
       aSubject.controllers.appendController(new findTypeController(this, aSubject));
       Cc["@mozilla.org/eventlistenerservice;1"]
         .getService(Ci.nsIEventListenerService)
         .addSystemEventListener(aSubject, "keypress", this, false);
     }
--- a/suite/browser/tabbrowser.xml
+++ b/suite/browser/tabbrowser.xml
@@ -3096,19 +3096,17 @@
           t.style.maxWidth = Services.prefs.getIntPref("browser.tabs.tabMaxWidth") + "px";
           t.style.minWidth = Services.prefs.getIntPref("browser.tabs.tabMinWidth") + "px";
           t.width = 0;
           t.flex = 100;
           t.setAttribute("validate", "never");
           t.setAttribute("onerror", "this.parentNode.parentNode.parentNode.parentNode.addToMissedIconCache(this.getAttribute('image')); this.removeAttribute('image');");
           this.referenceTab = t;
 
-          var os = Cc["@mozilla.org/observer-service;1"]
-                     .getService(Ci.nsIObserverService);
-          os.addObserver(this, "browser:purge-session-history");
+          Services.obs.addObserver(this, "browser:purge-session-history");
           Services.prefs.addObserver("browser.tabs.max_tabs_undo", this);
 
           var onclick = this.getAttribute("oncontentclick");
           if (onclick)
             this.onContentClick = new Function("event", onclick);
         ]]>
       </constructor>
 
@@ -3122,19 +3120,17 @@
           for (var i = 0; i < this.mTabListeners.length; ++i) {
             this.browsers[i].webProgress.removeProgressListener(this.mTabFilters[i]);
             this.mTabFilters[i].removeProgressListener(this.mTabListeners[i]);
             this.mTabFilters[i] = null;
             this.mTabListeners[i] = null;
             // eventListeners are removed from the browsers in display order of the browsers
             this.browsers[i].removeEventListener("DOMTitleChanged", this.onTitleChanged, true);
           }
-          var os = Cc["@mozilla.org/observer-service;1"]
-                     .getService(Ci.nsIObserverService);
-          os.removeObserver(this, "browser:purge-session-history");
+          Services.obs.removeObserver(this, "browser:purge-session-history");
           Services.prefs.removeObserver("browser.tabs.max_tabs_undo", this);
           this.savedBrowsers.forEach(function(aTabData) {
             delete aTabData.browserData;
           });
         ]]>
       </destructor>
 
       <!-- Deprecated stuff, implemented for backwards compatibility. -->
--- a/suite/components/bindings/notification.xml
+++ b/suite/components/bindings/notification.xml
@@ -36,23 +36,16 @@
       </field>
 
       <field name="_placesBundle" readonly="true">
         <![CDATA[
          Services.strings.createBundle("chrome://communicator/locale/places/places.properties");
         ]]>
       </field>
 
-      <field name="_prefs" readonly="true">
-        <![CDATA[
-          Cc["@mozilla.org/preferences-service;1"]
-            .getService(Ci.nsIPrefBranch);
-        ]]>
-      </field>
-
       <field name="_urlFormatter" readonly="true">
         <![CDATA[
           Cc["@mozilla.org/toolkit/URLFormatterService;1"]
             .getService(Ci.nsIURLFormatter);
         ]]>
       </field>
 
       <field name="wrappedJSObject">this</field>
@@ -147,22 +140,22 @@
               priority = this.PRIORITY_INFO_LOW;
             } else if (aState & nsIWebProgressListener.STATE_IS_BROKEN) {
               pref = "security.warn_viewing_mixed";
               message = "MixedContentMessage";
               priority = this.PRIORITY_CRITICAL_LOW;
             }
 
             if (aState & nsIWebProgressListener.STATE_LOADED_MIXED_ACTIVE_CONTENT &&
-                this._prefs.getBoolPref("security.warn_mixed_active_content")) {
+                Services.prefs.getBoolPref("security.warn_mixed_active_content")) {
               pref = "security.warn_mixed_active_content";
               message = "MixedActiveContentMessage";
               priority = this.PRIORITY_CRITICAL_LOW;
             } else if (aState & nsIWebProgressListener.STATE_BLOCKED_MIXED_ACTIVE_CONTENT &&
-                this._prefs.getBoolPref("security.warn_mixed_active_content")) {
+                Services.prefs.getBoolPref("security.warn_mixed_active_content")) {
               pref = "security.warn_mixed_active_content";
               message = "BlockedActiveContentMessage";
               priority = this.PRIORITY_INFO_LOW;
               this.lastState = aState & ~nsIWebProgressListener.STATE_BLOCKED_MIXED_ACTIVE_CONTENT;
               const nsIWebNavigation = Ci.nsIWebNavigation;
               buttons = [{
                 label: this._stringBundle.GetStringFromName("SecurityKeepBlocking.label"),
                 accessKey: this._stringBundle.GetStringFromName("SecurityKeepBlocking.accesskey"),
@@ -170,23 +163,23 @@
               }, {
                 label: this._stringBundle.GetStringFromName("SecurityUnblock.label"),
                 accessKey: this._stringBundle.GetStringFromName("SecurityUnblock.accesskey"),
                 callback: this.reloadPage.bind(this,
                               nsIWebNavigation.LOAD_FLAGS_ALLOW_MIXED_CONTENT |
                               nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE)
               }];
             } else if (aState & nsIWebProgressListener.STATE_LOADED_TRACKING_CONTENT &&
-                this._prefs.getBoolPref("privacy.warn_tracking_content")) {
+                Services.prefs.getBoolPref("privacy.warn_tracking_content")) {
               pref = "privacy.warn_tracking_content";
               message = "TrackingContentMessage";
               priority = this.PRIORITY_WARNING_LOW;
               pane = "security_pane";
             } else if (aState & nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT &&
-                this._prefs.getBoolPref("privacy.warn_tracking_content")) {
+                Services.prefs.getBoolPref("privacy.warn_tracking_content")) {
               pref = "privacy.warn_tracking_content";
               message = "BlockedTrackingContentMessage";
               priority = this.PRIORITY_INFO_LOW;
               pane = "security_pane";
               if (!this.usePrivateBrowsing) {
                 this.lastState = aState & ~nsIWebProgressListener.STATE_BLOCKED_TRACKING_CONTENT;
                 buttons = [{
                   label: this._stringBundle.GetStringFromName("SecurityKeepBlocking.label"),
@@ -202,37 +195,37 @@
                       .add(this.activeBrowser.currentURI,
                                    "trackingprotection",
                                    nsIPermissionManager.ALLOW_ACTION);
                     this.reloadPage();
                   }
                 }];
               }
             } else if (aState & nsIWebProgressListener.STATE_LOADED_MIXED_DISPLAY_CONTENT &&
-                this._prefs.getBoolPref("security.warn_mixed_display_content")) {
+                Services.prefs.getBoolPref("security.warn_mixed_display_content")) {
               pref = "security.warn_mixed_display_content";
               message = "MixedDisplayContentMessage";
               priority = this.PRIORITY_WARNING_LOW;
             } else if (aState & nsIWebProgressListener.STATE_BLOCKED_MIXED_DISPLAY_CONTENT &&
-                this._prefs.getBoolPref("security.warn_mixed_display_content")) {
+                Services.prefs.getBoolPref("security.warn_mixed_display_content")) {
               pref = "security.warn_mixed_display_content";
               message = "BlockedDisplayContentMessage";
               priority = this.PRIORITY_INFO_LOW;
             }
 
             if (this.lastMessage == message)
               return false;
 
             var box = this.getNotificationWithValue(this.lastMessage);
             if (box)
               box.close();
 
             this.lastMessage = message;
 
-            if (!this._prefs.getBoolPref(pref))
+            if (!Services.prefs.getBoolPref(pref))
               return true;
 
             if ("goPreferences" in window) {
               buttons.push({
                 label: this._stringBundle.GetStringFromName("SecurityPreferences.label"),
                 accessKey: this._stringBundle.GetStringFromName("SecurityPreferences.accesskey"),
                 callback: function() {
                   goPreferences(pane);
@@ -266,17 +259,17 @@
 
       <method name="onRefreshAttempted">
         <parameter name="aWebProgress" />
         <parameter name="aURI" />
         <parameter name="aDelay" />
         <parameter name="aSameURI" />
         <body>
           <![CDATA[
-            if (this._prefs.getBoolPref("accessibility.blockautorefresh")) {
+            if (Services.prefs.getBoolPref("accessibility.blockautorefresh")) {
               let brandShortName = this._brandStringBundle.GetStringFromName("brandShortName");
               let refreshButtonText =
                 this._stringBundle.GetStringFromName("refreshBlocked.goButton");
               let refreshButtonAccesskey =
                 this._stringBundle.GetStringFromName("refreshBlocked.goButton.accesskey");
               let message =
                 this._stringBundle.formatStringFromName(aSameURI ? "refreshBlocked.refreshLabel"
                                                                  : "refreshBlocked.redirectLabel",
@@ -334,17 +327,17 @@
             if (!browser || !browser.docShell || !browser.docShell.securityUI)
               return;
 
             // not our window:
             if (aWindow.top != browser.contentWindow)
               return;
 
             // pref disabled:
-            if (!this._prefs.getBoolPref("security.warn_submit_insecure"))
+            if (!Services.prefs.getBoolPref("security.warn_submit_insecure"))
               return;
 
             // HTTPS uninteresting:
             if (aActionURI.schemeIs("https"))
               return;
 
             // javascript doesn't hit the network:
             if (aActionURI.schemeIs("javascript"))
@@ -368,17 +361,17 @@
               this._stringBundle.GetStringFromName("PostToInsecureFromInsecureMessage"),
               prompt.BUTTON_TITLE_IS_STRING * prompt.BUTTON_POS_0 +
               prompt.BUTTON_TITLE_CANCEL * prompt.BUTTON_POS_1,
               this._stringBundle.GetStringFromName("PostToInsecureContinue"),
               null, null,
               this._stringBundle.GetStringFromName("PostToInsecureFromInsecureShowAgain"),
               warn) != 0;
             if (!aCancel.value)
-              this._prefs.setBoolPref("security.warn_submit_insecure", warn.value);
+              Services.prefs.setBoolPref("security.warn_submit_insecure", warn.value);
           ]]>
         </body>
       </method>
 
       <method name="observe">
         <parameter name="aSubject" />
         <parameter name="aTopic" />
         <parameter name="aData" />
@@ -460,44 +453,44 @@
                     this.checkUsage(manifestURI);
                 } catch (e) {
                   alert(e);
                 }
                 break;
 
               case "nsPref:changed":
                 if (aData == "privacy.popups.showBrowserMessage") {
-                  if (this._prefs.getBoolPref(aData))
+                  if (Services.prefs.getBoolPref(aData))
                     return;
 
                   var popupNotification = this.getNotificationWithValue("popup-blocked");
                   if (popupNotification)
                     this.removeNotification(popupNotification);
                 }
 
                 if (aData == "plugins.hide_infobar_for_outdated_plugin") {
-                  if (!this._prefs.getBoolPref(aData))
+                  if (!Services.prefs.getBoolPref(aData))
                     return;
 
                   var outdatedNotification = this.getNotificationWithValue("outdated-plugins");
                   if (outdatedNotification)
                     this.removeNotification(outdatedNotification);
                 }
 
                 if (aData == "plugins.hide_infobar_for_carbon_failure_plugin") {
-                  if (!this._prefs.getBoolPref(aData))
+                  if (!Services.prefs.getBoolPref(aData))
                     return;
 
                   var carbonfailureNotification = this.getNotificationWithValue("carbon-failure-plugins");
                   if (carbonfailureNotification)
                     this.removeNotification(carbonfailureNotification);
                 }
 
                 if (aData == "plugins.hide_infobar_for_missing_plugin") {
-                  if (!this._prefs.getBoolPref(aData))
+                  if (!Services.prefs.getBoolPref(aData))
                     return;
 
                   var missingNotification = this.getNotificationWithValue("missing-plugins");
                   if (missingNotification)
                     this.removeNotification(missingNotification);
 
                   var disabledNotification = this.getNotificationWithValue("disabled-plugins");
                   if (disabledNotification)
@@ -505,17 +498,17 @@
 
                   var blockedNotification = this.getNotificationWithValue("blocked-plugins");
                   if (blockedNotification)
                     this.removeNotification(blockedNotification);
                 }
 
                 if (aData == "dom.disable_open_during_load") {
                   // remove notifications when popup blocking has been turned off
-                  if (this._prefs.getBoolPref(aData) || !this.popupCount)
+                  if (Services.prefs.getBoolPref(aData) || !this.popupCount)
                     return;
 
                   var popupNotification = this.getNotificationWithValue("popup-blocked");
                   if (popupNotification)
                     this.removeNotification(popupNotification);
                   this.popupCount = 0;
                   this.notifyPopupCountChanged();
                 }
@@ -600,17 +593,17 @@
           <![CDATA[
             // Show the in-content UI if it's not too big. The crashed plugin handler already does this.
             var overlay = this.getPluginUI(aPlugin, "main");
             aPlugin.addEventListener("overflow", this);
             aPlugin.addEventListener("underflow", this);
             overlay.classList.toggle("visible",
                                      !this.isTooSmall(aPlugin, overlay));
 
-            if (this._prefs.getBoolPref(aPref || "plugins.hide_infobar_for_missing_plugin"))
+            if (Services.prefs.getBoolPref(aPref || "plugins.hide_infobar_for_missing_plugin"))
               return;
 
             var notification;
             var notifications = [
               "blocked-plugins",
               "disabled-plugins",
               "missing-plugins",
               "carbon-failure-plugins",
@@ -744,26 +737,26 @@
       <method name="openURLPref">
         <parameter name="aPref"/>
         <body>
           <![CDATA[
             var url = this._urlFormatter.formatURLPref(aPref);
             var nsIBrowserDOMWindow = Ci.nsIBrowserDOMWindow;
 
             var browserWin;
-            var whereToOpen = this._prefs.getIntPref("browser.link.open_external");
+            var whereToOpen = Services.prefs.getIntPref("browser.link.open_external");
 
             if (whereToOpen != nsIBrowserDOMWindow.OPEN_NEWWINDOW) {
               browserWin = Services.wm.getMostRecentWindow("navigator:browser");
             }
 
             if (!browserWin) {
               var browserURL = "chrome://navigator/content/navigator.xul";
               try {
-                browserURL = this._prefs.getCharPref("browser.chromeURL");
+                browserURL = Services.prefs.getCharPref("browser.chromeURL");
               } catch (ex) {}
 
               window.openDialog(browserURL, "_blank", "chrome,all,dialog=no", url);
             } else {
               if (whereToOpen == nsIBrowserDOMWindow.OPEN_CURRENTWINDOW)
                 browserWin.loadURI(url);
               else {
                 // new tab
@@ -1024,25 +1017,25 @@
           ]]>
         </body>
       </method>
 
       <method name="playSoundForBlockedPopup">
         <body>
           <![CDATA[
             const kCustomSound = 1;
-            var playSound = this._prefs.getBoolPref("privacy.popups.sound_enabled");
+            var playSound = Services.prefs.getBoolPref("privacy.popups.sound_enabled");
 
             if (playSound) {
               var sound = Cc["@mozilla.org/sound;1"]
                             .createInstance(Ci.nsISound);
 
-              var soundType = this._prefs.getIntPref("privacy.popups.sound_type");
+              var soundType = Services.prefs.getIntPref("privacy.popups.sound_type");
               if (soundType == kCustomSound) {
-                var soundUrlSpec = this._prefs.getCharPref("privacy.popups.sound_url");
+                var soundUrlSpec = Services.prefs.getCharPref("privacy.popups.sound_url");
                 var fileHandler = Cc["@mozilla.org/network/protocol;1?name=file"]
                                     .getService(Ci.nsIFileProtocolHandler);
                 var file = fileHandler.getFileFromURLSpec(soundUrlSpec);
                 if (file.exists()) {
                   var soundUrl = fileHandler.newFileURI(file);
                   sound.play(soundUrl);
                   return;
                 }
@@ -1167,17 +1160,17 @@
                               .getService(Ci.nsIIOService);
             var cacheService = Cc["@mozilla.org/network/application-cache-service;1"]
                                  .getService(Ci.nsIApplicationCacheService);
             cacheService.getGroups().forEach(function(aGroup) {
               var uri = ioService.newURI(aGroup);
               if (uri.asciiHost == host)
                 usage += cacheService.getActiveCache(aGroup).usage;
             });
-            var warnQuota = this._prefs.getIntPref("offline-apps.quota.warn");
+            var warnQuota = Services.prefs.getIntPref("offline-apps.quota.warn");
             if (usage < warnQuota * 1024)
               return;
 
             var message = this._stringBundle.formatStringFromName("offlineApps.quota", [host, warnQuota / 1024], 2);
             var priority = this.PRIORITY_WARNING_MEDIUM;
             this.appendNotification(message, "offline-app-usage", null,
                                     priority, null);
             pm.add(aURI, "offline-app",
@@ -1693,31 +1686,31 @@
           ]]>
         </body>
       </method>
 
       <method name="addonInstallDisabled">
         <parameter name="installInfo"/>
         <body>
           <![CDATA[
-            var messageString, buttons;
-            var prefBranch = this._prefs; // used by editPrefs callback
+            var messageString;
+            var buttons;
 
             var notificationName = "addon-install-disabled";
-            if (prefBranch.prefIsLocked("xpinstall.enabled")) {
+            if (Services.prefs.prefIsLocked("xpinstall.enabled")) {
               messageString = this._stringBundle.GetStringFromName("xpinstallDisabledMessageLocked");
               buttons = [];
             } else {
               messageString = this._stringBundle.GetStringFromName("xpinstallDisabledMessage");
               buttons = [{
                 label: this._stringBundle.GetStringFromName("xpinstallDisabledButton"),
                 accessKey: this._stringBundle.GetStringFromName("xpinstallDisabledButton.accesskey"),
                 popup: null,
                 callback: function editPrefs() {
-                  prefBranch.setBoolPref("xpinstall.enabled", true);
+                  Services.prefs.setBoolPref("xpinstall.enabled", true);
                   return false;
                 }
               }];
             }
 
             if (!this.getNotificationWithValue(notificationName)) {
               var priority = this.PRIORITY_WARNING_MEDIUM;
               this.appendNotification(messageString, notificationName,
@@ -1885,35 +1878,33 @@
           ]]>
         </body>
       </method>
       <constructor>
         <![CDATA[
           var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
           ChromeUtils.import("resource://gre/modules/BrowserUtils.jsm");
 
-          var os = Cc["@mozilla.org/observer-service;1"]
-                     .getService(Ci.nsIObserverService);
-          os.addObserver(this, "indexedDB-permissions-prompt");
-          os.addObserver(this, "indexedDB-quota-prompt");
-          os.addObserver(this, "indexedDB-quota-cancel");
-          os.addObserver(this, "addon-install-blocked");
-          os.addObserver(this, "addon-install-complete");
-          os.addObserver(this, "addon-install-disabled");
-          os.addObserver(this, "addon-install-failed");
-          os.addObserver(this, "addon-install-started");
-          os.addObserver(this, "offline-cache-update-completed");
-          os.addObserver(this, "perm-changed");
-          os.addObserver(this, "formsubmit");
-
-          this._prefs.addObserver("plugins.hide_infobar_for_outdated_plugin", this);
-          this._prefs.addObserver("plugins.hide_infobar_for_carbon_failure_plugin", this);
-          this._prefs.addObserver("plugins.hide_infobar_for_missing_plugin", this);
-          this._prefs.addObserver("privacy.popups.showBrowserMessage", this);
-          this._prefs.addObserver("dom.disable_open_during_load", this);
+          Services.obs.addObserver(this, "indexedDB-permissions-prompt");
+          Services.obs.addObserver(this, "indexedDB-quota-prompt");
+          Services.obs.addObserver(this, "indexedDB-quota-cancel");
+          Services.obs.addObserver(this, "addon-install-blocked");
+          Services.obs.addObserver(this, "addon-install-complete");
+          Services.obs.addObserver(this, "addon-install-disabled");
+          Services.obs.addObserver(this, "addon-install-failed");
+          Services.obs.addObserver(this, "addon-install-started");
+          Services.obs.addObserver(this, "offline-cache-update-completed");
+          Services.obs.addObserver(this, "perm-changed");
+          Services.obs.addObserver(this, "formsubmit");
+
+          Services.prefs.addObserver("plugins.hide_infobar_for_outdated_plugin", this);
+          Services.prefs.addObserver("plugins.hide_infobar_for_carbon_failure_plugin", this);
+          Services.prefs.addObserver("plugins.hide_infobar_for_missing_plugin", this);
+          Services.prefs.addObserver("privacy.popups.showBrowserMessage", this);
+          Services.prefs.addObserver("dom.disable_open_during_load", this);
 
           this.addProgressListener();
 
           if ("nsICrashReporter" in Ci)
             ChromeUtils.import("resource://gre/modules/CrashSubmit.jsm", this);
         ]]>
       </constructor>
 
@@ -1935,66 +1926,64 @@
             this.mDestroyed = true;
 
             if (this._addedProgressListener) {
               this.activeBrowser.webProgress.removeProgressListener(this);
               this._addedProgressListener = false;
             }
 
             this._activeBrowser = null;
-            var os = Cc["@mozilla.org/observer-service;1"]
-                                .getService(Ci.nsIObserverService);
             try {
-              os.removeObserver(this, "indexedDB-permissions-prompt");
+              Services.obs.removeObserver(this, "indexedDB-permissions-prompt");
+            } catch (ex) {}
+            try {
+              Services.obs.removeObserver(this, "indexedDB-quota-prompt");
             } catch (ex) {}
             try {
-              os.removeObserver(this, "indexedDB-quota-prompt");
+              Services.obs.removeObserver(this, "indexedDB-quota-cancel");
             } catch (ex) {}
             try {
-              os.removeObserver(this, "indexedDB-quota-cancel");
+              Services.obs.removeObserver(this, "addon-install-blocked");
             } catch (ex) {}
             try {
-              os.removeObserver(this, "addon-install-blocked");
+              Services.obs.removeObserver(this, "addon-install-complete");
             } catch (ex) {}
             try {
-              os.removeObserver(this, "addon-install-complete");
+              Services.obs.removeObserver(this, "addon-install-disabled");
             } catch (ex) {}
             try {
-              os.removeObserver(this, "addon-install-disabled");
-            } catch (ex) {}
-            try {
-              os.removeObserver(this, "addon-install-failed");
+              Services.obs.removeObserver(this, "addon-install-failed");
             } catch (ex) {}
             try {
-              os.removeObserver(this, "addon-install-started");
+              Services.obs.removeObserver(this, "addon-install-started");
             } catch (ex) {}
             try {
-              os.removeObserver(this, "offline-cache-update-completed");
+              Services.obs.removeObserver(this, "offline-cache-update-completed");
             } catch (ex) {}
             try {
-              os.removeObserver(this, "perm-changed");
+              Services.obs.removeObserver(this, "perm-changed");
             } catch (ex) {}
             try {
-              os.removeObserver(this, "formsubmit");
+              Services.obs.removeObserver(this, "formsubmit");
             } catch (ex) {}
 
             try {
-              this._prefs.removeObserver("plugins.hide_infobar_for_outdated_plugin", this);
+              Services.prefs.removeObserver("plugins.hide_infobar_for_outdated_plugin", this);
             } catch (ex) {}
             try {
-              this._prefs.removeObserver("plugins.hide_infobar_for_carbon_failure_plugin", this);
+              Services.prefs.removeObserver("plugins.hide_infobar_for_carbon_failure_plugin", this);
             } catch (ex) {}
             try {
-              this._prefs.removeObserver("plugins.hide_infobar_for_missing_plugin", this);
+              Services.prefs.removeObserver("plugins.hide_infobar_for_missing_plugin", this);
             } catch (ex) {}
             try {
-              this._prefs.removeObserver("privacy.popups.showBrowserMessage", this);
+              Services.prefs.removeObserver("privacy.popups.showBrowserMessage", this);
             } catch (ex) {}
             try {
-              this._prefs.removeObserver("dom.disable_open_during_load", this);
+              Services.prefs.removeObserver("dom.disable_open_during_load", this);
             } catch (ex) {}
           ]]>
         </body>
       </method>
     </implementation>
 
     <handlers>
       <handler event="DOMContentLoaded" phase="capturing">
@@ -2021,17 +2010,17 @@
           } else {
             this.popupCount++;
           }
           this.playSoundForBlockedPopup();
           this.notifyPopupCountChanged();
 
           var tmp = {};
           ChromeUtils.import("resource://gre/modules/PluralForm.jsm", tmp);
-          if (this._prefs.getBoolPref("privacy.popups.showBrowserMessage"))
+          if (Services.prefs.getBoolPref("privacy.popups.showBrowserMessage"))
           {
             var brandShortName = this._brandStringBundle.GetStringFromName("brandShortName");
             var message = this._stringBundle.GetStringFromName("popupWarning.message");
             message = tmp.PluralForm.get(this.popupCount, message)
                                     .replace("#1", brandShortName)
                                     .replace("#2", this.popupCount);
 
             var notification = this.getNotificationWithValue("popup-blocked");
@@ -2193,20 +2182,20 @@
             }
             else { // doPrompt
               status = "please";
               this.getPluginUI(plugin, "submitButton").addEventListener("click",
                 function (event) {
                   if (event.button != 0 || !event.isTrusted)
                     return;
                   this.submitReport(pluginDumpID, browserDumpID, plugin);
-                  this._prefs.setBoolPref("dom.ipc.plugins.reportCrashURL", optInCB.checked);
+                  Services.prefs.setBoolPref("dom.ipc.plugins.reportCrashURL", optInCB.checked);
                 }.bind(this));
                 let optInCB = this.getPluginUI(plugin, "submitURLOptIn");
-                optInCB.checked = this._prefs.getBoolPref("dom.ipc.plugins.reportCrashURL");
+                optInCB.checked = Services.prefs.getBoolPref("dom.ipc.plugins.reportCrashURL");
             }
 
             // If we're showing the link to manually trigger report submission, we'll
             // want to be able to update all the instances of the UI for this crash to
             // show an updated message when a report is submitted.
             if (doPrompt) {
               let observer = {
                 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
@@ -2292,19 +2281,18 @@
           var plugin = event.target;
           // Force a style flush, so that we ensure our binding is attached.
           plugin.clientTop;
 
           function callback() {
             // Notify all windows that an application quit has been requested.
             var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"]
                                .createInstance(Ci.nsISupportsPRBool);
-            var os = Cc["@mozilla.org/observer-service;1"]
-                       .getService(Ci.nsIObserverService);
-            os.notifyObservers(cancelQuit, "quit-application-requested");
+            Services.obs.notifyObservers(cancelQuit,
+                                         "quit-application-requested");
 
             // Something aborted the quit process.
             if (cancelQuit.data)
               return;
 
             var nsIAppStartup = Ci.nsIAppStartup;
             Cc["@mozilla.org/toolkit/app-startup;1"]
               .getService(nsIAppStartup)
@@ -2334,21 +2322,21 @@
           }];
 
           this.pluginUnavailable(plugin, notification, message, buttons, pref);
         ]]>
       </handler>
 
       <handler event="MozApplicationManifest" phase="capturing">
         <![CDATA[
-          if (!this._prefs.getBoolPref("browser.offline-apps.notify"))
+          if (!Services.prefs.getBoolPref("browser.offline-apps.notify"))
             return;
 
           try {
-            if (this._prefs.getBoolPref("offline-apps.allow_by_default"))
+            if (Services.prefs.getBoolPref("offline-apps.allow_by_default"))
               return;
           } catch (e) {
           }
 
           this.offlineAppRequested(event.originalTarget);
         ]]>
       </handler>
 
@@ -2802,27 +2790,26 @@
       </method>
 
       <method name="addonInstallDisabled">
         <parameter name="installInfo"/>
         <body>
           <![CDATA[
             var messageString;
             var action = null;
-            var prefBranch = this._prefs; // used by editPrefs callback
-
-            if (prefBranch.prefIsLocked("xpinstall.enabled"))
+
+            if (Services.prefs.prefIsLocked("xpinstall.enabled"))
               messageString = this._stringBundle.GetStringFromName("xpinstallDisabledMessageLocked");
             else {
               messageString = this._stringBundle.GetStringFromName("xpinstallDisabledMessage");
               action = {
                 label: this._stringBundle.GetStringFromName("xpinstallDisabledButton"),
                 accessKey: this._stringBundle.GetStringFromName("xpinstallDisabledButton.accesskey"),
                 callback: function editPrefs() {
-                  prefBranch.setBoolPref("xpinstall.enabled", true);
+                  Services.prefs.setBoolPref("xpinstall.enabled", true);
                 }
               };
             }
 
             // Make notifications persist a minimum of 30 seconds
             var options = {
               timeout: Date.now() + 30000
             };
--- a/suite/components/downloads/tests/chrome/test_basic_functionality.xul
+++ b/suite/components/downloads/tests/chrome/test_basic_functionality.xul
@@ -241,41 +241,39 @@ function test()
   }
   stmt.finalize();
 
   // See if the DM is already open, and if it is, close it!
   var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
-  var os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
   var testObs = {
     observe: function(aSubject, aTopic, aData)
     {
       if (aTopic != DLMGR_UI_DONE)
         return;
 
       var win = aSubject;
 
       // Now we can run our tests
       for (let t of testFuncs)
         t(win);
 
       win.close();
       dmFile.remove(false);
-      os.removeObserver(testObs, DLMGR_UI_DONE);
+      Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
       SimpleTest.finish();
     }
   };
 
   // Register with the observer service
-  os.addObserver(testObs, DLMGR_UI_DONE);
+  Services.obs.addObserver(testObs, DLMGR_UI_DONE);
 
   // Show the Download Manager UI
   Cc["@mozilla.org/download-manager-ui;1"]
     .getService(Ci.nsISuiteDownloadManagerUI)
     .showManager();
 
   SimpleTest.waitForExplicitFinish();
 }
--- a/suite/components/downloads/tests/chrome/test_delete_key_cancels.xul
+++ b/suite/components/downloads/tests/chrome/test_delete_key_cancels.xul
@@ -158,18 +158,16 @@ function test()
   // First, we clear out the database
   dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
 
   // See if the DM is already open, and if it is, close it!
   var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
-  var os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
   var testObs = {
     observe: function(aSubject, aTopic, aData)
     {
       if (aTopic != DLMGR_UI_DONE)
         return;
 
@@ -179,21 +177,21 @@ function test()
 
   function cancelDL(win) {
       var doc = win.document;
       dm.addListener(new dlObs(win));
 
       addDownload();
       // we need to focus the download as well
       doc.getElementById("downloadTree").view.selection.select(0);
-      os.removeObserver(testObs, DLMGR_UI_DONE);
+      Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
   }
 
   // Register with the observer service
-  os.addObserver(testObs, DLMGR_UI_DONE);
+  Services.obs.addObserver(testObs, DLMGR_UI_DONE);
 
   // Show the Download Manager UI
   Cc["@mozilla.org/download-manager-ui;1"]
     .getService(Ci.nsISuiteDownloadManagerUI)
     .showManager();
 
   SimpleTest.waitForExplicitFinish();
 }
--- a/suite/components/downloads/tests/chrome/test_delete_key_removes.xul
+++ b/suite/components/downloads/tests/chrome/test_delete_key_removes.xul
@@ -134,18 +134,16 @@ function test()
   }
   stmt.finalize();
 
   // See if the DM is already open, and if it is, close it!
   var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
-  var os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
   var testObs = {
     observe: function(aSubject, aTopic, aData)
     {
       if (aTopic != DLMGR_UI_DONE)
         return;
 
@@ -176,22 +174,22 @@ function test()
       }
       finally {
         stmt.reset();
         stmt.finalize();
       }
 
       win.close();
       dmFile.remove(false);
-      os.removeObserver(testObs, DLMGR_UI_DONE);
+      Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
       SimpleTest.finish();
   }
 
   // Register with the observer service
-  os.addObserver(testObs, DLMGR_UI_DONE);
+  Services.obs.addObserver(testObs, DLMGR_UI_DONE);
 
   // Show the Download Manager UI
   Cc["@mozilla.org/download-manager-ui;1"]
     .getService(Ci.nsISuiteDownloadManagerUI)
     .showManager();
 
   SimpleTest.waitForExplicitFinish();
 }
--- a/suite/components/downloads/tests/chrome/test_drag.xul
+++ b/suite/components/downloads/tests/chrome/test_drag.xul
@@ -141,18 +141,16 @@ function test()
   var dm = Cc["@mozilla.org/download-manager;1"]
              .getService(Ci.nsIDownloadManager);
 
   // See if the DM is already open, and if it is, close it!
   var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
-  var os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
   // load files into db
   var db = dm.DBConnection;
 
   var stmt = db.createStatement(
     "INSERT INTO moz_downloads ( name,  source,  target,  state)" +
     "VALUES                    (:name, :source, :target, :state)");
@@ -179,23 +177,23 @@ function test()
       var result = mouseDragStartOnCell(downloadTree, 0, 4, win, dragRealFile);
       is(result, null, "Checking for Real file match");
       result = mouseDragStartOnCell(downloadTree, 1, 4, win, dragMissingFile);
       isnot(result, null, "Drag start did not return item for missing file");
 
       // Done.
       win.close();
       realFile.remove(false);
-      os.removeObserver(testObs, DLMGR_UI_DONE);
+      Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
       SimpleTest.finish();
     }
   };
 
   // Register with the observer service
-  os.addObserver(testObs, DLMGR_UI_DONE);
+  Services.obs.addObserver(testObs, DLMGR_UI_DONE);
 
   // Show the Download Manager UI
   Cc["@mozilla.org/download-manager-ui;1"]
     .getService(Ci.nsISuiteDownloadManagerUI)
     .showManager();
 
   SimpleTest.waitForExplicitFinish();
 }
--- a/suite/components/downloads/tests/chrome/test_removeDownload_updates_ui.xul
+++ b/suite/components/downloads/tests/chrome/test_removeDownload_updates_ui.xul
@@ -94,18 +94,16 @@ function test()
   }
   stmt.finalize();
 
   // See if the DM is already open, and if it is, close it!
   var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
-  var os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
   var testObs = {
     observe: function(aSubject, aTopic, aData)
     {
       if (aTopic != DLMGR_UI_DONE)
         return;
 
@@ -126,23 +124,23 @@ function test()
 
       dm.removeDownload(id);
       var dlTreeView = doc.getElementById("downloadTree").view;
       is(dlTreeView.rowCount, 0,
          "The download was properly removed");
 
       win.close();
       dmFile.remove(false);
-      os.removeObserver(testObs, DLMGR_UI_DONE);
+      Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
       SimpleTest.finish();
     }
   }
 
   // Register with the observer service
-  os.addObserver(testObs, DLMGR_UI_DONE);
+  Services.obs.addObserver(testObs, DLMGR_UI_DONE);
 
   // Show the Download Manager UI
   Cc["@mozilla.org/download-manager-ui;1"]
     .getService(Ci.nsISuiteDownloadManagerUI)
     .showManager();
 
   SimpleTest.waitForExplicitFinish();
 }
--- a/suite/components/downloads/tests/chrome/test_search_keys.xul
+++ b/suite/components/downloads/tests/chrome/test_search_keys.xul
@@ -82,18 +82,16 @@ function test()
   var dm = Cc["@mozilla.org/download-manager;1"]
              .getService(Ci.nsIDownloadManager);
 
   // See if the DM is already open, and if it is, close it!
   var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
-  var os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
   var testObs = {
     observe: function(aSubject, aTopic, aData)
     {
       if (aTopic != DLMGR_UI_DONE)
         return;
 
@@ -102,22 +100,22 @@ function test()
   };
 
   function continueTest(win) {
       // Now we can run our tests
       for (let t of testFuncs)
         t(win);
 
       win.close();
-      os.removeObserver(testObs, DLMGR_UI_DONE);
+      Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
       SimpleTest.finish();
   }
 
   // Register with the observer service
-  os.addObserver(testObs, DLMGR_UI_DONE);
+  Services.obs.addObserver(testObs, DLMGR_UI_DONE);
 
   // Show the Download Manager UI
   Cc["@mozilla.org/download-manager-ui;1"]
     .getService(Ci.nsISuiteDownloadManagerUI)
     .showManager();
 
   SimpleTest.waitForExplicitFinish();
 }
--- a/suite/components/downloads/tests/chrome/test_space_key_pauses_resumes.xul
+++ b/suite/components/downloads/tests/chrome/test_space_key_pauses_resumes.xul
@@ -179,18 +179,16 @@ function test()
   // First, we clear out the database
   dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
 
   // See if the DM is already open, and if it is, close it!
   var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
-  var os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
   var testObs = {
     observe: function(aSubject, aTopic, aData)
     {
       if (aTopic != DLMGR_UI_DONE)
         return;
 
@@ -200,21 +198,21 @@ function test()
 
   function continueTest(win) {
       var doc = win.document;
       dm.addListener(new bug413985obs(win));
 
       addDownload();
       // we need to focus the download as well
       doc.getElementById("downloadTree").view.selection.select(0);
-      os.removeObserver(testObs, DLMGR_UI_DONE);
+      Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
   }
 
   // Register with the observer service
-  os.addObserver(testObs, DLMGR_UI_DONE);
+  Services.obs.addObserver(testObs, DLMGR_UI_DONE);
 
   // Show the Download Manager UI
   Cc["@mozilla.org/download-manager-ui;1"]
     .getService(Ci.nsISuiteDownloadManagerUI)
     .showManager();
 
   SimpleTest.waitForExplicitFinish();
 }
--- a/suite/components/downloads/tests/chrome/test_space_key_retries.xul
+++ b/suite/components/downloads/tests/chrome/test_space_key_retries.xul
@@ -156,18 +156,16 @@ function test()
   // First, we clear out the database
   dm.DBConnection.executeSimpleSQL("DELETE FROM moz_downloads");
 
   // See if the DM is already open, and if it is, close it!
   var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win)
     win.close();
 
-  var os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
   var testObs = {
     observe: function(aSubject, aTopic, aData)
     {
       if (aTopic != DLMGR_UI_DONE)
         return;
 
@@ -177,21 +175,21 @@ function test()
 
   function continueTest(win) {
       var doc = win.document;
       dm.addListener(new dlObs(win));
 
       addDownload();
       // we need to focus the download as well
       doc.getElementById("downloadTree").view.selection.select(0);
-      os.removeObserver(testObs, DLMGR_UI_DONE);
+      Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
   }
 
   // Register with the observer service
-  os.addObserver(testObs, DLMGR_UI_DONE);
+  Services.obs.addObserver(testObs, DLMGR_UI_DONE);
 
   // Show the Download Manager UI
   Cc["@mozilla.org/download-manager-ui;1"]
     .getService(Ci.nsISuiteDownloadManagerUI)
     .showManager();
 
   SimpleTest.waitForExplicitFinish();
 }
--- a/suite/components/downloads/tests/chrome/test_ui_stays_open_on_alert_clickback.xul
+++ b/suite/components/downloads/tests/chrome/test_ui_stays_open_on_alert_clickback.xul
@@ -66,18 +66,16 @@ function test()
 
   var setClose = aVal =>
     Services.prefs.setBoolPref("browser.download.manager.closeWhenDone", aVal);
 
   // Close the UI if necessary
   var win = Services.wm.getMostRecentWindow("Download:Manager");
   if (win) win.close();
 
-  var os = Cc["@mozilla.org/observer-service;1"]
-             .getService(Ci.nsIObserverService);
   const DLMGR_UI_DONE = "download-manager-ui-done";
 
   var testObs = {
     observe: function(aSubject, aTopic, aData)
     {
       if (aTopic != DLMGR_UI_DONE)
         return;
 
@@ -87,23 +85,23 @@ function test()
       //        synchronously in Startup in downloads.js
       // Make sure the window stays open
       var dmui = Cc["@mozilla.org/download-manager-ui;1"]
                    .getService(Ci.nsIDownloadManagerUI);
       ok(dmui.visible, "Download Manager stays open on alert click");
 
       win.close();
       setClose(false);
-      os.removeObserver(testObs, DLMGR_UI_DONE);
+      Services.obs.removeObserver(testObs, DLMGR_UI_DONE);
       SimpleTest.finish();
     }
   };
 
   // Register with the observer service
-  os.addObserver(testObs, DLMGR_UI_DONE);
+  Services.obs.addObserver(testObs, DLMGR_UI_DONE);
 
   // Simulate an alert click with pref set to true
   setClose(true);
   dm.QueryInterface(Ci.nsIObserver)
     .observe(null, "alertclickcallback", null);
 
   SimpleTest.waitForExplicitFinish();
 }
--- a/suite/components/places/nsPlacesAutoComplete.js
+++ b/suite/components/places/nsPlacesAutoComplete.js
@@ -455,20 +455,17 @@ function nsPlacesAutoComplete()
   // load preferences
   this._prefs = Cc["@mozilla.org/preferences-service;1"].
                 getService(Ci.nsIPrefService).
                 getBranch(kBrowserUrlbarBranch);
   this._syncEnabledPref();
   this._loadPrefs(true);
 
   // register observers
-  this._os = Cc["@mozilla.org/observer-service;1"].
-              getService(Ci.nsIObserverService);
-  this._os.addObserver(this, kTopicShutdown);
-
+  Services.obs.addObserver(this, kTopicShutdown);
 }
 
 nsPlacesAutoComplete.prototype = {
   //////////////////////////////////////////////////////////////////////////////
   //// nsIAutoCompleteSearch
 
   startSearch: function PAC_startSearch(aSearchString, aSearchParam,
                                         aPreviousResult, aListener)
@@ -650,17 +647,17 @@ nsPlacesAutoComplete.prototype = {
   },
 
   //////////////////////////////////////////////////////////////////////////////
   //// nsIObserver
 
   observe: function PAC_observe(aSubject, aTopic, aData)
   {
     if (aTopic == kTopicShutdown) {
-      this._os.removeObserver(this, kTopicShutdown);
+      Services.obs.removeObserver(this, kTopicShutdown);
 
       // Remove our preference observer.
       this._prefs.removeObserver("", this);
       delete this._prefs;
 
       // Finalize the statements that we have used.
       let stmts = [
         "_defaultQuery",
--- a/suite/components/places/tests/unit/test_browserGlue_prefs.js
+++ b/suite/components/places/tests/unit/test_browserGlue_prefs.js
@@ -17,19 +17,16 @@ var bg = Cc["@mozilla.org/suite/suiteglu
          getService(Ci.nsISuiteGlue);
 */
 
 // Initialize Places through Bookmarks Service.
 var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
          getService(Ci.nsINavBookmarksService);
 
 // Get other services.
-var os = Cc["@mozilla.org/observer-service;1"].
-         getService(Ci.nsIObserverService);
-
 const PREF_IMPORT_BOOKMARKS_HTML = "browser.places.importBookmarksHTML";
 const PREF_RESTORE_DEFAULT_BOOKMARKS = "browser.bookmarks.restore_default_bookmarks";
 const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
 const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML";
 
 function waitForImportAndSmartBookmarks(aCallback) {
   Services.obs.addObserver(function waitImport() {
     Services.obs.removeObserver(waitImport, "bookmarks-restore-success");
@@ -229,20 +226,20 @@ function finish_test() {
   do_test_finished();
 }
 var testIndex = 0;
 function next_test() {
   // Clean up database from all bookmarks.
   remove_all_bookmarks();
   // nsSuiteGlue stops observing topics after first notification,
   // so we add back the observer to test additional runs.
-  os.addObserver(bg.QueryInterface(Ci.nsIObserver),
-                 PlacesUtils.TOPIC_INIT_COMPLETE);
-  os.addObserver(bg.QueryInterface(Ci.nsIObserver),
-                 PlacesUtils.TOPIC_DATABASE_LOCKED);
+  Services.obs.addObserver(bg.QueryInterface(Ci.nsIObserver),
+                           PlacesUtils.TOPIC_INIT_COMPLETE);
+  Services.obs.addObserver(bg.QueryInterface(Ci.nsIObserver),
+                           PlacesUtils.TOPIC_DATABASE_LOCKED);
   // Execute next test.
   let test = tests.shift();
   print("\nTEST " + (++testIndex) + ": " + test.description);
   test.exec();
 }
 function run_test() {
   // Bug 539067: disabled due to random failures and timeouts.
   return;
--- a/suite/components/places/tests/unit/test_browserGlue_shutdown.js
+++ b/suite/components/places/tests/unit/test_browserGlue_shutdown.js
@@ -12,63 +12,60 @@
 // Initialize nsSuiteGlue after Places.
 var bg = Cc["@mozilla.org/suite/suiteglue;1"].
          getService(Ci.nsISuiteGlue);
 
 // Initialize Places through Bookmarks Service.
 var bs = PlacesUtils.bookmarks;
 
 // Get other services.
-var ps = Services.prefs;
-var os = Services.obs;
-
 const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML";
 
 var tests = [];
 
 //------------------------------------------------------------------------------
 
 tests.push({
   description: "Export to bookmarks.html if autoExportHTML is true.",
   exec: function() {
     // Sanity check: we should have bookmarks on the toolbar.
     do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0);
 
     // Set preferences.
-    ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
+    Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML);
 
     // Force nsSuiteGlue::_shutdownPlaces().
     bg.QueryInterface(Ci.nsIObserver).observe(null,
                                               PlacesUtils.TOPIC_SHUTDOWN,
                                               null);
 
     // Check bookmarks.html has been created.
     check_bookmarks_html();
     // Check JSON backup has been created.
     check_JSON_backup();
 
     // Check preferences have not been reverted.
-    do_check_true(ps.getBoolPref(PREF_AUTO_EXPORT_HTML));
+    do_check_true(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));
     // Reset preferences.
-    ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
+    Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
 
     next_test();
   }
 });
 
 //------------------------------------------------------------------------------
 
 tests.push({
   description: "Export to bookmarks.html if autoExportHTML is true and a bookmarks.html exists.",
   exec: function() {
     // Sanity check: we should have bookmarks on the toolbar.
     do_check_true(bs.getIdForItemAt(bs.toolbarFolder, 0) > 0);
 
     // Set preferences.
-    ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
+    Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
 
     // Create a bookmarks.html in the profile.
     let profileBookmarksHTMLFile = create_bookmarks_html("bookmarks.glue.html");
     // Get file lastModified and size.
     let lastMod = profileBookmarksHTMLFile.lastModifiedTime;
     let fileSize = profileBookmarksHTMLFile.fileSize;
 
     // Force nsSuiteGlue::_shutdownPlaces().
@@ -78,19 +75,19 @@ tests.push({
 
     // Check a new bookmarks.html has been created.
     let profileBookmarksHTMLFile = check_bookmarks_html();
     //XXX not working on Linux unit boxes. Could be filestats caching issue.
     //do_check_true(profileBookmarksHTMLFile.lastModifiedTime > lastMod);
     do_check_neq(profileBookmarksHTMLFile.fileSize, fileSize);
 
     // Check preferences have not been reverted.
-    do_check_true(ps.getBoolPref(PREF_AUTO_EXPORT_HTML));
+    do_check_true(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));
     // Reset preferences.
-    ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
+    Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
 
     next_test();
   }
 });
 
 //------------------------------------------------------------------------------
 
 tests.push({
--- a/suite/modules/Sanitizer.jsm
+++ b/suite/modules/Sanitizer.jsm
@@ -189,19 +189,17 @@ var Sanitizer = {
         const {PlacesUtils} = ChromeUtils.import("resource://gre/modules/PlacesUtils.jsm");
 
         // use try/catch for everything but the last task so we clear as much as possible
         try {
           PlacesUtils.history.clear();
         } catch(ex) {}
 
         try {
-          var os = Cc["@mozilla.org/observer-service;1"]
-                     .getService(Ci.nsIObserverService);
-          os.notifyObservers(null, "browser:purge-session-history");
+          Services.obs.notifyObservers(null, "browser:purge-session-history");
         } catch(ex) {}
       },
 
         // bug 347231: Always allow clearing history due to dependencies on
         // the browser:purge-session-history notification. (like error console)
       canClear: true
     },