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

Side by Side Diff: webrequest.js

Issue 6393086494113792: Issue 154 - Added devtools panel showing blocked and blockable items (Closed)
Patch Set: Rebased and fixed various issues Created March 12, 2015, 3:32 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
« no previous file with comments | « popupBlocker.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 <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 logRequest = require("devtools").logRequest;
21 22
22 var onFilterChangeTimeout = null; 23 var onFilterChangeTimeout = null;
23 function onFilterChange() 24 function onFilterChange()
24 { 25 {
25 onFilterChangeTimeout = null; 26 onFilterChangeTimeout = null;
26 ext.webRequest.handlerBehaviorChanged(); 27 ext.webRequest.handlerBehaviorChanged();
27 } 28 }
28 29
29 var importantNotifications = { 30 var importantNotifications = {
30 'filter.added': true, 31 'filter.added': true,
(...skipping 21 matching lines...) Expand all
52 window.clearTimeout(onFilterChangeTimeout); 53 window.clearTimeout(onFilterChangeTimeout);
53 onFilterChangeTimeout = window.setTimeout(onFilterChange, 2000); 54 onFilterChangeTimeout = window.setTimeout(onFilterChange, 2000);
54 } 55 }
55 }); 56 });
56 57
57 function onBeforeRequest(url, type, page, frame) 58 function onBeforeRequest(url, type, page, frame)
58 { 59 {
59 if (isFrameWhitelisted(page, frame)) 60 if (isFrameWhitelisted(page, frame))
60 return true; 61 return true;
61 62
63 var urlString = stringifyURL(url);
62 var docDomain = extractHostFromFrame(frame); 64 var docDomain = extractHostFromFrame(frame);
65 var thirdParty = isThirdParty(url, docDomain);
63 var key = getKey(page, frame); 66 var key = getKey(page, frame);
64 var filter = defaultMatcher.matchesAny( 67 var filter = defaultMatcher.matchesAny(urlString, type, docDomain, thirdParty, key);
65 stringifyURL(url),
66 type, docDomain,
67 isThirdParty(url, docDomain),
68 key
69 );
70 68
71 // We can't listen to onHeadersReceived in Safari so we need to 69 // We can't listen to onHeadersReceived in Safari so we need to
72 // check for notifications here 70 // check for notifications here
73 if (platform != "chromium" && type == "SUBDOCUMENT") 71 if (platform != "chromium" && type == "SUBDOCUMENT")
74 { 72 {
75 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(url) ); 73 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(url) );
76 if (notificationToShow) 74 if (notificationToShow)
77 showNotification(notificationToShow); 75 showNotification(notificationToShow);
78 } 76 }
79 77
78 logRequest(page, urlString, type, docDomain, thirdParty, key, filter);
80 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); 79 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page);
80
81 return !(filter instanceof BlockingFilter); 81 return !(filter instanceof BlockingFilter);
82 } 82 }
83 83
84 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest); 84 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest);
85 85
86 if (platform == "chromium") 86 if (platform == "chromium")
87 { 87 {
88 function onHeadersReceived(details) 88 function onHeadersReceived(details)
89 { 89 {
90 if (details.tabId == -1) 90 if (details.tabId == -1)
(...skipping 15 matching lines...) Expand all
106 processKey(header.value, page, frame); 106 processKey(header.value, page, frame);
107 } 107 }
108 108
109 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(new URL(details.url))); 109 var notificationToShow = NotificationStorage.getNextToShow(stringifyURL(new URL(details.url)));
110 if (notificationToShow) 110 if (notificationToShow)
111 showNotification(notificationToShow); 111 showNotification(notificationToShow);
112 } 112 }
113 113
114 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["ht tp://*/*", "https://*/*"]}, ["responseHeaders"]); 114 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["ht tp://*/*", "https://*/*"]}, ["responseHeaders"]);
115 } 115 }
OLDNEW
« no previous file with comments | « popupBlocker.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld