1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Don't store blocked entries in WebPage

It is not possible in this way with QtWebEngine
This commit is contained in:
David Rosca 2015-10-05 20:23:10 +02:00
parent e91d6482d1
commit 150252aea9
3 changed files with 1 additions and 83 deletions

View File

@ -148,23 +148,6 @@ void AdBlockIcon::createMenu(QMenu* menu)
action->setData(QVariant::fromValue((void*)pair.first));
}
}
menu->addSeparator();
QVector<WebPage::AdBlockedEntry> entries = page->adBlockedEntries();
if (entries.isEmpty()) {
menu->addAction(tr("No content blocked"))->setEnabled(false);
}
else {
menu->addAction(tr("Blocked URL (AdBlock Rule) - click to edit rule"))->setEnabled(false);
foreach (const WebPage::AdBlockedEntry &entry, entries) {
QString address = entry.url.toString().right(55);
QString actionText = tr("%1 with (%2)").arg(address, entry.rule->filter()).replace(QLatin1Char('&'), QLatin1String("&&"));
QAction* action = menu->addAction(actionText, manager, SLOT(showRule()));
action->setData(QVariant::fromValue((void*)entry.rule));
}
}
}
void AdBlockIcon::showMenu(const QPoint &pos)

View File

@ -165,7 +165,6 @@ void WebPage::urlChanged(const QUrl &url)
Q_UNUSED(url)
if (isLoading()) {
m_adBlockedEntries.clear();
m_blockAlerts = false;
}
}
@ -376,22 +375,6 @@ QStringList WebPage::chooseFiles(QWebEnginePage::FileSelectionMode mode, const Q
return files;
}
void WebPage::addAdBlockRule(const AdBlockRule* rule, const QUrl &url)
{
AdBlockedEntry entry;
entry.rule = rule;
entry.url = url;
if (!m_adBlockedEntries.contains(entry)) {
m_adBlockedEntries.append(entry);
}
}
QVector<WebPage::AdBlockedEntry> WebPage::adBlockedEntries() const
{
return m_adBlockedEntries;
}
bool WebPage::hasMultipleUsernames() const
{
return m_passwordEntries.count() > 1;
@ -409,40 +392,6 @@ void WebPage::cleanBlockedObjects()
return;
}
#if QTWEBENGINE_DISABLED
const QWebElement docElement = mainFrame()->documentElement();
foreach (const AdBlockedEntry &entry, m_adBlockedEntries) {
const QString urlString = entry.url.toString();
if (urlString.endsWith(QLatin1String(".js")) || urlString.endsWith(QLatin1String(".css"))) {
continue;
}
QString urlEnd;
int pos = urlString.lastIndexOf(QLatin1Char('/'));
if (pos > 8) {
urlEnd = urlString.mid(pos + 1);
}
if (urlString.endsWith(QLatin1Char('/'))) {
urlEnd = urlString.left(urlString.size() - 1);
}
QString selector("img[src$=\"%1\"], iframe[src$=\"%1\"],embed[src$=\"%1\"]");
QWebElementCollection elements = docElement.findAll(selector.arg(urlEnd));
foreach (QWebElement element, elements) {
QString src = element.attribute("src");
src.remove(QLatin1String("../"));
if (urlString.contains(src)) {
element.setStyleProperty("display", "none");
}
}
}
#endif
// Apply domain-specific element hiding rules
const QString elementHiding = manager->elementHidingRulesForDomain(url());
if (elementHiding.isEmpty()) {

View File

@ -28,7 +28,6 @@ class QEventLoop;
class QWebEngineDownloadItem;
class WebView;
class AdBlockRule;
class WebHitTestResult;
class DelayedFileWatcher;
@ -36,16 +35,7 @@ class QUPZILLA_EXPORT WebPage : public QWebEnginePage
{
Q_OBJECT
public:
struct AdBlockedEntry {
const AdBlockRule* rule;
QUrl url;
bool operator==(const AdBlockedEntry &other) const {
return (this->rule == other.rule && this->url == other.url);
}
};
WebPage(QObject* parent = 0);
explicit WebPage(QObject* parent = 0);
~WebPage();
WebView *view() const;
@ -62,9 +52,6 @@ public:
void setJavaScriptEnabled(bool enabled);
void addAdBlockRule(const AdBlockRule* rule, const QUrl &url);
QVector<AdBlockedEntry> adBlockedEntries() const;
bool hasMultipleUsernames() const;
QVector<PasswordEntry> autoFillData() const;
@ -107,7 +94,6 @@ private:
DelayedFileWatcher* m_fileWatcher;
QEventLoop* m_runningLoop;
QVector<AdBlockedEntry> m_adBlockedEntries;
QVector<PasswordEntry> m_passwordEntries;
QUrl m_lastRequestUrl;