mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 07:13:57 +02:00
BUGZ-1363: crash when checking for web content restrictions
This commit is contained in:
parent
3134332513
commit
954773124a
8 changed files with 40 additions and 25 deletions
|
@ -18,6 +18,7 @@
|
|||
#include <QtQuick/QQuickWindow>
|
||||
#include <QQuickView>
|
||||
|
||||
#include <ui/types/ContextAwareProfile.h>
|
||||
#include <DependencyManager.h>
|
||||
#include <DockWidget.h>
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
@ -228,9 +229,15 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
|||
_dockWidget->setObjectName("DockedWidget");
|
||||
mainWindow->addDockWidget(dockArea, _dockWidget.get());
|
||||
} else {
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
// Build the event bridge and wrapper on the main thread
|
||||
offscreenUi->loadInNewContext(CONTENT_WINDOW_QML, [&](QQmlContext* context, QObject* object) {
|
||||
auto contextInitLambda = [&](QQmlContext* context) {
|
||||
#if !defined(Q_OS_ANDROID)
|
||||
// If the restricted flag is on, override the FileTypeProfile and HFWebEngineProfile objects in the
|
||||
// QML surface root context with local ones
|
||||
ContextAwareProfile::restrictContext(context, false);
|
||||
#endif
|
||||
};
|
||||
|
||||
auto objectInitLambda = [&](QQmlContext* context, QObject* object) {
|
||||
_qmlWindowProxy = std::shared_ptr<QmlWindowProxy>(new QmlWindowProxy(object, nullptr), qmlWindowProxyDeleter);
|
||||
context->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy.get());
|
||||
if (properties.contains(ADDITIONAL_FLAGS_PROPERTY)) {
|
||||
|
@ -286,7 +293,11 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
|||
}
|
||||
object->setObjectName("InteractiveWindow");
|
||||
object->setProperty(SOURCE_PROPERTY, sourceURL);
|
||||
});
|
||||
};
|
||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||
|
||||
// Build the event bridge and wrapper on the main thread
|
||||
offscreenUi->loadInNewContext(CONTENT_WINDOW_QML, objectInitLambda, contextInitLambda);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -136,10 +136,8 @@ void QmlWindowClass::initQml(QVariantMap properties) {
|
|||
#if !defined(Q_OS_ANDROID)
|
||||
// If the restricted flag is on, override the FileTypeProfile and HFWebEngineProfile objects in the
|
||||
// QML surface root context with local ones
|
||||
qDebug() << "Context initialization lambda";
|
||||
ContextAwareProfile::restrictContext(context, _restricted);
|
||||
if (_restricted) {
|
||||
qDebug() << "Restricting web content";
|
||||
ContextAwareProfile::restrictContext(context);
|
||||
FileTypeProfile::registerWithContext(context);
|
||||
HFWebEngineProfile::registerWithContext(context);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
//
|
||||
|
||||
#include "ContextAwareProfile.h"
|
||||
#include <QtCore/QThread>
|
||||
#include <shared/QtHelpers.h>
|
||||
|
||||
#if !defined(Q_OS_ANDROID)
|
||||
|
||||
|
@ -17,16 +19,20 @@
|
|||
|
||||
static const QString RESTRICTED_FLAG_PROPERTY = "RestrictFileAccess";
|
||||
|
||||
ContextAwareProfile::ContextAwareProfile(QQmlContext* parent) :
|
||||
QQuickWebEngineProfile(parent), _context(parent) { }
|
||||
ContextAwareProfile::ContextAwareProfile(QQmlContext* context) :
|
||||
QQuickWebEngineProfile(context), _context(context) { }
|
||||
|
||||
|
||||
void ContextAwareProfile::restrictContext(QQmlContext* context) {
|
||||
context->setContextProperty(RESTRICTED_FLAG_PROPERTY, true);
|
||||
void ContextAwareProfile::restrictContext(QQmlContext* context, bool restrict) {
|
||||
context->setContextProperty(RESTRICTED_FLAG_PROPERTY, restrict);
|
||||
}
|
||||
|
||||
bool ContextAwareProfile::isRestricted(QQmlContext* context) {
|
||||
return context->contextProperty(RESTRICTED_FLAG_PROPERTY).toBool();
|
||||
bool ContextAwareProfile::isRestricted() {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
bool restrictedResult = false;
|
||||
BLOCKING_INVOKE_METHOD(this, "isRestricted", Q_RETURN_ARG(bool, restrictedResult));
|
||||
}
|
||||
return _context->contextProperty(RESTRICTED_FLAG_PROPERTY).toBool();
|
||||
}
|
||||
|
||||
#endif
|
|
@ -20,16 +20,16 @@
|
|||
class QQmlContext;
|
||||
|
||||
class ContextAwareProfile : public QQuickWebEngineProfile {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static void restrictContext(QQmlContext* context);
|
||||
static bool isRestricted(QQmlContext* context);
|
||||
QQmlContext* getContext() const { return _context; }
|
||||
static void restrictContext(QQmlContext* context, bool restrict = true);
|
||||
Q_INVOKABLE bool isRestricted();
|
||||
protected:
|
||||
|
||||
class RequestInterceptor : public QWebEngineUrlRequestInterceptor {
|
||||
public:
|
||||
RequestInterceptor(ContextAwareProfile* parent) : QWebEngineUrlRequestInterceptor(parent), _profile(parent) {}
|
||||
QQmlContext* getContext() const { return _profile->getContext(); }
|
||||
bool isRestricted() { return _profile->isRestricted(); }
|
||||
protected:
|
||||
ContextAwareProfile* _profile;
|
||||
};
|
||||
|
|
|
@ -29,8 +29,8 @@ FileTypeProfile::FileTypeProfile(QQmlContext* parent) :
|
|||
}
|
||||
|
||||
void FileTypeProfile::RequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) {
|
||||
RequestFilters::interceptHFWebEngineRequest(info, getContext());
|
||||
RequestFilters::interceptFileType(info, getContext());
|
||||
RequestFilters::interceptHFWebEngineRequest(info, isRestricted());
|
||||
RequestFilters::interceptFileType(info);
|
||||
}
|
||||
|
||||
void FileTypeProfile::registerWithContext(QQmlContext* context) {
|
||||
|
|
|
@ -28,7 +28,7 @@ HFWebEngineProfile::HFWebEngineProfile(QQmlContext* parent) : Parent(parent)
|
|||
}
|
||||
|
||||
void HFWebEngineProfile::RequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) {
|
||||
RequestFilters::interceptHFWebEngineRequest(info, getContext());
|
||||
RequestFilters::interceptHFWebEngineRequest(info, isRestricted());
|
||||
}
|
||||
|
||||
void HFWebEngineProfile::registerWithContext(QQmlContext* context) {
|
||||
|
|
|
@ -63,8 +63,8 @@ namespace {
|
|||
}
|
||||
}
|
||||
|
||||
void RequestFilters::interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info, QQmlContext* context) {
|
||||
if (ContextAwareProfile::isRestricted(context) && blockLocalFiles(info)) {
|
||||
void RequestFilters::interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info, bool restricted) {
|
||||
if (restricted && blockLocalFiles(info)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ void RequestFilters::interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info,
|
|||
info.setHttpHeader(USER_AGENT.toLocal8Bit(), tokenString.toLocal8Bit());
|
||||
}
|
||||
|
||||
void RequestFilters::interceptFileType(QWebEngineUrlRequestInfo& info, QQmlContext* context) {
|
||||
void RequestFilters::interceptFileType(QWebEngineUrlRequestInfo& info) {
|
||||
QString filename = info.requestUrl().fileName();
|
||||
if (isScript(filename) || isJSON(filename)) {
|
||||
static const QString CONTENT_HEADER = "Accept";
|
||||
|
|
|
@ -24,8 +24,8 @@ class QQmlContext;
|
|||
|
||||
class RequestFilters : public QObject {
|
||||
public:
|
||||
static void interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info, QQmlContext* context);
|
||||
static void interceptFileType(QWebEngineUrlRequestInfo& info, QQmlContext* context);
|
||||
static void interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info, bool restricted);
|
||||
static void interceptFileType(QWebEngineUrlRequestInfo& info);
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue