Bug 1467919 - Don't initialize PushService unless dom.push.enabled is true r=lina draft
authorJames Willcox <snorp@snorp.net>
Fri, 08 Jun 2018 16:36:40 -0500
changeset 811563 3d3ad864aca3f182a13416e6881b060a91ecb28f
parent 811562 bacbdfc1434d0531e808167a243ba65dc52963db
child 811564 8fde3073308dd503804f3b09115331d2fbc67004
child 812648 57b191cdd36dc4aa7a63a792e3f3e03ee9ccfb92
child 812657 256f2a069f713f011572491fb095202b8762f50c
push id114352
push userbmo:snorp@snorp.net
push dateWed, 27 Jun 2018 20:49:37 +0000
reviewerslina
bugs1467919
milestone63.0a1
Bug 1467919 - Don't initialize PushService unless dom.push.enabled is true r=lina MozReview-Commit-ID: JfQUHf1JCRb
dom/push/PushComponents.js
--- 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) {