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

Side by Side Diff: lib/whitelisting.js

Issue 29532767: Issue 5593 - Use messaging in popup for prefs, whitelisting, and stats (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Fix lint error and simplify code Created Sept. 24, 2017, 10:34 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 | « lib/stats.js ('k') | notification.js » ('j') | popup.js » ('J')
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 /** @module whitelisting */ 18 /** @module whitelisting */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {defaultMatcher} = require("matcher"); 22 const {defaultMatcher} = require("matcher");
23 const {RegExpFilter} = require("filterClasses"); 23 const {Filter, RegExpFilter} = require("filterClasses");
24 const {FilterNotifier} = require("filterNotifier"); 24 const {FilterNotifier} = require("filterNotifier");
25 const {FilterStorage} = require("filterStorage");
25 const {stringifyURL, getDecodedHostname, 26 const {stringifyURL, getDecodedHostname,
26 extractHostFromFrame, isThirdParty} = require("url"); 27 extractHostFromFrame, isThirdParty} = require("url");
27 const {port} = require("messaging"); 28 const {port} = require("messaging");
28 const devtools = require("devtools"); 29 const devtools = require("devtools");
29 const {verifySignature} = require("rsa"); 30 const {verifySignature} = require("rsa");
30 31
31 let sitekeys = new ext.PageMap(); 32 let sitekeys = new ext.PageMap();
32 33
33 function match(page, url, typeMask, docDomain, sitekey) 34 function match(page, url, typeMask, docDomain, sitekey)
34 { 35 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 filter = match(page, frame.url, typeMask, docDomain, sitekey); 81 filter = match(page, frame.url, typeMask, docDomain, sitekey);
81 frame = parent; 82 frame = parent;
82 } 83 }
83 84
84 return filter; 85 return filter;
85 } 86 }
86 87
87 return match(page, page.url, typeMask); 88 return match(page, page.url, typeMask);
88 }; 89 };
89 90
91 port.on("filters.isWhitelisted", message =>
92 {
93 return !!checkWhitelisted(new ext.Page(message.tab));
94 });
95
96 port.on("filters.whitelist", message =>
97 {
98 let page = new ext.Page(message.tab);
99 let host = getDecodedHostname(page.url).replace(/^www\./, "");
100 let filter = Filter.fromText("@@||" + host + "^$document");
101 if (filter.subscriptions.length && filter.disabled)
102 {
103 filter.disabled = false;
104 }
105 else
106 {
107 filter.disabled = false;
108 FilterStorage.addFilter(filter);
109 }
110 });
111
112 port.on("filters.unwhitelist", message =>
113 {
114 let page = new ext.Page(message.tab);
115 // Remove any exception rules applying to this URL
116 let filter = checkWhitelisted(page);
117 while (filter)
118 {
119 FilterStorage.removeFilter(filter);
120 if (filter.subscriptions.length)
121 filter.disabled = true;
122 filter = checkWhitelisted(page);
123 }
124 });
125
90 function revalidateWhitelistingState(page) 126 function revalidateWhitelistingState(page)
91 { 127 {
92 FilterNotifier.emit( 128 FilterNotifier.emit(
93 "page.WhitelistingStateRevalidate", 129 "page.WhitelistingStateRevalidate",
94 page, checkWhitelisted(page) 130 page, checkWhitelisted(page)
95 ); 131 );
96 } 132 }
97 133
98 FilterNotifier.on("filter.behaviorChanged", () => 134 FilterNotifier.on("filter.behaviorChanged", () =>
99 { 135 {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 { 225 {
190 chrome.webRequest.onHeadersReceived.addListener( 226 chrome.webRequest.onHeadersReceived.addListener(
191 onHeadersReceived, 227 onHeadersReceived,
192 { 228 {
193 urls: ["http://*/*", "https://*/*"], 229 urls: ["http://*/*", "https://*/*"],
194 types: ["main_frame", "sub_frame"] 230 types: ["main_frame", "sub_frame"]
195 }, 231 },
196 ["responseHeaders"] 232 ["responseHeaders"]
197 ); 233 );
198 } 234 }
OLDNEW
« no previous file with comments | « lib/stats.js ('k') | notification.js » ('j') | popup.js » ('J')

Powered by Google App Engine
This is Rietveld