Пример #1
0
QNetworkReply* AdBlockManager::block(const QNetworkRequest &request)
{
    const QString &urlString = request.url().toEncoded();
    const QString &urlDomain = request.url().host();
    const QString &urlScheme = request.url().scheme();

    if (!isEnabled() || !canRunOnScheme(urlScheme)) {
        return 0;
    }

    foreach(AdBlockSubscription * subscription, m_subscriptions) {
        const AdBlockRule* blockedRule = subscription->match(request, urlDomain, urlString);

        if (blockedRule) {
            QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
            WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
            if (WebPage::isPointerSafeToUse(webPage)) {
                if (!canBeBlocked(webPage->url())) {
                    return 0;
                }

                webPage->addAdBlockRule(blockedRule, request.url());
            }

            AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(subscription, blockedRule, this);
            reply->setRequest(request);

            return reply;
        }
    }

    return 0;
}
Пример #2
0
QNetworkReply* AdBlockManager::block(const QNetworkRequest &request)
{
#ifdef ADBLOCK_DEBUG
    QElapsedTimer timer;
    timer.start();
#endif
    const QString urlString = request.url().toEncoded().toLower();
    const QString urlDomain = request.url().host().toLower();
    const QString urlScheme = request.url().scheme().toLower();

    if (!isEnabled() || !canRunOnScheme(urlScheme)) {
        return 0;
    }

    foreach (AdBlockSubscription* subscription, m_subscriptions) {
        const AdBlockRule* blockedRule = subscription->match(request, urlDomain, urlString);

        if (blockedRule) {
            QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
            WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
            if (WebPage::isPointerSafeToUse(webPage)) {
                if (!canBeBlocked(webPage->url())) {
                    return 0;
                }

                webPage->addAdBlockRule(blockedRule, request.url());
            }

            AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(subscription, blockedRule, this);
            reply->setRequest(request);

#ifdef ADBLOCK_DEBUG
            qDebug() << "BLOCKED: " << timer.elapsed() << blockedRule->filter() << request.url();
#endif

            return reply;
        }
    }

#ifdef ADBLOCK_DEBUG
    qDebug() << timer.elapsed() << request.url();
#endif

    return 0;
}
Пример #3
0
QNetworkReply* AdBlockNetwork::block(const QNetworkRequest &request)
{
    const QString &urlString = request.url().toEncoded();
    const QString &urlScheme = request.url().scheme();

    if (urlScheme == "data" || urlScheme == "qrc" || urlScheme == "file" || urlScheme == "qupzilla") {
        return 0;
    }

    AdBlockManager* manager = AdBlockManager::instance();
    if (!manager->isEnabled()) {
        return 0;
    }

    const AdBlockRule* blockedRule = 0;
    AdBlockSubscription* subscription = manager->subscription();

    if (subscription->allow(urlString)) {
        return 0;
    }

    if (const AdBlockRule* rule = subscription->block(urlString)) {
        blockedRule = rule;
    }

    if (blockedRule) {
        QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
        WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
        if (WebPage::isPointerSafeToUse(webPage)) {
            webPage->addAdBlockRule(blockedRule->filter(), request.url());
        }

        AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(request, blockedRule, this);
        return reply;
    }
    return 0;
}
Пример #4
0
QNetworkReply* AdBlockNetwork::block(const QNetworkRequest &request)
{
    QUrl url = request.url();
    if (url.scheme() == "data") {
        return 0;
    }

    AdBlockManager* manager = AdBlockManager::instance();
    if (!manager->isEnabled()) {
        return 0;
    }

    QString urlString = url.toEncoded();
    const AdBlockRule* blockedRule = 0;
    AdBlockSubscription* subscription = manager->subscription();

    if (subscription->allow(urlString)) {
        return 0;
    }

    if (const AdBlockRule* rule = subscription->block(urlString)) {
        blockedRule = rule;
    }

    if (blockedRule) {
        QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
        WebPage* webPage = (WebPage*)(v.value<void*>());
        if (webPage) {
            webPage->addAdBlockRule(blockedRule->filter(), request.url());
        }

        AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(request, blockedRule, this);
        return reply;
    }
    return 0;
}