From 6f04e039fe48d529affc1e98c05851ea3d10e0e6 Mon Sep 17 00:00:00 2001 From: amerhifi Date: Fri, 24 May 2019 14:12:24 -0700 Subject: [PATCH] adding whitelisting for dockedWidgets --- interface/src/ui/InteractiveWindow.cpp | 16 ++++++++-------- libraries/ui/src/ui/OffscreenQmlSurface.cpp | 10 +++++----- libraries/ui/src/ui/OffscreenQmlSurface.h | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/interface/src/ui/InteractiveWindow.cpp b/interface/src/ui/InteractiveWindow.cpp index 3f97fe4dc2..7ce8822209 100644 --- a/interface/src/ui/InteractiveWindow.cpp +++ b/interface/src/ui/InteractiveWindow.cpp @@ -109,16 +109,14 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap auto mainWindow = qApp->getWindow(); _dockWidget = std::shared_ptr(new DockWidget(title, mainWindow), dockWidgetDeleter); auto quickView = _dockWidget->getQuickView(); - Application::setupQmlSurface(quickView->rootContext(), true); + + Application::setupQmlSurface(quickView->rootContext() , true); + + //add any whitelisted callbacks auto offscreenUi = DependencyManager::get(); - // Build the event bridge and wrapper on the main thread - auto context = offscreenUi->widgetContextForUrl(sourceUrl); - - - if(context!=nullptr){ - _dockWidget->getQuickView()->rootContext()->setContextObject(context); - } + offscreenUi->widgetContextForUrl(sourceUrl, quickView->rootContext()); + /**jsdoc * Configures how a NATIVE window is displayed. * @typedef {object} InteractiveWindow.PresentationWindowInfo @@ -158,6 +156,8 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap } }); _dockWidget->setSource(QUrl(sourceUrl)); + + mainWindow->addDockWidget(dockArea, _dockWidget.get()); } else { auto offscreenUi = DependencyManager::get(); diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index 175ad1fedf..8be0ca6c84 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -307,16 +307,16 @@ void OffscreenQmlSurface::onRootContextCreated(QQmlContext* qmlContext) { #endif } -QQmlContext* OffscreenQmlSurface::widgetContextForUrl(const QUrl& url) { +void OffscreenQmlSurface::widgetContextForUrl(const QUrl& url, QQmlContext* context) { // Get any whitelist functionality QList callbacks = getQmlWhitelist()->getCallbacksForUrl(url); // If we have whitelisted content, we must load a new context - if(callbacks.empty()){ - return nullptr; + if(!callbacks.empty()){ + for(const auto& callback : callbacks){ + callback(context); + } } - - return contextForUrl(url,nullptr, false); } QQmlContext* OffscreenQmlSurface::contextForUrl(const QUrl& qmlSource, QQuickItem* parent, bool forceNewContext) { diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.h b/libraries/ui/src/ui/OffscreenQmlSurface.h index 6d2141eebc..de821da90b 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.h +++ b/libraries/ui/src/ui/OffscreenQmlSurface.h @@ -36,7 +36,7 @@ public: Q_INVOKABLE void lowerKeyboard(); PointerEvent::EventType choosePointerEventType(QEvent::Type type); Q_INVOKABLE unsigned int deviceIdByTouchPoint(qreal x, qreal y); - QQmlContext* widgetContextForUrl(const QUrl& url); + void widgetContextForUrl(const QUrl& url,QQmlContext* context); signals: void focusObjectChanged(QObject* newFocus);