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

Unified Diff: lib/contentPolicy.js

Issue 29329467: Issue 3208 - Minor consistency fixes (Closed)
Patch Set: Updated JSDoc comment Created Oct. 29, 2015, 6:16 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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");
@@ -70,19 +72,19 @@ var Policy = exports.Policy =
/**
* Map of localized content type names by their identifiers.
* @type Map
*/
localizedDescr: new Map(),
/**
* Map containing all schemes that should be ignored by content policy.
- * @type Object
+ * @type Set
*/
- 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}
Thomas Greiner 2015/11/02 14:09:03 Detail: That line's in wrong order. It should be `
* @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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld