OLD | NEW |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 26 matching lines...) Expand all Loading... |
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 && devtools) | 46 if (filter && devtools) |
| 47 { |
47 devtools.logWhitelistedDocument( | 48 devtools.logWhitelistedDocument( |
48 page, urlString, typeMask, docDomain, filter | 49 page, urlString, typeMask, docDomain, filter |
49 ); | 50 ); |
| 51 } |
50 | 52 |
51 return filter; | 53 return filter; |
52 } | 54 } |
53 | 55 |
54 let checkWhitelisted = | 56 let checkWhitelisted = |
55 /** | 57 /** |
56 * Gets the active whitelisting filter for the document associated | 58 * Gets the active whitelisting filter for the document associated |
57 * with the given page/frame, or null if it's not whitelisted. | 59 * with the given page/frame, or null if it's not whitelisted. |
58 * | 60 * |
59 * @param {Page} page | 61 * @param {Page} page |
60 * @param {Frame} [frame] | 62 * @param {Frame} [frame] |
61 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] | 63 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] |
62 * @return {?WhitelistFilter} | 64 * @return {?WhitelistFilter} |
63 */ | 65 */ |
64 exports.checkWhitelisted = (page, frame, typeMask) => | 66 exports.checkWhitelisted = (page, frame, typeMask) => |
65 { | 67 { |
66 if (typeof typeMask == "undefined") | 68 if (typeof typeMask == "undefined") |
67 typeMask = RegExpFilter.typeMap.DOCUMENT; | 69 typeMask = RegExpFilter.typeMap.DOCUMENT; |
68 | 70 |
69 if (frame) | 71 if (frame) |
70 { | 72 { |
71 let filter = null; | 73 let filter = null; |
72 | 74 |
73 while (frame && !filter) | 75 while (frame && !filter) |
74 { | 76 { |
75 let parent = frame.parent; | 77 let {parent} = frame; |
76 let docDomain = extractHostFromFrame(parent); | 78 let docDomain = extractHostFromFrame(parent); |
77 let sitekey = getKey(page, frame); | 79 let sitekey = getKey(page, frame); |
78 | 80 |
79 filter = match(page, frame.url, typeMask, docDomain, sitekey); | 81 filter = match(page, frame.url, typeMask, docDomain, sitekey); |
80 frame = parent; | 82 frame = parent; |
81 } | 83 } |
82 | 84 |
83 return filter; | 85 return filter; |
84 } | 86 } |
85 | 87 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 if (header.name.toLowerCase() == "x-adblock-key" && header.value) | 181 if (header.name.toLowerCase() == "x-adblock-key" && header.value) |
180 { | 182 { |
181 let url = new URL(details.url); | 183 let url = new URL(details.url); |
182 let key = checkKey(header.value, url); | 184 let key = checkKey(header.value, url); |
183 if (key) | 185 if (key) |
184 { | 186 { |
185 // For pre-rendered tabs we don't know for sure the navigation is going | 187 // For pre-rendered tabs we don't know for sure the navigation is going |
186 // to happen until the onCommitted event fires. Unfortunately if we want | 188 // to happen until the onCommitted event fires. Unfortunately if we want |
187 // sitekey whitelisting to work for requests made before onCommitted has | 189 // sitekey whitelisting to work for requests made before onCommitted has |
188 // been fired we must update the page structure now anyway. | 190 // been fired we must update the page structure now anyway. |
189 ext._updatePageFrameStructure(details.frameId, details.tabId, details.ur
l, true); | 191 ext._updatePageFrameStructure(details.frameId, details.tabId, |
| 192 details.url, true); |
190 recordKey(key, page, url); | 193 recordKey(key, page, url); |
191 break; | 194 break; |
192 } | 195 } |
193 } | 196 } |
194 } | 197 } |
195 } | 198 } |
196 | 199 |
197 if (typeof chrome == "object") | 200 if (typeof chrome == "object") |
| 201 { |
198 chrome.webRequest.onHeadersReceived.addListener( | 202 chrome.webRequest.onHeadersReceived.addListener( |
199 onHeadersReceived, | 203 onHeadersReceived, |
200 { | 204 { |
201 urls: ["http://*/*", "https://*/*"], | 205 urls: ["http://*/*", "https://*/*"], |
202 types: ["main_frame", "sub_frame"] | 206 types: ["main_frame", "sub_frame"] |
203 }, | 207 }, |
204 ["responseHeaders"] | 208 ["responseHeaders"] |
205 ); | 209 ); |
| 210 } |
OLD | NEW |