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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/notificationHelper.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 { 126 {
127 selectedItem = subscription; 127 selectedItem = subscription;
128 selectedPrefix = prefix; 128 selectedPrefix = prefix;
129 } 129 }
130 } 130 }
131 } 131 }
132 } 132 }
133 return selectedItem; 133 return selectedItem;
134 } 134 }
135 135
136 function supportsNotificationsWithButtons()
137 {
138 // Microsoft Edge (as of EdgeHTML 16) doesn't have the notifications API.
139 // Opera gives an asynchronous error when buttons are provided (we cannot
140 // detect that behavior without attempting to show a notification).
141 if (!("notifications" in browser) || info.application == "opera")
142 return false;
143
144 // Firefox throws synchronously if the "buttons" option is provided.
145 // If buttons are supported (i.e. on Chrome), this fails with
146 // a different error message due to missing required options.
147 // https://bugzilla.mozilla.org/show_bug.cgi?id=1190681
148 try
149 {
150 browser.notifications.create({buttons: []});
151 }
152 catch (e)
153 {
154 if (e.toString().includes('"buttons" is unsupported'))
155 return false;
156 }
157
158 return true;
159 }
160
136 /** 161 /**
137 * Gets the filter subscriptions to be added when the extnesion is loaded. 162 * Gets the filter subscriptions to be added when the extnesion is loaded.
138 * 163 *
139 * @return {Promise|Subscription[]} 164 * @return {Promise|Subscription[]}
140 */ 165 */
141 function getSubscriptions() 166 function getSubscriptions()
142 { 167 {
143 let subscriptions = []; 168 let subscriptions = [];
144 169
145 // Add pre-configured subscriptions 170 // Add pre-configured subscriptions
146 for (let url of Prefs.additional_subscriptions) 171 for (let url of Prefs.additional_subscriptions)
147 subscriptions.push(Subscription.fromURL(url)); 172 subscriptions.push(Subscription.fromURL(url));
148 173
149 // Add "acceptable ads" and "anti-adblock messages" subscriptions 174 // Add "acceptable ads" and "anti-adblock messages" subscriptions
150 if (firstRun) 175 if (firstRun)
151 { 176 {
152 let acceptableAdsSubscription = Subscription.fromURL( 177 let acceptableAdsSubscription = Subscription.fromURL(
153 Prefs.subscriptions_exceptionsurl 178 Prefs.subscriptions_exceptionsurl
154 ); 179 );
155 acceptableAdsSubscription.title = "Allow non-intrusive advertising"; 180 acceptableAdsSubscription.title = "Allow non-intrusive advertising";
156 subscriptions.push(acceptableAdsSubscription); 181 subscriptions.push(acceptableAdsSubscription);
157 182
158 let antiAdblockSubscription = Subscription.fromURL( 183 // Only add the anti-adblock messages subscription if
159 Prefs.subscriptions_antiadblockurl 184 // the related notification can be shown on this browser.
160 ); 185 if (supportsNotificationsWithButtons())
161 antiAdblockSubscription.disabled = true; 186 {
162 subscriptions.push(antiAdblockSubscription); 187 let antiAdblockSubscription = Subscription.fromURL(
188 Prefs.subscriptions_antiadblockurl
189 );
190 antiAdblockSubscription.disabled = true;
191 subscriptions.push(antiAdblockSubscription);
192 }
163 } 193 }
164 194
165 // Add default ad blocking subscription (e.g. EasyList) 195 // Add default ad blocking subscription (e.g. EasyList)
166 if (shouldAddDefaultSubscription()) 196 if (shouldAddDefaultSubscription())
167 { 197 {
168 return fetch("subscriptions.xml") 198 return fetch("subscriptions.xml")
169 .then(response => response.text()) 199 .then(response => response.text())
170 .then(text => 200 .then(text =>
171 { 201 {
172 let doc = new DOMParser().parseFromString(text, "application/xml"); 202 let doc = new DOMParser().parseFromString(text, "application/xml");
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 * Sets a callback that is called with an array of subscriptions to be added 282 * Sets a callback that is called with an array of subscriptions to be added
253 * during initialization. The callback must return an array of subscriptions 283 * during initialization. The callback must return an array of subscriptions
254 * that will effectively be added. 284 * that will effectively be added.
255 * 285 *
256 * @param {function} callback 286 * @param {function} callback
257 */ 287 */
258 exports.setSubscriptionsCallback = callback => 288 exports.setSubscriptionsCallback = callback =>
259 { 289 {
260 subscriptionsCallback = callback; 290 subscriptionsCallback = callback;
261 }; 291 };
OLDNEW
« 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