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

Side by Side Diff: lib/whitelisting.js

Issue 29739594: Issue 6543 - Match requests without tabId/frameId in their originating context (Closed)
Patch Set: Created April 2, 2018, 2:55 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
« lib/requestBlocker.js ('K') | « lib/url.js ('k') | 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-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 25 matching lines...) Expand all
36 let thirdParty = !!docDomain && isThirdParty(url, docDomain); 36 let thirdParty = !!docDomain && isThirdParty(url, docDomain);
37 let urlString = stringifyURL(url); 37 let urlString = stringifyURL(url);
38 38
39 if (!docDomain) 39 if (!docDomain)
40 docDomain = getDecodedHostname(url); 40 docDomain = getDecodedHostname(url);
41 41
42 let filter = defaultMatcher.whitelist.matchesAny( 42 let filter = defaultMatcher.whitelist.matchesAny(
43 urlString, typeMask, docDomain, thirdParty, sitekey 43 urlString, typeMask, docDomain, thirdParty, sitekey
44 ); 44 );
45 45
46 if (filter) 46 if (filter && page)
47 logWhitelistedDocument(page.id, urlString, typeMask, docDomain, filter); 47 logWhitelistedDocument(page.id, urlString, typeMask, docDomain, filter);
48 48
49 return filter; 49 return filter;
50 } 50 }
51 51
52 let checkWhitelisted = 52 let checkWhitelisted =
53 /** 53 /**
54 * Gets the active whitelisting filter for the document associated 54 * Gets the active whitelisting filter for the document associated
55 * with the given page/frame, or null if it's not whitelisted. 55 * with the given page/frame, or null if it's not whitelisted.
56 * 56 *
57 * @param {Page} page 57 * @param {?Page} page
58 * @param {Frame} [frame] 58 * @param {?Frame} [frame]
59 * @param {?URL} [originUrl]
59 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] 60 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT]
60 * @return {?WhitelistFilter} 61 * @return {?WhitelistFilter}
61 */ 62 */
62 exports.checkWhitelisted = (page, frame, typeMask) => 63 exports.checkWhitelisted = (page, frame, originUrl,
64 typeMask = RegExpFilter.typeMap.DOCUMENT) =>
63 { 65 {
64 if (typeof typeMask == "undefined") 66 if (frame || originUrl)
65 typeMask = RegExpFilter.typeMap.DOCUMENT; 67 {
68 while (frame)
69 {
70 let parentFrame = frame.parent;
71 let filter = match(page, frame.url, typeMask,
72 extractHostFromFrame(parentFrame, originUrl),
73 getKey(page, frame, originUrl));
66 74
67 if (frame) 75 if (filter)
68 { 76 return filter;
69 let filter = null;
70 77
71 while (frame && !filter) 78 frame = parentFrame;
72 {
73 let {parent} = frame;
74 let docDomain = extractHostFromFrame(parent);
75 let sitekey = getKey(page, frame);
76
77 filter = match(page, frame.url, typeMask, docDomain, sitekey);
78 frame = parent;
79 } 79 }
80 80
81 return filter; 81 return originUrl && match(page, originUrl, typeMask, null,
kzar 2018/04/03 12:49:30 How come you changed the logic to `originUrl && ..
Sebastian Noack 2018/04/04 01:04:45 It's the same semantics for checkWhitelisted(), ge
82 getKey(null, null, originUrl));
82 } 83 }
83 84
84 return match(page, page.url, typeMask); 85 return page && match(page, page.url, typeMask);
85 }; 86 };
86 87
87 port.on("filters.isWhitelisted", message => 88 port.on("filters.isWhitelisted", message =>
88 { 89 {
89 return !!checkWhitelisted(new ext.Page(message.tab)); 90 return !!checkWhitelisted(new ext.Page(message.tab));
90 }); 91 });
91 92
92 port.on("filters.whitelist", message => 93 port.on("filters.whitelist", message =>
93 { 94 {
94 let page = new ext.Page(message.tab); 95 let page = new ext.Page(message.tab);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 }); 137 });
137 }); 138 });
138 139
139 ext.pages.onLoading.addListener(revalidateWhitelistingState); 140 ext.pages.onLoading.addListener(revalidateWhitelistingState);
140 141
141 let getKey = 142 let getKey =
142 /** 143 /**
143 * Gets the public key, previously recorded for the given page 144 * Gets the public key, previously recorded for the given page
144 * and frame, to be considered for the $sitekey filter option. 145 * and frame, to be considered for the $sitekey filter option.
145 * 146 *
146 * @param {Page} page 147 * @param {?Page} page
147 * @param {Frame} frame 148 * @param {?Frame} frame
149 * @param {URL} [originUrl]
148 * @return {string} 150 * @return {string}
149 */ 151 */
150 exports.getKey = (page, frame) => 152 exports.getKey = (page, frame, originUrl) =>
151 { 153 {
152 let keys = sitekeys.get(page); 154 if (page)
153 if (!keys) 155 {
154 return null; 156 let keys = sitekeys.get(page);
157 if (keys)
158 {
159 for (; frame; frame = frame.parent)
160 {
161 let key = keys.get(stringifyURL(frame.url));
162 if (key)
163 return key;
164 }
165 }
166 }
155 167
156 for (; frame != null; frame = frame.parent) 168 if (originUrl)
157 { 169 {
158 let key = keys.get(stringifyURL(frame.url)); 170 for (let keys of sitekeys._map.values())
159 if (key) 171 {
160 return key; 172 let key = keys.get(stringifyURL(originUrl));
173 if (key)
174 return key;
175 }
161 } 176 }
162 177
163 return null; 178 return null;
164 }; 179 };
165 180
166 function checkKey(token, url) 181 function checkKey(token, url)
167 { 182 {
168 let parts = token.split("_"); 183 let parts = token.split("_");
169 if (parts.length < 2) 184 if (parts.length < 2)
170 return false; 185 return false;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 { 236 {
222 browser.webRequest.onHeadersReceived.addListener( 237 browser.webRequest.onHeadersReceived.addListener(
223 onHeadersReceived, 238 onHeadersReceived,
224 { 239 {
225 urls: ["http://*/*", "https://*/*"], 240 urls: ["http://*/*", "https://*/*"],
226 types: ["main_frame", "sub_frame"] 241 types: ["main_frame", "sub_frame"]
227 }, 242 },
228 ["responseHeaders"] 243 ["responseHeaders"]
229 ); 244 );
230 } 245 }
OLDNEW
« lib/requestBlocker.js ('K') | « lib/url.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld