diff options
Diffstat (limited to 'src/browser.cpp')
-rw-r--r-- | src/browser.cpp | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index 22af1f0..d1e763f 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -24,21 +24,15 @@ Browser::Browser(int &argc, char *argv[]) Browser::~Browser() { - /* We can't modify config, so no point in saving it - if(m_config) { - //QtConcurrent::run(QThreadPool::globalInstance(), m_config.get(), &Configuration::writeIfNeeded); - QtConcurrent::run([c = m_config.get()]() { - qDebug("Writing configuration: %s", c->writeIfNeeded() ? "ok" : "failed"); - }); - } - */ - if(m_bookmarksManager) { QtConcurrent::run(QThreadPool::globalInstance(), m_bookmarksManager.get(), &BookmarksWidget::save); } qDebug("Waiting for threads to wind down..."); qDebug("Thread pool is done: %s", QThreadPool::globalInstance()->waitForDone() ? "okay" : "failed"); + + delete m_urlRequestInterceptor; + delete m_cookieInterceptor; } void Browser::setConfiguration(std::shared_ptr<Configuration> &config) @@ -66,8 +60,10 @@ void Browser::setConfiguration(std::shared_ptr<Configuration> &config) m_bookmarksManager = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value())); m_downloadManager = std::make_shared<DownloadsWidget>(QString::fromStdString(m_config->value<std::string>("downloads.path").value())); - m_urlRequestInterceptor = std::make_shared<UrlRequestInterceptor>(QString::fromStdString(m_config->value<std::string>("filter.path").value())); - m_cookieInterceptor = std::make_shared<CookieInterceptor>(""); + m_urlRequestInterceptor = new UrlRequestInterceptor(QString::fromStdString(m_config->value<std::string>("filter.path").value())); + m_cookieInterceptor = new CookieFilter( + m_config->value<bool>("filter.cookies.block.all").value(), + m_config->value<bool>("filter.cookies.block.thirdParty").value()); // set default profile m_defaultProfile = profile(QString::fromStdString(m_config->value<std::string>("browser.profile").value())); @@ -140,11 +136,25 @@ std::shared_ptr<WebEngineProfile> Browser::profile(const QString &storageName) Q_ASSERT(m_config); const QString &path = QString::fromStdString(m_config->value<std::string>("profile.path").value()); - std::shared_ptr<WebEngineProfile> _profile = std::shared_ptr<WebEngineProfile>(createProfile(storageName, path, nullptr)); - _profile->setRequestInterceptor(m_urlRequestInterceptor.get()); - _profile->setCookieInterceptor(m_cookieInterceptor.get()); + std::shared_ptr<WebEngineProfile> _profile; + + if(storageName.isEmpty()) { + // create off-the-record profile + _profile = std::make_shared<WebEngineProfile>(nullptr); + } else { + // regular profile + _profile = std::make_shared<WebEngineProfile>(storageName, nullptr); + _profile->setPersistentStoragePath(path + "/storage"); + _profile->setCachePath(path + "/cache"); + } + + _profile->setRequestInterceptor(m_urlRequestInterceptor); + _profile->cookieStore()->setCookieFilter([this](QWebEngineCookieStore::FilterRequest &request) { + request.accepted = !m_cookieInterceptor->shouldBlock(request); + }); + connect(_profile.get(), &WebEngineProfile::downloadRequested, m_downloadManager.get(), &DownloadsWidget::addDownload); - m_profiles.insert(storageName, _profile); + m_profiles.insert(storageName, _profile); return _profile; } |