1# Copyright (c) 2017-2021 Cedric Bellegarde <cedric.bellegarde@adishatz.org>
2# This program is free software: you can redistribute it and/or modify
3# it under the terms of the GNU General Public License as published by
4# the Free Software Foundation, either version 3 of the License, or
5# (at your option) any later version.
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10# You should have received a copy of the GNU General Public License
11# along with this program. If not, see <http://www.gnu.org/licenses/>.
12
13import json
14
15from eolie.content_blocker import ContentBlocker
16from eolie.logger import Logger
17
18
19class PopupsContentBlocker(ContentBlocker):
20    """
21        A WebKit Content Blocker for popups
22    """
23
24    DEFAULT = [
25        {
26            "trigger": {
27                "url-filter": ".*",
28                "load-type": ["third-party"],
29                "resource-type": ["popup"]
30            },
31            "action": {
32                "type": "block"
33            }
34        }
35    ]
36
37    def __init__(self):
38        """
39            Init adblock helper
40        """
41        try:
42            ContentBlocker.__init__(self, "block-popups")
43            rules = self.DEFAULT + self.exceptions.rules
44            bytes = json.dumps(rules).encode("utf-8")
45            self.save(bytes)
46        except Exception as e:
47            Logger.error("PopupsContentBlocker::__init__(): %s", e)
48