Bug 1467919 - Don't initialize PushService unless dom.push.enabled is true r=lina a=lizzard
authorJames Willcox <snorp@snorp.net>
Fri, 08 Jun 2018 16:36:40 -0500
changeset 477844 2d9b44bd2d74fbb8f64d86b666e05bb08fa04a6b
parent 477843 db0c2c7b36318f970b417373d611ad9971c9bf98
child 477845 3c8ab5a011e3e53fe125693ce8922314ffcf7a8b
push id9444
push userarchaeopteryx@coole-files.de
push dateSat, 07 Jul 2018 21:01:06 +0000
treeherdermozilla-beta@3c8ab5a011e3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslina, lizzard
bugs1467919
milestone62.0
Bug 1467919 - Don't initialize PushService unless dom.push.enabled is true r=lina a=lizzard 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) {