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

Side by Side Diff: lib/requestBlocker.js

Issue 29711592: Issue 6424 - Use internal symbol in ext namespace (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Switch to internal methods everywhere Created March 1, 2018, 11:58 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 if (devtools) 84 if (devtools)
85 { 85 {
86 devtools.logRequest( 86 devtools.logRequest(
87 page, url, type, docDomain, 87 page, url, type, docDomain,
88 thirdParty, sitekey, 88 thirdParty, sitekey,
89 specificOnly, filter 89 specificOnly, filter
90 ); 90 );
91 } 91 }
92 } 92 }
93 93
94 ext.webRequest.onBeforeRequest.addListener((url, type, page, frame) => 94 function shouldAllowRequest(url, type, page, frame)
95 { 95 {
96 let docDomain = null; 96 let docDomain = null;
97 let sitekey = null; 97 let sitekey = null;
98 let specificOnly = false; 98 let specificOnly = false;
99 let thirdParty = false; 99 let thirdParty = false;
100 let urlString = stringifyURL(url); 100 let urlString = stringifyURL(url);
101 101
102
103 if (frame && page) 102 if (frame && page)
104 { 103 {
105 if (checkWhitelisted(page, frame)) 104 if (checkWhitelisted(page, frame))
106 return true; 105 return true;
107 106
108 docDomain = extractHostFromFrame(frame); 107 docDomain = extractHostFromFrame(frame);
109 sitekey = getKey(page, frame); 108 sitekey = getKey(page, frame);
110 thirdParty = isThirdParty(url, docDomain); 109 thirdParty = isThirdParty(url, docDomain);
111 specificOnly = !!checkWhitelisted(page, frame, 110 specificOnly = !!checkWhitelisted(page, frame,
112 RegExpFilter.typeMap.GENERICBLOCK); 111 RegExpFilter.typeMap.GENERICBLOCK);
113 } 112 }
114 113
115 let mappedType = resourceTypes.get(type) || "OTHER"; 114 let mappedType = resourceTypes.get(type) || "OTHER";
116 115
117 let filter = defaultMatcher.matchesAny( 116 let filter = defaultMatcher.matchesAny(
118 urlString, RegExpFilter.typeMap[mappedType], 117 urlString, RegExpFilter.typeMap[mappedType],
119 docDomain, thirdParty, sitekey, specificOnly 118 docDomain, thirdParty, sitekey, specificOnly
120 ); 119 );
121 120
122 setTimeout(onBeforeRequestAsync, 0, page, urlString, 121 setTimeout(onBeforeRequestAsync, 0, page, urlString,
123 mappedType, docDomain, 122 mappedType, docDomain,
124 thirdParty, sitekey, 123 thirdParty, sitekey,
125 specificOnly, filter); 124 specificOnly, filter);
126 125
127 return !(filter instanceof BlockingFilter); 126 return !(filter instanceof BlockingFilter);
128 }); 127 }
128
129 ext.webRequest.onBeforeRequest.addListener(shouldAllowRequest);
129 130
130 port.on("filters.collapse", (message, sender) => 131 port.on("filters.collapse", (message, sender) =>
131 { 132 {
132 if (checkWhitelisted(sender.page, sender.frame)) 133 if (checkWhitelisted(sender.page, sender.frame))
133 return false; 134 return false;
134 135
135 let typeMask = RegExpFilter.typeMap[message.mediatype]; 136 let typeMask = RegExpFilter.typeMap[message.mediatype];
136 let documentHost = extractHostFromFrame(sender.frame); 137 let documentHost = extractHostFromFrame(sender.frame);
137 let sitekey = getKey(sender.page, sender.frame); 138 let sitekey = getKey(sender.page, sender.frame);
138 let blocked = false; 139 let blocked = false;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // messages from the wrapper here (see https://crbug.com/129353). Hopefully 212 // messages from the wrapper here (see https://crbug.com/129353). Hopefully
212 // WebRTC will be supported soon too (see https://crbug.com/707683). 213 // WebRTC will be supported soon too (see https://crbug.com/707683).
213 // Edge supports neither webRequest.ResourceType nor WebSocket blocking yet: 214 // Edge supports neither webRequest.ResourceType nor WebSocket blocking yet:
214 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/102973 76/ 215 // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/102973 76/
215 if (browser.webRequest.ResourceType && 216 if (browser.webRequest.ResourceType &&
216 (msg.requestType.toUpperCase() in browser.webRequest.ResourceType)) 217 (msg.requestType.toUpperCase() in browser.webRequest.ResourceType))
217 { 218 {
218 return false; 219 return false;
219 } 220 }
220 221
221 return ext.webRequest.onBeforeRequest._dispatch( 222 return !shouldAllowRequest(new URL(msg.url), msg.requestType, sender.page,
222 new URL(msg.url), 223 sender.frame);
223 msg.requestType,
224 sender.page,
225 sender.frame
226 ).includes(false);
227 }); 224 });
OLDNEW
« ext/background.js ('K') | « ext/content.js ('k') | metadata.chrome » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld