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

Delta Between Two Patch Sets: adblockplus/Api.jsm

Issue 5365916275572736: Issue 2351 - Add a custom menu item for whitelisting the current site (Closed)
Left Patch Set: Minimally invasive approach Created May 6, 2015, 12:12 a.m.
Right Patch Set: Address comments, rename location, change item label Created May 6, 2015, 4:41 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 | « no previous file | mobile/android/base/BrowserApp.java » ('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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 28 matching lines...) Expand all
39 let {Filter} = require("filterClasses"); 39 let {Filter} = require("filterClasses");
40 let {FilterStorage} = require("filterStorage"); 40 let {FilterStorage} = require("filterStorage");
41 let {defaultMatcher} = require("matcher"); 41 let {defaultMatcher} = require("matcher");
42 let {Prefs} = require("prefs"); 42 let {Prefs} = require("prefs");
43 let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscri ption, ExternalSubscription} = require("subscriptionClasses"); 43 let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscri ption, ExternalSubscription} = require("subscriptionClasses");
44 let {Synchronizer} = require("synchronizer"); 44 let {Synchronizer} = require("synchronizer");
45 let {UI} = require("ui"); 45 let {UI} = require("ui");
46 46
47 function getWhitelistingFilter(url) 47 function getWhitelistingFilter(url)
48 { 48 {
49 let location = Services.io.newURI(url, null, null); 49 let uriObject = Services.io.newURI(url, null, null);
50 try 50 try
51 { 51 {
52 return defaultMatcher.whitelist.matchesAny( 52 return defaultMatcher.whitelist.matchesAny(
53 location.spec, "DOCUMENT", location.host, false, null); 53 uriObject.spec, "DOCUMENT", uriObject.host, false, null);
54 } 54 }
55 catch (e) 55 catch (e)
56 { 56 {
57 return null; 57 return null;
58 } 58 }
59 } 59 }
60 60
61 var AdblockPlusApi = 61 var AdblockPlusApi =
62 { 62 {
63 get filtersLoaded() 63 get filtersLoaded()
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 Synchronizer.execute(subscription); 101 Synchronizer.execute(subscription);
102 } 102 }
103 }, 103 },
104 removeSubscription: function(url) 104 removeSubscription: function(url)
105 { 105 {
106 FilterStorage.removeSubscription( 106 FilterStorage.removeSubscription(
107 FilterStorage.knownSubscriptions[url]); 107 FilterStorage.knownSubscriptions[url]);
108 }, 108 },
109 isLocal: function(url) 109 isLocal: function(url)
110 { 110 {
111 let location = Services.io.newURI(url, null, null); 111 let uriObject = Services.io.newURI(url, null, null);
112 return !location.schemeIs("http") && !location.schemeIs("https"); 112 return !uriObject.schemeIs("http") && !uriObject.schemeIs("https");
113 }, 113 },
114 isPageWhitelisted: function(url) 114 isPageWhitelisted: function(url)
115 { 115 {
116 return !!getWhitelistingFilter(url); 116 return AdblockPlusApi.isLocal(url) || !!getWhitelistingFilter(url);
117 }, 117 },
118 whitelistSite: function(url, whitelisted) 118 whitelistSite: function(url, whitelisted)
119 { 119 {
120 let location = Services.io.newURI(url, null, null); 120 let uriObject = Services.io.newURI(url, null, null);
121 if (whitelisted) 121 if (whitelisted)
122 { 122 {
123 var host = location.host.replace(/^www\./, ""); 123 var host = uriObject.host.replace(/^www\./, "");
124 var filter = Filter.fromText("@@||" + host + "^$document"); 124 var filter = Filter.fromText("@@||" + host + "^$document");
125 if (filter.subscriptions.length && filter.disabled) 125 if (filter.subscriptions.length && filter.disabled)
126 filter.disabled = false; 126 filter.disabled = false;
127 else 127 else
128 { 128 {
129 filter.disabled = false; 129 filter.disabled = false;
130 FilterStorage.addFilter(filter); 130 FilterStorage.addFilter(filter);
131 } 131 }
132 } 132 }
133 else 133 else
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 "value": this.isLocal(data["url"])}; 196 "value": this.isLocal(data["url"])};
197 break; 197 break;
198 case "isPageWhitelisted": 198 case "isPageWhitelisted":
199 if ("url" in data) 199 if ("url" in data)
200 return {"success": true, 200 return {"success": true,
201 "value": this.isPageWhitelisted(data["url"])}; 201 "value": this.isPageWhitelisted(data["url"])};
202 break; 202 break;
203 case "whitelistSite": 203 case "whitelistSite":
204 if ("url" in data && "whitelisted" in data) 204 if ("url" in data && "whitelisted" in data)
205 { 205 {
206 this.whitelistSite(data["url"], data["whitelisted"] == "true"); 206 this.whitelistSite(data["url"], data["whitelisted"]);
René Jeschke 2015/05/06 10:56:33 Wouldn't it be better to use a 'boolean' here (dat
Felix Dahlke 2015/05/06 16:42:50 Done.
207 return {"success": true}; 207 return {"success": true};
208 } 208 }
209 break; 209 break;
210 } 210 }
211 return {"success": false, "error": "malformed request"}; 211 return {"success": false, "error": "malformed request"};
212 }).bind(this), "AdblockPlus:Api"); 212 }).bind(this), "AdblockPlus:Api");
213 } 213 }
214 }; 214 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld