Bug 1188937 - Only add Push API interfaces to build if the feature is enabled. r=kitcambridge
authorNikhil Marathe <nsm.nikhil@gmail.com>
Wed, 29 Jul 2015 09:12:51 -0700
changeset 255521 9a5f4793b17fb8df0f1b3b2d5bee606968b270b4
parent 255520 f251b383631427a9d2dbc1c4bb2b5b3148c9c19a
child 255522 a110782901107a9c9d7c9a38120554df3a71336b
push id29149
push usercbook@mozilla.com
push dateFri, 31 Jul 2015 10:10:16 +0000
treeherdermozilla-central@e9389ca320ff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskitcambridge
bugs1188937
milestone42.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 1188937 - Only add Push API interfaces to build if the feature is enabled. r=kitcambridge
browser/base/content/sanitize.js
dom/moz.build
toolkit/content/aboutServiceWorkers.js
--- a/browser/base/content/sanitize.js
+++ b/browser/base/content/sanitize.js
@@ -511,19 +511,23 @@ Sanitizer.prototype = {
 
         // Clear site security settings - no support for ranges in this
         // interface either, so we clearAll().
         var sss = Cc["@mozilla.org/ssservice;1"]
                     .getService(Ci.nsISiteSecurityService);
         sss.clearAll();
 
         // Clear all push notification subscriptions
-        var push = Cc["@mozilla.org/push/NotificationService;1"]
-                    .getService(Ci.nsIPushNotificationService);
-        push.clearAll();
+        try {
+          var push = Cc["@mozilla.org/push/NotificationService;1"]
+                      .getService(Ci.nsIPushNotificationService);
+          push.clearAll();
+        } catch (e) {
+          dump("Web Push may not be available.\n");
+        }
 
         TelemetryStopwatch.finish("FX_SANITIZE_SITESETTINGS");
       },
 
       get canClear()
       {
         return true;
       }
--- a/dom/moz.build
+++ b/dom/moz.build
@@ -20,26 +20,28 @@ interfaces = [
     'range',
     'xbl',
     'xpath',
     'xul',
     'security',
     'storage',
     'json',
     'offline',
-    'push',
     'geolocation',
     'notification',
     'permission',
     'svg',
     'smil',
     'apps',
     'gamepad',
 ]
 
+if not CONFIG['MOZ_SIMPLEPUSH']:
+    interfaces += ['push']
+
 DIRS += ['interfaces/' + i for i in interfaces]
 
 DIRS += [
     'animation',
     'apps',
     'base',
     'bluetooth',
     'activities',
--- a/toolkit/content/aboutServiceWorkers.js
+++ b/toolkit/content/aboutServiceWorkers.js
@@ -4,23 +4,16 @@
 
 'use strict';
 
 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import('resource://gre/modules/XPCOMUtils.jsm');
 
-XPCOMUtils.defineLazyServiceGetter(
-  this,
-  "PushNotificationService",
-  "@mozilla.org/push/NotificationService;1",
-  "nsIPushNotificationService"
-);
-
 const bundle = Services.strings.createBundle(
   "chrome://global/locale/aboutServiceWorkers.properties");
 
 const brandBundle = Services.strings.createBundle(
   "chrome://branding/locale/brand.properties");
 
 let gSWM;
 let gSWCount = 0;
@@ -48,28 +41,36 @@ function init() {
 
   let length = data.length;
   if (!length) {
     let div = document.getElementById("warning_no_serviceworkers");
     div.classList.add("active");
     return;
   }
 
+  let pns = undefined;
+  try {
+    pns = Cc["@mozilla.org/push/NotificationService;1"]
+            .getService(Ci.nsIPushNotificationService);
+  } catch(e) {
+    dump("Could not acquire PushNotificationService\n");
+  }
+
   for (let i = 0; i < length; ++i) {
     let info = data.queryElementAt(i, Ci.nsIServiceWorkerInfo);
     if (!info) {
       dump("AboutServiceWorkers: Invalid nsIServiceWorkerInfo interface.\n");
       continue;
     }
 
-    display(info);
+    display(info, pns);
   }
 }
 
-function display(info) {
+function display(info, pushNotificationService) {
   let parent = document.getElementById("serviceworkers");
 
   let div = document.createElement('div');
   parent.appendChild(div);
 
   let title = document.createElement('h2');
   let titleStr = bundle.formatStringFromName('title', [info.principal.origin], 1);
   title.appendChild(document.createTextNode(titleStr));
@@ -115,24 +116,24 @@ function display(info) {
 
   createItem(bundle.GetStringFromName('scope'), info.scope);
   createItem(bundle.GetStringFromName('scriptSpec'), info.scriptSpec, true);
   createItem(bundle.GetStringFromName('currentWorkerURL'), info.currentWorkerURL, true);
   createItem(bundle.GetStringFromName('activeCacheName'), info.activeCacheName);
   createItem(bundle.GetStringFromName('waitingCacheName'), info.waitingCacheName);
 
   let pushItem = createItem(bundle.GetStringFromName('pushEndpoint'), bundle.GetStringFromName('waiting'));
-  PushNotificationService.registration(info.scope, info.principal.originAttributes).then(
-    pushRecord => {
-      pushItem.data = JSON.stringify(pushRecord);
-    },
-    error => {
-      dump("about:serviceworkers - push registration failed\n");
-    }
-  );
+  if (pushNotificationService) {
+    pushNotificationService.registration(info.scope, info.principal.originAttributes)
+      .then(pushRecord => {
+        pushItem.data = JSON.stringify(pushRecord);
+      }).catch(error => {
+        dump("about:serviceworkers - retrieving push registration failed\n");
+      });
+  }
 
   let updateButton = document.createElement("button");
   updateButton.appendChild(document.createTextNode(bundle.GetStringFromName('update')));
   updateButton.onclick = function() {
     gSWM.propagateSoftUpdate(info.principal.originAttributes, info.scope);
   };
   div.appendChild(updateButton);