OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 Cu.import("resource://gre/modules/Messaging.jsm"); | 26 Cu.import("resource://gre/modules/Messaging.jsm"); |
27 | 27 |
28 function require(module) | 28 function require(module) |
29 { | 29 { |
30 let result = {}; | 30 let result = {}; |
31 result.wrappedJSObject = result; | 31 result.wrappedJSObject = result; |
32 Services.obs.notifyObservers(result, "adblockplus-require", module); | 32 Services.obs.notifyObservers(result, "adblockplus-require", module); |
33 return result.exports; | 33 return result.exports; |
34 } | 34 } |
35 | 35 |
| 36 let {Filter} = require("filterClasses"); |
36 let {FilterStorage} = require("filterStorage"); | 37 let {FilterStorage} = require("filterStorage"); |
| 38 let {defaultMatcher} = require("matcher"); |
37 let {Prefs} = require("prefs"); | 39 let {Prefs} = require("prefs"); |
38 let {UI} = require("ui"); | 40 let {UI} = require("ui"); |
39 | 41 |
40 var AdblockPlusApi = | 42 var AdblockPlusApi = |
41 { | 43 { |
42 get filtersLoaded() | 44 get filtersLoaded() |
43 { | 45 { |
44 return !FilterStorage._loading; | 46 return !FilterStorage._loading; |
45 }, | 47 }, |
46 get acceptableAdsEnabled() | 48 get acceptableAdsEnabled() |
(...skipping 26 matching lines...) Expand all Loading... |
73 case "setAcceptableAdsEnabled": | 75 case "setAcceptableAdsEnabled": |
74 if ("enable" in data) | 76 if ("enable" in data) |
75 { | 77 { |
76 this.acceptableAdsEnabled = !!data["enable"]; | 78 this.acceptableAdsEnabled = !!data["enable"]; |
77 return {"success" : true}; | 79 return {"success" : true}; |
78 } | 80 } |
79 return {"success": false, "error": "malformed request"}; | 81 return {"success": false, "error": "malformed request"}; |
80 } | 82 } |
81 return {"success": false, "error": "malformed request"}; | 83 return {"success": false, "error": "malformed request"}; |
82 }).bind(this), "AdblockPlus:Api"); | 84 }).bind(this), "AdblockPlus:Api"); |
| 85 }, |
| 86 isLocal: function(location) |
| 87 { |
| 88 return !location.schemeIs("http") && !location.schemeIs("https"); |
| 89 }, |
| 90 isPageWhitelisted: function(location) |
| 91 { |
| 92 return defaultMatcher.whitelist.matchesAny( |
| 93 location.spec, "DOCUMENT", location.host, false, null); |
| 94 }, |
| 95 whitelistSite: function(location, whitelisted) |
| 96 { |
| 97 if (whitelisted) |
| 98 { |
| 99 var host = location.host.replace(/^www\./, ""); |
| 100 var filter = Filter.fromText("@@||" + host + "^$document"); |
| 101 if (filter.subscriptions.length && filter.disabled) |
| 102 filter.disabled = false; |
| 103 else |
| 104 { |
| 105 filter.disabled = false; |
| 106 FilterStorage.addFilter(filter); |
| 107 } |
| 108 } |
| 109 else |
| 110 { |
| 111 // Remove any exception rules applying to this URL |
| 112 var filter = AdblockPlusApi.isPageWhitelisted(location); |
| 113 while (filter) |
| 114 { |
| 115 FilterStorage.removeFilter(filter); |
| 116 if (filter.subscriptions.length) |
| 117 filter.disabled = true; |
| 118 filter = AdblockPlusApi.isPageWhitelisted(location); |
| 119 } |
| 120 } |
83 } | 121 } |
84 }; | 122 }; |
85 | 123 |
OLD | NEW |