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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 var FilterNotifier = require("filterNotifier").FilterNotifier; | 18 var FilterNotifier = require("filterNotifier").FilterNotifier; |
19 var RegExpFilter = require("filterClasses").RegExpFilter; | 19 var RegExpFilter = require("filterClasses").RegExpFilter; |
20 var platform = require("info").platform; | 20 var platform = require("info").platform; |
| 21 var showNextNotification = require("notificationHelper").showNextNotification; |
21 | 22 |
22 ext.webRequest.indistinguishableTypes.forEach(function(types) | 23 ext.webRequest.indistinguishableTypes.forEach(function(types) |
23 { | 24 { |
24 for (var i = 1; i < types.length; i++) | 25 for (var i = 1; i < types.length; i++) |
25 RegExpFilter.typeMap[types[i]] = RegExpFilter.typeMap[types[0]]; | 26 RegExpFilter.typeMap[types[i]] = RegExpFilter.typeMap[types[0]]; |
26 }); | 27 }); |
27 | 28 |
28 FilterNotifier.addListener(function(action, arg) | 29 FilterNotifier.addListener(function(action, arg) |
29 { | 30 { |
30 switch (action) | 31 switch (action) |
(...skipping 13 matching lines...) Expand all Loading... |
44 ext.webRequest.handlerBehaviorChanged(); | 45 ext.webRequest.handlerBehaviorChanged(); |
45 break; | 46 break; |
46 } | 47 } |
47 }); | 48 }); |
48 | 49 |
49 function onBeforeRequestAsync(url, type, page, filter) | 50 function onBeforeRequestAsync(url, type, page, filter) |
50 { | 51 { |
51 // We can't listen to onHeadersReceived in Safari so we need to | 52 // We can't listen to onHeadersReceived in Safari so we need to |
52 // check for notifications here | 53 // check for notifications here |
53 if (platform != "chromium" && type == "SUBDOCUMENT") | 54 if (platform != "chromium" && type == "SUBDOCUMENT") |
54 { | 55 showNextNotification(url); |
55 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(url)
); | |
56 if (notificationToShow) | |
57 showNotification(notificationToShow); | |
58 } | |
59 | 56 |
60 if (filter) | 57 if (filter) |
61 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); | 58 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); |
62 } | 59 } |
63 | 60 |
64 function onBeforeRequest(url, type, page, frame) | 61 function onBeforeRequest(url, type, page, frame) |
65 { | 62 { |
66 if (isFrameWhitelisted(page, frame)) | 63 if (isFrameWhitelisted(page, frame)) |
67 return true; | 64 return true; |
68 | 65 |
(...skipping 23 matching lines...) Expand all Loading... |
92 if (!frame || frame.url.href != details.url) | 89 if (!frame || frame.url.href != details.url) |
93 return; | 90 return; |
94 | 91 |
95 for (var i = 0; i < details.responseHeaders.length; i++) | 92 for (var i = 0; i < details.responseHeaders.length; i++) |
96 { | 93 { |
97 var header = details.responseHeaders[i]; | 94 var header = details.responseHeaders[i]; |
98 if (header.name.toLowerCase() == "x-adblock-key" && header.value) | 95 if (header.name.toLowerCase() == "x-adblock-key" && header.value) |
99 processKey(header.value, page, frame); | 96 processKey(header.value, page, frame); |
100 } | 97 } |
101 | 98 |
102 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(new
URL(details.url))); | 99 showNextNotification(new URL(details.url)); |
103 if (notificationToShow) | |
104 showNotification(notificationToShow); | |
105 } | 100 } |
106 | 101 |
107 chrome.webRequest.onHeadersReceived.addListener( | 102 chrome.webRequest.onHeadersReceived.addListener( |
108 onHeadersReceived, | 103 onHeadersReceived, |
109 { | 104 { |
110 urls: ["http://*/*", "https://*/*"], | 105 urls: ["http://*/*", "https://*/*"], |
111 types: ["main_frame", "sub_frame"] | 106 types: ["main_frame", "sub_frame"] |
112 }, | 107 }, |
113 ["responseHeaders"] | 108 ["responseHeaders"] |
114 ); | 109 ); |
115 } | 110 } |
OLD | NEW |