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

Side by Side Diff: webrequest.js

Issue 5630329503088640: Fixed miscellaneous issues with anti-adblock notification port (Closed)
Patch Set: Created March 28, 2014, 3:29 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« background.js ('K') | « background.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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 platform = require("info").platform;
19 20
20 var onFilterChangeTimeout = null; 21 var onFilterChangeTimeout = null;
21 function onFilterChange() 22 function onFilterChange()
22 { 23 {
23 onFilterChangeTimeout = null; 24 onFilterChangeTimeout = null;
24 ext.webRequest.handlerBehaviorChanged(); 25 ext.webRequest.handlerBehaviorChanged();
25 } 26 }
26 27
27 var importantNotifications = { 28 var importantNotifications = {
28 'filter.added': true, 29 'filter.added': true,
(...skipping 23 matching lines...) Expand all
52 return true; 53 return true;
53 54
54 var docDomain = extractHostFromURL(frame.url); 55 var docDomain = extractHostFromURL(frame.url);
55 var filter = defaultMatcher.matchesAny( 56 var filter = defaultMatcher.matchesAny(
56 url, 57 url,
57 type == "sub_frame" ? "SUBDOCUMENT" : type.toUpperCase(), 58 type == "sub_frame" ? "SUBDOCUMENT" : type.toUpperCase(),
58 docDomain, 59 docDomain,
59 isThirdParty(extractHostFromURL(url), docDomain) 60 isThirdParty(extractHostFromURL(url), docDomain)
60 ); 61 );
61 62
63 // We can't listen to onHeadersReceived in Safari so we need to
64 // check for notifications here
65 if (platform != "chromium" && type == "sub_frame")
66 {
67 var notificationToShow = Notification.getNextToShow(url);
68 if (notificationToShow)
69 showNotification(notificationToShow);
70 }
71
62 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, tab); 72 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, tab);
63 return !(filter instanceof BlockingFilter); 73 return !(filter instanceof BlockingFilter);
64 } 74 }
65 75
66 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest); 76 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest);
67 77
68 if (require("info").platform == "chromium") 78 if (platform == "chromium")
69 { 79 {
70 function onHeadersReceived(details) 80 function onHeadersReceived(details)
71 { 81 {
72 if (details.tabId == -1) 82 if (details.tabId == -1)
73 return; 83 return;
74 84
75 if (details.type != "main_frame" && details.type != "sub_frame") 85 if (details.type != "main_frame" && details.type != "sub_frame")
76 return; 86 return;
77 87
78 var tab = new Tab({id: details.tabId}); 88 var tab = new Tab({id: details.tabId});
79 var frame = new Frame({id: details.frameId, tab: tab}); 89 var frame = new Frame({id: details.frameId, tab: tab});
80 90
81 if (frame.url != details.url) 91 if (frame.url != details.url)
82 return; 92 return;
83 93
84 for (var i = 0; i < details.responseHeaders.length; i++) 94 for (var i = 0; i < details.responseHeaders.length; i++)
85 { 95 {
86 var header = details.responseHeaders[i]; 96 var header = details.responseHeaders[i];
87 if (header.name.toLowerCase() == "x-adblock-key" && header.value) 97 if (header.name.toLowerCase() == "x-adblock-key" && header.value)
88 processKeyException(header.value, tab, frame); 98 processKeyException(header.value, tab, frame);
89 } 99 }
90 100
91 var notificationToShow = Notification.getNextToShow(details.url); 101 var notificationToShow = Notification.getNextToShow(details.url);
92 if (notificationToShow) 102 if (notificationToShow)
93 showNotification(notificationToShow); 103 showNotification(notificationToShow);
94 } 104 }
95 105
96 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["<a ll_urls>"]}, ["responseHeaders"]); 106 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["<a ll_urls>"]}, ["responseHeaders"]);
97 } 107 }
OLDNEW
« background.js ('K') | « background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld