LEFT | RIGHT |
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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 this.RegExpFilter = RegExpFilter; | 23 this.RegExpFilter = RegExpFilter; |
24 } | 24 } |
25 with(require("subscriptionClasses")) | 25 with(require("subscriptionClasses")) |
26 { | 26 { |
27 this.Subscription = Subscription; | 27 this.Subscription = Subscription; |
28 this.DownloadableSubscription = DownloadableSubscription; | 28 this.DownloadableSubscription = DownloadableSubscription; |
29 this.SpecialSubscription = SpecialSubscription; | 29 this.SpecialSubscription = SpecialSubscription; |
30 } | 30 } |
31 with(require("whitelisting")) | 31 with(require("whitelisting")) |
32 { | 32 { |
33 this.isPageWhitelisted = isPageWhitelisted; | 33 this.checkWhitelisted = checkWhitelisted; |
34 this.isFrameWhitelisted = isFrameWhitelisted; | |
35 this.processKey = processKey; | 34 this.processKey = processKey; |
36 this.getKey = getKey; | 35 this.getKey = getKey; |
37 } | 36 } |
38 with(require("url")) | 37 with(require("url")) |
39 { | 38 { |
40 this.stringifyURL = stringifyURL; | 39 this.stringifyURL = stringifyURL; |
41 this.isThirdParty = isThirdParty; | 40 this.isThirdParty = isThirdParty; |
42 this.extractHostFromFrame = extractHostFromFrame; | 41 this.extractHostFromFrame = extractHostFromFrame; |
43 } | 42 } |
44 var FilterStorage = require("filterStorage").FilterStorage; | 43 var FilterStorage = require("filterStorage").FilterStorage; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 contexts: ["image", "video", "audio"], | 119 contexts: ["image", "video", "audio"], |
121 onclick: function(page) | 120 onclick: function(page) |
122 { | 121 { |
123 page.sendMessage({type: "clickhide-new-filter"}); | 122 page.sendMessage({type: "clickhide-new-filter"}); |
124 } | 123 } |
125 }; | 124 }; |
126 | 125 |
127 // Adds or removes browser action icon according to options. | 126 // Adds or removes browser action icon according to options. |
128 function refreshIconAndContextMenu(page) | 127 function refreshIconAndContextMenu(page) |
129 { | 128 { |
130 var whitelisted = isPageWhitelisted(page); | 129 var whitelisted = !!checkWhitelisted(page); |
131 updateIcon(page, whitelisted); | 130 updateIcon(page, whitelisted); |
132 | 131 |
133 // show or hide the context menu entry dependent on whether | 132 // show or hide the context menu entry dependent on whether |
134 // adblocking is active on that page | 133 // adblocking is active on that page |
135 page.contextMenus.remove(contextMenuItem); | 134 page.contextMenus.remove(contextMenuItem); |
136 if (Prefs.shouldShowBlockElementMenu && !whitelisted && htmlPages.has(page)) | 135 if (Prefs.shouldShowBlockElementMenu && !whitelisted && htmlPages.has(page)) |
137 page.contextMenus.create(contextMenuItem); | 136 page.contextMenus.create(contextMenuItem); |
138 } | 137 } |
139 | 138 |
140 function refreshIconAndContextMenuForAllPages() | 139 function refreshIconAndContextMenuForAllPages() |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 280 } |
282 | 281 |
283 ext.onMessage.addListener(function (msg, sender, sendResponse) | 282 ext.onMessage.addListener(function (msg, sender, sendResponse) |
284 { | 283 { |
285 switch (msg.type) | 284 switch (msg.type) |
286 { | 285 { |
287 case "get-selectors": | 286 case "get-selectors": |
288 var selectors = []; | 287 var selectors = []; |
289 var trace = devtools && devtools.hasPanel(sender.page); | 288 var trace = devtools && devtools.hasPanel(sender.page); |
290 | 289 |
291 if (!isFrameWhitelisted(sender.page, sender.frame, | 290 if (!checkWhitelisted(sender.page, sender.frame, |
292 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeM
ap.ELEMHIDE)) | 291 RegExpFilter.typeMap.DOCUMENT | |
| 292 RegExpFilter.typeMap.ELEMHIDE)) |
293 { | 293 { |
294 var noStyleRules = false; | 294 var noStyleRules = false; |
295 var specificOnly = isFrameWhitelisted(sender.page, sender.frame, | 295 var specificOnly = checkWhitelisted(sender.page, sender.frame, |
296 RegExpFilter.typeMap.GENERICHIDE); | 296 RegExpFilter.typeMap.GENERICHIDE); |
297 var host = extractHostFromFrame(sender.frame); | 297 var host = extractHostFromFrame(sender.frame); |
298 | 298 |
299 for (var i = 0; i < noStyleRulesHosts.length; i++) | 299 for (var i = 0; i < noStyleRulesHosts.length; i++) |
300 { | 300 { |
301 var noStyleHost = noStyleRulesHosts[i]; | 301 var noStyleHost = noStyleRulesHosts[i]; |
302 if (host == noStyleHost || (host.length > noStyleHost.length && | 302 if (host == noStyleHost || (host.length > noStyleHost.length && |
303 host.substr(host.length - noStyleHost.leng
th - 1) == "." + noStyleHost)) | 303 host.substr(host.length - noStyleHost.leng
th - 1) == "." + noStyleHost)) |
304 { | 304 { |
305 noStyleRules = true; | 305 noStyleRules = true; |
306 } | 306 } |
307 } | 307 } |
308 selectors = ElemHide.getSelectorsForDomain(host, specificOnly); | 308 selectors = ElemHide.getSelectorsForDomain(host, specificOnly); |
309 if (noStyleRules) | 309 if (noStyleRules) |
310 { | 310 { |
311 selectors = selectors.filter(function(s) | 311 selectors = selectors.filter(function(s) |
312 { | 312 { |
313 return !/\[style[\^\$]?=/.test(s); | 313 return !/\[style[\^\$]?=/.test(s); |
314 }); | 314 }); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 sendResponse({selectors: selectors, trace: trace}); | 318 sendResponse({selectors: selectors, trace: trace}); |
319 break; | 319 break; |
320 case "should-collapse": | 320 case "should-collapse": |
321 if (isFrameWhitelisted(sender.page, sender.frame, RegExpFilter.typeMap.DOC
UMENT)) | 321 if (checkWhitelisted(sender.page, sender.frame)) |
322 { | 322 { |
323 sendResponse(false); | 323 sendResponse(false); |
324 break; | 324 break; |
325 } | 325 } |
326 | 326 |
327 var typeMask = RegExpFilter.typeMap[msg.mediatype]; | 327 var typeMask = RegExpFilter.typeMap[msg.mediatype]; |
328 var documentHost = extractHostFromFrame(sender.frame); | 328 var documentHost = extractHostFromFrame(sender.frame); |
329 var sitekey = getKey(sender.page, sender.frame); | 329 var sitekey = getKey(sender.page, sender.frame); |
330 var blocked = false; | 330 var blocked = false; |
331 | 331 |
(...skipping 17 matching lines...) Expand all Loading... |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 sendResponse(blocked && Prefs.hidePlaceholders); | 352 sendResponse(blocked && Prefs.hidePlaceholders); |
353 break; | 353 break; |
354 case "get-domain-enabled-state": | 354 case "get-domain-enabled-state": |
355 // Returns whether this domain is in the exclusion list. | 355 // Returns whether this domain is in the exclusion list. |
356 // The browser action popup asks us this. | 356 // The browser action popup asks us this. |
357 if(sender.page) | 357 if(sender.page) |
358 { | 358 { |
359 sendResponse({enabled: !isPageWhitelisted(sender.page)}); | 359 sendResponse({enabled: !checkWhitelisted(sender.page)}); |
360 return; | 360 return; |
361 } | 361 } |
362 break; | 362 break; |
363 case "add-filters": | 363 case "add-filters": |
364 var result = parseFilters(msg.text); | 364 var result = parseFilters(msg.text); |
365 | 365 |
366 if (result.errors.length > 0) | 366 if (result.errors.length > 0) |
367 { | 367 { |
368 sendResponse({status: "invalid", error: result.errors.join("\n")}); | 368 sendResponse({status: "invalid", error: result.errors.join("\n")}); |
369 break; | 369 break; |
(...skipping 19 matching lines...) Expand all Loading... |
389 style: msg.style, | 389 style: msg.style, |
390 classes: msg.classes, | 390 classes: msg.classes, |
391 urls: msg.urls, | 391 urls: msg.urls, |
392 type: msg.mediatype, | 392 type: msg.mediatype, |
393 baseURL: msg.baseURL, | 393 baseURL: msg.baseURL, |
394 page: sender.page, | 394 page: sender.page, |
395 frame: sender.frame | 395 frame: sender.frame |
396 })); | 396 })); |
397 break; | 397 break; |
398 case "trace-elemhide": | 398 case "trace-elemhide": |
399 devtools.logHiddenElements(sender.page, msg.selectors, extractHostFromFram
e(sender.frame)); | 399 devtools.logHiddenElements( |
| 400 sender.page, msg.selectors, |
| 401 extractHostFromFrame(sender.frame) |
| 402 ); |
400 break; | 403 break; |
401 case "forward": | 404 case "forward": |
402 if (sender.page) | 405 if (sender.page) |
403 { | 406 { |
404 if (msg.expectsResponse) | 407 if (msg.expectsResponse) |
405 { | 408 { |
406 sender.page.sendMessage(msg.payload, sendResponse); | 409 sender.page.sendMessage(msg.payload, sendResponse); |
407 return true; | 410 return true; |
408 } | 411 } |
409 | 412 |
410 sender.page.sendMessage(msg.payload); | 413 sender.page.sendMessage(msg.payload); |
411 } | 414 } |
412 break; | 415 break; |
413 } | 416 } |
414 }); | 417 }); |
415 | 418 |
416 // update icon when page changes location | 419 // update icon when page changes location |
417 ext.pages.onLoading.addListener(function(page) | 420 ext.pages.onLoading.addListener(function(page) |
418 { | 421 { |
419 page.sendMessage({type: "clickhide-deactivate"}); | 422 page.sendMessage({type: "clickhide-deactivate"}); |
420 refreshIconAndContextMenu(page); | 423 refreshIconAndContextMenu(page); |
421 showNextNotificationForUrl(page.url); | 424 showNextNotificationForUrl(page.url); |
422 }); | 425 }); |
LEFT | RIGHT |