Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/subscriptionInit.js

Issue 29726570: Issue 6496 - Account for browsers that don't support notifications with buttons (Closed)
Patch Set: Fixed typo in comment Created March 19, 2018, 4:58 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/notificationHelper.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/subscriptionInit.js
===================================================================
--- a/lib/subscriptionInit.js
+++ b/lib/subscriptionInit.js
@@ -133,6 +133,31 @@
return selectedItem;
}
+function supportsNotificationsWithButtons()
+{
+ // Microsoft Edge (as of EdgeHTML 16) doesn't have the notifications API.
+ // Opera gives an asynchronous error when buttons are provided (we cannot
+ // detect that behavior without attempting to show a notification).
+ if (!("notifications" in browser) || info.application == "opera")
+ return false;
+
+ // Firefox throws synchronously if the "buttons" option is provided.
+ // If buttons are supported (i.e. on Chrome), this fails with
+ // a different error message due to missing required options.
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1190681
+ try
+ {
+ browser.notifications.create({buttons: []});
+ }
+ catch (e)
+ {
+ if (e.toString().includes('"buttons" is unsupported'))
+ return false;
+ }
+
+ return true;
+}
+
/**
* Gets the filter subscriptions to be added when the extnesion is loaded.
*
@@ -155,11 +180,16 @@
acceptableAdsSubscription.title = "Allow non-intrusive advertising";
subscriptions.push(acceptableAdsSubscription);
- let antiAdblockSubscription = Subscription.fromURL(
- Prefs.subscriptions_antiadblockurl
- );
- antiAdblockSubscription.disabled = true;
- subscriptions.push(antiAdblockSubscription);
+ // Only add the anti-adblock messages subscription if
+ // the related notification can be shown on this browser.
+ if (supportsNotificationsWithButtons())
+ {
+ let antiAdblockSubscription = Subscription.fromURL(
+ Prefs.subscriptions_antiadblockurl
+ );
+ antiAdblockSubscription.disabled = true;
+ subscriptions.push(antiAdblockSubscription);
+ }
}
// Add default ad blocking subscription (e.g. EasyList)
« no previous file with comments | « lib/notificationHelper.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld