@@ -111,17 +111,16 @@ function getCnameAliases(domain) {
111111 * @returns {Object }
112112 */
113113function makeDnrBlockRule ( domain , priority = constants . DNR_BLOCK ) {
114- let id = badger . getDynamicRuleId ( ) ;
114+ let id = badger . getDynamicRuleId ( ) ,
115+ base = getBaseDomain ( domain ) ;
115116
116117 let action = {
117118 type : 'block'
118119 } ;
119120
120121 let condition = {
121122 requestDomains : [ domain ] ,
122- // TODO "A request is said to be first party if it has the same domain (eTLD+1) as the frame in which the request originated."
123- // TODO will this ever be a problem? frame vs. top-level frame
124- domainType : 'thirdParty' ,
123+ excludedTopDomains : [ base ]
125124 } ;
126125
127126 let cnames = getCnameAliases ( domain ) ;
@@ -131,16 +130,9 @@ function makeDnrBlockRule(domain, priority = constants.DNR_BLOCK) {
131130 condition . requestDomains = condition . requestDomains . concat ( cnames ) ;
132131 }
133132
134- let mdfpList = mdfp . getEntityList ( getBaseDomain ( domain ) ) ;
133+ let mdfpList = mdfp . getEntityList ( base ) ;
135134 if ( mdfpList . length ) {
136- condition . excludedInitiatorDomains = mdfpList ;
137- }
138-
139- if ( cnames . length ) {
140- delete condition . domainType ;
141- if ( ! condition . excludedInitiatorDomains ) {
142- condition . excludedInitiatorDomains = [ domain ] ;
143- }
135+ condition . excludedTopDomains = mdfpList ;
144136 }
145137
146138 let rule = { id, action, condition, priority } ;
@@ -157,7 +149,8 @@ function makeDnrBlockRule(domain, priority = constants.DNR_BLOCK) {
157149 * @returns {Object }
158150 */
159151function makeDnrCookieblockRule ( domain , priority = constants . DNR_COOKIEBLOCK_HEADERS ) {
160- let id = badger . getDynamicRuleId ( ) ;
152+ let id = badger . getDynamicRuleId ( ) ,
153+ base = getBaseDomain ( domain ) ;
161154
162155 let action = {
163156 type : 'modifyHeaders' ,
@@ -167,7 +160,7 @@ function makeDnrCookieblockRule(domain, priority = constants.DNR_COOKIEBLOCK_HEA
167160
168161 let condition = {
169162 requestDomains : [ domain ] ,
170- domainType : 'thirdParty' ,
163+ excludedTopDomains : [ base ]
171164 } ;
172165
173166 let cnames = getCnameAliases ( domain ) ;
@@ -177,16 +170,9 @@ function makeDnrCookieblockRule(domain, priority = constants.DNR_COOKIEBLOCK_HEA
177170 condition . requestDomains = condition . requestDomains . concat ( cnames ) ;
178171 }
179172
180- let mdfpList = mdfp . getEntityList ( getBaseDomain ( domain ) ) ;
173+ let mdfpList = mdfp . getEntityList ( base ) ;
181174 if ( mdfpList . length ) {
182- condition . excludedInitiatorDomains = mdfpList ;
183- }
184-
185- if ( cnames . length ) {
186- delete condition . domainType ;
187- if ( ! condition . excludedInitiatorDomains ) {
188- condition . excludedInitiatorDomains = [ domain ] ;
189- }
175+ condition . excludedTopDomains = mdfpList ;
190176 }
191177
192178 let rule = { id, action, condition, priority } ;
@@ -214,13 +200,11 @@ function makeDnrAllowRule(domain, priority = constants.DNR_COOKIEBLOCK_ALLOW) {
214200
215201 let condition = {
216202 requestDomains : [ domain ] ,
217- domainType : 'thirdParty'
218203 } ;
219204
220205 let cnames = getCnameAliases ( domain ) ;
221206
222207 if ( cnames . length ) {
223- delete condition . domainType ;
224208 // important for requestDomains[0] to be the domain
225209 condition . requestDomains = condition . requestDomains . concat ( cnames ) ;
226210 }
@@ -245,6 +229,8 @@ function makeDnrAllowRule(domain, priority = constants.DNR_COOKIEBLOCK_ALLOW) {
245229function makeDnrSurrogateRule ( id , script_host , surrogate_path , extraConditions ,
246230 priority = constants . DNR_SURROGATE_REDIRECT , resource_type = 'script' ) {
247231
232+ let script_base = getBaseDomain ( script_host ) ;
233+
248234 let rule = {
249235 id,
250236 priority,
@@ -257,21 +243,21 @@ function makeDnrSurrogateRule(id, script_host, surrogate_path, extraConditions,
257243 condition : {
258244 requestDomains : [ script_host ] ,
259245 resourceTypes : [ resource_type ] ,
260- domainType : 'thirdParty' ,
261- excludedInitiatorDomains : mdfp . getEntityList ( getBaseDomain ( script_host ) )
246+ excludedTopDomains : [ script_base ]
262247 }
263248 } ;
264249
250+ let mdfpList = mdfp . getEntityList ( script_base ) ;
251+ if ( mdfpList . length ) {
252+ rule . condition . excludedTopDomains = mdfpList ;
253+ }
254+
265255 if ( extraConditions ) {
266256 for ( let key in extraConditions ) {
267257 rule . condition [ key ] = extraConditions [ key ] ;
268258 }
269259 }
270260
271- if ( ! rule . condition . excludedInitiatorDomains . length ) {
272- delete rule . condition . excludedInitiatorDomains ;
273- }
274-
275261 return rule ;
276262}
277263
@@ -349,6 +335,14 @@ function getDnrSurrogateRules(domain, is_user_action) {
349335 * @returns {Object }
350336 */
351337function makeDnrFpScriptBlockRule ( id , domain , path ) {
338+ let base = getBaseDomain ( domain ) ,
339+ excludedTopDomains = [ base ] ;
340+
341+ let mdfpList = mdfp . getEntityList ( base ) ;
342+ if ( mdfpList . length ) {
343+ excludedTopDomains = mdfpList ;
344+ }
345+
352346 return {
353347 id,
354348 priority : constants . DNR_FP_SCRIPT_BLOCK ,
@@ -357,8 +351,7 @@ function makeDnrFpScriptBlockRule(id, domain, path) {
357351 requestDomains : [ domain ] ,
358352 resourceTypes : [ 'script' ] ,
359353 urlFilter : '||' + domain + path + '^' ,
360- domainType : 'thirdParty' ,
361- excludedInitiatorDomains : mdfp . getEntityList ( getBaseDomain ( domain ) )
354+ excludedTopDomains
362355 }
363356 } ;
364357}
@@ -450,7 +443,7 @@ let updateSessionAllowRules = utils.debounce(async function (tempAllowlist) {
450443 * Reregisters DNR session rules for site-specific domain overrides.
451444 *
452445 * These are session rules because we can scope session rules to tab IDs.
453- * What we actually want to do though is make topDomains-scoped dynamic rules.
446+ * TODO What we actually want to do though is make topDomains-scoped dynamic rules.
454447 *
455448 * @param {Number } tab_id
456449 * @param {String } tab_host
@@ -786,7 +779,7 @@ async function updateWidgetSiteAllowlistRules(widgetSiteAllowlist) {
786779 priority : constants . DNR_WIDGET_ALLOW_ALL ,
787780 action : { type : 'allowAllRequests' } ,
788781 condition : {
789- initiatorDomains : [ site_host ] ,
782+ topDomains : [ site_host ] ,
790783 requestDomains : [ domain ] ,
791784 resourceTypes : [ 'sub_frame' ]
792785 }
@@ -804,7 +797,7 @@ async function updateWidgetSiteAllowlistRules(widgetSiteAllowlist) {
804797 priority : constants . DNR_WIDGET_ALLOW_ALL ,
805798 action : { type : 'allow' } ,
806799 condition : {
807- initiatorDomains : [ site_host ] ,
800+ topDomains : [ site_host ] ,
808801 requestDomains : [ domain ]
809802 }
810803 } ;
@@ -905,8 +898,7 @@ async function updateDntSignalHeaderRules() {
905898 let exceptionSites = Object . keys (
906899 badger . getPrivateSettings ( ) . getItem ( "gpcDisabledSites" ) ) ;
907900 if ( exceptionSites . length ) {
908- // TODO switch to excludedTopDomains once widely available
909- rule . condition . excludedInitiatorDomains = exceptionSites ;
901+ rule . condition . excludedTopDomains = exceptionSites ;
910902 }
911903 opts . addRules . push ( rule ) ;
912904
@@ -930,8 +922,7 @@ async function updateDntSignalHeaderRules() {
930922 condition : { }
931923 } ;
932924 if ( exceptionSites . length ) {
933- // TODO switch to excludedTopDomains once widely available
934- rule . condition . excludedInitiatorDomains = exceptionSites ;
925+ rule . condition . excludedTopDomains = exceptionSites ;
935926 }
936927 opts . addRules . push ( rule ) ;
937928 }
0 commit comments