• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.12
  • kdepim
  • messageviewer
  • adblock
adblockmanager.h
Go to the documentation of this file.
1 /* ============================================================
2 *
3 * This file is a part of the rekonq project
4 * Copyright (c) 2013 Montel Laurent <montel@kde.org>
5 * based on code from rekonq
6 * Copyright (C) 2010-2012 by Andrea Diamantini <adjam7 at gmail dot com>
7 *
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License or (at your option) version 3 or any later version
13 * accepted by the membership of KDE e.V. (or its successor approved
14 * by the membership of KDE e.V.), which shall act as a proxy
15 * defined in Section 14 of version 3 of the license.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * ============================================================ */
26 
27 
28 
29 #ifndef ADBLOCK_MANAGER_H
30 #define ADBLOCK_MANAGER_H
31 
32 
33 // NOTE: AdBlockPlus Filters (fast) summary
34 //
35 // ### Basic Filter rules
36 //
37 // RULE = http://example.com/ads/*
38 // this should block every link containing all things from that link
39 //
40 // ### Exception rules (@@)
41 //
42 // RULE = @@advice*
43 //
44 // this will save every site, also that matched by other rules, cointaining words
45 // that starts with "advice". Wildcards && regular expression allowed here.
46 //
47 // ### Beginning/end matching rules (||)
48 //
49 // RULE=||http://badsite.com
50 //
51 // will stop all links starting with http://badsite.com
52 //
53 // RULE=*swf||
54 //
55 // will stop all links to direct flash contents
56 //
57 // ### Comments (!)
58 //
59 // RULE=!azz..
60 //
61 // Every rule starting with a ! is commented out and should not be checked
62 //
63 // ### Filter Options
64 //
65 // There are 3 kind of filter options:
66 //
67 // --- ### TYPE OPTIONS
68 //
69 // You can also specify a number of options to modify the behavior of a filter.
70 // You list these options separated with commas after a dollar sign ($) at the end of the filter
71 //
72 // RULE=*/ads/*$element,match-case
73 //
74 // where $element can be one of the following:
75 // $script external scripts loaded via HTML script tag
76 // $image regular images, typically loaded via HTML img tag
77 // $background background images, often specified via CSS
78 // $stylesheet external CSS stylesheet files
79 // $object content handled by browser plugins, e.g. Flash or Java
80 // $xbl XBL bindings (typically loaded by -moz-binding CSS property) Firefox 3 or higher required
81 // $ping link pings Firefox 3 or higher required
82 // $xmlhttprequest requests started by the XMLHttpRequest object Firefox 3 or higher required
83 // $object-subrequest requests started plugins like Flash Firefox 3 or higher required
84 // $dtd DTD files loaded by XML documents Firefox 3 or higher required
85 // $subdocument embedded pages, usually included via HTML frames
86 // $document the page itself (only exception rules can be applied to the page)
87 // $other types of requests not covered in the list above
88 //
89 //
90 // --- ### INVERSE TYPE OPTIONS
91 //
92 // Inverse type options are allowed through the ~ sign, for example:
93 //
94 // RULE=*/ads/*~$script,match-case
95 //
96 //
97 // --- ### THIRD-PARTY OPTIONS
98 //
99 // If "third-party" option is specified, filter is applied just to requests coming from a different
100 // origin than the currently viewed page.
101 // In the same way, the "~third-party" option restricts the filter to the requests coming from the
102 // same origin as the currently viewed page.
103 //
104 //
105 // ### Regular expressions
106 //
107 // They usually allow to check for (a lot of) sites, using just one rule, but be careful:
108 // BASIC FILTERS ARE PROCESSED FASTER THAN REGULAR EXPRESSIONS
109 // (That's true at least in ABP! In rekonq, I don't know...)
110 //
111 //
112 // ### ELEMENT HIDING (##)
113 //
114 // This is quite different from usual adblock (but, for me, more powerful!). Sometimes you will find advertisements
115 // that can’t be blocked because they are embedded as text in the web page itself.
116 // All you can do there is HIDE the element :)
117 //
118 // RULE=##div.advise
119 //
120 // The previous rule will hide every div whose class is named "advise". Usual CSS selectors apply here :)
121 //
122 // END NOTE ----------------------------------------------------------------------------------------------------------
123 
124 
125 
126 // Local Includes
127 #include "adblockelementhiding.h"
128 #include "adblockhostmatcher.h"
129 #include "adblock/adblockrule.h"
130 
131 // KDE Includes
132 #include <KIO/Job>
133 
134 // Qt Includes
135 #include <QObject>
136 #include <QStringList>
137 #include <QByteArray>
138 #include <QFuture>
139 
140 // Forward Includes
141 class QNetworkRequest;
142 class QWebFrame;
143 
144 // Definitions
145 typedef QList<MessageViewer::AdBlockRule> AdBlockRuleList;
146 
147 namespace MessageViewer {
148 class AdBlockManager : public QObject
149 {
150  Q_OBJECT
151 
152 public:
158  static AdBlockManager *self();
159 
160  ~AdBlockManager();
161 
162  bool isEnabled();
163  bool isHidingElements();
164 
165  bool blockRequest(const QNetworkRequest &request);
166 
167  void addCustomRule(const QString &, bool reloadPage = true);
168 
169  bool isAdblockEnabledForHost(const QString &host);
170 
171  void reloadConfig();
172 
173 private:
174  AdBlockManager(QObject *parent = 0);
175 
176  void updateSubscription(const QString &path, const QString &url);
177  bool subscriptionFileExists(int);
178 
179  // load a file rule, given a path
180  void loadRules(const QString &rulesFilePath);
181 
182  // load a single rule
183  void loadRuleString(const QString &stringRule);
184 
185 private Q_SLOTS:
186  void loadSettings();
187 
188  void slotFinished(KJob *);
189 
190  void applyHidingRules(QWebFrame *);
191  void applyHidingRules(bool);
192 
193 Q_SIGNALS:
194  void reloadCurrentPage();
195 
196 private:
197  AdBlockHostMatcher _hostBlackList;
198  AdBlockHostMatcher _hostWhiteList;
199  AdBlockRuleList _blackList;
200  AdBlockRuleList _whiteList;
201 
202  AdBlockElementHiding _elementHiding;
203 
204  QFuture<void> _settingsLoaded;
205 
206  static QWeakPointer<AdBlockManager> s_adBlockManager;
207 };
208 }
209 #endif
MessageViewer::AdBlockManager::reloadCurrentPage
void reloadCurrentPage()
adblockrule.h
MessageViewer::AdBlockManager::~AdBlockManager
~AdBlockManager()
Definition: adblockmanager.cpp:76
MessageViewer::AdBlockManager::isAdblockEnabledForHost
bool isAdblockEnabledForHost(const QString &host)
Definition: adblockmanager.cpp:361
adblockhostmatcher.h
QObject
MessageViewer::AdBlockManager::addCustomRule
void addCustomRule(const QString &, bool reloadPage=true)
Definition: adblockmanager.cpp:319
MessageViewer::AdBlockManager::isHidingElements
bool isHidingElements()
Definition: adblockmanager.cpp:89
MessageViewer::AdBlockManager::reloadConfig
void reloadConfig()
Definition: adblockmanager.cpp:94
MessageViewer::AdBlockManager::blockRequest
bool blockRequest(const QNetworkRequest &request)
Definition: adblockmanager.cpp:210
MessageViewer::AdBlockHostMatcher
Definition: adblockhostmatcher.h:37
MessageViewer::AdBlockElementHiding
Definition: adblockelementhiding.h:35
MessageViewer::AdBlockManager::isEnabled
bool isEnabled()
Definition: adblockmanager.cpp:83
MessageViewer::AdBlockManager
Definition: adblockmanager.h:148
AdBlockRuleList
QList< MessageViewer::AdBlockRule > AdBlockRuleList
Definition: adblockmanager.h:142
adblockelementhiding.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:57 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal