diff --git a/dom/base/DOMRequestHelper.jsm b/dom/base/DOMRequestHelper.jsm index afff2eb219d..964be76f853 100644 --- a/dom/base/DOMRequestHelper.jsm +++ b/dom/base/DOMRequestHelper.jsm @@ -15,14 +15,6 @@ 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() { } @@ -62,7 +54,7 @@ DOMRequestIpcHelper.prototype = { 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(); @@ -78,11 +70,11 @@ DOMRequestIpcHelper.prototype = { 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); } } diff --git a/dom/base/Webapps.js b/dom/base/Webapps.js index 110d0267af3..d0c485cb130 100644 --- a/dom/base/Webapps.js +++ b/dom/base/Webapps.js @@ -11,14 +11,6 @@ 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++) { @@ -64,27 +56,27 @@ WebappsRegistry.prototype = { 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); @@ -109,29 +101,29 @@ WebappsRegistry.prototype = { 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); @@ -140,17 +132,17 @@ WebappsRegistry.prototype = { 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; }, @@ -235,18 +227,18 @@ WebappsApplication.prototype = { 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; }, @@ -257,10 +249,10 @@ WebappsApplication.prototype = { 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); @@ -308,9 +300,9 @@ WebappsApplicationMgmt.prototype = { 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; }, @@ -346,10 +338,10 @@ WebappsApplicationMgmt.prototype = { 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) { diff --git a/dom/base/Webapps.jsm b/dom/base/Webapps.jsm index 5f3c93fe731..fd4f2703670 100644 --- a/dom/base/Webapps.jsm +++ b/dom/base/Webapps.jsm @@ -17,10 +17,6 @@ XPCOMUtils.defineLazyGetter(this, "NetUtil", function() { 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 @@ -37,7 +33,7 @@ let DOMApplicationRegistry = { "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); @@ -62,10 +58,9 @@ let DOMApplicationRegistry = { 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; } }, @@ -125,7 +120,7 @@ let DOMApplicationRegistry = { if (msg.hasPrivileges) this.getAll(msg); else - ppmm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg); + Services.ppmm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg); break; } }, @@ -159,7 +154,7 @@ let DOMApplicationRegistry = { }, denyInstall: function(aData) { - ppmm.sendAsyncMessage("Webapps:Install:Return:KO", aData); + Services.ppmm.sendAsyncMessage("Webapps:Install:Return:KO", aData); }, confirmInstall: function(aData, aFromSync) { @@ -192,7 +187,7 @@ let DOMApplicationRegistry = { 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)); }, @@ -246,13 +241,13 @@ let DOMApplicationRegistry = { } 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) { @@ -269,7 +264,7 @@ let DOMApplicationRegistry = { 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)); }, @@ -288,7 +283,7 @@ let DOMApplicationRegistry = { 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)); }, @@ -305,7 +300,7 @@ let DOMApplicationRegistry = { 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)); }, @@ -351,7 +346,7 @@ let DOMApplicationRegistry = { 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; @@ -360,7 +355,7 @@ let DOMApplicationRegistry = { 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); } } } diff --git a/dom/contacts/ContactManager.js b/dom/contacts/ContactManager.js index cd7efd9938a..3039628ed2b 100644 --- a/dom/contacts/ContactManager.js +++ b/dom/contacts/ContactManager.js @@ -19,14 +19,6 @@ 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; @@ -225,8 +217,9 @@ ContactManager.prototype = { 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; @@ -237,8 +230,9 @@ ContactManager.prototype = { 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; @@ -303,8 +297,9 @@ ContactManager.prototype = { 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"); @@ -316,7 +311,8 @@ ContactManager.prototype = { 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"); diff --git a/dom/contacts/fallback/ContactService.jsm b/dom/contacts/fallback/ContactService.jsm index 5eb2b6c6821..6649c7c0a37 100644 --- a/dom/contacts/fallback/ContactService.jsm +++ b/dom/contacts/fallback/ContactService.jsm @@ -16,14 +16,9 @@ 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 = { @@ -31,7 +26,7 @@ let DOMContactManager = { 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); @@ -54,10 +49,9 @@ let DOMContactManager = { 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(); @@ -91,23 +85,23 @@ let DOMContactManager = { } 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)); } } } diff --git a/dom/settings/SettingsManager.js b/dom/settings/SettingsManager.js index c5f1909d7a5..50b8e1eace8 100644 --- a/dom/settings/SettingsManager.js +++ b/dom/settings/SettingsManager.js @@ -114,10 +114,6 @@ 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}"); diff --git a/toolkit/content/Services.jsm b/toolkit/content/Services.jsm index a4ae3c86c54..68d0d179fc9 100644 --- a/toolkit/content/Services.jsm +++ b/toolkit/content/Services.jsm @@ -93,7 +93,9 @@ let initTable = [ ["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])