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

Delta Between Two Patch Sets: webrequest.js

Issue 5138680696012800: Issue 616 - Enforce $generichide and $genericblock in Chrome (Closed)
Left Patch Set: Created March 11, 2015, 5:09 p.m.
Right Patch Set: Updated adblockplustests dependency Created Oct. 5, 2015, 9:52 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « popupBlocker.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 platform = require("info").platform; 20 var platform = require("info").platform;
21 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl;
20 22
21 var onFilterChangeTimeout = null; 23 ext.webRequest.indistinguishableTypes.forEach(function(types)
22 function onFilterChange()
23 { 24 {
24 onFilterChangeTimeout = null; 25 for (var i = 1; i < types.length; i++)
25 ext.webRequest.handlerBehaviorChanged(); 26 RegExpFilter.typeMap[types[i]] = RegExpFilter.typeMap[types[0]];
26 } 27 });
27 28
28 var importantNotifications = { 29 FilterNotifier.addListener(function(action, arg)
29 'filter.added': true,
30 'filter.removed': true,
31 'filter.disabled': true,
32 'subscription.added': true,
33 'subscription.removed': true,
34 'subscription.disabled': true,
35 'subscription.updated': true,
36 'load': true
37 };
38
39 FilterNotifier.addListener(function(action)
40 { 30 {
41 if (action in importantNotifications) 31 switch (action)
42 { 32 {
43 // Execute delayed to prevent multiple executions in a quick succession 33 case "filter.added":
44 if (onFilterChangeTimeout != null) 34 case "filter.removed":
45 window.clearTimeout(onFilterChangeTimeout); 35 case "filter.disabled":
46 onFilterChangeTimeout = window.setTimeout(onFilterChange, 2000); 36 // Only request blocking/whitelisting filters have
37 // an effect on the webRequest handler behavior.
38 if (!(arg instanceof RegExpFilter))
39 break;
40 case "subscription.added":
41 case "subscription.removed":
42 case "subscription.disabled":
43 case "subscription.updated":
44 case "load":
45 ext.webRequest.handlerBehaviorChanged();
46 break;
47 } 47 }
48 }); 48 });
49
50 function onBeforeRequestAsync(url, type, page, filter)
51 {
52 // We can't listen to onHeadersReceived in Safari so we need to
53 // check for notifications here
54 if (platform != "chromium" && type == "SUBDOCUMENT")
55 showNextNotificationForUrl(url);
56
57 if (filter)
58 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page);
59 }
49 60
50 function onBeforeRequest(url, type, page, frame) 61 function onBeforeRequest(url, type, page, frame)
51 { 62 {
52 if (isFrameWhitelisted(page, frame)) 63 if (isFrameWhitelisted(page, frame))
53 return true; 64 return true;
54 65
55 var docDomain = extractHostFromFrame(frame); 66 var docDomain = extractHostFromFrame(frame);
56 var key = getKey(page, frame); 67 var key = getKey(page, frame);
57 var specificOnly = isFrameWhitelisted(page, frame, "GENERICBLOCK"); 68 var specificOnly = isFrameWhitelisted(page, frame,
69 RegExpFilter.typeMap.GENERICBLOCK);
58 var filter = defaultMatcher.matchesAny( 70 var filter = defaultMatcher.matchesAny(
59 stringifyURL(url), 71 stringifyURL(url),
60 type == "sub_frame" ? "SUBDOCUMENT" : type.toUpperCase(), 72 RegExpFilter.typeMap[type], docDomain,
61 docDomain,
62 isThirdParty(url, docDomain), 73 isThirdParty(url, docDomain),
63 key, 74 key,
64 specificOnly 75 specificOnly
Sebastian Noack 2015/03/12 12:36:12 I suppose this isn't the only call that needs to b
kzar 2015/03/12 19:22:45 Good point, I didn't consider popups! I updated my
65 ); 76 );
66 77
67 // We can't listen to onHeadersReceived in Safari so we need to 78 setTimeout(onBeforeRequestAsync, 0, url, type, page, filter);
68 // check for notifications here
69 if (platform != "chromium" && type == "sub_frame")
70 {
71 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(url) );
72 if (notificationToShow)
73 showNotification(notificationToShow);
74 }
75 79
76 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page);
77 return !(filter instanceof BlockingFilter); 80 return !(filter instanceof BlockingFilter);
78 } 81 }
79 82
80 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest); 83 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest);
81 84
82 if (platform == "chromium") 85 if (platform == "chromium")
83 { 86 {
84 function onHeadersReceived(details) 87 function onHeadersReceived(details)
85 { 88 {
86 if (details.tabId == -1)
87 return;
88
89 if (details.type != "main_frame" && details.type != "sub_frame")
90 return;
91
92 var page = new ext.Page({id: details.tabId}); 89 var page = new ext.Page({id: details.tabId});
93 var frame = ext.getFrame(details.tabId, details.frameId); 90 var frame = ext.getFrame(details.tabId, details.frameId);
94 91
95 if (!frame || frame.url.href != details.url) 92 if (!frame || frame.url.href != details.url)
96 return; 93 return;
97 94
98 for (var i = 0; i < details.responseHeaders.length; i++) 95 for (var i = 0; i < details.responseHeaders.length; i++)
99 { 96 {
100 var header = details.responseHeaders[i]; 97 var header = details.responseHeaders[i];
101 if (header.name.toLowerCase() == "x-adblock-key" && header.value) 98 if (header.name.toLowerCase() == "x-adblock-key" && header.value)
102 processKey(header.value, page, frame); 99 processKey(header.value, page, frame);
103 } 100 }
104 101
105 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(new URL(details.url))); 102 showNextNotificationForUrl(new URL(details.url));
106 if (notificationToShow)
107 showNotification(notificationToShow);
108 } 103 }
109 104
110 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["ht tp://*/*", "https://*/*"]}, ["responseHeaders"]); 105 chrome.webRequest.onHeadersReceived.addListener(
106 onHeadersReceived,
107 {
108 urls: ["http://*/*", "https://*/*"],
109 types: ["main_frame", "sub_frame"]
110 },
111 ["responseHeaders"]
112 );
111 } 113 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld