Bug 1467919 - Don't initialize PushService unless dom.push.enabled is true r=lina
MozReview-Commit-ID: JfQUHf1JCRb
--- a/dom/push/PushComponents.js
+++ b/dom/push/PushComponents.js
@@ -11,20 +11,24 @@
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
var isParent = Services.appinfo.processType === Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
// The default Push service implementation.
XPCOMUtils.defineLazyGetter(this, "PushService", function() {
- const {PushService} = ChromeUtils.import("resource://gre/modules/PushService.jsm",
- {});
- PushService.init();
- return PushService;
+ if (Services.prefs.getBoolPref("dom.push.enabled")) {
+ const {PushService} = ChromeUtils.import("resource://gre/modules/PushService.jsm",
+ {});
+ PushService.init();
+ return PushService;
+ }
+
+ throw Cr.NS_ERROR_NOT_AVAILABLE;
});
// Observer notification topics for push messages and subscription status
// changes. These are duplicated and used in `nsIPushNotifier`. They're exposed
// on `nsIPushService` so that JS callers only need to import this service.
const OBSERVER_TOPIC_PUSH = "push-message";
const OBSERVER_TOPIC_SUBSCRIPTION_CHANGE = "push-subscription-change";
const OBSERVER_TOPIC_SUBSCRIPTION_MODIFIED = "push-subscription-modified";
@@ -246,17 +250,17 @@ Object.assign(PushServiceParent.prototyp
data.systemRecord = principal.isSystemPrincipal;
data.originAttributes =
ChromeUtils.originAttributesToSuffix(principal.originAttributes);
return data;
},
- _handleRequest(name, principal, data) {
+ async _handleRequest(name, principal, data) {
if (name == "Push:Clear") {
return this.service.clear(data);
}
let pageRecord;
try {
pageRecord = this._toPageRecord(principal, data);
} catch (e) {