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

Unified Diff: lib/contentPolicy.js

Issue 29329473: Issue 3222 - Don`t do localization in the contentPolicy module (Closed)
Patch Set: Created Oct. 29, 2015, 1:25 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
Index: lib/contentPolicy.js
===================================================================
--- a/lib/contentPolicy.js
+++ b/lib/contentPolicy.js
@@ -29,35 +29,16 @@ 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");
let {ElemHide} = require("elemHide");
/**
- * Set of explicitly supported content types
- * @type Set
- */
-let contentTypes = new Set([
- "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT",
- "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "ELEMHIDE", "POPUP",
- "GENERICHIDE", "GENERICBLOCK"
-]);
-
-/**
- * Set of content types that aren't associated with a visual document area
- * @type Set
- */
-let nonVisualTypes = new Set([
- "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT",
- "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK"
-]);
-
-/**
* Randomly generated class name, to be applied to collapsed nodes.
*/
let collapsedClass = "";
/**
* Maps numerical content type IDs to strings.
* @type Map
*/
@@ -65,20 +46,33 @@ let types = new Map();
/**
* Public policy checking functions and auxiliary objects
* @class
*/
var Policy = exports.Policy =
{
/**
- * Map of localized content type names by their identifiers.
- * @type Map
+ * Set of explicitly supported content types
+ * @type Set
*/
- localizedDescr: new Map(),
+ contentTypes: new Set([
+ "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT",
+ "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "ELEMHIDE", "POPUP",
+ "GENERICHIDE", "GENERICBLOCK"
+ ]),
+
+ /**
+ * Set of content types that aren't associated with a visual document area
+ * @type Set
+ */
+ nonVisualTypes: new Set([
+ "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT",
+ "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK"
+ ]),
/**
* Map containing all schemes that should be ignored by content policy.
* @type Object
*/
whitelistSchemes: new Set(),
/**
@@ -87,20 +81,16 @@ var Policy = exports.Policy =
init: function()
{
// Populate types map
let iface = Ci.nsIContentPolicy;
for (let name in iface)
if (name.indexOf("TYPE_") == 0 && name != "TYPE_DATAREQUEST")
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.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++)
@@ -127,17 +117,17 @@ var Policy = exports.Policy =
*/
processNode: function(wnd, node, contentType, location, collapse)
{
let topWnd = wnd.top;
if (!topWnd || !topWnd.location || !topWnd.location.href)
return true;
// Interpret unknown types as "other"
- if (!contentTypes.has(contentType))
+ if (!this.contentTypes.has(contentType))
contentType = "OTHER";
let originWindow = Utils.getOriginWindow(wnd);
let wndLocation = originWindow.location.href;
let docDomain = getHostname(wndLocation);
let match = null;
let [sitekey, sitekeyWnd] = getSitekey(wnd);
let nogeneric = false;
@@ -228,17 +218,17 @@ var Policy = exports.Policy =
}
let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location, docDomain));
if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentType))
{
match = defaultMatcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty, sitekey, nogeneric);
- if (match instanceof BlockingFilter && node.ownerDocument && !nonVisualTypes.has(contentType))
+ if (match instanceof BlockingFilter && node.ownerDocument && !this.nonVisualTypes.has(contentType))
{
let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fastcollapse);
if (collapse || prefCollapse)
schedulePostProcess(node);
}
// Track mouse events for objects
if (!match && contentType == "OBJECT" && node.nodeType == Ci.nsIDOMNode.ELEMENT_NODE)

Powered by Google App Engine
This is Rietveld