File indexing completed on 2025-01-26 04:57:24

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "blocktrackingurlinterceptor.h"
0008 #include "webengineviewer_block_tracking_url_interceptor_debug.h"
0009 #include <QWebEngineUrlRequestInfo>
0010 
0011 using namespace WebEngineViewer;
0012 BlockTrackingUrlInterceptor::BlockTrackingUrlInterceptor(QObject *parent)
0013     : WebEngineViewer::NetworkPluginUrlInterceptorInterface(parent)
0014 {
0015     qRegisterMetaType<WebEngineViewer::BlockTrackingUrlInterceptor::TrackerBlackList>();
0016     initializeList();
0017 }
0018 
0019 BlockTrackingUrlInterceptor::~BlockTrackingUrlInterceptor() = default;
0020 
0021 bool BlockTrackingUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
0022 {
0023     if (!mEnabledMailTrackingInterceptor) {
0024         return false;
0025     }
0026     const QUrl urlRequestUrl(info.requestUrl());
0027     if (urlRequestUrl.scheme() != QLatin1StringView("data")) {
0028         qCDebug(WEBENGINEVIEWER_BLOCK_TRACKING_URL_LOG) << " Tracking url " << urlRequestUrl;
0029     }
0030     for (int i = 0, total = mBackList.size(); i < total; ++i) {
0031         const auto blackListinfo{mBackList.at(i)};
0032         if (urlRequestUrl.url().startsWith(blackListinfo.mCompanyUrl)) {
0033             qCDebug(WEBENGINEVIEWER_BLOCK_TRACKING_URL_LOG) << " found tracker " << blackListinfo;
0034             Q_EMIT trackingFound(blackListinfo);
0035             return true;
0036         }
0037     }
0038     return false;
0039 }
0040 
0041 void BlockTrackingUrlInterceptor::initializeList()
0042 {
0043     mBackList = {{QStringLiteral("Sidekick"), QStringLiteral("t.signaux"), QStringLiteral("http://getsidekick.com")},
0044                  {QStringLiteral("Sidekick"), QStringLiteral("t.sidekickopen"), QStringLiteral("http://getsidekick.com")},
0045                  {QStringLiteral("Sidekick"), QStringLiteral("t.sigopn"), QStringLiteral("http://getsidekick.com")},
0046                  {QStringLiteral("Banana Tag"), QStringLiteral("bl-1.com"), QStringLiteral("http://bananatag.com")},
0047                  {QStringLiteral("Boomerang"), QStringLiteral("mailstat.us/tr"), QStringLiteral("http://boomeranggmail.com")},
0048                  {QStringLiteral("Cirrus Insight"), QStringLiteral("tracking.cirrusinsight.com"), QStringLiteral("http://cirrusinsight.com")},
0049                  {QStringLiteral("Yesware"), QStringLiteral("app.yesware.com"), QStringLiteral("http://yesware.com")},
0050                  {QStringLiteral("Yesware"), QStringLiteral("t.yesware.com"), QStringLiteral("http://yesware.com")},
0051                  {QStringLiteral("Streak"), QStringLiteral("mailfoogae.appspot.com"), QStringLiteral("http://streak.com")},
0052                  {QStringLiteral("LaunchBit"), QStringLiteral("launchbit.com/taz-pixel"), QStringLiteral("http://launchbit.com")},
0053                  {QStringLiteral("MailChimp"), QStringLiteral("list-manage.com/track"), QStringLiteral("http://mailchimp.com")},
0054                  {QStringLiteral("Postmark"), QStringLiteral("cmail1.com/t"), QStringLiteral("http://postmarkapp.com")},
0055                  {QStringLiteral("iContact"), QStringLiteral("click.icptrack.com/icp/"), QStringLiteral("http://icontact.com")},
0056                  {QStringLiteral("Infusionsoft"), QStringLiteral("infusionsoft.com/app/emailOpened"), QStringLiteral("http://infusionsoft.com")},
0057                  {QStringLiteral("Intercom"), QStringLiteral("via.intercom.io/o"), QStringLiteral("http://intercom.io")},
0058                  {QStringLiteral("Mandrill"), QStringLiteral("mandrillapp.com/track"), QStringLiteral("http://mandrillapp.com")},
0059                  {QStringLiteral("Hubspot"), QStringLiteral("t.hsms06.com"), QStringLiteral("http://hubspot.com")},
0060                  {QStringLiteral("RelateIQ"), QStringLiteral("app.relateiq.com/t.png"), QStringLiteral("http://relateiq.com")},
0061                  {QStringLiteral("RJ Metrics"), QStringLiteral("go.rjmetrics.com"), QStringLiteral("http://rjmetrics.com")},
0062                  {QStringLiteral("Mixpanel"), QStringLiteral("api.mixpanel.com/track"), QStringLiteral("http://mixpanel.com")},
0063                  {QStringLiteral("Front App"), QStringLiteral("web.frontapp.com/api"), QStringLiteral("http://frontapp.com")},
0064                  {QStringLiteral("Mailtrack.io"), QStringLiteral("mailtrack.io/trace"), QStringLiteral("http://mailtrack.io")},
0065                  {QStringLiteral("ToutApp"), QStringLiteral("go.toutapp.com"), QStringLiteral("http://toutapp.com")},
0066                  {QStringLiteral("Outreach"), QStringLiteral("app.outreach.io"), QStringLiteral("http://outreach.io")}};
0067     // https://github.com/JannikArndt/EMailTrackerBlocker
0068 }
0069 
0070 bool BlockTrackingUrlInterceptor::enabledMailTrackingInterceptor() const
0071 {
0072     return mEnabledMailTrackingInterceptor;
0073 }
0074 
0075 void BlockTrackingUrlInterceptor::setEnabledMailTrackingInterceptor(bool enabledMailTrackingInterceptor)
0076 {
0077     mEnabledMailTrackingInterceptor = enabledMailTrackingInterceptor;
0078 }
0079 
0080 QDebug operator<<(QDebug d, const WebEngineViewer::BlockTrackingUrlInterceptor::TrackerBlackList &t)
0081 {
0082     d << "CompanyName : " << t.mCompanyName;
0083     d << "mCompanyUrl : " << t.mCompanyUrl;
0084     d << "mPattern : " << t.mPattern;
0085     return d;
0086 }
0087 
0088 #include "moc_blocktrackingurlinterceptor.cpp"