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

Side by Side Diff: lib/whitelisting.js

Issue 29338764: Issue 3842 - Split up the logic updating the icon and context menu (Closed)
Patch Set: Prevent visible delays Created March 21, 2016, 10:10 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 | « lib/icon.js ('k') | popup.js » ('j') | 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 /** @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 {FilterNotifier} = require("filterNotifier");
24 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url"); 25 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url");
25 let {port} = require("messaging"); 26 let {port} = require("messaging");
26 let devtools = require("devtools"); 27 let devtools = require("devtools");
27 28
28 let pagesWithKey = new ext.PageMap(); 29 let pagesWithKey = new ext.PageMap();
29 30
30 function match(page, url, typeMask, docDomain, sitekey) 31 function match(page, url, typeMask, docDomain, sitekey)
31 { 32 {
32 let thirdParty = !!docDomain && isThirdParty(url, docDomain); 33 let thirdParty = !!docDomain && isThirdParty(url, docDomain);
33 let urlString = stringifyURL(url); 34 let urlString = stringifyURL(url);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 filter = match(page, frame.url, typeMask, docDomain, sitekey); 75 filter = match(page, frame.url, typeMask, docDomain, sitekey);
75 frame = parent; 76 frame = parent;
76 } 77 }
77 78
78 return filter; 79 return filter;
79 } 80 }
80 81
81 return match(page, page.url, typeMask); 82 return match(page, page.url, typeMask);
82 }; 83 };
83 84
85 function revalidateWhitelistingState(page)
86 {
87 FilterNotifier.triggerListeners(
88 "page.WhitelistingStateRevalidate", page,
89 match(page, page.url, RegExpFilter.typeMap.DOCUMENT)
90 );
91 }
92
93 let expectsSave = false;
94 FilterNotifier.addListener((action, filter) =>
95 {
96 switch (action)
97 {
98 case "subscription.added": // On subscription changes, defer
99 case "subscription.removed": // revalidation until the changes
100 case "subscription.disabled": // are saved to avoid revalidating the
101 case "subscription.updated": // whitelisting state unnecessarily often.
102 expectsSave = true;
103 break;
104
105 case "save":
106 if (!expectsSave)
107 break;
108 expectsSave = false;
109
110 case "load":
111 case "filter.added": // On filter changes, revalidate imediatelly
112 case "filter.removed": // to avoid visible delays when the user
113 case "filter.disabled": // disables/enables the extension for a website.
114 ext.pages.query({}, pages =>
115 {
116 for (let page of pages)
117 revalidateWhitelistingState(page);
118 });
119 }
120 });
121
122 ext.pages.onLoading.addListener(revalidateWhitelistingState);
123
84 let getKey = 124 let getKey =
85 /** 125 /**
86 * Gets the public key, previously recorded for the given page 126 * Gets the public key, previously recorded for the given page
87 * and frame, to be considered for the $sitekey filter option. 127 * and frame, to be considered for the $sitekey filter option.
88 * 128 *
89 * @param {Page} page 129 * @param {Page} page
90 * @param {Frame} frame 130 * @param {Frame} frame
91 * @return {string} 131 * @return {string}
92 */ 132 */
93 exports.getKey = function(page, frame) 133 exports.getKey = function(page, frame)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 key = key.replace(/=/g, ""); 191 key = key.replace(/=/g, "");
152 192
153 if (verifyKey(key, signature, frame.url)) 193 if (verifyKey(key, signature, frame.url))
154 recordKey(page, frame.url, key); 194 recordKey(page, frame.url, key);
155 }; 195 };
156 196
157 port.on("filters.addKey", (message, sender) => 197 port.on("filters.addKey", (message, sender) =>
158 { 198 {
159 processKey(message.token, sender.page, sender.frame); 199 processKey(message.token, sender.page, sender.frame);
160 }); 200 });
OLDNEW
« no previous file with comments | « lib/icon.js ('k') | popup.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld