Index: lib/contentPolicy.js |
=================================================================== |
--- a/lib/contentPolicy.js |
+++ b/lib/contentPolicy.js |
@@ -14,18 +14,20 @@ |
* You should have received a copy of the GNU General Public License |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
/** |
* @fileOverview Content policy implementation, responsible for blocking things. |
*/ |
-Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
-Cu.import("resource://gre/modules/Services.jsm"); |
+"use strict"; |
+ |
+let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); |
+let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
let {Utils} = require("utils"); |
let {Prefs} = require("prefs"); |
let {FilterStorage} = require("filterStorage"); |
let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); |
let {defaultMatcher} = require("matcher"); |
let {objectMouseEventHander} = require("objectTabs"); |
let {RequestNotifier} = require("requestNotifier"); |
@@ -72,17 +74,17 @@ var Policy = exports.Policy = |
* @type Map |
*/ |
localizedDescr: new Map(), |
/** |
* Map containing all schemes that should be ignored by content policy. |
* @type Object |
tschuster
2015/10/29 13:23:22
@type Set
Wladimir Palant
2015/10/29 18:17:23
Done.
|
*/ |
- whitelistSchemes: {}, |
+ whitelistSchemes: new Set(), |
/** |
* Called on module startup, initializes various exported properties. |
*/ |
init: function() |
{ |
// Populate types map |
let iface = Ci.nsIContentPolicy; |
@@ -91,17 +93,17 @@ var Policy = exports.Policy = |
types.set(iface[name], name.substr(5)); |
// Populate localized type names |
for (let typeName of contentTypes) |
this.localizedDescr.set(typeName, Utils.getString("type_label_" + typeName.toLowerCase())); |
// whitelisted URL schemes |
for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) |
- this.whitelistSchemes[scheme] = true; |
+ this.whitelistSchemes.add(scheme); |
// Generate class identifier used to collapse node and register corresponding |
// stylesheet. |
let offset = "a".charCodeAt(0); |
for (let i = 0; i < 20; i++) |
collapsedClass += String.fromCharCode(offset + Math.random() * 26); |
let collapseStyle = Services.io.newURI("data:text/css," + |
@@ -258,34 +260,34 @@ var Policy = exports.Policy = |
/** |
* Checks whether the location's scheme is blockable. |
* @param location {nsIURI} |
* @return {Boolean} |
*/ |
isBlockableScheme: function(location) |
{ |
- return !(location.scheme in Policy.whitelistSchemes); |
+ return !Policy.whitelistSchemes.has(location.scheme); |
}, |
/** |
* Checks whether a page is whitelisted. |
* @param {String} url |
* @param {String} [parentUrl] location of the parent page |
* @param {String} [sitekey] public key provided on the page |
* @return {Filter} filter that matched the URL or null if not whitelisted |
*/ |
isWhitelisted: function(url, parentUrl, sitekey) |
{ |
if (!url) |
return null; |
// Do not apply exception rules to schemes on our whitelistschemes list. |
let match = /^([\w\-]+):/.exec(url); |
- if (match && match[1] in Policy.whitelistSchemes) |
+ if (match && Policy.whitelistSchemes.has(match[1])) |
return null; |
if (!parentUrl) |
parentUrl = url; |
// Ignore fragment identifier |
let index = url.indexOf("#"); |
if (index >= 0) |