summaryrefslogtreecommitdiffstats
path: root/src/core/profile_adapter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/profile_adapter.cpp')
-rw-r--r--src/core/profile_adapter.cpp133
1 files changed, 121 insertions, 12 deletions
diff --git a/src/core/profile_adapter.cpp b/src/core/profile_adapter.cpp
index 1b946949a..7070292d6 100644
--- a/src/core/profile_adapter.cpp
+++ b/src/core/profile_adapter.cpp
@@ -44,10 +44,12 @@
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/download_manager.h"
+#include "api/qwebengineurlscheme.h"
#include "content_client_qt.h"
#include "download_manager_delegate_qt.h"
#include "net/url_request_context_getter_qt.h"
#include "permission_manager_qt.h"
+#include "profile_adapter_client.h"
#include "profile_qt.h"
#include "renderer_host/user_resource_controller_host.h"
#include "type_conversion.h"
@@ -57,6 +59,10 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h"
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+#include "extensions/browser/extension_system.h"
+#endif
+
#include <QCoreApplication>
#include <QDir>
#include <QString>
@@ -78,10 +84,12 @@ namespace QtWebEngineCore {
ProfileAdapter::ProfileAdapter(const QString &storageName):
m_name(storageName)
, m_offTheRecord(storageName.isEmpty())
+ , m_downloadPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation))
, m_httpCacheType(DiskHttpCache)
, m_persistentCookiesPolicy(AllowPersistentCookies)
, m_visitedLinksPolicy(TrackVisitedLinksOnDisk)
, m_httpCacheMaxSize(0)
+ , m_pageRequestInterceptors(0)
{
WebEngineContext::current()->addProfileAdapter(this);
// creation of profile requires webengine context
@@ -89,6 +97,11 @@ ProfileAdapter::ProfileAdapter(const QString &storageName):
content::BrowserContext::Initialize(m_profile.data(), toFilePath(dataPath()));
// fixme: this should not be here
m_profile->m_profileIOData->initializeOnUIThread();
+ m_customUrlSchemeHandlers.insert(QByteArrayLiteral("qrc"), &m_qrcHandler);
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+ if (!storageName.isEmpty())
+ extensions::ExtensionSystem::Get(m_profile.data())->InitForRegularProfile(true);
+#endif
}
ProfileAdapter::~ProfileAdapter()
@@ -101,6 +114,8 @@ ProfileAdapter::~ProfileAdapter()
m_profile->GetDownloadManager(m_profile.data())->Shutdown();
m_downloadManagerDelegate.reset();
}
+ delete m_clientCertificateStore;
+ Q_ASSERT(m_pageRequestInterceptors == 0);
}
void ProfileAdapter::setStorageName(const QString &storageName)
@@ -177,6 +192,22 @@ void ProfileAdapter::removeClient(ProfileAdapterClient *adapterClient)
m_clients.removeOne(adapterClient);
}
+void ProfileAdapter::addPageRequestInterceptor()
+{
+ ++m_pageRequestInterceptors;
+ if (m_profile->m_urlRequestContextGetter.get())
+ m_profile->m_profileIOData->updateRequestInterceptor();
+}
+
+void ProfileAdapter::removePageRequestInterceptor()
+{
+ Q_ASSERT(m_pageRequestInterceptors > 0);
+ --m_pageRequestInterceptors;
+ if (m_profile->m_urlRequestContextGetter.get())
+ m_profile->m_profileIOData->updateRequestInterceptor();
+}
+
+
void ProfileAdapter::cancelDownload(quint32 downloadId)
{
downloadManagerDelegate()->cancelDownload(downloadId);
@@ -237,6 +268,11 @@ void ProfileAdapter::setDataPath(const QString &path)
}
}
+void ProfileAdapter::setDownloadPath(const QString &path)
+{
+ m_downloadPath = path.isEmpty() ? QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) : path;
+}
+
QString ProfileAdapter::cachePath() const
{
if (m_offTheRecord)
@@ -405,9 +441,23 @@ void ProfileAdapter::setHttpCacheMaxSize(int maxSize)
m_profile->m_profileIOData->updateHttpCache();
}
-const QHash<QByteArray, QWebEngineUrlSchemeHandler *> &ProfileAdapter::customUrlSchemeHandlers() const
+static bool isInternalScheme(const QByteArray &scheme)
{
- return m_customUrlSchemeHandlers;
+ static QSet<QByteArray> internalSchemes{
+ QByteArrayLiteral("qrc"),
+ QByteArrayLiteral("data"),
+ QByteArrayLiteral("blob"),
+ QByteArrayLiteral("http"),
+ QByteArrayLiteral("https"),
+ QByteArrayLiteral("ftp"),
+ QByteArrayLiteral("javascript"),
+ };
+ return internalSchemes.contains(scheme);
+}
+
+QWebEngineUrlSchemeHandler *ProfileAdapter::urlSchemeHandler(const QByteArray &scheme)
+{
+ return m_customUrlSchemeHandlers.value(scheme.toLower()).data();
}
const QList<QByteArray> ProfileAdapter::customUrlSchemes() const
@@ -421,12 +471,17 @@ void ProfileAdapter::updateCustomUrlSchemeHandlers()
m_profile->m_profileIOData->updateJobFactory();
}
-bool ProfileAdapter::removeCustomUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler)
+void ProfileAdapter::removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler)
{
+ Q_ASSERT(handler);
bool removedOneOrMore = false;
auto it = m_customUrlSchemeHandlers.begin();
while (it != m_customUrlSchemeHandlers.end()) {
if (it.value() == handler) {
+ if (isInternalScheme(it.key())) {
+ qWarning("Cannot remove the URL scheme handler for an internal scheme: %s", it.key().constData());
+ continue;
+ }
it = m_customUrlSchemeHandlers.erase(it);
removedOneOrMore = true;
continue;
@@ -435,26 +490,43 @@ bool ProfileAdapter::removeCustomUrlSchemeHandler(QWebEngineUrlSchemeHandler *ha
}
if (removedOneOrMore)
updateCustomUrlSchemeHandlers();
- return removedOneOrMore;
}
-QWebEngineUrlSchemeHandler *ProfileAdapter::takeCustomUrlSchemeHandler(const QByteArray &scheme)
+void ProfileAdapter::removeUrlScheme(const QByteArray &scheme)
{
- QWebEngineUrlSchemeHandler *handler = m_customUrlSchemeHandlers.take(scheme);
- if (handler)
+ QByteArray canonicalScheme = scheme.toLower();
+ if (isInternalScheme(canonicalScheme)) {
+ qWarning("Cannot remove the URL scheme handler for an internal scheme: %s", scheme.constData());
+ return;
+ }
+ if (m_customUrlSchemeHandlers.remove(canonicalScheme))
updateCustomUrlSchemeHandlers();
- return handler;
}
-void ProfileAdapter::addCustomUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler *handler)
+void ProfileAdapter::installUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler *handler)
{
- m_customUrlSchemeHandlers.insert(scheme, handler);
+ Q_ASSERT(handler);
+ QByteArray canonicalScheme = scheme.toLower();
+ if (isInternalScheme(canonicalScheme)) {
+ qWarning("Cannot install a URL scheme handler overriding internal scheme: %s", scheme.constData());
+ return;
+ }
+ if (m_customUrlSchemeHandlers.value(canonicalScheme, handler) != handler) {
+ qWarning("URL scheme handler already installed for the scheme: %s", scheme.constData());
+ return;
+ }
+ if (QWebEngineUrlScheme::schemeByName(canonicalScheme) == QWebEngineUrlScheme())
+ qWarning("Please register the custom scheme '%s' via QWebEngineUrlScheme::registerScheme() "
+ "before installing the custom scheme handler.", scheme.constData());
+
+ m_customUrlSchemeHandlers.insert(canonicalScheme, handler);
updateCustomUrlSchemeHandlers();
}
-void ProfileAdapter::clearCustomUrlSchemeHandlers()
+void ProfileAdapter::removeAllUrlSchemeHandlers()
{
m_customUrlSchemeHandlers.clear();
+ m_customUrlSchemeHandlers.insert(QByteArrayLiteral("qrc"), &m_qrcHandler);
updateCustomUrlSchemeHandlers();
}
@@ -563,7 +635,44 @@ void ProfileAdapter::removeWebContentsAdapterClient(WebContentsAdapterClient *cl
void ProfileAdapter::resetVisitedLinksManager()
{
- m_visitedLinksManager.reset(new VisitedLinksManagerQt(this));
+ m_visitedLinksManager.reset(new VisitedLinksManagerQt(m_profile.data(), persistVisitedLinks()));
+}
+
+void ProfileAdapter::setUseForGlobalCertificateVerification(bool enable)
+{
+ if (m_usedForGlobalCertificateVerification == enable)
+ return;
+
+ static QPointer<ProfileAdapter> profileForglobalCertificateVerification;
+
+ m_usedForGlobalCertificateVerification = enable;
+ if (enable) {
+ if (profileForglobalCertificateVerification) {
+ profileForglobalCertificateVerification->m_usedForGlobalCertificateVerification = false;
+ for (auto *client : qAsConst(profileForglobalCertificateVerification->m_clients))
+ client->useForGlobalCertificateVerificationChanged();
+ }
+ profileForglobalCertificateVerification = this;
+ } else {
+ Q_ASSERT(profileForglobalCertificateVerification);
+ Q_ASSERT(profileForglobalCertificateVerification == this);
+ profileForglobalCertificateVerification = nullptr;
+ }
+
+ if (m_profile->m_urlRequestContextGetter.get())
+ m_profile->m_profileIOData->updateUsedForGlobalCertificateVerification();
+}
+
+bool ProfileAdapter::isUsedForGlobalCertificateVerification() const
+{
+ return m_usedForGlobalCertificateVerification;
+}
+
+QWebEngineClientCertificateStore *ProfileAdapter::clientCertificateStore()
+{
+ if (!m_clientCertificateStore)
+ m_clientCertificateStore = new QWebEngineClientCertificateStore(m_profile->m_profileIOData->clientCertificateStoreData());
+ return m_clientCertificateStore;
}
} // namespace QtWebEngineCore