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

Side by Side Diff: adblockplus/Api.jsm

Issue 29543774: Issue 2801 - Create 'Whitelisted websites' screen and add link to 'Ad blocking' screen (Closed)
Patch Set: Created Sept. 13, 2017, 5:01 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 | « no previous file | mobile/android/base/locales/adblockbrowser/en-US/android_strings.dtd » ('j') | 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 Services.prefs.savePrefFile(null); 92 Services.prefs.savePrefFile(null);
93 } 93 }
94 94
95 function getPrefsBranch() 95 function getPrefsBranch()
96 { 96 {
97 let {addonRoot, addonName} = require("info"); 97 let {addonRoot, addonName} = require("info");
98 let branchName = "extensions." + addonName + "."; 98 let branchName = "extensions." + addonName + ".";
99 return Services.prefs.getBranch(branchName); 99 return Services.prefs.getBranch(branchName);
100 } 100 }
101 101
102 function getWhitelistingFilter(url) 102 function getWhitelistingFilter(url, host)
103 { 103 {
104 let uriObject = Services.io.newURI(url, null, null);
Thomas Greiner 2017/09/15 15:08:06 It's not a big deal whether or not we're extractin
diegocarloslima 2017/09/18 14:16:36 I do agree with you, the intention of the formatUr
105 try 104 try
106 { 105 {
107 return defaultMatcher.whitelist.matchesAny( 106 return defaultMatcher.whitelist.matchesAny(
108 uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null , false); 107 url, RegExpFilter.typeMap.DOCUMENT, host, false, null, false);
109 } 108 }
110 catch (e) 109 catch (e)
111 { 110 {
112 return null; 111 return null;
113 } 112 }
114 } 113 }
115 114
116 var AdblockPlusApi = 115 var AdblockPlusApi =
117 { 116 {
118 get filtersLoaded() 117 get filtersLoaded()
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 { 178 {
180 let subscriptions = []; 179 let subscriptions = [];
181 for (let i = 0; i < FilterStorage.subscriptions.length; i++) 180 for (let i = 0; i < FilterStorage.subscriptions.length; i++)
182 { 181 {
183 let subscription = FilterStorage.subscriptions[i]; 182 let subscription = FilterStorage.subscriptions[i];
184 if (!subscription.disabled) 183 if (!subscription.disabled)
185 subscriptions.push({"title": subscription.title, "url": subscription.url }); 184 subscriptions.push({"title": subscription.title, "url": subscription.url });
186 } 185 }
187 return subscriptions; 186 return subscriptions;
188 }, 187 },
189 isLocal: function(url) 188 get whitelistedWebsites()
190 { 189 {
191 let uriObject = Services.io.newURI(url, null, null); 190 let whitelistedWebsites = [];
192 return !uriObject.schemeIs("http") && !uriObject.schemeIs("https"); 191 for (let i = 0; i < FilterStorage.subscriptions.length; i++)
192 {
193 let subscription = FilterStorage.subscriptions[i];
194 if (subscription.url && subscription.url.startsWith("~user~") && subscript ion.filters)
195 {
196 for (let j = 0; j < subscription.filters.length; j++)
197 {
198 let filter = subscription.filters[j];
199 let whitelistMatch = filter.text ? filter.text.match(/@@\|\|(.*)\^\$do cument/) : null;
Thomas Greiner 2017/09/15 15:08:06 We're using a slightly different regular expressio
diegocarloslima 2017/09/18 14:16:36 Acknowledged.
200 if(whitelistMatch)
201 {
202 whitelistedWebsites.push({"url": whitelistMatch[1]})
203 }
204 }
205 }
206 }
207 return whitelistedWebsites;
193 }, 208 },
194 isPageWhitelisted: function(url) 209 isWebsiteWhitelisted: function(url, host)
195 { 210 {
196 return AdblockPlusApi.isLocal(url) || !!getWhitelistingFilter(url); 211 return !!getWhitelistingFilter(url, host);
197 }, 212 },
198 whitelistSite: function(url, whitelisted) 213 whitelistWebsite: function(url, host, whitelisted)
199 { 214 {
200 let uriObject = Services.io.newURI(url, null, null);
201 if (whitelisted) 215 if (whitelisted)
202 { 216 {
203 var host = uriObject.host.replace(/^www\./, "");
204 var filter = Filter.fromText("@@||" + host + "^$document"); 217 var filter = Filter.fromText("@@||" + host + "^$document");
205 if (filter.subscriptions.length && filter.disabled) 218 if (filter.subscriptions.length && filter.disabled)
206 filter.disabled = false; 219 filter.disabled = false;
207 else 220 else
208 { 221 {
209 filter.disabled = false; 222 filter.disabled = false;
210 FilterStorage.addFilter(filter); 223 FilterStorage.addFilter(filter);
211 } 224 }
212 } 225 }
213 else 226 else
214 { 227 {
215 // Remove any exception rules applying to this URL 228 // Remove any exception rules applying to this URL
216 var filter = getWhitelistingFilter(url); 229 var filter = getWhitelistingFilter(url, host);
217 while (filter) 230 while (filter)
218 { 231 {
219 FilterStorage.removeFilter(filter); 232 FilterStorage.removeFilter(filter);
220 if (filter.subscriptions.length) 233 if (filter.subscriptions.length)
221 filter.disabled = true; 234 filter.disabled = true;
222 filter = getWhitelistingFilter(url); 235 filter = getWhitelistingFilter(url);
223 } 236 }
224 } 237 }
225 }, 238 },
226 initCommunication: function() 239 initCommunication: function()
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return {"success": true}; 286 return {"success": true};
274 } 287 }
275 break; 288 break;
276 case "removeSubscription": 289 case "removeSubscription":
277 if ("url" in data) 290 if ("url" in data)
278 { 291 {
279 this.removeSubscription(data["url"]); 292 this.removeSubscription(data["url"]);
280 return {"success": true}; 293 return {"success": true};
281 } 294 }
282 break; 295 break;
283 case "isLocal": 296 case "getWhitelistedWebsites":
284 if ("url" in data) 297 return {"success": true, "value": this.whitelistedWebsites};
298 case "isWebsiteWhitelisted":
299 if ("url" in data && "host" in data)
300 {
285 return {"success": true, 301 return {"success": true,
286 "value": this.isLocal(data["url"])}; 302 "value": this.isWebsiteWhitelisted(data["url"], data["host"] )};
303 }
287 break; 304 break;
288 case "isPageWhitelisted": 305 case "whitelistWebsite":
289 if ("url" in data) 306 if ("url" in data && "host" in data && "whitelisted" in data)
290 return {"success": true,
291 "value": this.isPageWhitelisted(data["url"])};
292 break;
293 case "whitelistSite":
294 if ("url" in data && "whitelisted" in data)
295 { 307 {
296 this.whitelistSite(data["url"], data["whitelisted"]); 308 this.whitelistWebsite(data["url"], data["host"], data["whitelisted"] );
297 return {"success": true}; 309 return {"success": true};
298 } 310 }
299 break; 311 break;
300 } 312 }
301 return {"success": false, "error": "malformed request"}; 313 return {"success": false, "error": "malformed request"};
302 }).bind(this), "AdblockPlus:Api"); 314 }).bind(this), "AdblockPlus:Api");
303 } 315 }
304 }; 316 };
OLDNEW
« no previous file with comments | « no previous file | mobile/android/base/locales/adblockbrowser/en-US/android_strings.dtd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld