Commit a3fe8bc7 authored by Allan Sandfeld Jensen's avatar Allan Sandfeld Jensen
Browse files

Protect QML profiles as well as core


Moves QWebEngineBrowserContext to core and makes use of it from both
widget and qml.

Change-Id: I34748f302b0515b11b5831690d28478dfa6a852b
Reviewed-by: default avatarMichal Klocek <michal.klocek@qt.io>
Reviewed-by: default avatarAlexandru Croitor <alexandru.croitor@qt.io>
Showing with 181 additions and 54 deletions
......@@ -33,6 +33,7 @@ HEADERS = \
qwebenginecallback_p.h \
qtwebenginecoreglobal.h \
qtwebenginecoreglobal_p.h \
qwebenginebrowsercontext_p.h \
qwebenginecookiestore.h \
qwebenginecookiestore_p.h \
qwebenginehttprequest.h \
......@@ -44,6 +45,7 @@ HEADERS = \
SOURCES = \
qtwebenginecoreglobal.cpp \
qwebenginebrowsercontext.cpp \
qwebenginecookiestore.cpp \
qwebenginehttprequest.cpp \
qwebengineurlrequestinfo.cpp \
......
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qwebenginebrowsercontext_p.h"
#include "browser_context_adapter.h"
#include <qtwebenginecoreglobal.h>
QT_BEGIN_NAMESPACE
QWebEngineBrowserContext::QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext,
QtWebEngineCore::BrowserContextAdapterClient *profile)
: QObject(QtWebEngineCore::BrowserContextAdapter::globalQObjectRoot())
, browserContextRef(browserContext)
, m_profile(profile)
{
browserContextRef->addClient(m_profile);
}
QWebEngineBrowserContext::~QWebEngineBrowserContext()
{
if (m_profile)
shutdown();
}
void QWebEngineBrowserContext::shutdown()
{
Q_ASSERT(m_profile);
// In the case the user sets this profile as the parent of the interceptor
// it can be deleted before the browser-context still referencing it is.
browserContextRef->setRequestInterceptor(nullptr);
browserContextRef->removeClient(m_profile);
m_profile = 0;
deleteLater();
}
QT_END_NAMESPACE
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QWEBENGINEBROWSERCONTEXT_P_H
#define QWEBENGINEBROWSERCONTEXT_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "qtwebenginecoreglobal_p.h"
#include <QObject>
#include <QSharedPointer>
namespace QtWebEngineCore {
class BrowserContextAdapter;
class BrowserContextAdapterClient;
}
QT_BEGIN_NAMESPACE
// This is a wrapper class for BrowserContextAdapter. BrowserContextAdapter must be destructed before WebEngineContext
// is destructed. Therefore access it via the QWebEngineBrowserContext which parent is the WebEngineContext::globalQObject.
// This guarantees the destruction together with the WebEngineContext.
class QWEBENGINE_PRIVATE_EXPORT QWebEngineBrowserContext : public QObject {
public:
QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext, QtWebEngineCore::BrowserContextAdapterClient *profile);
~QWebEngineBrowserContext();
void shutdown();
QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContextRef;
private:
QtWebEngineCore::BrowserContextAdapterClient *m_profile;
};
QT_END_NAMESPACE
#endif // QWEBENGINEBROWSERCONTEXT_P_H
......@@ -142,9 +142,8 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineC
QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(QSharedPointer<BrowserContextAdapter> browserContext)
: m_settings(new QQuickWebEngineSettings())
, m_browserContextRef(browserContext)
, m_browserContext(new QWebEngineBrowserContext(browserContext, this))
{
m_browserContextRef->addClient(this);
m_settings->d_ptr->initDefaults(browserContext->isOffTheRecord());
// Fullscreen API was implemented before the supported setting, so we must
// make it default true to avoid change in default API behavior.
......@@ -153,21 +152,26 @@ QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(QSharedPointer<Brow
QQuickWebEngineProfilePrivate::~QQuickWebEngineProfilePrivate()
{
m_browserContextRef->setRequestInterceptor(nullptr);
m_browserContextRef->removeClient(this);
Q_FOREACH (QQuickWebEngineDownloadItem* download, m_ongoingDownloads) {
Q_FOREACH (QQuickWebEngineDownloadItem *download, m_ongoingDownloads) {
if (download)
download->cancel();
}
m_ongoingDownloads.clear();
if (m_browserContext)
m_browserContext->shutdown();
}
QSharedPointer<QtWebEngineCore::BrowserContextAdapter> QQuickWebEngineProfilePrivate::browserContext() const
{
return m_browserContext ? m_browserContext->browserContextRef : nullptr;
}
void QQuickWebEngineProfilePrivate::cancelDownload(quint32 downloadId)
{
browserContext()->cancelDownload(downloadId);
if (m_browserContext)
m_browserContext->browserContextRef->cancelDownload(downloadId);
}
void QQuickWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId)
......
......@@ -52,8 +52,9 @@
//
#include "browser_context_adapter_client.h"
#include "qquickwebengineprofile_p.h"
#include "browser_context_adapter.h"
#include "qwebenginebrowsercontext_p.h"
#include "qquickwebengineprofile_p.h"
#include <QExplicitlySharedDataPointer>
#include <QMap>
......@@ -71,7 +72,7 @@ public:
QQuickWebEngineProfilePrivate(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext);
~QQuickWebEngineProfilePrivate();
QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext() const { return m_browserContextRef; }
QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext() const;
QQuickWebEngineSettings *settings() const { return m_settings.data(); }
void cancelDownload(quint32 downloadId);
......@@ -90,7 +91,7 @@ private:
friend class QQuickWebEngineViewPrivate;
QQuickWebEngineProfile *q_ptr;
QScopedPointer<QQuickWebEngineSettings> m_settings;
QSharedPointer<QtWebEngineCore::BrowserContextAdapter> m_browserContextRef;
QPointer<QWebEngineBrowserContext> m_browserContext;
QMap<quint32, QPointer<QQuickWebEngineDownloadItem> > m_ongoingDownloads;
QList<QQuickWebEngineScript *> m_userScripts;
};
......
......@@ -47,8 +47,9 @@
#include "qwebenginesettings.h"
#include "qwebenginescriptcollection_p.h"
#include "qwebenginebrowsercontext_p.h"
#include "qtwebenginecoreglobal.h"
#include "browser_context_adapter.h"
#include <qtwebenginecoreglobal.h>
#include "visited_links_manager_qt.h"
#include "web_engine_settings.h"
......@@ -145,30 +146,6 @@ using QtWebEngineCore::BrowserContextAdapter;
\sa QWebEngineDownloadItem
*/
QWebEngineBrowserContext::QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext, QWebEngineProfilePrivate *profile)
: QObject(BrowserContextAdapter::globalQObjectRoot())
, browserContextRef(browserContext)
, m_profile(profile)
{
browserContextRef->addClient(m_profile);
}
QWebEngineBrowserContext::~QWebEngineBrowserContext()
{
if (m_profile)
shutdown();
}
void QWebEngineBrowserContext::shutdown()
{
Q_ASSERT(m_profile);
// In the case the user sets this profile as the parent of the interceptor
// it can be deleted before the browser-context still referencing it is.
browserContextRef->setRequestInterceptor(nullptr);
browserContextRef->removeClient(m_profile);
m_profile = 0;
}
QWebEngineProfilePrivate::QWebEngineProfilePrivate(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext)
: m_settings(new QWebEngineSettings())
, m_scriptCollection(new QWebEngineScriptCollection(new QWebEngineScriptCollectionPrivate(browserContext->userResourceController())))
......@@ -194,12 +171,13 @@ QWebEngineProfilePrivate::~QWebEngineProfilePrivate()
QSharedPointer<QtWebEngineCore::BrowserContextAdapter> QWebEngineProfilePrivate::browserContext() const
{
return m_browserContext->browserContextRef;
return m_browserContext ? m_browserContext->browserContextRef : nullptr;
}
void QWebEngineProfilePrivate::cancelDownload(quint32 downloadId)
{
browserContext()->cancelDownload(downloadId);
if (m_browserContext)
m_browserContext->browserContextRef->cancelDownload(downloadId);
}
void QWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId)
......
......@@ -54,6 +54,7 @@
#include "browser_context_adapter_client.h"
#include "qwebengineprofile.h"
#include "qwebenginescriptcollection.h"
#include <QMap>
#include <QPointer>
#include <QScopedPointer>
......@@ -65,25 +66,10 @@ class BrowserContextAdapter;
QT_BEGIN_NAMESPACE
class QWebEngineBrowserContext;
class QWebEngineProfilePrivate;
class QWebEngineSettings;
// This is a wrapper class for BrowserContextAdapter. BrowserContextAdapter must be destructed before WebEngineContext
// is destructed. Therefore access it via the QWebEngineBrowserContext which parent is the WebEngineContext::globalQObject.
// This guarantees the destruction together with the WebEngineContext.
class QWebEngineBrowserContext : public QObject {
public:
QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext, QWebEngineProfilePrivate *profile);
~QWebEngineBrowserContext();
void shutdown();
QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContextRef;
private:
QWebEngineProfilePrivate *m_profile;
};
class QWebEngineProfilePrivate : public QtWebEngineCore::BrowserContextAdapterClient {
public:
Q_DECLARE_PUBLIC(QWebEngineProfile)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment