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

Delta Between Two Patch Sets: lib/whitelisting.js

Issue 29338764: Issue 3842 - Split up the logic updating the icon and context menu (Closed)
Left Patch Set: Created March 19, 2016, 8:33 p.m.
Right Patch Set: Rebased Created March 22, 2016, 8:26 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 | « lib/icon.js ('k') | popup.js » ('j') | 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-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 /** @module whitelisting */ 18 /** @module whitelisting */
19 19
20 "use strict"; 20 "use strict";
21 21
22 let {defaultMatcher} = require("matcher"); 22 let {defaultMatcher} = require("matcher");
23 let {RegExpFilter} = require("filterClasses"); 23 let {RegExpFilter} = require("filterClasses");
24 let {DownloadableSubscription} = require("subscriptionClasses");
24 let {FilterNotifier} = require("filterNotifier"); 25 let {FilterNotifier} = require("filterNotifier");
25 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url"); 26 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url");
26 let {port} = require("messaging"); 27 let {port} = require("messaging");
27 let devtools = require("devtools"); 28 let devtools = require("devtools");
28 29
29 let pagesWithKey = new ext.PageMap(); 30 let pagesWithKey = new ext.PageMap();
30 31
31 function match(page, url, typeMask, docDomain, sitekey) 32 function match(page, url, typeMask, docDomain, sitekey)
32 { 33 {
33 let thirdParty = !!docDomain && isThirdParty(url, docDomain); 34 let thirdParty = !!docDomain && isThirdParty(url, docDomain);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 filter = match(page, frame.url, typeMask, docDomain, sitekey); 77 filter = match(page, frame.url, typeMask, docDomain, sitekey);
77 frame = parent; 78 frame = parent;
78 } 79 }
79 80
80 return filter; 81 return filter;
81 } 82 }
82 83
83 return match(page, page.url, typeMask); 84 return match(page, page.url, typeMask);
84 }; 85 };
85 86
86 FilterNotifier.addListener(action => 87 function revalidateWhitelistingState(page)
87 {
88 if (action == "load" || action == "save")
89 ext.pages.query({}, pages =>
90 {
91 for (let page of pages)
92 FilterNotifier.triggerListeners(
93 "page.WhitelistingStateRevalidate",
94 page, checkWhitelisted(page)
95 );
96 });
97 });
98
99 ext.pages.onLoading.addListener(page =>
100 { 88 {
101 FilterNotifier.triggerListeners( 89 FilterNotifier.triggerListeners(
102 "page.WhitelistingStateRevalidate", 90 "page.WhitelistingStateRevalidate",
103 page, checkWhitelisted(page) 91 page, checkWhitelisted(page)
104 ); 92 );
93 }
94
95 let revalidating = false;
96 FilterNotifier.addListener((action, arg) =>
97 {
98 switch (action)
99 {
100 case "subscription.added":
101 if (arg instanceof DownloadableSubscription && !arg.lastDownload)
102 break;
103 case "subscription.removed":
104 case "subscription.disabled":
105 case "subscription.updated":
106 case "filter.added":
107 case "filter.removed":
108 case "filter.disabled":
109 case "load":
110 if (!revalidating)
111 {
112 revalidating = true;
113 ext.pages.query({}, pages =>
114 {
115 revalidating = false;
116 for (let page of pages)
117 revalidateWhitelistingState(page);
118 });
119 }
120 }
105 }); 121 });
122
123 ext.pages.onLoading.addListener(revalidateWhitelistingState);
106 124
107 let getKey = 125 let getKey =
108 /** 126 /**
109 * Gets the public key, previously recorded for the given page 127 * Gets the public key, previously recorded for the given page
110 * and frame, to be considered for the $sitekey filter option. 128 * and frame, to be considered for the $sitekey filter option.
111 * 129 *
112 * @param {Page} page 130 * @param {Page} page
113 * @param {Frame} frame 131 * @param {Frame} frame
114 * @return {string} 132 * @return {string}
115 */ 133 */
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 key = key.replace(/=/g, ""); 192 key = key.replace(/=/g, "");
175 193
176 if (verifyKey(key, signature, frame.url)) 194 if (verifyKey(key, signature, frame.url))
177 recordKey(page, frame.url, key); 195 recordKey(page, frame.url, key);
178 }; 196 };
179 197
180 port.on("filters.addKey", (message, sender) => 198 port.on("filters.addKey", (message, sender) =>
181 { 199 {
182 processKey(message.token, sender.page, sender.frame); 200 processKey(message.token, sender.page, sender.frame);
183 }); 201 });
202
203 port.on("filters.isPageWhitelisted", (message, sender) =>
204 {
205 return !!checkWhitelisted(sender.page);
206 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld