From 89a4bc8434c680d454ac1ae28739b685b92b3287 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 14 Oct 2016 18:23:34 -0700 Subject: [PATCH] add custom QWebEngine request interceptor --- interface/CMakeLists.txt | 5 +++- interface/src/Application.cpp | 7 +++++ .../src/HFWebEngineRequestInterceptor.cpp | 18 +++++++++++++ interface/src/HFWebEngineRequestInterceptor.h | 26 +++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 interface/src/HFWebEngineRequestInterceptor.cpp create mode 100644 interface/src/HFWebEngineRequestInterceptor.h diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 9c564f6518..b43376c374 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -41,8 +41,10 @@ endif () if (ANDROID) set(PLATFORM_QT_COMPONENTS AndroidExtras) + set(PLATFORM_QT_LIBRARIES Qt5::AndroidExtras) else () set(PLATFORM_QT_COMPONENTS WebEngine WebEngineWidgets) + set(PLATFORM_QT_LIBRARIES Qt5::WebEngine Qt5::WebEngineWidgets) endif () find_package( @@ -244,7 +246,8 @@ target_link_libraries( ${TARGET_NAME} Qt5::Gui Qt5::Network Qt5::Multimedia Qt5::OpenGL Qt5::Qml Qt5::Quick Qt5::Script Qt5::Svg - Qt5::WebChannel Qt5::WebEngine + Qt5::WebChannel Qt5::WebEngine + ${PLATFORM_QT_LIBRARIES} ) if (UNIX) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b13c432a14..5b4c76f3bc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -34,6 +34,8 @@ #include #include +#include + #include #include @@ -121,6 +123,7 @@ #include "devices/Leapmotion.h" #include "DiscoverabilityManager.h" #include "GLCanvas.h" +#include "HFWebEngineRequestInterceptor.h" #include "InterfaceActionFactory.h" #include "InterfaceLogging.h" #include "LODManager.h" @@ -1094,6 +1097,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : SpacemouseManager::getInstance().init(); #endif + // we use the HFWebEngineRequestInterceptor to make sure that web requests are authenticated for the interface user + auto requestInterceptor = new HFWebEngineRequestInterceptor(this); + QWebEngineProfile::defaultProfile()->setRequestInterceptor(requestInterceptor); + // If the user clicks an an entity, we will check that it's an unlocked web entity, and if so, set the focus to it auto entityScriptingInterface = DependencyManager::get(); connect(entityScriptingInterface.data(), &EntityScriptingInterface::clickDownOnEntity, diff --git a/interface/src/HFWebEngineRequestInterceptor.cpp b/interface/src/HFWebEngineRequestInterceptor.cpp new file mode 100644 index 0000000000..9a710a7551 --- /dev/null +++ b/interface/src/HFWebEngineRequestInterceptor.cpp @@ -0,0 +1,18 @@ +// +// HFWebEngineRequestInterceptor.cpp +// libraries/networking/src +// +// Created by Stephen Birarda on 2016-10-14. +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "HFWebEngineRequestInterceptor.h" + +#include + +void HFWebEngineRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { + qDebug() << "==================== We have a request we can intercept! COOL!"; +} diff --git a/interface/src/HFWebEngineRequestInterceptor.h b/interface/src/HFWebEngineRequestInterceptor.h new file mode 100644 index 0000000000..ba96662f9e --- /dev/null +++ b/interface/src/HFWebEngineRequestInterceptor.h @@ -0,0 +1,26 @@ +// +// HFWebEngineRequestInterceptor.h +// interface/src +// +// Created by Stephen Birarda on 2016-10-14. +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once + +#ifndef hifi_HFWebEngineRequestInterceptor_h +#define hifi_HFWebEngineRequestInterceptor_h + +#include + +class HFWebEngineRequestInterceptor : public QWebEngineUrlRequestInterceptor { +public: + HFWebEngineRequestInterceptor(QObject* parent) : QWebEngineUrlRequestInterceptor(parent) {}; + + virtual void interceptRequest(QWebEngineUrlRequestInfo& info); +}; + +#endif // hifi_HFWebEngineRequestInterceptor_h