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: Use chrome.runtime.onConnect directly Created Feb. 2, 2016, 11:19 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 | « 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 devtools = require("devtools");
21 22
22 ext.webRequest.getIndistinguishableTypes().forEach(function(types) 23 ext.webRequest.getIndistinguishableTypes().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)
31 { 32 {
32 case "filter.added": 33 case "filter.added":
33 case "filter.removed": 34 case "filter.removed":
34 case "filter.disabled": 35 case "filter.disabled":
35 // Only request blocking/whitelisting filters have 36 // Only request blocking/whitelisting filters have
36 // an effect on the webRequest handler behavior. 37 // an effect on the webRequest handler behavior.
37 if (!(arg instanceof RegExpFilter)) 38 if (!(arg instanceof RegExpFilter))
38 break; 39 break;
39 case "subscription.added": 40 case "subscription.added":
40 case "subscription.removed": 41 case "subscription.removed":
41 case "subscription.disabled": 42 case "subscription.disabled":
42 case "subscription.updated": 43 case "subscription.updated":
43 case "load": 44 case "load":
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(page, url, type, docDomain,
51 thirdParty, key, specificOnly,
52 filter)
50 { 53 {
51 if (filter) 54 if (filter)
52 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); 55 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page);
56
57 if (devtools)
58 devtools.logRequest(
59 page, url, type, docDomain,
60 thirdParty, key, specificOnly,
61 filter
62 );
53 } 63 }
54 64
55 function onBeforeRequest(url, type, page, frame) 65 function onBeforeRequest(url, type, page, frame)
56 { 66 {
57 if (isFrameWhitelisted(page, frame)) 67 if (checkWhitelisted(page, frame))
58 return true; 68 return true;
59 69
70 var urlString = stringifyURL(url);
60 var docDomain = extractHostFromFrame(frame); 71 var docDomain = extractHostFromFrame(frame);
72 var thirdParty = isThirdParty(url, docDomain);
61 var key = getKey(page, frame); 73 var key = getKey(page, frame);
62 var specificOnly = isFrameWhitelisted(page, frame, 74
63 RegExpFilter.typeMap.GENERICBLOCK); 75 var specificOnly = checkWhitelisted(
64 var filter = defaultMatcher.matchesAny( 76 page, frame, RegExpFilter.typeMap.GENERICBLOCK
65 stringifyURL(url),
66 RegExpFilter.typeMap[type], docDomain,
67 isThirdParty(url, docDomain),
68 key,
69 specificOnly
70 ); 77 );
71 78
72 setTimeout(onBeforeRequestAsync, 0, url, type, page, filter); 79 var filter = defaultMatcher.matchesAny(
80 urlString, RegExpFilter.typeMap[type],
81 docDomain, thirdParty, key, specificOnly
82 );
83
84 setTimeout(onBeforeRequestAsync, 0, page, urlString,
85 type, docDomain,
86 thirdParty, key,
87 specificOnly, filter);
73 88
74 return !(filter instanceof BlockingFilter); 89 return !(filter instanceof BlockingFilter);
75 } 90 }
76 91
77 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest); 92 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest);
78 93
79 if (platform == "chromium") 94 if (platform == "chromium")
80 { 95 {
81 function onHeadersReceived(details) 96 function onHeadersReceived(details)
82 { 97 {
(...skipping 13 matching lines...) Expand all
96 111
97 chrome.webRequest.onHeadersReceived.addListener( 112 chrome.webRequest.onHeadersReceived.addListener(
98 onHeadersReceived, 113 onHeadersReceived,
99 { 114 {
100 urls: ["http://*/*", "https://*/*"], 115 urls: ["http://*/*", "https://*/*"],
101 types: ["main_frame", "sub_frame"] 116 types: ["main_frame", "sub_frame"]
102 }, 117 },
103 ["responseHeaders"] 118 ["responseHeaders"]
104 ); 119 );
105 } 120 }
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