| 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 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 var FilterStorage = require("filterStorage").FilterStorage; | 35 var FilterStorage = require("filterStorage").FilterStorage; |
| 36 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; | 36 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; |
| 37 var ElemHide = require("elemHide").ElemHide; | 37 var ElemHide = require("elemHide").ElemHide; |
| 38 var defaultMatcher = require("matcher").defaultMatcher; | 38 var defaultMatcher = require("matcher").defaultMatcher; |
| 39 var Prefs = require("prefs").Prefs; | 39 var Prefs = require("prefs").Prefs; |
| 40 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat
ionForUrl; | 40 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat
ionForUrl; |
| 41 var port = require("messaging").port; | 41 var port = require("messaging").port; |
| 42 var devtools = require("devtools"); | 42 var devtools = require("devtools"); |
| 43 | 43 |
| 44 // Special-case domains for which we cannot use style-based hiding rules. | |
| 45 // See http://crbug.com/68705. | |
| 46 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; | |
| 47 | |
| 48 // This is a hack to speedup loading of the options page on Safari. | 44 // This is a hack to speedup loading of the options page on Safari. |
| 49 // Once we replaced the background page proxy with message passing | 45 // Once we replaced the background page proxy with message passing |
| 50 // this global function should removed. | 46 // this global function should removed. |
| 51 function getUserFilters() | 47 function getUserFilters() |
| 52 { | 48 { |
| 53 var filters = []; | 49 var filters = []; |
| 54 var exceptions = []; | 50 var exceptions = []; |
| 55 | 51 |
| 56 for (var i = 0; i < FilterStorage.subscriptions.length; i++) | 52 for (var i = 0; i < FilterStorage.subscriptions.length; i++) |
| 57 { | 53 { |
| 58 var subscription = FilterStorage.subscriptions[i]; | 54 var subscription = FilterStorage.subscriptions[i]; |
| 59 if (!(subscription instanceof SpecialSubscription)) | 55 if (!(subscription instanceof SpecialSubscription)) |
| 60 continue; | 56 continue; |
| 61 | 57 |
| 62 for (var j = 0; j < subscription.filters.length; j++) | 58 for (var j = 0; j < subscription.filters.length; j++) |
| 63 { | 59 { |
| 64 var filter = subscription.filters[j]; | 60 var filter = subscription.filters[j]; |
| 65 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.
test(filter.text)) | 61 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.
test(filter.text)) |
| 66 exceptions.push(RegExp.$1); | 62 exceptions.push(RegExp.$1); |
| 67 else | 63 else |
| 68 filters.push(filter.text); | 64 filters.push(filter.text); |
| 69 } | 65 } |
| 70 } | 66 } |
| 71 | 67 |
| 72 return {filters: filters, exceptions: exceptions}; | 68 return {filters: filters, exceptions: exceptions}; |
| 73 } | 69 } |
| 74 | 70 |
| 75 port.on("get-selectors", function(msg, sender) | 71 port.on("get-selectors", function(msg, sender) |
| 76 { | 72 { |
| 77 var selectors = []; | 73 var selectors; |
| 78 var trace = devtools && devtools.hasPanel(sender.page); | 74 var trace = devtools && devtools.hasPanel(sender.page); |
| 79 | 75 |
| 80 if (!checkWhitelisted(sender.page, sender.frame, | 76 if (!checkWhitelisted(sender.page, sender.frame, |
| 81 RegExpFilter.typeMap.DOCUMENT | | 77 RegExpFilter.typeMap.DOCUMENT | |
| 82 RegExpFilter.typeMap.ELEMHIDE)) | 78 RegExpFilter.typeMap.ELEMHIDE)) |
| 83 { | 79 selectors = ElemHide.getSelectorsForDomain( |
| 84 var noStyleRules = false; | 80 extractHostFromFrame(sender.frame), |
| 85 var specificOnly = checkWhitelisted(sender.page, sender.frame, | 81 checkWhitelisted(sender.page, sender.frame, |
| 86 RegExpFilter.typeMap.GENERICHIDE); | 82 RegExpFilter.typeMap.GENERICHIDE) |
| 87 var host = extractHostFromFrame(sender.frame); | 83 ); |
| 88 | 84 else |
| 89 for (var i = 0; i < noStyleRulesHosts.length; i++) | 85 selectors = []; |
| 90 { | |
| 91 var noStyleHost = noStyleRulesHosts[i]; | |
| 92 if (host == noStyleHost || (host.length > noStyleHost.length && | |
| 93 host.substr(host.length - noStyleHost.length -
1) == "." + noStyleHost)) | |
| 94 { | |
| 95 noStyleRules = true; | |
| 96 } | |
| 97 } | |
| 98 selectors = ElemHide.getSelectorsForDomain(host, specificOnly); | |
| 99 if (noStyleRules) | |
| 100 { | |
| 101 selectors = selectors.filter(function(s) | |
| 102 { | |
| 103 return !/\[style[\^\$]?=/.test(s); | |
| 104 }); | |
| 105 } | |
| 106 } | |
| 107 | 86 |
| 108 return {selectors: selectors, trace: trace}; | 87 return {selectors: selectors, trace: trace}; |
| 109 }); | 88 }); |
| 110 | 89 |
| 111 port.on("should-collapse", function(msg, sender) | 90 port.on("should-collapse", function(msg, sender) |
| 112 { | 91 { |
| 113 if (checkWhitelisted(sender.page, sender.frame)) | 92 if (checkWhitelisted(sender.page, sender.frame)) |
| 114 return false; | 93 return false; |
| 115 | 94 |
| 116 var typeMask = RegExpFilter.typeMap[msg.mediatype]; | 95 var typeMask = RegExpFilter.typeMap[msg.mediatype]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 137 if (filter.collapse != null) | 116 if (filter.collapse != null) |
| 138 return filter.collapse; | 117 return filter.collapse; |
| 139 | 118 |
| 140 blocked = true; | 119 blocked = true; |
| 141 } | 120 } |
| 142 } | 121 } |
| 143 | 122 |
| 144 return blocked && Prefs.hidePlaceholders; | 123 return blocked && Prefs.hidePlaceholders; |
| 145 }); | 124 }); |
| 146 | 125 |
| 147 port.on("get-domain-enabled-state", function(msg, sender) | |
| 148 { | |
| 149 return {enabled: !checkWhitelisted(sender.page)}; | |
| 150 }); | |
| 151 | |
| 152 port.on("forward", function(msg, sender) | 126 port.on("forward", function(msg, sender) |
| 153 { | 127 { |
| 154 var targetPage; | 128 var targetPage; |
| 155 if (msg.targetPageId) | 129 if (msg.targetPageId) |
| 156 targetPage = ext.getPage(msg.targetPageId); | 130 targetPage = ext.getPage(msg.targetPageId); |
| 157 else | 131 else |
| 158 targetPage = sender.page; | 132 targetPage = sender.page; |
| 159 | 133 |
| 160 if (targetPage) | 134 if (targetPage) |
| 161 { | 135 { |
| 162 msg.payload.sender = sender.page.id; | 136 msg.payload.sender = sender.page.id; |
| 163 if (msg.expectsResponse) | 137 if (msg.expectsResponse) |
| 164 return new Promise(targetPage.sendMessage.bind(targetPage, msg.payload)); | 138 return new Promise(targetPage.sendMessage.bind(targetPage, msg.payload)); |
| 165 targetPage.sendMessage(msg.payload); | 139 targetPage.sendMessage(msg.payload); |
| 166 } | 140 } |
| 167 }); | 141 }); |
| 168 | 142 |
| 169 // update icon when page changes location | 143 // update icon when page changes location |
| 170 ext.pages.onLoading.addListener(function(page) | 144 ext.pages.onLoading.addListener(function(page) |
| 171 { | 145 { |
| 172 page.sendMessage({type: "composer.content.finished"}); | 146 page.sendMessage({type: "composer.content.finished"}); |
| 173 showNextNotificationForUrl(page.url); | 147 showNextNotificationForUrl(page.url); |
| 174 }); | 148 }); |
| LEFT | RIGHT |