Bug 734018 - Don't patch DOMRequestService into Services.jsm, define message managers. r=gavin,fabrice
☠☠ backed out by e46fd6a8cff5 ☠ ☠
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Fri, 06 Apr 2012 17:42:11 -0700
changeset 91210 26adf71d5c6154e94050cc1ec8554e548b3c3657
parent 91209 be20d1f8c8a3c51842fe351ae350ee05ac1ecda5
child 91211 d7a4dfac3acf04d10e68458fb490c3d6c72549e7
push id22425
push usermbrubeck@mozilla.com
push dateMon, 09 Apr 2012 17:06:51 +0000
treeherdermozilla-central@7227004c8893 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin, fabrice
bugs734018
milestone14.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 734018 - Don't patch DOMRequestService into Services.jsm, define message managers. r=gavin,fabrice
dom/base/DOMRequestHelper.jsm
dom/base/Webapps.js
dom/base/Webapps.jsm
dom/contacts/ContactManager.js
dom/contacts/fallback/ContactService.jsm
dom/settings/SettingsManager.js
toolkit/content/Services.jsm
--- a/dom/base/DOMRequestHelper.jsm
+++ b/dom/base/DOMRequestHelper.jsm
@@ -10,24 +10,16 @@ const Cu = Components.utils;
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 let EXPORTED_SYMBOLS = ["DOMRequestIpcHelper"];
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
-XPCOMUtils.defineLazyGetter(Services, "rs", function() {
-  return Cc["@mozilla.org/dom/dom-request-service;1"].getService(Ci.nsIDOMRequestService);
-});
-
-XPCOMUtils.defineLazyGetter(this, "cpmm", function() {
-  return Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager);
-});
-
 function DOMRequestIpcHelper() {
 }
 
 DOMRequestIpcHelper.prototype = {
   getRequestId: function(aRequest) {
     let id = "id" + this._getRandomId();
     this._requests[id] = aRequest;
     return id;
@@ -57,32 +49,32 @@ DOMRequestIpcHelper.prototype = {
 
   observe: function(aSubject, aTopic, aData) {
     let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
     if (wId == this.innerWindowID) {
       Services.obs.removeObserver(this, "inner-window-destroyed");
       this._requests = [];
       this._window = null;
       this._messages.forEach((function(msgName) {
-        cpmm.removeMessageListener(msgName, this);
+        Services.cpmm.removeMessageListener(msgName, this);
       }).bind(this));
       if(this.uninit)
         this.uninit();
     }
   },
 
   initHelper: function(aWindow, aMessages) {
     this._messages = aMessages;
     this._requests = [];
     this._window = aWindow;
     let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
     this.innerWindowID = util.currentInnerWindowID;
     this._id = this._getRandomId();
     Services.obs.addObserver(this, "inner-window-destroyed", false);
     this._messages.forEach((function(msgName) {
-      cpmm.addMessageListener(msgName, this);
+      Services.cpmm.addMessageListener(msgName, this);
     }).bind(this));
   },
 
   createRequest: function() {
-    return Services.rs.createRequest(this._window);
+    return Services.DOMRequest.createRequest(this._window);
   }
 }
--- a/dom/base/Webapps.js
+++ b/dom/base/Webapps.js
@@ -6,24 +6,16 @@ const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cr = Components.results;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
 
-XPCOMUtils.defineLazyGetter(Services, "rs", function() {
-  return Cc["@mozilla.org/dom/dom-request-service;1"].getService(Ci.nsIDOMRequestService);
-});
-
-XPCOMUtils.defineLazyGetter(this, "cpmm", function() {
-  return Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager);
-});
-
 function convertAppsArray(aApps, aWindow) {
   let apps = new Array();
   for (let i = 0; i < aApps.length; i++) {
     let app = aApps[i];
     apps.push(new WebappsApplication(aWindow, app.origin, app.manifest, app.manifestURL, 
                                      app.receipts, app.installOrigin, app.installTime));
   }
   return apps;
@@ -59,37 +51,37 @@ WebappsRegistry.prototype = {
     if (msg.oid != this._id)
       return
     let req = this.getRequest(msg.requestID);
     if (!req)
       return;
     let app = msg.app;
     switch (aMessage.name) {
       case "Webapps:Install:Return:OK":
-        Services.rs.fireSuccess(req, new WebappsApplication(this._window, app.origin, app.manifest, app.manifestURL, app.receipts,
+        Services.DOMRequest.fireSuccess(req, new WebappsApplication(this._window, app.origin, app.manifest, app.manifestURL, app.receipts,
                                                 app.installOrigin, app.installTime));
         break;
       case "Webapps:Install:Return:KO":
-        Services.rs.fireError(req, "DENIED");
+        Services.DOMRequest.fireError(req, "DENIED");
         break;
       case "Webapps:GetSelf:Return:OK":
         if (msg.apps.length) {
           app = msg.apps[0];
-          Services.rs.fireSuccess(req, new WebappsApplication(this._window, app.origin, app.manifest, app.manifestURL, app.receipts,
+          Services.DOMRequest.fireSuccess(req, new WebappsApplication(this._window, app.origin, app.manifest, app.manifestURL, app.receipts,
                                                   app.installOrigin, app.installTime));
         } else {
-          Services.rs.fireSuccess(req, null);
+          Services.DOMRequest.fireSuccess(req, null);
         }
         break;
       case "Webapps:GetInstalled:Return:OK":
-        Services.rs.fireSuccess(req, convertAppsArray(msg.apps, this._window));
+        Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
         break;
       case "Webapps:GetSelf:Return:KO":
       case "Webapps:GetInstalled:Return:KO":
-        Services.rs.fireError(req, "ERROR");
+        Services.DOMRequest.fireError(req, "ERROR");
         break;
     }
     this.removeRequest(msg.requestID);
   },
 
   _getOrigin: function(aURL) {
     let uri = Services.io.newURI(aURL, null, null);
     return uri.prePath; 
@@ -104,58 +96,58 @@ WebappsRegistry.prototype = {
     xhr.open("GET", aURL, true);
 
     xhr.addEventListener("load", (function() {
       if (xhr.status == 200) {
         try {
           let installOrigin = this._getOrigin(this._window.location.href);
           let manifest = JSON.parse(xhr.responseText, installOrigin);
           if (!this.checkManifest(manifest, installOrigin)) {
-            Services.rs.fireError(request, "INVALID_MANIFEST");
+            Services.DOMRequest.fireError(request, "INVALID_MANIFEST");
           } else {
             let receipts = (aParams && aParams.receipts && Array.isArray(aParams.receipts)) ? aParams.receipts : [];
-            cpmm.sendAsyncMessage("Webapps:Install", { app: { installOrigin: installOrigin,
-                                                              origin: this._getOrigin(aURL),
-                                                              manifestURL: aURL,
-                                                              manifest: manifest,
-                                                              receipts: receipts },
-                                                              from: this._window.location.href,
-                                                              oid: this._id,
-                                                              requestID: requestID });
+            Services.cpmm.sendAsyncMessage("Webapps:Install", { app: { installOrigin: installOrigin,
+                                                                       origin: this._getOrigin(aURL),
+                                                                       manifestURL: aURL,
+                                                                       manifest: manifest,
+                                                                       receipts: receipts },
+                                                                from: this._window.location.href,
+                                                                oid: this._id,
+                                                                requestID: requestID });
           }
         } catch(e) {
-          Services.rs.fireError(request, "MANIFEST_PARSE_ERROR");
+          Services.DOMRequest.fireError(request, "MANIFEST_PARSE_ERROR");
         }
       }
       else {
-        Services.rs.fireError(request, "MANIFEST_URL_ERROR");
+        Services.DOMRequest.fireError(request, "MANIFEST_URL_ERROR");
       }      
     }).bind(this), false);
 
     xhr.addEventListener("error", (function() {
-      Services.rs.fireError(request, "NETWORK_ERROR");
+      Services.DOMRequest.fireError(request, "NETWORK_ERROR");
     }).bind(this), false);
 
     xhr.send(null);
     return request;
   },
 
   getSelf: function() {
     let request = this.createRequest();
-    cpmm.sendAsyncMessage("Webapps:GetSelf", { origin: this._getOrigin(this._window.location.href),
-                                               oid: this._id,
-                                               requestID: this.getRequestId(request) });
+    Services.cpmm.sendAsyncMessage("Webapps:GetSelf", { origin: this._getOrigin(this._window.location.href),
+                                                        oid: this._id,
+                                                        requestID: this.getRequestId(request) });
     return request;
   },
 
   getInstalled: function() {
     let request = this.createRequest();
-    cpmm.sendAsyncMessage("Webapps:GetInstalled", { origin: this._getOrigin(this._window.location.href),
-                                                    oid: this._id,
-                                                    requestID: this.getRequestId(request) });
+    Services.cpmm.sendAsyncMessage("Webapps:GetInstalled", { origin: this._getOrigin(this._window.location.href),
+                                                             oid: this._id,
+                                                             requestID: this.getRequestId(request) });
     return request;
   },
 
   get mgmt() {
     if (!this._mgmt)
       this._mgmt = new WebappsApplicationMgmt(this._window);
     return this._mgmt;
   },
@@ -230,42 +222,42 @@ WebappsApplication.prototype = {
   },
   
   get installTime() {
     return this._installTime;
   },
 
   launch: function(aStartPoint) {
     let request = this.createRequest();
-    cpmm.sendAsyncMessage("Webapps:Launch", { origin: this._origin,
-                                              startPoint: aStartPoint,
-                                              oid: this._id,
-                                              requestID: this.getRequestId(request) });
+    Services.cpmm.sendAsyncMessage("Webapps:Launch", { origin: this._origin,
+                                                       startPoint: aStartPoint,
+                                                       oid: this._id,
+                                                       requestID: this.getRequestId(request) });
     return request;
   },
 
   uninstall: function() {
     let request = this.createRequest();
-    cpmm.sendAsyncMessage("Webapps:Uninstall", { origin: this._origin,
-                                                 oid: this._id,
-                                                 requestID: this.getRequestId(request) });
+    Services.cpmm.sendAsyncMessage("Webapps:Uninstall", { origin: this._origin,
+                                                          oid: this._id,
+                                                          requestID: this.getRequestId(request) });
     return request;
   },
 
   receiveMessage: function(aMessage) {
     var msg = aMessage.json;
     let req = this.getRequest(msg.requestID);
     if (msg.oid != this._id || !req)
       return;
     switch (aMessage.name) {
       case "Webapps:Uninstall:Return:OK":
-        Services.rs.fireSuccess(req, msg.origin);
+        Services.DOMRequest.fireSuccess(req, msg.origin);
         break;
       case "Webapps:Uninstall:Return:KO":
-        Services.rs.fireError(req, msg.origin);
+        Services.DOMRequest.fireError(req, msg.origin);
         break;
     }
     this.removeRequest(msg.requestID);
   },
 
   classID: Components.ID("{723ed303-7757-4fb0-b261-4f78b1f6bd22}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.mozIDOMApplication]),
@@ -303,19 +295,19 @@ WebappsApplicationMgmt.prototype = {
 
   uninit: function() {
     this._oninstall = null;
     this._onuninstall = null;
   },
 
   getAll: function() {
     let request = this.createRequest();
-    cpmm.sendAsyncMessage("Webapps:GetAll", { oid: this._id,
-                                              requestID: this.getRequestId(request),
-                                              hasPrivileges: this.hasPrivileges });
+    Services.cpmm.sendAsyncMessage("Webapps:GetAll", { oid: this._id,
+                                                       requestID: this.getRequestId(request),
+                                                       hasPrivileges: this.hasPrivileges });
     return request;
   },
 
   get oninstall() {
     return this._oninstall;
   },
 
   get onuninstall() {
@@ -341,20 +333,20 @@ WebappsApplicationMgmt.prototype = {
     let req = this.getRequest(msg.requestID);
     // We want Webapps:Install:Return:OK and Webapps:Uninstall:Return:OK to be boradcasted
     // to all instances of mozApps.mgmt
     if (!((msg.oid == this._id && req) 
        || aMessage.name == "Webapps:Install:Return:OK" || aMessage.name == "Webapps:Uninstall:Return:OK"))
       return;
     switch (aMessage.name) {
       case "Webapps:GetAll:Return:OK":
-        Services.rs.fireSuccess(req, convertAppsArray(msg.apps, this._window));
+        Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
         break;
       case "Webapps:GetAll:Return:KO":
-        Services.rs.fireError(req, "DENIED");
+        Services.DOMRequest.fireError(req, "DENIED");
         break;
       case "Webapps:Install:Return:OK":
         if (this._oninstall) {
           let app = msg.app;
           let event = new WebappsApplicationEvent(new WebappsApplication(this._window, app.origin, app.manifest, app.manifestURL, app.receipts,
                                                 app.installOrigin, app.installTime));
           this._oninstall.handleEvent(event);
         }
--- a/dom/base/Webapps.jsm
+++ b/dom/base/Webapps.jsm
@@ -12,37 +12,33 @@ Cu.import("resource://gre/modules/XPCOMU
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "NetUtil", function() {
   Cu.import("resource://gre/modules/NetUtil.jsm");
   return NetUtil;
 });
 
-XPCOMUtils.defineLazyGetter(this, "ppmm", function() {
-  return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager);
-});
-
 #ifdef MOZ_WIDGET_GONK
   const DIRECTORY_NAME = "webappsDir";
 #else
   const DIRECTORY_NAME = "ProfD";
 #endif
 
 let DOMApplicationRegistry = {
   appsFile: null,
   webapps: { },
 
   init: function() {
     this.messages = ["Webapps:Install", "Webapps:Uninstall",
                     "Webapps:GetSelf", "Webapps:GetInstalled",
                     "Webapps:Launch", "Webapps:GetAll"];
 
     this.messages.forEach((function(msgName) {
-      ppmm.addMessageListener(msgName, this);
+      Services.ppmm.addMessageListener(msgName, this);
     }).bind(this));
 
     Services.obs.addObserver(this, "xpcom-shutdown", false);
 
     let appsDir = FileUtils.getDir(DIRECTORY_NAME, ["webapps"], true, true);
     this.appsFile = FileUtils.getFile(DIRECTORY_NAME, ["webapps", "webapps.json"], true);
 
     if (!this.appsFile.exists())
@@ -57,20 +53,19 @@ let DOMApplicationRegistry = {
                            Ci.nsIPermissionManager.ALLOW_ACTION);
       });
     } catch(e) { }
   },
 
   observe: function(aSubject, aTopic, aData) {
     if (aTopic == "xpcom-shutdown") {
       this.messages.forEach((function(msgName) {
-        ppmm.removeMessageListener(msgName, this);
+        Services.ppmm.removeMessageListener(msgName, this);
       }).bind(this));
       Services.obs.removeObserver(this, "xpcom-shutdown");
-      ppmm = null;
     }
   },
 
   _loadJSONAsync: function(aFile, aCallback) {
     try {
       let channel = NetUtil.newChannel(aFile);
       channel.contentType = "application/json";
       NetUtil.asyncFetch(channel, function(aStream, aResult) {
@@ -120,17 +115,17 @@ let DOMApplicationRegistry = {
         break;
       case "Webapps:GetInstalled":
         this.getInstalled(msg);
         break;
       case "Webapps:GetAll":
         if (msg.hasPrivileges)
           this.getAll(msg);
         else
-          ppmm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg);
+          Services.ppmm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg);
         break;
     }
   },
 
   _writeFile: function ss_writeFile(aFile, aData, aCallbak) {
     // Initialize the file output stream.
     let ostream = FileUtils.openSafeFileOutputStream(aFile);
 
@@ -154,17 +149,17 @@ let DOMApplicationRegistry = {
       receipts: aApp.receipts,
       installTime: aApp.installTime,
       manifestURL: aApp.manifestURL
     };
     return clone;
   },
 
   denyInstall: function(aData) {
-    ppmm.sendAsyncMessage("Webapps:Install:Return:KO", aData);
+    Services.ppmm.sendAsyncMessage("Webapps:Install:Return:KO", aData);
   },
 
   confirmInstall: function(aData, aFromSync) {
     let app = aData.app;
     let id = app.syncId || this._appId(app.origin);
 
     // install an application again is considered as an update
     if (id) {
@@ -187,17 +182,17 @@ let DOMApplicationRegistry = {
 
     this.webapps[id] = this._cloneAppObject(app);
     delete this.webapps[id].manifest;
     this.webapps[id].installTime = (new Date()).getTime()
 
     
     if (!aFromSync)
       this._saveApps((function() {
-        ppmm.sendAsyncMessage("Webapps:Install:Return:OK", aData);
+        Services.ppmm.sendAsyncMessage("Webapps:Install:Return:OK", aData);
         Services.obs.notifyObservers(this, "webapps-sync-install", id);
       }).bind(this));
   },
 
   _appId: function(aURI) {
     for (let id in this.webapps) {
       if (this.webapps[id].origin == aURI)
         return id;
@@ -241,40 +236,40 @@ let DOMApplicationRegistry = {
         found = true;
         delete this.webapps[id];
         let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
         try {
           dir.remove(true);
         } catch (e) {
         }
         this._saveApps((function() {
-          ppmm.sendAsyncMessage("Webapps:Uninstall:Return:OK", aData);
+          Services.ppmm.sendAsyncMessage("Webapps:Uninstall:Return:OK", aData);
           Services.obs.notifyObservers(this, "webapps-sync-uninstall", id);
         }).bind(this));
       }
     }
     if (!found)
-      ppmm.sendAsyncMessage("Webapps:Uninstall:Return:KO", aData);
+      Services.ppmm.sendAsyncMessage("Webapps:Uninstall:Return:KO", aData);
   },
 
   getSelf: function(aData) {
     aData.apps = [];
     let tmp = [];
     let id = this._appId(aData.origin);
 
     if (id) {
       let app = this._cloneAppObject(this.webapps[id]);
       aData.apps.push(app);
       tmp.push({ id: id });
     }
 
     this._readManifests(tmp, (function(aResult) {
       for (let i = 0; i < aResult.length; i++)
         aData.apps[i].manifest = aResult[i].manifest;
-      ppmm.sendAsyncMessage("Webapps:GetSelf:Return:OK", aData);
+      Services.ppmm.sendAsyncMessage("Webapps:GetSelf:Return:OK", aData);
     }).bind(this));
   },
 
   getInstalled: function(aData) {
     aData.apps = [];
     let tmp = [];
     let id = this._appId(aData.origin);
 
@@ -283,34 +278,34 @@ let DOMApplicationRegistry = {
         aData.apps.push(this._cloneAppObject(this.webapps[id]));
         tmp.push({ id: id });
       }
     }
 
     this._readManifests(tmp, (function(aResult) {
       for (let i = 0; i < aResult.length; i++)
         aData.apps[i].manifest = aResult[i].manifest;
-      ppmm.sendAsyncMessage("Webapps:GetInstalled:Return:OK", aData);
+      Services.ppmm.sendAsyncMessage("Webapps:GetInstalled:Return:OK", aData);
     }).bind(this));
   },
 
   getAll: function(aData) {
     aData.apps = [];
     let tmp = [];
 
     for (id in this.webapps) {
       let app = this._cloneAppObject(this.webapps[id]);
       aData.apps.push(app);
       tmp.push({ id: id });
     }
 
     this._readManifests(tmp, (function(aResult) {
       for (let i = 0; i < aResult.length; i++)
         aData.apps[i].manifest = aResult[i].manifest;
-      ppmm.sendAsyncMessage("Webapps:GetAll:Return:OK", aData);
+      Services.ppmm.sendAsyncMessage("Webapps:GetAll:Return:OK", aData);
     }).bind(this));
   },
 
   getManifestFor: function(aOrigin, aCallback) {
     if (!aCallback)
       return;
 
     let id = this._appId(aOrigin);
@@ -346,26 +341,26 @@ let DOMApplicationRegistry = {
           continue;
         let origin = this.webapps[record.id].origin;
         delete this.webapps[record.id];
         let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", record.id], true, true);
         try {
           dir.remove(true);
         } catch (e) {
         }
-        ppmm.sendAsyncMessage("Webapps:Uninstall:Return:OK", { origin: origin });
+        Services.ppmm.sendAsyncMessage("Webapps:Uninstall:Return:OK", { origin: origin });
       } else {
         if (!!this.webapps[record.id]) {
           this.webapps[record.id] = record.value;
           delete this.webapps[record.id].manifest;
         }
         else {
           let data = { app: record.value };
           this.confirmInstall(data, true);
-          ppmm.sendAsyncMessage("Webapps:Install:Return:OK", data);
+          Services.ppmm.sendAsyncMessage("Webapps:Install:Return:OK", data);
         }
       }
     }
     this._saveApps(aCallback);
   },
 
   /*
    * May be removed once sync API change
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -14,24 +14,16 @@ else
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
 
-XPCOMUtils.defineLazyGetter(Services, "DOMRequest", function() {
-  return Cc["@mozilla.org/dom/dom-request-service;1"].getService(Ci.nsIDOMRequestService);
-});
-
-XPCOMUtils.defineLazyGetter(this, "cpmm", function() {
-  return Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager);
-});
-
 const nsIClassInfo            = Ci.nsIClassInfo;
 const CONTACTPROPERTIES_CID   = Components.ID("{53ed7c20-ceda-11e0-9572-0800200c9a66}");
 const nsIDOMContactProperties = Ci.nsIDOMContactProperties;
 
 // ContactProperties is not directly instantiated. It is used as interface.
 
 ContactProperties.prototype = {
 
@@ -220,30 +212,32 @@ ContactManager.prototype = {
         // for example {25c00f01-90e5-c545-b4d4-21E2ddbab9e0} becomes
         // 25c00f0190e5c545b4d421E2ddbab9e0
         aContact.id = this._getRandomId().replace('-', '').replace('{', '').replace('}', '');
       }
 
       this._setMetaData(newContact, aContact);
       debug("send: " + JSON.stringify(newContact));
       request = this.createRequest();
-      cpmm.sendAsyncMessage("Contact:Save", {contact: newContact,
-                                             requestID: this.getRequestId(request)});
+      Services.cpmm.sendAsyncMessage("Contact:Save",
+                                     {contact: newContact,
+                                      requestID: this.getRequestId(request)});
       return request;
     } else {
       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     }
   },
 
   remove: function removeContact(aRecord) {
     let request;
     if (this.hasPrivileges) {
       request = this.createRequest();
-      cpmm.sendAsyncMessage("Contact:Remove", {id: aRecord.id,
-                                               requestID: this.getRequestId(request)});
+      Services.cpmm.sendAsyncMessage("Contact:Remove",
+                                     {id: aRecord.id,
+                                      requestID: this.getRequestId(request)});
       return request;
     } else {
       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     }
   },
 
   _setMetaData: function(aNewContact, aRecord) {
     aNewContact.id = aRecord.id;
@@ -298,30 +292,32 @@ ContactManager.prototype = {
     }
     this.removeRequest(msg.requestID);
   },
 
   find: function(aOptions) {
     let request;
     if (this.hasPrivileges) {
       request = this.createRequest();
-      cpmm.sendAsyncMessage("Contacts:Find", {findOptions: aOptions, 
-                                              requestID: this.getRequestId(request)});
+      Services.cpmm.sendAsyncMessage("Contacts:Find",
+                                     {findOptions: aOptions, 
+                                      requestID: this.getRequestId(request)});
       return request;
     } else {
       debug("find not allowed");
       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     }
   },
 
   clear: function() {
     let request;
     if (this.hasPrivileges) {
       request = this.createRequest();
-      cpmm.sendAsyncMessage("Contacts:Clear", {requestID: this.getRequestId(request)});
+      Services.cpmm.sendAsyncMessage("Contacts:Clear",
+                                     {requestID: this.getRequestId(request)});
       return request;
     } else {
       debug("clear not allowed");
       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
     }
   },
 
   init: function(aWindow) {
--- a/dom/contacts/fallback/ContactService.jsm
+++ b/dom/contacts/fallback/ContactService.jsm
@@ -11,32 +11,27 @@ else
   debug = function (s) {}
 
 const Cu = Components.utils; 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 let EXPORTED_SYMBOLS = ["DOMContactManager"];
 
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/ContactDB.jsm");
 
-XPCOMUtils.defineLazyGetter(this, "ppmm", function() {
-  return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIFrameMessageManager);
-});
-
 let myGlobal = this;
 
 let DOMContactManager = {
   init: function() {
     debug("Init");
     this._messages = ["Contacts:Find", "Contacts:Clear", "Contact:Save", "Contact:Remove"];
     this._messages.forEach((function(msgName) {
-      ppmm.addMessageListener(msgName, this);
+      Services.ppmm.addMessageListener(msgName, this);
     }).bind(this));
 
     var idbManager = Components.classes["@mozilla.org/dom/indexeddb/manager;1"].getService(Ci.nsIIndexedDatabaseManager);
     idbManager.initWindowless(myGlobal);
     this._db = new ContactDB(myGlobal);
 
     Services.obs.addObserver(this, "profile-before-change", false);
 
@@ -49,20 +44,19 @@ let DOMContactManager = {
                              Ci.nsIPermissionManager.ALLOW_ACTION);
       });
     } catch(e) { debug(e); }
   },
 
   observe: function(aSubject, aTopic, aData) {
     myGlobal = null;
     this._messages.forEach((function(msgName) {
-      ppmm.removeMessageListener(msgName, this);
+      Services.ppmm.removeMessageListener(msgName, this);
     }).bind(this));
     Services.obs.removeObserver(this, "profile-before-change");
-    ppmm = null;
     this._messages = null;
     if (this._db)
       this._db.close();
   },
 
   receiveMessage: function(aMessage) {
     function sortfunction(a, b){
       let x, y;
@@ -86,30 +80,30 @@ let DOMContactManager = {
             if (msg.findOptions.sortOrder !== 'undefined' && msg.findOptions.sortBy !== 'undefined') {
               debug('sortBy: ' + msg.findOptions.sortBy + ', sortOrder: ' + msg.findOptions.sortOrder );
               result.sort(sortfunction);
               if (msg.findOptions.filterLimit)
                 result = result.slice(0, msg.findOptions.filterLimit);
             }
 
             debug("result:" + JSON.stringify(result));
-            ppmm.sendAsyncMessage("Contacts:Find:Return:OK", {requestID: msg.requestID, contacts: result});
+            Services.ppmm.sendAsyncMessage("Contacts:Find:Return:OK", {requestID: msg.requestID, contacts: result});
           }.bind(this),
-          function(aErrorMsg) { ppmm.sendAsyncMessage("Contacts:Find:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }) }.bind(this), 
+          function(aErrorMsg) { Services.ppmm.sendAsyncMessage("Contacts:Find:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }) }.bind(this), 
           msg.findOptions);
         break;
       case "Contact:Save":
-        this._db.saveContact(msg.contact, function() { ppmm.sendAsyncMessage("Contact:Save:Return:OK", { requestID: msg.requestID }); }.bind(this), 
-                             function(aErrorMsg) { ppmm.sendAsyncMessage("Contact:Save:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }); }.bind(this));
+        this._db.saveContact(msg.contact, function() { Services.ppmm.sendAsyncMessage("Contact:Save:Return:OK", { requestID: msg.requestID }); }.bind(this), 
+                             function(aErrorMsg) { Services.ppmm.sendAsyncMessage("Contact:Save:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }); }.bind(this));
         break;
       case "Contact:Remove":
         this._db.removeContact(msg.id, 
-                               function() { ppmm.sendAsyncMessage("Contact:Remove:Return:OK", { requestID: msg.requestID }); }.bind(this), 
-                               function(aErrorMsg) { ppmm.sendAsyncMessage("Contact:Remove:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }); }.bind(this));
+                               function() { Services.ppmm.sendAsyncMessage("Contact:Remove:Return:OK", { requestID: msg.requestID }); }.bind(this), 
+                               function(aErrorMsg) { Services.ppmm.sendAsyncMessage("Contact:Remove:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }); }.bind(this));
         break;
       case "Contacts:Clear":
-        this._db.clear(function() { ppmm.sendAsyncMessage("Contacts:Clear:Return:OK", { requestID: msg.requestID }); }.bind(this),
-                       function(aErrorMsg) { ppmm.sendAsyncMessage("Contacts:Clear:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }); }.bind(this));
+        this._db.clear(function() { Services.ppmm.sendAsyncMessage("Contacts:Clear:Return:OK", { requestID: msg.requestID }); }.bind(this),
+                       function(aErrorMsg) { Services.ppmm.sendAsyncMessage("Contacts:Clear:Return:KO", { requestID: msg.requestID, errorMsg: aErrorMsg }); }.bind(this));
     }
   }
 }
 
 DOMContactManager.init();
--- a/dom/settings/SettingsManager.js
+++ b/dom/settings/SettingsManager.js
@@ -109,20 +109,16 @@ SettingsDB.prototype = {
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
-XPCOMUtils.defineLazyGetter(Services, "DOMRequest", function() {
-  return Cc["@mozilla.org/dom/dom-request-service;1"].getService(Ci.nsIDOMRequestService);
-});
-
 const nsIClassInfo            = Ci.nsIClassInfo;
 const SETTINGSLOCK_CONTRACTID = "@mozilla.org/settingsLock;1";
 const SETTINGSLOCK_CID        = Components.ID("{ef95ddd0-6308-11e1-b86c-0800200c9a66}");
 const nsIDOMSettingsLock      = Ci.nsIDOMSettingsLock;
 
 function SettingsLock(aSettingsManager)
 {
   this._open = true;
--- a/toolkit/content/Services.jsm
+++ b/toolkit/content/Services.jsm
@@ -88,15 +88,17 @@ let initTable = [
   ["tm", "@mozilla.org/thread-manager;1", "nsIThreadManager"],
   ["urlFormatter", "@mozilla.org/toolkit/URLFormatterService;1", "nsIURLFormatter"],
   ["vc", "@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"],
   ["wm", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"],
   ["ww", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"],
   ["startup", "@mozilla.org/toolkit/app-startup;1", "nsIAppStartup"],
   ["sysinfo", "@mozilla.org/system-info;1", "nsIPropertyBag2"],
   ["clipboard", "@mozilla.org/widget/clipboard;1", "nsIClipboard"],
-  ["DOMRequest", "@mozilla.org/dom/dom-request-service;1", "nsIDOMRequestService"]
+  ["DOMRequest", "@mozilla.org/dom/dom-request-service;1", "nsIDOMRequestService"],
+  ["cpmm", "@mozilla.org/childprocessmessagemanager;1", "nsIFrameMessageManager"],
+  ["ppmm", "@mozilla.org/parentprocessmessagemanager;1", "nsIFrameMessageManager"],
 ];
 
 initTable.forEach(function ([name, contract, intf])
   XPCOMUtils.defineLazyServiceGetter(Services, name, contract, intf));
 
 initTable = undefined;