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-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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 }); | 48 }); |
49 | 49 |
50 function onBeforeRequest(url, type, page, frame) | 50 function onBeforeRequest(url, type, page, frame) |
51 { | 51 { |
52 if (isFrameWhitelisted(page, frame)) | 52 if (isFrameWhitelisted(page, frame)) |
53 return true; | 53 return true; |
54 | 54 |
55 var docDomain = extractHostFromFrame(frame); | 55 var docDomain = extractHostFromFrame(frame); |
56 var key = getKey(page, frame); | 56 var key = getKey(page, frame); |
57 var filter = defaultMatcher.matchesAny( | 57 var filter = defaultMatcher.matchesAny( |
58 url, | 58 stringifyURL(url), |
59 type == "sub_frame" ? "SUBDOCUMENT" : type.toUpperCase(), | 59 type == "sub_frame" ? "SUBDOCUMENT" : type.toUpperCase(), |
60 docDomain, | 60 docDomain, |
61 isThirdParty(extractHostFromURL(url), docDomain), | 61 isThirdParty(url, docDomain), |
62 key | 62 key |
63 ); | 63 ); |
64 | 64 |
65 // We can't listen to onHeadersReceived in Safari so we need to | 65 // We can't listen to onHeadersReceived in Safari so we need to |
66 // check for notifications here | 66 // check for notifications here |
67 if (platform != "chromium" && type == "sub_frame") | 67 if (platform != "chromium" && type == "sub_frame") |
68 { | 68 { |
69 var notificationToShow = NotificationStorage.getNextToShow(url); | 69 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(url)
); |
70 if (notificationToShow) | 70 if (notificationToShow) |
71 showNotification(notificationToShow); | 71 showNotification(notificationToShow); |
72 } | 72 } |
73 | 73 |
74 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); | 74 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); |
75 return !(filter instanceof BlockingFilter); | 75 return !(filter instanceof BlockingFilter); |
76 } | 76 } |
77 | 77 |
78 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest); | 78 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest); |
79 | 79 |
80 if (platform == "chromium") | 80 if (platform == "chromium") |
81 { | 81 { |
82 function onHeadersReceived(details) | 82 function onHeadersReceived(details) |
83 { | 83 { |
84 if (details.tabId == -1) | 84 if (details.tabId == -1) |
85 return; | 85 return; |
86 | 86 |
87 if (details.type != "main_frame" && details.type != "sub_frame") | 87 if (details.type != "main_frame" && details.type != "sub_frame") |
88 return; | 88 return; |
89 | 89 |
90 var page = new ext.Page({id: details.tabId}); | 90 var page = new ext.Page({id: details.tabId}); |
91 var frame = ext.getFrame(details.tabId, details.frameId); | 91 var frame = ext.getFrame(details.tabId, details.frameId); |
92 | 92 |
93 if (!frame || frame.url != details.url) | 93 if (!frame || frame.url.href != details.url) |
94 return; | 94 return; |
95 | 95 |
96 for (var i = 0; i < details.responseHeaders.length; i++) | 96 for (var i = 0; i < details.responseHeaders.length; i++) |
97 { | 97 { |
98 var header = details.responseHeaders[i]; | 98 var header = details.responseHeaders[i]; |
99 if (header.name.toLowerCase() == "x-adblock-key" && header.value) | 99 if (header.name.toLowerCase() == "x-adblock-key" && header.value) |
100 processKey(header.value, page, frame); | 100 processKey(header.value, page, frame); |
101 } | 101 } |
102 | 102 |
103 var notificationToShow = NotificationStorage.getNextToShow(details.url); | 103 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(new
URL(details.url))); |
104 if (notificationToShow) | 104 if (notificationToShow) |
105 showNotification(notificationToShow); | 105 showNotification(notificationToShow); |
106 } | 106 } |
107 | 107 |
108 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["ht
tp://*/*", "https://*/*"]}, ["responseHeaders"]); | 108 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["ht
tp://*/*", "https://*/*"]}, ["responseHeaders"]); |
109 } | 109 } |
OLD | NEW |