From 079c3d0a1b415bdec3bbdc1e6735ba4aff69a9b3 Mon Sep 17 00:00:00 2001 From: Nikhil Marathe Date: Wed, 29 Jul 2015 09:12:51 -0700 Subject: [PATCH] Bug 1188937 - Only add Push API interfaces to build if the feature is enabled. r=kitcambridge --HG-- extra : commitid : BRZ0gZEecxz extra : amend_source : fb91b88616e837bf5e09a6a19c31acb1b94e4e64 extra : transplant_source : %84W%27%B8%40A%7F%26%04%0E%C6%A9%13o%25%D4SOD6 --- browser/base/content/sanitize.js | 10 +++++--- dom/moz.build | 4 ++- toolkit/content/aboutServiceWorkers.js | 35 +++++++++++++------------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/browser/base/content/sanitize.js b/browser/base/content/sanitize.js index a657a9c058f4..153bfd651fea 100644 --- a/browser/base/content/sanitize.js +++ b/browser/base/content/sanitize.js @@ -516,9 +516,13 @@ Sanitizer.prototype = { 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"); }, diff --git a/dom/moz.build b/dom/moz.build index 236e9d352f7b..4279c8ff757f 100644 --- a/dom/moz.build +++ b/dom/moz.build @@ -25,7 +25,6 @@ interfaces = [ 'storage', 'json', 'offline', - 'push', 'geolocation', 'notification', 'permission', @@ -35,6 +34,9 @@ interfaces = [ 'gamepad', ] +if not CONFIG['MOZ_SIMPLEPUSH']: + interfaces += ['push'] + DIRS += ['interfaces/' + i for i in interfaces] DIRS += [ diff --git a/toolkit/content/aboutServiceWorkers.js b/toolkit/content/aboutServiceWorkers.js index b56b7716b664..e7c1deda8643 100644 --- a/toolkit/content/aboutServiceWorkers.js +++ b/toolkit/content/aboutServiceWorkers.js @@ -9,13 +9,6 @@ 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"); @@ -53,6 +46,14 @@ function init() { 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) { @@ -60,11 +61,11 @@ function init() { continue; } - display(info); + display(info, pns); } } -function display(info) { +function display(info, pushNotificationService) { let parent = document.getElementById("serviceworkers"); let div = document.createElement('div'); @@ -120,14 +121,14 @@ function display(info) { 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')));