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

Delta Between Two Patch Sets: lib/api.js

Issue 29366747: Issue 4657 - Add Acceptable Ads API (Closed)
Left Patch Set: Created Dec. 2, 2016, 4:27 p.m.
Right Patch Set: fix typo Created April 5, 2017, 4:53 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 | « include/AdblockPlus/FilterEngine.h ('k') | lib/compat.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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2017 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 var API = (function() 18 var API = (function()
19 { 19 {
20 var Filter = require("filterClasses").Filter; 20 var Filter = require("filterClasses").Filter;
21 var Subscription = require("subscriptionClasses").Subscription; 21 var Subscription = require("subscriptionClasses").Subscription;
22 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; 22 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
23 var FilterStorage = require("filterStorage").FilterStorage; 23 var FilterStorage = require("filterStorage").FilterStorage;
24 var defaultMatcher = require("matcher").defaultMatcher; 24 var defaultMatcher = require("matcher").defaultMatcher;
25 var ElemHide = require("elemHide").ElemHide; 25 var ElemHide = require("elemHide").ElemHide;
26 var Synchronizer = require("synchronizer").Synchronizer; 26 var Synchronizer = require("synchronizer").Synchronizer;
27 var Prefs = require("prefs").Prefs; 27 var Prefs = require("prefs").Prefs;
28 var checkForUpdates = require("updater").checkForUpdates; 28 var checkForUpdates = require("updater").checkForUpdates;
29 var Notification = require("notification").Notification; 29 var Notification = require("notification").Notification;
30 30
31 // returns first element of the array that satifies predicate.
sergei 2016/12/02 16:36:06 Should I move it into utils.js or extend Array.pro
sergei 2016/12/02 16:38:02 I meant extend in compat.js. The link is https://
Eric 2016/12/05 14:40:58 At the point of use, it would be better to use the
sergei 2017/03/17 15:55:25 Done.
32 var find = function (array, pred) {
33 for (var i = 0; i < array.length; ++i)
34 if (pred(array[i]))
35 return array[i];
36 };
37
38 return { 31 return {
39 getFilterFromText: function(text) 32 getFilterFromText: function(text)
40 { 33 {
41 text = Filter.normalize(text); 34 text = Filter.normalize(text);
42 if (!text) 35 if (!text)
43 throw "Attempted to create a filter from empty text"; 36 throw "Attempted to create a filter from empty text";
44 return Filter.fromText(text); 37 return Filter.fromText(text);
45 }, 38 },
46 39
47 isListedFilter: function(filter) 40 isListedFilter: function(filter)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 result.push(subscription); 135 result.push(subscription);
143 } 136 }
144 return result; 137 return result;
145 }, 138 },
146 139
147 isAASubscription: function(subscription) 140 isAASubscription: function(subscription)
148 { 141 {
149 return subscription.url == Prefs.subscriptions_exceptionsurl; 142 return subscription.url == Prefs.subscriptions_exceptionsurl;
150 }, 143 },
151 144
152 setAASubscriptionEnabled: function (enabled) 145 setAASubscriptionEnabled: function(enabled)
Eric 2016/12/05 14:40:58 Nit: extra space after 'function'
sergei 2017/03/17 15:55:25 Done.
153 { 146 {
154 var aaSubscription = find(FilterStorage.subscriptions, API.isAASubscriptio n); 147 var aaSubscription = FilterStorage.subscriptions.find(API.isAASubscription );
Eric 2016/12/05 14:40:58 See comment on line 173
155 if (!enabled) 148 if (!enabled)
156 { 149 {
157 if (aaSubscription && !aaSubscription.disabled) 150 if (aaSubscription && !aaSubscription.disabled)
158 aaSubscription.disabled = true; 151 aaSubscription.disabled = true;
159 return; 152 return;
160 } 153 }
161 if (!aaSubscription) { 154 if (!aaSubscription)
155 {
162 aaSubscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl) ; 156 aaSubscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl) ;
163 FilterStorage.addSubscription(aaSubscription); 157 FilterStorage.addSubscription(aaSubscription);
164 } 158 }
165 if (aaSubscription.disabled) 159 if (aaSubscription.disabled)
166 aaSubscription.disabled = false; 160 aaSubscription.disabled = false;
167 if (!aaSubscription.lastDownload) 161 if (!aaSubscription.lastDownload)
168 Synchronizer.execute(aaSubscription); 162 Synchronizer.execute(aaSubscription);
169 }, 163 },
170 164
171 isAASubscriptionEnabled: function() 165 isAASubscriptionEnabled: function()
172 { 166 {
173 var aaSubscription = find(FilterStorage.subscriptions, API.isAASubscriptio n); 167 var aaSubscription = FilterStorage.subscriptions.find(API.isAASubscription );
Eric 2016/12/05 14:40:58 Also see comment on line 154. With the above line
sergei 2017/03/17 15:55:25 I would like to avoid augmenting of FilterStorage
174 return aaSubscription && !aaSubscription.disabled; 168 return aaSubscription && !aaSubscription.disabled;
175 }, 169 },
176 170
177 showNextNotification: function(url) 171 showNextNotification: function(url)
178 { 172 {
179 Notification.showNext(url); 173 Notification.showNext(url);
180 }, 174 },
181 175
182 getNotificationTexts: function(notification) 176 getNotificationTexts: function(notification)
183 { 177 {
(...skipping 22 matching lines...) Expand all
206 return Prefs[pref]; 200 return Prefs[pref];
207 }, 201 },
208 202
209 setPref: function(pref, value) 203 setPref: function(pref, value)
210 { 204 {
211 Prefs[pref] = value; 205 Prefs[pref] = value;
212 }, 206 },
213 207
214 forceUpdateCheck: function(eventName) 208 forceUpdateCheck: function(eventName)
215 { 209 {
216 checkForUpdates(_triggerEvent.bind(null, eventName)); 210 checkForUpdates(eventName ? _triggerEvent.bind(null, eventName) : null);
217 }, 211 },
218 212
219 getHostFromUrl: function(url) 213 getHostFromUrl: function(url)
220 { 214 {
221 return extractHostFromURL(url); 215 return extractHostFromURL(url);
222 }, 216 },
223 217
224 compareVersions: function(v1, v2) 218 compareVersions: function(v1, v2)
225 { 219 {
226 return Services.vc.compare(v1, v2); 220 return Services.vc.compare(v1, v2);
227 } 221 }
228 }; 222 };
229 })(); 223 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld