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

Delta Between Two Patch Sets: adblockplus/extensionBridge.js

Issue 29863604: Issue 6865 - Update ABP dependency to version 3.2 (Closed)
Left Patch Set: Created Aug. 24, 2018, 8:38 p.m.
Right Patch Set: Adjusting code style Created Jan. 16, 2019, 1:45 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 | « adblockplus/build.py ('k') | adblockplus/issue-6070.patch » ('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
(...skipping 20 matching lines...) Expand all
31 const TITLE_PROP = "title"; 31 const TITLE_PROP = "title";
32 const URL_PROP = "url"; 32 const URL_PROP = "url";
33 33
34 function init() 34 function init()
35 { 35 {
36 Promise.all([FilterNotifier.once("load"), Prefs.untilLoaded]).then(onLoaded); 36 Promise.all([FilterNotifier.once("load"), Prefs.untilLoaded]).then(onLoaded);
37 } 37 }
38 38
39 function onLoaded() 39 function onLoaded()
40 { 40 {
41 browser.runtime.abbRegisterRequestListener(handleRequest); 41 browser.runtime.registerAbbMessageListener(handleMessage);
42 browser.runtime.abbSendRequest("Abb:OnLoaded"); 42 browser.runtime.sendAbbMessage("OnLoaded");
43 FilterNotifier.on("save", onFiltersSaved); 43 FilterNotifier.on("save", onFiltersSaved);
44 } 44 }
45 45
46 function onFiltersSaved() 46 function onFiltersSaved()
47 { 47 {
48 browser.runtime.abbSendRequest("Abb:OnFiltersSaved"); 48 browser.runtime.sendAbbMessage("OnFiltersSaved");
49 } 49 }
50 50
51 function handleRequest(data) 51 function handleMessage(data)
52 { 52 {
53
54 switch ((data["action"])) 53 switch ((data["action"]))
55 { 54 {
56 case "getAdblockPlusEnabled": 55 case "getAdblockPlusEnabled":
57 return successData(Prefs.enabled); 56 return successData(Prefs.enabled);
58 57
59 case "setAdblockPlusEnabled": 58 case "setAdblockPlusEnabled":
60 if (!checkData(data, ENABLE_PROP)) break; 59 if (!checkData(data, ENABLE_PROP)) break;
61 Prefs.enabled = !!data[ENABLE_PROP]; 60 Prefs.enabled = !!data[ENABLE_PROP];
62 return successData(); 61 return successData();
63 62
64 case "getAcceptableAdsEnabled": 63 case "getAcceptableAdsEnabled":
65 return successData(isSubscriptionEnabled( 64 return successData(isSubscriptionEnabled(
66 Prefs.subscriptions_exceptionsurl)); 65 Prefs.subscriptions_exceptionsurl));
67 66
68 case "setAcceptableAdsEnabled": 67 case "setAcceptableAdsEnabled":
69 if (!checkData(data, ENABLE_PROP)) break; 68 if (!checkData(data, ENABLE_PROP)) break;
70 const acceptableAdsTitle = "Allow non-intrusive advertising"; 69 const acceptableAdsTitle = "Allow non-intrusive advertising";
71 setSubscriptionEnabled(!!data[ENABLE_PROP], 70 setSubscriptionEnabled(!!data[ENABLE_PROP],
72 Prefs.subscriptions_exceptionsurl, acceptableAdsTitle); 71 Prefs.subscriptions_exceptionsurl, acceptableAdsTitle);
73 return successData(getAllSubscriptions()); 72 return successData();
74 73
75 case "getEnabledSubscriptions": 74 case "getEnabledSubscriptions":
76 return successData(getEnabledSubscriptions()); 75 return successData(getEnabledSubscriptions());
77 76
78 case "isSubscriptionEnabled": 77 case "isSubscriptionEnabled":
79 if (!checkData(data, URL_PROP)) break; 78 if (!checkData(data, URL_PROP)) break;
80 return successData(isSubscriptionEnabled(data[URL_PROP])); 79 return successData(isSubscriptionEnabled(data[URL_PROP]));
81 80
82 case "addSubscription": 81 case "addSubscription":
83 if (!checkData(data, URL_PROP)) break; 82 if (!checkData(data, URL_PROP)) break;
(...skipping 12 matching lines...) Expand all
96 if (!checkData(data, [URL_PROP, HOST_PROP])) break; 95 if (!checkData(data, [URL_PROP, HOST_PROP])) break;
97 return successData(isDomainWhitelisted(data[URL_PROP], data[HOST_PROP])); 96 return successData(isDomainWhitelisted(data[URL_PROP], data[HOST_PROP]));
98 97
99 case "whitelistDomain": 98 case "whitelistDomain":
100 if (!checkData(data, [ENABLE_PROP, URL_PROP, HOST_PROP])) break; 99 if (!checkData(data, [ENABLE_PROP, URL_PROP, HOST_PROP])) break;
101 setDomainWhitelisted(!!data[ENABLE_PROP], data[URL_PROP], data[HOST_PROP]) ; 100 setDomainWhitelisted(!!data[ENABLE_PROP], data[URL_PROP], data[HOST_PROP]) ;
102 return successData(); 101 return successData();
103 102
104 } 103 }
105 return errorData("Malformed request"); 104 return errorData("Malformed request");
106 }
107
108 // remove
109 function getAllSubscriptions()
110 {
111 return FilterStorage.subscriptions.map(sub => ({"title": sub.title, "url": sub .url, "downloadable": (sub instanceof DownloadableSubscription), "special": (sub instanceof SpecialSubscription), "disabled": sub.disabled}));
112 } 105 }
113 106
114 function getEnabledSubscriptions() 107 function getEnabledSubscriptions()
115 { 108 {
116 return FilterStorage.subscriptions.filter(sub => !sub.disabled).map(sub => 109 return FilterStorage.subscriptions.filter(sub => !sub.disabled).map(sub =>
117 ({[TITLE_PROP]: sub.title, [URL_PROP]: sub.url})); 110 ({[TITLE_PROP]: sub.title, [URL_PROP]: sub.url}));
118 } 111 }
119 112
120 function isSubscriptionEnabled(url) 113 function isSubscriptionEnabled(url)
121 { 114 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 { 152 {
160 FilterStorage.removeFilter(filter); 153 FilterStorage.removeFilter(filter);
161 if (filter.subscriptions.length) filter.disabled = true; 154 if (filter.subscriptions.length) filter.disabled = true;
162 } 155 }
163 156
164 function getWhitelistedDomains() 157 function getWhitelistedDomains()
165 { 158 {
166 const whitelistRegex = /^@@\|\|([^/:]+)\^\$document$/; 159 const whitelistRegex = /^@@\|\|([^/:]+)\^\$document$/;
167 const results = []; 160 const results = [];
168 161
169 FilterStorage.subscriptions.forEach(function(sub) { 162 for (const sub of FilterStorage.subscriptions)
170 if (!(sub instanceof SpecialSubscription) || sub.disabled) return; 163 {
171 sub.filters.forEach(function(filter) { 164 if (!(sub instanceof SpecialSubscription) || sub.disabled) continue;
165 for (const filter of sub.filters)
166 {
172 const match = filter.text.match(whitelistRegex); 167 const match = filter.text.match(whitelistRegex);
173 if (match) results.push({[URL_PROP]: match[1]}); 168 if (match) results.push({[URL_PROP]: match[1]});
174 }); 169 }
175 }); 170 }
176 171
177 return results; 172 return results;
178 }
179
180 function flatIt(array)
181 {
182 let flatArray = [];
183 array.forEach(function(item) {
184 flatArray = flatArray.concat(item);
185 });
186 return flatArray;
187 } 173 }
188 174
189 function isDomainWhitelisted(url, host) 175 function isDomainWhitelisted(url, host)
190 { 176 {
191 return !!getWhitelistingFilter(url, host); 177 return !!getWhitelistingFilter(url, host);
192 } 178 }
193 179
194 function setDomainWhitelisted(isWhitelisted, url, host) 180 function setDomainWhitelisted(isWhitelisted, url, host)
195 { 181 {
196 if (isDomainWhitelisted(url, host) == isWhitelisted) return; 182 if (isDomainWhitelisted(url, host) == isWhitelisted) return;
(...skipping 24 matching lines...) Expand all
221 url, RegExpFilter.typeMap.DOCUMENT, host, false, null, false); 207 url, RegExpFilter.typeMap.DOCUMENT, host, false, null, false);
222 } 208 }
223 catch (e) {} 209 catch (e) {}
224 return null; 210 return null;
225 } 211 }
226 212
227 function checkData(data, check) 213 function checkData(data, check)
228 { 214 {
229 if (!data) return false; 215 if (!data) return false;
230 const properties = [].concat(check || []); 216 const properties = [].concat(check || []);
231 return properties.every(function(item) { 217 return properties.every(function(item)
218 {
232 return item in data; 219 return item in data;
233 }); 220 });
234 } 221 }
235 222
236 function successData(value) 223 function successData(value)
237 { 224 {
238 const data = {}; 225 const data = {};
239 data.success = true; 226 data.success = true;
240 if (value != null) data.value = value; 227 if (value != null) data.value = value;
241 return data; 228 return data;
242 } 229 }
243 230
244 function errorData(errorMsg) 231 function errorData(errorMsg)
245 { 232 {
246 const data = {}; 233 const data = {};
247 if (errorMsg) data.errorMsg = errorMsg; 234 if (errorMsg) data.error = errorMsg;
248 return data; 235 return data;
249 } 236 }
250 237
251 init(); 238 init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld