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

Side by Side Diff: webrequest.js

Issue 4938965924708352: Issue 2297 - Call chrome.webRequst.behaviorChanged() only for request filter changes (Closed)
Patch Set: Created April 10, 2015, 10:24 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | 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 <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 21
22 var importantNotifications = {
23 'filter.added': true,
24 'filter.removed': true,
25 'filter.disabled': true,
26 'subscription.added': true,
27 'subscription.removed': true,
28 'subscription.disabled': true,
29 'subscription.updated': true,
30 'load': true
31 };
32
33 ext.webRequest.indistinguishableTypes.forEach(function(types) 22 ext.webRequest.indistinguishableTypes.forEach(function(types)
34 { 23 {
35 for (var i = 1; i < types.length; i++) 24 for (var i = 1; i < types.length; i++)
36 RegExpFilter.typeMap[types[i]] = RegExpFilter.typeMap[types[0]]; 25 RegExpFilter.typeMap[types[i]] = RegExpFilter.typeMap[types[0]];
37 }); 26 });
38 27
39 FilterNotifier.addListener(function(action) 28 FilterNotifier.addListener(function(action, arg)
40 { 29 {
41 if (action in importantNotifications) 30 switch (action)
42 ext.webRequest.handlerBehaviorChanged(); 31 {
32 case "filter.added":
33 case "filter.removed":
34 case "filter.disabled":
35 // Only request blocking/whitelisting filters have
36 // an effect on the webRequest handler behavior.
37 if (!(arg instanceof RegExpFilter))
38 break;
39 case "subscription.added":
40 case "subscription.removed":
41 case "subscription.disabled":
42 case "subscription.updated":
43 case "load":
44 ext.webRequest.handlerBehaviorChanged();
45 break;
46 }
43 }); 47 });
44 48
45 function onBeforeRequest(url, type, page, frame) 49 function onBeforeRequest(url, type, page, frame)
46 { 50 {
47 if (isFrameWhitelisted(page, frame)) 51 if (isFrameWhitelisted(page, frame))
48 return true; 52 return true;
49 53
50 var docDomain = extractHostFromFrame(frame); 54 var docDomain = extractHostFromFrame(frame);
51 var key = getKey(page, frame); 55 var key = getKey(page, frame);
52 var filter = defaultMatcher.matchesAny( 56 var filter = defaultMatcher.matchesAny(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 processKey(header.value, page, frame); 98 processKey(header.value, page, frame);
95 } 99 }
96 100
97 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(new URL(details.url))); 101 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(new URL(details.url)));
98 if (notificationToShow) 102 if (notificationToShow)
99 showNotification(notificationToShow); 103 showNotification(notificationToShow);
100 } 104 }
101 105
102 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["ht tp://*/*", "https://*/*"]}, ["responseHeaders"]); 106 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["ht tp://*/*", "https://*/*"]}, ["responseHeaders"]);
103 } 107 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld