OLD | NEW |
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 var RegExpFilter = require("filterClasses").RegExpFilter; |
19 { | |
20 this.RegExpFilter = RegExpFilter; | |
21 this.WhitelistFilter = WhitelistFilter; | |
22 } | |
23 var FilterStorage = require("filterStorage").FilterStorage; | |
24 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; | |
25 var ElemHide = require("elemHide").ElemHide; | 19 var ElemHide = require("elemHide").ElemHide; |
26 var checkWhitelisted = require("whitelisting").checkWhitelisted; | 20 var checkWhitelisted = require("whitelisting").checkWhitelisted; |
27 var extractHostFromFrame = require("url").extractHostFromFrame; | 21 var extractHostFromFrame = require("url").extractHostFromFrame; |
28 var port = require("messaging").port; | 22 var port = require("messaging").port; |
29 var devtools = require("devtools"); | 23 var devtools = require("devtools"); |
30 | 24 |
31 // This is a hack to speedup loading of the options page on Safari. | |
32 // Once we replaced the background page proxy with message passing | |
33 // this global function should removed. | |
34 function getUserFilters() | |
35 { | |
36 var filters = []; | |
37 var exceptions = []; | |
38 | |
39 for (var i = 0; i < FilterStorage.subscriptions.length; i++) | |
40 { | |
41 var subscription = FilterStorage.subscriptions[i]; | |
42 if (!(subscription instanceof SpecialSubscription)) | |
43 continue; | |
44 | |
45 for (var j = 0; j < subscription.filters.length; j++) | |
46 { | |
47 var filter = subscription.filters[j]; | |
48 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.
test(filter.text)) | |
49 exceptions.push(RegExp.$1); | |
50 else | |
51 filters.push(filter.text); | |
52 } | |
53 } | |
54 | |
55 return {filters: filters, exceptions: exceptions}; | |
56 } | |
57 | |
58 port.on("get-selectors", function(msg, sender) | 25 port.on("get-selectors", function(msg, sender) |
59 { | 26 { |
60 var selectors; | 27 var selectors; |
61 var trace = devtools && devtools.hasPanel(sender.page); | 28 var trace = devtools && devtools.hasPanel(sender.page); |
62 | 29 |
63 if (!checkWhitelisted(sender.page, sender.frame, | 30 if (!checkWhitelisted(sender.page, sender.frame, |
64 RegExpFilter.typeMap.DOCUMENT | | 31 RegExpFilter.typeMap.DOCUMENT | |
65 RegExpFilter.typeMap.ELEMHIDE)) | 32 RegExpFilter.typeMap.ELEMHIDE)) |
66 selectors = ElemHide.getSelectorsForDomain( | 33 selectors = ElemHide.getSelectorsForDomain( |
67 extractHostFromFrame(sender.frame), | 34 extractHostFromFrame(sender.frame), |
(...skipping 15 matching lines...) Expand all Loading... |
83 targetPage = sender.page; | 50 targetPage = sender.page; |
84 | 51 |
85 if (targetPage) | 52 if (targetPage) |
86 { | 53 { |
87 msg.payload.sender = sender.page.id; | 54 msg.payload.sender = sender.page.id; |
88 if (msg.expectsResponse) | 55 if (msg.expectsResponse) |
89 return new Promise(targetPage.sendMessage.bind(targetPage, msg.payload)); | 56 return new Promise(targetPage.sendMessage.bind(targetPage, msg.payload)); |
90 targetPage.sendMessage(msg.payload); | 57 targetPage.sendMessage(msg.payload); |
91 } | 58 } |
92 }); | 59 }); |
OLD | NEW |