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

Unified Diff: lib/contentPolicy.js

Issue 29333254: Issue 3459 - Don't duplicate content type definition (Closed)
Patch Set: Created Jan. 6, 2016, 1:29 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 | « chrome/content/ui/sidebar.js ('k') | 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
@@ -38,32 +38,30 @@
var Policy = exports.Policy =
{
/**
- * Set of explicitly supported content types
- * @type Set.<string>
- */
- contentTypes: new Set([
- "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT",
- "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "PING", "ELEMHIDE",
- "POPUP", "GENERICHIDE", "GENERICBLOCK"
- ]),
-
- /**
* Map of content types reported by Firefox to the respecitve content types
* used by Adblock Plus. Other content types are simply mapped to OTHER.
* @type Map.<string,string>
*/
- contentTypesMap: new Map([
+ contentTypes: new Map(function* ()
+ {
// Treat navigator.sendBeacon() the same as <a ping>,
// it's essentially the same concept - merely generalized.
- ["BEACON", "PING"],
+ yield ["BEACON", "PING"];
// Treat <img srcset> and <picture> the same as other images.
- ["IMAGESET", "IMAGE"],
+ yield ["IMAGESET", "IMAGE"];
// Treat fetch() the same as XMLHttpRequest,
// it's essentially the same - merely a more modern API.
- ["FETCH", "XMLHTTPREQUEST"]
- ]),
+ yield ["FETCH", "XMLHTTPREQUEST"];
+
+ // Everything else is mapped to itself
+ for (let contentType of ["OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT",
+ "SUBDOCUMENT", "DOCUMENT", "XMLHTTPREQUEST",
+ "OBJECT_SUBREQUEST", "FONT", "MEDIA", "PING",
+ "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK"])
+ yield [contentType, contentType];
+ }()),
/**
* Set of content types that aren't associated with a visual document area
@@ -85,9 +83,6 @@
*/
init: function()
{
- for (let contentType of this.contentTypes)
- this.contentTypesMap.set(contentType, contentType);
-
// whitelisted URL schemes
for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" "))
this.whitelistSchemes.add(scheme);
@@ -147,7 +142,7 @@
return response(true, false);
// Interpret unknown types as "other"
- contentType = this.contentTypesMap.get(contentType) || "OTHER";
+ contentType = this.contentTypes.get(contentType) || "OTHER";
let wndLocation = frames[0].location;
let docDomain = getHostname(wndLocation);
« no previous file with comments | « chrome/content/ui/sidebar.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld