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

Delta Between Two Patch Sets: lib/subscriptionInit.js

Issue 29713631: Issue 5760 - Use relative require paths (Closed)
Left Patch Set: Created March 3, 2018, 4:09 a.m.
Right Patch Set: Address PS4 comments, rebase Created April 5, 2018, 11:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/stats.js ('k') | lib/uninstall.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module subscriptionInit */ 18 /** @module subscriptionInit */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {Subscription, DownloadableSubscription, 22 const {Subscription,
23 SpecialSubscription} = require( 23 DownloadableSubscription,
kzar 2018/03/19 21:50:08 Please fix the way this is wrapped too.
Jon Sonesen 2018/03/20 23:25:18 Acknowledged.
24 "../adblockpluscore/lib/subscriptionClasses"); 24 SpecialSubscription} =
25 require("../adblockpluscore/lib/subscriptionClasses");
25 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage"); 26 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage");
26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 27 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier");
27 const info = require("../buildtools/info"); 28 const info = require("../buildtools/info");
28 const {Prefs} = require("./prefs"); 29 const {Prefs} = require("./prefs");
29 const {Synchronizer} = require("../adblockpluscore/lib/synchronizer"); 30 const {Synchronizer} = require("../adblockpluscore/lib/synchronizer");
30 const {Utils} = require("./utils"); 31 const {Utils} = require("./utils");
31 const {initNotifications} = require("./notificationHelper"); 32 const {initNotifications} = require("./notificationHelper");
32 const {updatesVersion} = require("../adblockplusui/lib/prefs"); 33 const {updatesVersion} = require("../adblockplusui/lib/prefs");
33 34
34 let firstRun; 35 let firstRun;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 { 128 {
128 selectedItem = subscription; 129 selectedItem = subscription;
129 selectedPrefix = prefix; 130 selectedPrefix = prefix;
130 } 131 }
131 } 132 }
132 } 133 }
133 } 134 }
134 return selectedItem; 135 return selectedItem;
135 } 136 }
136 137
138 function supportsNotificationsWithButtons()
139 {
140 // Microsoft Edge (as of EdgeHTML 16) doesn't have the notifications API.
141 // Opera gives an asynchronous error when buttons are provided (we cannot
142 // detect that behavior without attempting to show a notification).
143 if (!("notifications" in browser) || info.application == "opera")
144 return false;
145
146 // Firefox throws synchronously if the "buttons" option is provided.
147 // If buttons are supported (i.e. on Chrome), this fails with
148 // a different error message due to missing required options.
149 // https://bugzilla.mozilla.org/show_bug.cgi?id=1190681
150 try
151 {
152 browser.notifications.create({buttons: []});
153 }
154 catch (e)
155 {
156 if (e.toString().includes('"buttons" is unsupported'))
157 return false;
158 }
159
160 return true;
161 }
162
137 /** 163 /**
138 * Gets the filter subscriptions to be added when the extnesion is loaded. 164 * Gets the filter subscriptions to be added when the extnesion is loaded.
139 * 165 *
140 * @return {Promise|Subscription[]} 166 * @return {Promise|Subscription[]}
141 */ 167 */
142 function getSubscriptions() 168 function getSubscriptions()
143 { 169 {
144 let subscriptions = []; 170 let subscriptions = [];
145 171
146 // Add pre-configured subscriptions 172 // Add pre-configured subscriptions
147 for (let url of Prefs.additional_subscriptions) 173 for (let url of Prefs.additional_subscriptions)
148 subscriptions.push(Subscription.fromURL(url)); 174 subscriptions.push(Subscription.fromURL(url));
149 175
150 // Add "acceptable ads" and "anti-adblock messages" subscriptions 176 // Add "acceptable ads" and "anti-adblock messages" subscriptions
151 if (firstRun) 177 if (firstRun)
152 { 178 {
153 let acceptableAdsSubscription = Subscription.fromURL( 179 let acceptableAdsSubscription = Subscription.fromURL(
154 Prefs.subscriptions_exceptionsurl 180 Prefs.subscriptions_exceptionsurl
155 ); 181 );
156 acceptableAdsSubscription.title = "Allow non-intrusive advertising"; 182 acceptableAdsSubscription.title = "Allow non-intrusive advertising";
157 subscriptions.push(acceptableAdsSubscription); 183 subscriptions.push(acceptableAdsSubscription);
158 184
159 let antiAdblockSubscription = Subscription.fromURL( 185 // Only add the anti-adblock messages subscription if
160 Prefs.subscriptions_antiadblockurl 186 // the related notification can be shown on this browser.
161 ); 187 if (supportsNotificationsWithButtons())
162 antiAdblockSubscription.disabled = true; 188 {
163 subscriptions.push(antiAdblockSubscription); 189 let antiAdblockSubscription = Subscription.fromURL(
190 Prefs.subscriptions_antiadblockurl
191 );
192 antiAdblockSubscription.disabled = true;
193 subscriptions.push(antiAdblockSubscription);
194 }
164 } 195 }
165 196
166 // Add default ad blocking subscription (e.g. EasyList) 197 // Add default ad blocking subscription (e.g. EasyList)
167 if (shouldAddDefaultSubscription()) 198 if (shouldAddDefaultSubscription())
168 { 199 {
169 return fetch("subscriptions.xml") 200 return fetch("subscriptions.xml")
170 .then(response => response.text()) 201 .then(response => response.text())
171 .then(text => 202 .then(text =>
172 { 203 {
173 let doc = new DOMParser().parseFromString(text, "application/xml"); 204 let doc = new DOMParser().parseFromString(text, "application/xml");
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 * Sets a callback that is called with an array of subscriptions to be added 284 * Sets a callback that is called with an array of subscriptions to be added
254 * during initialization. The callback must return an array of subscriptions 285 * during initialization. The callback must return an array of subscriptions
255 * that will effectively be added. 286 * that will effectively be added.
256 * 287 *
257 * @param {function} callback 288 * @param {function} callback
258 */ 289 */
259 exports.setSubscriptionsCallback = callback => 290 exports.setSubscriptionsCallback = callback =>
260 { 291 {
261 subscriptionsCallback = callback; 292 subscriptionsCallback = callback;
262 }; 293 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld