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

Delta Between Two Patch Sets: background.js

Issue 29338503: Issue 3823 - Adapt message names used by "Block element" feature for consistency (Closed)
Left Patch Set: Created March 17, 2016, 2:05 p.m.
Right Patch Set: Rebased Created March 19, 2016, 7:41 p.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 | « no previous file | block.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 with(require("filterClasses")) 18 with(require("filterClasses"))
19 { 19 {
20 this.BlockingFilter = BlockingFilter; 20 this.BlockingFilter = BlockingFilter;
21 this.WhitelistFilter = WhitelistFilter; 21 this.WhitelistFilter = WhitelistFilter;
22 this.RegExpFilter = RegExpFilter; 22 this.RegExpFilter = RegExpFilter;
23 } 23 }
24 with(require("whitelisting")) 24 with(require("whitelisting"))
25 { 25 {
26 this.checkWhitelisted = checkWhitelisted; 26 this.checkWhitelisted = checkWhitelisted;
27 this.processKey = processKey;
27 this.getKey = getKey; 28 this.getKey = getKey;
28 } 29 }
29 with(require("url")) 30 with(require("url"))
30 { 31 {
31 this.stringifyURL = stringifyURL; 32 this.stringifyURL = stringifyURL;
32 this.isThirdParty = isThirdParty; 33 this.isThirdParty = isThirdParty;
33 this.extractHostFromFrame = extractHostFromFrame; 34 this.extractHostFromFrame = extractHostFromFrame;
34 } 35 }
35 var FilterStorage = require("filterStorage").FilterStorage; 36 var FilterStorage = require("filterStorage").FilterStorage;
36 var FilterNotifier = require("filterNotifier").FilterNotifier; 37 var FilterNotifier = require("filterNotifier").FilterNotifier;
37 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; 38 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
38 var ElemHide = require("elemHide").ElemHide; 39 var ElemHide = require("elemHide").ElemHide;
39 var defaultMatcher = require("matcher").defaultMatcher; 40 var defaultMatcher = require("matcher").defaultMatcher;
40 var Prefs = require("prefs").Prefs; 41 var Prefs = require("prefs").Prefs;
42 var parseFilters = require("filterValidation").parseFilters;
43 var composeFilters = require("filterComposer").composeFilters;
41 var updateIcon = require("icon").updateIcon; 44 var updateIcon = require("icon").updateIcon;
42 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl; 45 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl;
43 var port = require("messaging").port;
44 var devtools = require("devtools"); 46 var devtools = require("devtools");
45 47
46 // Special-case domains for which we cannot use style-based hiding rules. 48 // Special-case domains for which we cannot use style-based hiding rules.
47 // See http://crbug.com/68705. 49 // See http://crbug.com/68705.
48 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 50 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
49 51
50 var htmlPages = new ext.PageMap(); 52 var htmlPages = new ext.PageMap();
51 53
52 var contextMenuItem = { 54 var contextMenuItem = {
53 title: ext.i18n.getMessage("block_element"), 55 title: ext.i18n.getMessage("block_element"),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/. test(filter.text)) 113 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/. test(filter.text))
112 exceptions.push(RegExp.$1); 114 exceptions.push(RegExp.$1);
113 else 115 else
114 filters.push(filter.text); 116 filters.push(filter.text);
115 } 117 }
116 } 118 }
117 119
118 return {filters: filters, exceptions: exceptions}; 120 return {filters: filters, exceptions: exceptions};
119 } 121 }
120 122
121 port.on("get-selectors", function(msg, sender) 123 ext.onMessage.addListener(function (msg, sender, sendResponse)
122 { 124 {
123 var selectors = []; 125 switch (msg.type)
124 var trace = devtools && devtools.hasPanel(sender.page); 126 {
125 127 case "composer.openDialog":
126 if (!checkWhitelisted(sender.page, sender.frame, 128 ext.windows.create({
127 RegExpFilter.typeMap.DOCUMENT | 129 url: ext.getURL("block.html"),
128 RegExpFilter.typeMap.ELEMHIDE)) 130 left: 50,
129 { 131 top: 50,
130 var noStyleRules = false; 132 width: 420,
131 var specificOnly = checkWhitelisted(sender.page, sender.frame, 133 height: 200,
132 RegExpFilter.typeMap.GENERICHIDE); 134 focused: true,
133 var host = extractHostFromFrame(sender.frame); 135 type: "popup"
134 136 },
135 for (var i = 0; i < noStyleRulesHosts.length; i++) 137 function (popupPage) {
136 { 138 var popupPageId = popupPage.id;
137 var noStyleHost = noStyleRulesHosts[i]; 139 function onRemoved(removedPageId)
138 if (host == noStyleHost || (host.length > noStyleHost.length && 140 {
139 host.substr(host.length - noStyleHost.length - 1) == "." + noStyleHost)) 141 if (popupPageId == removedPageId)
140 { 142 {
141 noStyleRules = true; 143 sender.page.sendMessage({
142 } 144 type: "composer.content.dialogClosed",
143 } 145 popupId: popupPageId
144 selectors = ElemHide.getSelectorsForDomain(host, specificOnly); 146 });
145 if (noStyleRules) 147 ext.pages.onRemoved.removeListener(onRemoved);
146 { 148 }
147 selectors = selectors.filter(function(s) 149 }
148 { 150 ext.pages.onRemoved.addListener(onRemoved);
149 return !/\[style[\^\$]?=/.test(s); 151
152 sendResponse(popupPageId);
150 }); 153 });
151 } 154 return true;
152 } 155 break;
153 156 case "get-selectors":
154 return {selectors: selectors, trace: trace}; 157 var selectors = [];
155 }); 158 var trace = devtools && devtools.hasPanel(sender.page);
156 159
157 port.on("should-collapse", function(msg, sender) 160 if (!checkWhitelisted(sender.page, sender.frame,
158 { 161 RegExpFilter.typeMap.DOCUMENT |
159 if (checkWhitelisted(sender.page, sender.frame)) 162 RegExpFilter.typeMap.ELEMHIDE))
160 return false; 163 {
161 164 var noStyleRules = false;
162 var typeMask = RegExpFilter.typeMap[msg.mediatype]; 165 var specificOnly = checkWhitelisted(sender.page, sender.frame,
163 var documentHost = extractHostFromFrame(sender.frame); 166 RegExpFilter.typeMap.GENERICHIDE);
164 var sitekey = getKey(sender.page, sender.frame); 167 var host = extractHostFromFrame(sender.frame);
165 var blocked = false; 168
166 169 for (var i = 0; i < noStyleRulesHosts.length; i++)
167 var specificOnly = checkWhitelisted( 170 {
168 sender.page, sender.frame, 171 var noStyleHost = noStyleRulesHosts[i];
169 RegExpFilter.typeMap.GENERICBLOCK 172 if (host == noStyleHost || (host.length > noStyleHost.length &&
170 ); 173 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost))
171 174 {
172 for (var i = 0; i < msg.urls.length; i++) 175 noStyleRules = true;
173 { 176 }
174 var url = new URL(msg.urls[i], msg.baseURL); 177 }
175 var filter = defaultMatcher.matchesAny( 178 selectors = ElemHide.getSelectorsForDomain(host, specificOnly);
176 stringifyURL(url), typeMask, 179 if (noStyleRules)
177 documentHost, isThirdParty(url, documentHost), 180 {
178 sitekey, specificOnly 181 selectors = selectors.filter(function(s)
179 ); 182 {
180 183 return !/\[style[\^\$]?=/.test(s);
181 if (filter instanceof BlockingFilter) 184 });
182 { 185 }
183 if (filter.collapse != null) 186 }
184 return filter.collapse; 187
185 188 sendResponse({selectors: selectors, trace: trace});
186 blocked = true; 189 break;
187 } 190 case "should-collapse":
188 } 191 if (checkWhitelisted(sender.page, sender.frame))
189 192 {
190 return blocked && Prefs.hidePlaceholders; 193 sendResponse(false);
191 }); 194 break;
192 195 }
193 port.on("get-domain-enabled-state", function(msg, sender) 196
194 { 197 var typeMask = RegExpFilter.typeMap[msg.mediatype];
195 return {enabled: !checkWhitelisted(sender.page)}; 198 var documentHost = extractHostFromFrame(sender.frame);
196 }); 199 var sitekey = getKey(sender.page, sender.frame);
197 200 var blocked = false;
198 port.on("forward", function(msg, sender) 201
199 { 202 var specificOnly = checkWhitelisted(
200 var targetPage; 203 sender.page, sender.frame,
201 if (msg.targetPageId) 204 RegExpFilter.typeMap.GENERICBLOCK
202 targetPage = ext.getPage(msg.targetPageId); 205 );
203 else 206
204 targetPage = sender.page; 207 for (var i = 0; i < msg.urls.length; i++)
205 208 {
206 if (targetPage) 209 var url = new URL(msg.urls[i], msg.baseURL);
207 { 210 var filter = defaultMatcher.matchesAny(
208 msg.payload.sender = sender.page.id; 211 stringifyURL(url), typeMask,
209 if (msg.expectsResponse) 212 documentHost, isThirdParty(url, documentHost),
210 return new Promise(targetPage.sendMessage.bind(targetPage, msg.payload)); 213 sitekey, specificOnly
211 targetPage.sendMessage(msg.payload); 214 );
215
216 if (filter instanceof BlockingFilter)
217 {
218 if (filter.collapse != null)
219 {
220 sendResponse(filter.collapse);
221 return;
222 }
223
224 blocked = true;
225 }
226 }
227
228 sendResponse(blocked && Prefs.hidePlaceholders);
229 break;
230 case "get-domain-enabled-state":
231 // Returns whether this domain is in the exclusion list.
232 // The browser action popup asks us this.
233 if(sender.page)
234 {
235 sendResponse({enabled: !checkWhitelisted(sender.page)});
236 return;
237 }
238 break;
239 case "add-sitekey":
240 processKey(msg.token, sender.page, sender.frame);
241 break;
242 case "composer.ready":
243 htmlPages.set(sender.page, null);
244 refreshIconAndContextMenu(sender.page);
245 break;
246 case "composer.getFilters":
247 sendResponse(composeFilters({
248 tagName: msg.tagName,
249 id: msg.id,
250 src: msg.src,
251 style: msg.style,
252 classes: msg.classes,
253 urls: msg.urls,
254 type: msg.mediatype,
255 baseURL: msg.baseURL,
256 page: sender.page,
257 frame: sender.frame
258 }));
259 break;
260 case "trace-elemhide":
261 devtools.logHiddenElements(
262 sender.page, msg.selectors,
263 extractHostFromFrame(sender.frame)
264 );
265 break;
266 case "has-devtools-panel":
267 sendResponse(Prefs.show_devtools_panel);
268 break;
269 case "forward":
270 var targetPage;
271 if (msg.targetPageId)
272 targetPage = ext.getPage(msg.targetPageId);
273 else
274 targetPage = sender.page;
275
276 if (targetPage)
277 {
278 msg.payload.sender = sender.page.id;
279 if (msg.expectsResponse)
280 {
281 targetPage.sendMessage(msg.payload, sendResponse);
282 return true;
283 }
284
285 targetPage.sendMessage(msg.payload);
286 }
287 break;
212 } 288 }
213 }); 289 });
214 290
215 // update icon when page changes location 291 // update icon when page changes location
216 ext.pages.onLoading.addListener(function(page) 292 ext.pages.onLoading.addListener(function(page)
217 { 293 {
218 page.sendMessage({type: "composer.content.finished"}); 294 page.sendMessage({type: "composer.content.finished"});
219 refreshIconAndContextMenu(page); 295 refreshIconAndContextMenu(page);
220 showNextNotificationForUrl(page.url); 296 showNextNotificationForUrl(page.url);
221 }); 297 });
LEFTRIGHT
« no previous file | block.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld