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

Side by Side Diff: lib/contentPolicy.js

Issue 29333097: Isssue 3459 - Map the content type IMAGESET to IMAGE and FETCH to XMLHTTPREQUEST (Closed)
Patch Set: Added missing comment Created Dec. 28, 2015, 4:31 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 var Policy = exports.Policy = 38 var Policy = exports.Policy =
39 { 39 {
40 /** 40 /**
41 * Set of explicitly supported content types 41 * Set of explicitly supported content types
42 * @type Set.<string> 42 * @type Set.<string>
43 */ 43 */
44 contentTypes: new Set([ 44 contentTypes: new Set([
45 "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT ", 45 "OTHER", "SCRIPT", "IMAGE", "STYLESHEET", "OBJECT", "SUBDOCUMENT", "DOCUMENT ",
46 "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "PING", "ELEMHIDE", 46 "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", "MEDIA", "PING", "ELEMHIDE",
47 "POPUP", "GENERICHIDE", "GENERICBLOCK" 47 "POPUP", "GENERICHIDE", "GENERICBLOCK"
48 ]), 48 ]),
Wladimir Palant 2015/12/29 23:19:48 This member becomes unnecessary with your change,
Sebastian Noack 2015/12/30 15:54:58 Note that chrome/content/ui/sidebar.js and chrome/
Wladimir Palant 2016/01/06 12:46:00 You are right but that's not a reason to duplicate
Sebastian Noack 2016/01/06 13:29:50 There you go: https://codereview.adblockplus.org/2
49 49
50 /** 50 /**
51 * Map of content types reported by Firefox to the respecitve content types
52 * used by Adblock Plus. Other content types are simply mapped to OTHER.
53 * @type Map.<string,string>
54 */
55 contentTypesMap: new Map([
56 // Treat navigator.sendBeacon() the same as <a ping>,
57 // it's essentially the same concept - merely generalized.
58 ["BEACON", "PING"],
59
60 // Treat <img srcset> and <picture> the same as other images.
61 ["IMAGESET", "IMAGE"],
62
63 // Treat fetch() the same as XMLHttpRequest,
64 // it's essentially the same - merely a more modern API.
65 ["FETCH", "XMLHTTPREQUEST"]
66 ]),
67
68 /**
51 * Set of content types that aren't associated with a visual document area 69 * Set of content types that aren't associated with a visual document area
52 * @type Set.<string> 70 * @type Set.<string>
53 */ 71 */
54 nonVisualTypes: new Set([ 72 nonVisualTypes: new Set([
55 "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT", 73 "SCRIPT", "STYLESHEET", "XMLHTTPREQUEST", "OBJECT_SUBREQUEST", "FONT",
56 "PING", "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK" 74 "PING", "ELEMHIDE", "POPUP", "GENERICHIDE", "GENERICBLOCK"
57 ]), 75 ]),
58 76
59 /** 77 /**
60 * Map containing all schemes that should be ignored by content policy. 78 * Map containing all schemes that should be ignored by content policy.
61 * @type Set.<string> 79 * @type Set.<string>
62 */ 80 */
63 whitelistSchemes: new Set(), 81 whitelistSchemes: new Set(),
64 82
65 /** 83 /**
66 * Called on module startup, initializes various exported properties. 84 * Called on module startup, initializes various exported properties.
67 */ 85 */
68 init: function() 86 init: function()
69 { 87 {
88 for (let contentType of this.contentTypes)
89 this.contentTypesMap.set(contentType, contentType);
90
70 // whitelisted URL schemes 91 // whitelisted URL schemes
71 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" ")) 92 for (let scheme of Prefs.whitelistschemes.toLowerCase().split(" "))
72 this.whitelistSchemes.add(scheme); 93 this.whitelistSchemes.add(scheme);
73 94
74 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", message => this.sho uldAllow(message)); 95 Utils.addChildMessageListener("AdblockPlus:ShouldAllow", message => this.sho uldAllow(message));
75 96
76 // Generate class identifier used to collapse nodes and register 97 // Generate class identifier used to collapse nodes and register
77 // corresponding stylesheet. 98 // corresponding stylesheet.
78 let collapsedClass = ""; 99 let collapsedClass = "";
79 let offset = "a".charCodeAt(0); 100 let offset = "a".charCodeAt(0);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 139
119 function response(allow, collapse) 140 function response(allow, collapse)
120 { 141 {
121 return {allow, collapse, hits}; 142 return {allow, collapse, hits};
122 } 143 }
123 144
124 // Ignore whitelisted schemes 145 // Ignore whitelisted schemes
125 if (!this.isBlockableScheme(location)) 146 if (!this.isBlockableScheme(location))
126 return response(true, false); 147 return response(true, false);
127 148
128 // Treat navigator.sendBeacon() the same as <a ping>, it's essentially the
129 // same concept - merely generalized.
130 if (contentType == "BEACON")
131 contentType = "PING";
132
133 // Interpret unknown types as "other" 149 // Interpret unknown types as "other"
134 if (!this.contentTypes.has(contentType)) 150 contentType = this.contentTypesMap.get(contentType) || "OTHER";
135 contentType = "OTHER";
136 151
137 let wndLocation = frames[0].location; 152 let wndLocation = frames[0].location;
138 let docDomain = getHostname(wndLocation); 153 let docDomain = getHostname(wndLocation);
139 let match = null; 154 let match = null;
140 let [sitekey, sitekeyFrame] = getSitekey(frames); 155 let [sitekey, sitekeyFrame] = getSitekey(frames);
141 let nogeneric = false; 156 let nogeneric = false;
142 if (!match && Prefs.enabled) 157 if (!match && Prefs.enabled)
143 { 158 {
144 let testSitekey = sitekey; 159 let testSitekey = sitekey;
145 let testSitekeyFrame = sitekeyFrame; 160 let testSitekeyFrame = sitekeyFrame;
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 { 415 {
401 // EffectiveTLDService throws on IP addresses, just compare the host name 416 // EffectiveTLDService throws on IP addresses, just compare the host name
402 let host = ""; 417 let host = "";
403 try 418 try
404 { 419 {
405 host = uri.host; 420 host = uri.host;
406 } catch (e) {} 421 } catch (e) {}
407 return host != docDomain; 422 return host != docDomain;
408 } 423 }
409 } 424 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld