From 89a4bc8434c680d454ac1ae28739b685b92b3287 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 14 Oct 2016 18:23:34 -0700 Subject: [PATCH 01/12] 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 From b4b5c648c23be398770ad5bc0643318ce5ffdeb8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Oct 2016 11:29:09 -0700 Subject: [PATCH 02/12] use a QWebEngineProfile request interceptor for auth in HTTP header --- .../qml/controls-uit/BaseWebView.qml | 22 --------------- interface/resources/qml/hifi/Desktop.qml | 6 ++--- interface/src/Application.cpp | 7 ++--- interface/src/HFWebEngineProfile.cpp | 27 +++++++++++++++++++ interface/src/HFWebEngineProfile.h | 25 +++++++++++++++++ .../src/HFWebEngineRequestInterceptor.cpp | 24 +++++++++++++++-- libraries/gl/src/gl/OffscreenQmlSurface.cpp | 18 ------------- libraries/ui/src/QmlWebWindowClass.cpp | 5 +--- libraries/ui/src/QmlWebWindowClass.h | 2 +- 9 files changed, 80 insertions(+), 56 deletions(-) create mode 100644 interface/src/HFWebEngineProfile.cpp create mode 100644 interface/src/HFWebEngineProfile.h diff --git a/interface/resources/qml/controls-uit/BaseWebView.qml b/interface/resources/qml/controls-uit/BaseWebView.qml index a5b724f113..6c351a1ed0 100644 --- a/interface/resources/qml/controls-uit/BaseWebView.qml +++ b/interface/resources/qml/controls-uit/BaseWebView.qml @@ -25,28 +25,6 @@ WebEngineView { }); } - // FIXME hack to get the URL with the auth token included. Remove when we move to Qt 5.6 - Timer { - id: urlReplacementTimer - running: false - repeat: false - interval: 50 - onTriggered: url = newUrl; - } - - onUrlChanged: { - var originalUrl = url.toString(); - newUrl = urlHandler.fixupUrl(originalUrl).toString(); - if (newUrl !== originalUrl) { - root.stop(); - if (urlReplacementTimer.running) { - console.warn("Replacement timer already running"); - return; - } - urlReplacementTimer.start(); - } - } - onLoadingChanged: { // Required to support clicking on "hifi://" links if (WebEngineView.LoadStartedStatus == loadRequest.status) { diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index 7e523bbb70..6581d6761c 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -2,6 +2,7 @@ import QtQuick 2.5 import QtQuick.Controls 1.4 import QtWebEngine 1.1; import Qt.labs.settings 1.0 +import HFWebEngineProfile 1.0 import "../desktop" as OriginalDesktop import ".." @@ -20,17 +21,14 @@ OriginalDesktop.Desktop { onEntered: ApplicationCompositor.reticleOverDesktop = true onExited: ApplicationCompositor.reticleOverDesktop = false acceptedButtons: Qt.NoButton - - } // The tool window, one instance property alias toolWindow: toolWindow ToolWindow { id: toolWindow } - property var browserProfile: WebEngineProfile { + property var browserProfile: HFWebEngineProfile { id: webviewProfile - httpUserAgent: "Chrome/48.0 (HighFidelityInterface)" storageName: "qmlWebEngine" } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5b4c76f3bc..41287746a0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -123,7 +123,7 @@ #include "devices/Leapmotion.h" #include "DiscoverabilityManager.h" #include "GLCanvas.h" -#include "HFWebEngineRequestInterceptor.h" +#include "HFWebEngineProfile.h" #include "InterfaceActionFactory.h" #include "InterfaceLogging.h" #include "LODManager.h" @@ -1097,10 +1097,6 @@ 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, @@ -1681,6 +1677,7 @@ void Application::initializeUi() { UpdateDialog::registerType(); qmlRegisterType("Hifi", 1, 0, "Preference"); + qmlRegisterType("HFWebEngineProfile", 1, 0, "HFWebEngineProfile"); auto offscreenUi = DependencyManager::get(); offscreenUi->create(_glWidget->qglContext()); diff --git a/interface/src/HFWebEngineProfile.cpp b/interface/src/HFWebEngineProfile.cpp new file mode 100644 index 0000000000..2e76ebfcf2 --- /dev/null +++ b/interface/src/HFWebEngineProfile.cpp @@ -0,0 +1,27 @@ +// +// HFWebEngineProfile.cpp +// interface/src +// +// Created by Stephen Birarda on 2016-10-17. +// 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 "HFWebEngineProfile.h" + +#include "HFWebEngineRequestInterceptor.h" + +static const QString QML_WEB_ENGINE_STORAGE_NAME = "qmlWebEngine"; + +HFWebEngineProfile::HFWebEngineProfile(QObject* parent) : + QQuickWebEngineProfile(parent) +{ + static const QString WEB_ENGINE_USER_AGENT = "Chrome/48.0 (HighFidelityInterface)"; + setHttpUserAgent(WEB_ENGINE_USER_AGENT); + + // we use the HFWebEngineRequestInterceptor to make sure that web requests are authenticated for the interface user + auto requestInterceptor = new HFWebEngineRequestInterceptor(this); + setRequestInterceptor(requestInterceptor); +} diff --git a/interface/src/HFWebEngineProfile.h b/interface/src/HFWebEngineProfile.h new file mode 100644 index 0000000000..68d1fcc934 --- /dev/null +++ b/interface/src/HFWebEngineProfile.h @@ -0,0 +1,25 @@ +// +// HFWebEngineProfile.h +// interface/src +// +// Created by Stephen Birarda on 2016-10-17. +// 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_HFWebEngineProfile_h +#define hifi_HFWebEngineProfile_h + +#include + +class HFWebEngineProfile : public QQuickWebEngineProfile { +public: + HFWebEngineProfile(QObject* parent = Q_NULLPTR); +}; + + +#endif // hifi_HFWebEngineProfile_h diff --git a/interface/src/HFWebEngineRequestInterceptor.cpp b/interface/src/HFWebEngineRequestInterceptor.cpp index 9a710a7551..0fd7ff029c 100644 --- a/interface/src/HFWebEngineRequestInterceptor.cpp +++ b/interface/src/HFWebEngineRequestInterceptor.cpp @@ -13,6 +13,26 @@ #include -void HFWebEngineRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { - qDebug() << "==================== We have a request we can intercept! COOL!"; +#include + +bool isHighFidelityURL(const QUrl& url) { + static const QStringList HF_HOSTS = { + "highfidelity.com", "highfidelity.io", + "metaverse.highfidelity.com", "metaverse.highfidelity.io" + }; + + return HF_HOSTS.contains(url.host()); +} + +void HFWebEngineRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { + // check if this is a request to a highfidelity URL + if (isHighFidelityURL(info.requestUrl())) { + // if we have an access token, add it to the right HTTP header for authorization + auto accountManager = DependencyManager::get(); + + static const QString OAUTH_AUTHORIZATION_HEADER = "Authorization"; + + QString bearerTokenString = "Bearer " + accountManager->getAccountInfo().getAccessToken().token; + info.setHttpHeader(OAUTH_AUTHORIZATION_HEADER.toLocal8Bit(), bearerTokenString.toLocal8Bit()); + } } diff --git a/libraries/gl/src/gl/OffscreenQmlSurface.cpp b/libraries/gl/src/gl/OffscreenQmlSurface.cpp index d16968f370..8bf510bb2a 100644 --- a/libraries/gl/src/gl/OffscreenQmlSurface.cpp +++ b/libraries/gl/src/gl/OffscreenQmlSurface.cpp @@ -40,19 +40,6 @@ #include "TextureRecycler.h" #include "Context.h" -QString fixupHifiUrl(const QString& urlString) { - static const QString ACCESS_TOKEN_PARAMETER = "access_token"; - static const QString ALLOWED_HOST = "metaverse.highfidelity.com"; - QUrl url(urlString); - QUrlQuery query(url); - if (url.host() == ALLOWED_HOST && query.allQueryItemValues(ACCESS_TOKEN_PARAMETER).empty()) { - auto accountManager = DependencyManager::get(); - query.addQueryItem(ACCESS_TOKEN_PARAMETER, accountManager->getAccountInfo().getAccessToken().token); - url.setQuery(query.query()); - return url.toString(); - } - return urlString; -} class UrlHandler : public QObject { Q_OBJECT @@ -66,11 +53,6 @@ public: static auto handler = dynamic_cast(qApp); return handler->acceptURL(url); } - - // FIXME hack for authentication, remove when we migrate to Qt 5.6 - Q_INVOKABLE QString fixupUrl(const QString& originalUrl) { - return fixupHifiUrl(originalUrl); - } }; // Time between receiving a request to render the offscreen UI actually triggering diff --git a/libraries/ui/src/QmlWebWindowClass.cpp b/libraries/ui/src/QmlWebWindowClass.cpp index 84d0aa0489..2130e84220 100644 --- a/libraries/ui/src/QmlWebWindowClass.cpp +++ b/libraries/ui/src/QmlWebWindowClass.cpp @@ -86,13 +86,10 @@ QString QmlWebWindowClass::getURL() const { return result.toString(); } -// HACK find a good place to declare and store this -extern QString fixupHifiUrl(const QString& urlString); - void QmlWebWindowClass::setURL(const QString& urlString) { DependencyManager::get()->executeOnUiThread([=] { if (!_qmlWindow.isNull()) { - _qmlWindow->setProperty(URL_PROPERTY, fixupHifiUrl(urlString)); + _qmlWindow->setProperty(URL_PROPERTY, urlString); } }); } diff --git a/libraries/ui/src/QmlWebWindowClass.h b/libraries/ui/src/QmlWebWindowClass.h index e32c6d5a04..731afb3acb 100644 --- a/libraries/ui/src/QmlWebWindowClass.h +++ b/libraries/ui/src/QmlWebWindowClass.h @@ -19,7 +19,7 @@ class QmlWebWindowClass : public QmlWindowClass { public: static QScriptValue constructor(QScriptContext* context, QScriptEngine* engine); - public slots: +public slots: QString getURL() const; void setURL(const QString& url); From 08dc9e0c4d405a5231d90b824db833e4ca4201ff Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Oct 2016 11:32:31 -0700 Subject: [PATCH 03/12] use HTTP header for access token added for XMLHttpRequest --- libraries/script-engine/src/XMLHttpRequestClass.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/script-engine/src/XMLHttpRequestClass.cpp b/libraries/script-engine/src/XMLHttpRequestClass.cpp index 818521ecc5..1d3c8fda32 100644 --- a/libraries/script-engine/src/XMLHttpRequestClass.cpp +++ b/libraries/script-engine/src/XMLHttpRequestClass.cpp @@ -144,12 +144,12 @@ void XMLHttpRequestClass::open(const QString& method, const QString& url, bool a auto accountManager = DependencyManager::get(); if (accountManager->hasValidAccessToken()) { - QUrlQuery urlQuery(_url.query()); - urlQuery.addQueryItem("access_token", accountManager->getAccountInfo().getAccessToken().token); - _url.setQuery(urlQuery); + static const QString HTTP_AUTHORIZATION_HEADER = "Authorization"; + QString bearerString = "Bearer " + accountManager->getAccountInfo().getAccessToken().token; + _request.setRawHeader(HTTP_AUTHORIZATION_HEADER.toLocal8Bit(), bearerString.toLocal8Bit()); } - } + if (!username.isEmpty()) { _url.setUserName(username); } From edc83f547b14ab039357e72c17f373ba2a1212b5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Oct 2016 11:33:17 -0700 Subject: [PATCH 04/12] only add token for HFWebEngineProfile if present --- interface/src/HFWebEngineRequestInterceptor.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/interface/src/HFWebEngineRequestInterceptor.cpp b/interface/src/HFWebEngineRequestInterceptor.cpp index 0fd7ff029c..32c4bce76c 100644 --- a/interface/src/HFWebEngineRequestInterceptor.cpp +++ b/interface/src/HFWebEngineRequestInterceptor.cpp @@ -30,9 +30,11 @@ void HFWebEngineRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& i // if we have an access token, add it to the right HTTP header for authorization auto accountManager = DependencyManager::get(); - static const QString OAUTH_AUTHORIZATION_HEADER = "Authorization"; + if (accountManager->hasValidAccessToken()) { + static const QString OAUTH_AUTHORIZATION_HEADER = "Authorization"; - QString bearerTokenString = "Bearer " + accountManager->getAccountInfo().getAccessToken().token; - info.setHttpHeader(OAUTH_AUTHORIZATION_HEADER.toLocal8Bit(), bearerTokenString.toLocal8Bit()); + QString bearerTokenString = "Bearer " + accountManager->getAccountInfo().getAccessToken().token; + info.setHttpHeader(OAUTH_AUTHORIZATION_HEADER.toLocal8Bit(), bearerTokenString.toLocal8Bit()); + } } } From 3ce47631b7871db1fa0d8cc53a5151889123ea44 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Oct 2016 14:25:59 -0700 Subject: [PATCH 05/12] move the intercepted web engine profile to BaseWebView --- .../qml/controls-uit/BaseWebView.qml | 7 ++++-- .../resources/qml/controls-uit/WebView.qml | 1 + interface/resources/qml/controls/WebView.qml | 22 ------------------- interface/resources/qml/hifi/Desktop.qml | 5 ----- 4 files changed, 6 insertions(+), 29 deletions(-) diff --git a/interface/resources/qml/controls-uit/BaseWebView.qml b/interface/resources/qml/controls-uit/BaseWebView.qml index 6c351a1ed0..c2bb19e328 100644 --- a/interface/resources/qml/controls-uit/BaseWebView.qml +++ b/interface/resources/qml/controls-uit/BaseWebView.qml @@ -10,12 +10,15 @@ import QtQuick 2.5 import QtWebEngine 1.2 +import HFWebEngineProfile 1.0 WebEngineView { id: root - property var newUrl; - profile: desktop.browserProfile + profile: HFWebEngineProfile { + id: webviewProfile + storageName: "qmlWebEngine" + } Component.onCompleted: { console.log("Connecting JS messaging to Hifi Logging") diff --git a/interface/resources/qml/controls-uit/WebView.qml b/interface/resources/qml/controls-uit/WebView.qml index 2895f36944..3c6ad0be62 100644 --- a/interface/resources/qml/controls-uit/WebView.qml +++ b/interface/resources/qml/controls-uit/WebView.qml @@ -9,6 +9,7 @@ // import QtQuick 2.5 +import HFWebEngineProfile 1.0 import "." BaseWebView { diff --git a/interface/resources/qml/controls/WebView.qml b/interface/resources/qml/controls/WebView.qml index 1056a3b75e..7b61c0fa8e 100644 --- a/interface/resources/qml/controls/WebView.qml +++ b/interface/resources/qml/controls/WebView.qml @@ -62,28 +62,6 @@ Item { root.profile.httpUserAgent = "Mozilla/5.0 Chrome (HighFidelityInterface)"; } - // FIXME hack to get the URL with the auth token included. Remove when we move to Qt 5.6 - Timer { - id: urlReplacementTimer - running: false - repeat: false - interval: 50 - onTriggered: url = root.newUrl; - } - - onUrlChanged: { - var originalUrl = url.toString(); - root.newUrl = urlHandler.fixupUrl(originalUrl).toString(); - if (root.newUrl !== originalUrl) { - root.stop(); - if (urlReplacementTimer.running) { - console.warn("Replacement timer already running"); - return; - } - urlReplacementTimer.start(); - } - } - onFeaturePermissionRequested: { grantFeaturePermission(securityOrigin, feature, true); } diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index 6581d6761c..dd474a3889 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -27,11 +27,6 @@ OriginalDesktop.Desktop { property alias toolWindow: toolWindow ToolWindow { id: toolWindow } - property var browserProfile: HFWebEngineProfile { - id: webviewProfile - storageName: "qmlWebEngine" - } - Action { text: "Open Browser" shortcut: "Ctrl+B" From 4ec703b7dc08f4045cd5a70bb1b3812a73d63cae Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Oct 2016 14:29:12 -0700 Subject: [PATCH 06/12] remove unused import from uit WebView --- interface/resources/qml/controls-uit/WebView.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/resources/qml/controls-uit/WebView.qml b/interface/resources/qml/controls-uit/WebView.qml index 3c6ad0be62..2895f36944 100644 --- a/interface/resources/qml/controls-uit/WebView.qml +++ b/interface/resources/qml/controls-uit/WebView.qml @@ -9,7 +9,6 @@ // import QtQuick 2.5 -import HFWebEngineProfile 1.0 import "." BaseWebView { From 3cbdf1393133d8ee1ffafdfe2f602733328b12d3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Oct 2016 15:04:33 -0700 Subject: [PATCH 07/12] add intercepted profile to uit WebView --- interface/resources/qml/controls/WebView.qml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interface/resources/qml/controls/WebView.qml b/interface/resources/qml/controls/WebView.qml index 7b61c0fa8e..abaf11a8e2 100644 --- a/interface/resources/qml/controls/WebView.qml +++ b/interface/resources/qml/controls/WebView.qml @@ -2,6 +2,7 @@ import QtQuick 2.5 import QtWebEngine 1.1 import QtWebChannel 1.0 import "../controls-uit" as HiFiControls +import HFWebEngineProfile 1.0 Item { property alias url: root.url @@ -31,6 +32,11 @@ Item { width: parent.width height: keyboardEnabled && keyboardRaised ? parent.height - keyboard.height : parent.height + profile: HFWebEngineProfile { + id: webviewProfile + storageName: "qmlWebEngine" + } + // creates a global EventBridge object. WebEngineScript { id: createGlobalEventBridge From a45677c2a256698e144ec0686537fdfb2d017a1e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 18 Oct 2016 10:03:46 -0700 Subject: [PATCH 08/12] mark intercept override, only add header for HTTPS --- interface/src/HFWebEngineRequestInterceptor.cpp | 6 +++--- interface/src/HFWebEngineRequestInterceptor.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/HFWebEngineRequestInterceptor.cpp b/interface/src/HFWebEngineRequestInterceptor.cpp index 32c4bce76c..67ab1b3d02 100644 --- a/interface/src/HFWebEngineRequestInterceptor.cpp +++ b/interface/src/HFWebEngineRequestInterceptor.cpp @@ -15,18 +15,18 @@ #include -bool isHighFidelityURL(const QUrl& url) { +bool isAuthableHighFidelityURL(const QUrl& url) { static const QStringList HF_HOSTS = { "highfidelity.com", "highfidelity.io", "metaverse.highfidelity.com", "metaverse.highfidelity.io" }; - return HF_HOSTS.contains(url.host()); + return url.scheme() == "https" && HF_HOSTS.contains(url.host()); } void HFWebEngineRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { // check if this is a request to a highfidelity URL - if (isHighFidelityURL(info.requestUrl())) { + if (isAuthableHighFidelityURL(info.requestUrl())) { // if we have an access token, add it to the right HTTP header for authorization auto accountManager = DependencyManager::get(); diff --git a/interface/src/HFWebEngineRequestInterceptor.h b/interface/src/HFWebEngineRequestInterceptor.h index ba96662f9e..0b812243f4 100644 --- a/interface/src/HFWebEngineRequestInterceptor.h +++ b/interface/src/HFWebEngineRequestInterceptor.h @@ -20,7 +20,7 @@ class HFWebEngineRequestInterceptor : public QWebEngineUrlRequestInterceptor { public: HFWebEngineRequestInterceptor(QObject* parent) : QWebEngineUrlRequestInterceptor(parent) {}; - virtual void interceptRequest(QWebEngineUrlRequestInfo& info); + virtual void interceptRequest(QWebEngineUrlRequestInfo& info) override; }; #endif // hifi_HFWebEngineRequestInterceptor_h From 81cb33574deff78ee1a8ac52f2a10fe42a9568ba Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 18 Oct 2016 10:04:43 -0700 Subject: [PATCH 09/12] check for HTTPS scheme in bearer add in XMLHttpRequest --- libraries/script-engine/src/XMLHttpRequestClass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/script-engine/src/XMLHttpRequestClass.cpp b/libraries/script-engine/src/XMLHttpRequestClass.cpp index 1d3c8fda32..4e528ec52c 100644 --- a/libraries/script-engine/src/XMLHttpRequestClass.cpp +++ b/libraries/script-engine/src/XMLHttpRequestClass.cpp @@ -143,7 +143,7 @@ void XMLHttpRequestClass::open(const QString& method, const QString& url, bool a if (url.toLower().left(METAVERSE_API_URL.length()) == METAVERSE_API_URL) { auto accountManager = DependencyManager::get(); - if (accountManager->hasValidAccessToken()) { + if (_url.scheme() == "https" && accountManager->hasValidAccessToken()) { static const QString HTTP_AUTHORIZATION_HEADER = "Authorization"; QString bearerString = "Bearer " + accountManager->getAccountInfo().getAccessToken().token; _request.setRawHeader(HTTP_AUTHORIZATION_HEADER.toLocal8Bit(), bearerString.toLocal8Bit()); From c4cec8eb1e1534ce3827a9aabf5268e914f0ee59 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 18 Oct 2016 10:20:38 -0700 Subject: [PATCH 10/12] use desktop profile again, move classes to networking subdir --- interface/resources/qml/controls-uit/BaseWebView.qml | 5 +---- interface/resources/qml/desktop/Desktop.qml | 2 +- interface/resources/qml/hifi/Desktop.qml | 5 +++++ interface/src/Application.cpp | 2 +- interface/src/{ => networking}/HFWebEngineProfile.cpp | 2 +- interface/src/{ => networking}/HFWebEngineProfile.h | 2 +- .../src/{ => networking}/HFWebEngineRequestInterceptor.cpp | 2 +- .../src/{ => networking}/HFWebEngineRequestInterceptor.h | 2 +- 8 files changed, 12 insertions(+), 10 deletions(-) rename interface/src/{ => networking}/HFWebEngineProfile.cpp (96%) rename interface/src/{ => networking}/HFWebEngineProfile.h (95%) rename interface/src/{ => networking}/HFWebEngineRequestInterceptor.cpp (97%) rename interface/src/{ => networking}/HFWebEngineRequestInterceptor.h (96%) diff --git a/interface/resources/qml/controls-uit/BaseWebView.qml b/interface/resources/qml/controls-uit/BaseWebView.qml index c2bb19e328..763e6530fb 100644 --- a/interface/resources/qml/controls-uit/BaseWebView.qml +++ b/interface/resources/qml/controls-uit/BaseWebView.qml @@ -15,10 +15,7 @@ import HFWebEngineProfile 1.0 WebEngineView { id: root - profile: HFWebEngineProfile { - id: webviewProfile - storageName: "qmlWebEngine" - } + profile: desktop.browserProfile Component.onCompleted: { console.log("Connecting JS messaging to Hifi Logging") diff --git a/interface/resources/qml/desktop/Desktop.qml b/interface/resources/qml/desktop/Desktop.qml index ea2f048c1f..b207087be0 100644 --- a/interface/resources/qml/desktop/Desktop.qml +++ b/interface/resources/qml/desktop/Desktop.qml @@ -33,7 +33,7 @@ FocusScope { } } - + onHeightChanged: d.handleSizeChanged(); onWidthChanged: d.handleSizeChanged(); diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index dd474a3889..e0f8cee1f9 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -27,6 +27,11 @@ OriginalDesktop.Desktop { property alias toolWindow: toolWindow ToolWindow { id: toolWindow } + property var browserProfile: WebEngineProfile { + id: webviewProfile + storageName: "qmlWebEngine" + } + Action { text: "Open Browser" shortcut: "Ctrl+B" diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 41287746a0..c9eb1423a6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -123,11 +123,11 @@ #include "devices/Leapmotion.h" #include "DiscoverabilityManager.h" #include "GLCanvas.h" -#include "HFWebEngineProfile.h" #include "InterfaceActionFactory.h" #include "InterfaceLogging.h" #include "LODManager.h" #include "ModelPackager.h" +#include "networking/HFWebEngineProfile.h" #include "scripting/AccountScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" diff --git a/interface/src/HFWebEngineProfile.cpp b/interface/src/networking/HFWebEngineProfile.cpp similarity index 96% rename from interface/src/HFWebEngineProfile.cpp rename to interface/src/networking/HFWebEngineProfile.cpp index 2e76ebfcf2..6b377fa900 100644 --- a/interface/src/HFWebEngineProfile.cpp +++ b/interface/src/networking/HFWebEngineProfile.cpp @@ -1,6 +1,6 @@ // // HFWebEngineProfile.cpp -// interface/src +// interface/src/networking // // Created by Stephen Birarda on 2016-10-17. // Copyright 2016 High Fidelity, Inc. diff --git a/interface/src/HFWebEngineProfile.h b/interface/src/networking/HFWebEngineProfile.h similarity index 95% rename from interface/src/HFWebEngineProfile.h rename to interface/src/networking/HFWebEngineProfile.h index 68d1fcc934..5c7655479e 100644 --- a/interface/src/HFWebEngineProfile.h +++ b/interface/src/networking/HFWebEngineProfile.h @@ -1,6 +1,6 @@ // // HFWebEngineProfile.h -// interface/src +// interface/src/networking // // Created by Stephen Birarda on 2016-10-17. // Copyright 2016 High Fidelity, Inc. diff --git a/interface/src/HFWebEngineRequestInterceptor.cpp b/interface/src/networking/HFWebEngineRequestInterceptor.cpp similarity index 97% rename from interface/src/HFWebEngineRequestInterceptor.cpp rename to interface/src/networking/HFWebEngineRequestInterceptor.cpp index 67ab1b3d02..9c3f0b232e 100644 --- a/interface/src/HFWebEngineRequestInterceptor.cpp +++ b/interface/src/networking/HFWebEngineRequestInterceptor.cpp @@ -1,6 +1,6 @@ // // HFWebEngineRequestInterceptor.cpp -// libraries/networking/src +// interface/src/networking // // Created by Stephen Birarda on 2016-10-14. // Copyright 2016 High Fidelity, Inc. diff --git a/interface/src/HFWebEngineRequestInterceptor.h b/interface/src/networking/HFWebEngineRequestInterceptor.h similarity index 96% rename from interface/src/HFWebEngineRequestInterceptor.h rename to interface/src/networking/HFWebEngineRequestInterceptor.h index 0b812243f4..a4c308426c 100644 --- a/interface/src/HFWebEngineRequestInterceptor.h +++ b/interface/src/networking/HFWebEngineRequestInterceptor.h @@ -1,6 +1,6 @@ // // HFWebEngineRequestInterceptor.h -// interface/src +// interface/src/networking // // Created by Stephen Birarda on 2016-10-14. // Copyright 2016 High Fidelity, Inc. From 5682d5166787f3ea04645c07185b3186092fdffd Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 18 Oct 2016 11:42:55 -0700 Subject: [PATCH 11/12] use the HFWebEngineProfile in Desktop.qml --- interface/resources/qml/hifi/Desktop.qml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index e0f8cee1f9..b4fe773364 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -27,7 +27,7 @@ OriginalDesktop.Desktop { property alias toolWindow: toolWindow ToolWindow { id: toolWindow } - property var browserProfile: WebEngineProfile { + property var browserProfile: HFWebEngineProfile { id: webviewProfile storageName: "qmlWebEngine" } @@ -125,5 +125,3 @@ OriginalDesktop.Desktop { return result; } } - - From f8e0d7ad88fa20cfc162e6ee5cc97854d07fdfb0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 18 Oct 2016 12:53:32 -0700 Subject: [PATCH 12/12] move QWebEngine classes to ui library --- interface/src/Application.cpp | 3 ++- libraries/ui/CMakeLists.txt | 2 +- .../src/networking => libraries/ui/src}/HFWebEngineProfile.cpp | 0 .../src/networking => libraries/ui/src}/HFWebEngineProfile.h | 0 .../ui/src}/HFWebEngineRequestInterceptor.cpp | 0 .../ui/src}/HFWebEngineRequestInterceptor.h | 0 6 files changed, 3 insertions(+), 2 deletions(-) rename {interface/src/networking => libraries/ui/src}/HFWebEngineProfile.cpp (100%) rename {interface/src/networking => libraries/ui/src}/HFWebEngineProfile.h (100%) rename {interface/src/networking => libraries/ui/src}/HFWebEngineRequestInterceptor.cpp (100%) rename {interface/src/networking => libraries/ui/src}/HFWebEngineRequestInterceptor.h (100%) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c9eb1423a6..bdfe0b4387 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -127,7 +128,7 @@ #include "InterfaceLogging.h" #include "LODManager.h" #include "ModelPackager.h" -#include "networking/HFWebEngineProfile.h" + #include "scripting/AccountScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h" #include "scripting/AudioDeviceScriptingInterface.h" diff --git a/libraries/ui/CMakeLists.txt b/libraries/ui/CMakeLists.txt index cc2382926f..3328830921 100644 --- a/libraries/ui/CMakeLists.txt +++ b/libraries/ui/CMakeLists.txt @@ -1,3 +1,3 @@ set(TARGET_NAME ui) -setup_hifi_library(OpenGL Network Qml Quick Script WebChannel WebSockets XmlPatterns) +setup_hifi_library(OpenGL Network Qml Quick Script WebChannel WebEngine WebSockets XmlPatterns) link_hifi_libraries(shared networking gl) diff --git a/interface/src/networking/HFWebEngineProfile.cpp b/libraries/ui/src/HFWebEngineProfile.cpp similarity index 100% rename from interface/src/networking/HFWebEngineProfile.cpp rename to libraries/ui/src/HFWebEngineProfile.cpp diff --git a/interface/src/networking/HFWebEngineProfile.h b/libraries/ui/src/HFWebEngineProfile.h similarity index 100% rename from interface/src/networking/HFWebEngineProfile.h rename to libraries/ui/src/HFWebEngineProfile.h diff --git a/interface/src/networking/HFWebEngineRequestInterceptor.cpp b/libraries/ui/src/HFWebEngineRequestInterceptor.cpp similarity index 100% rename from interface/src/networking/HFWebEngineRequestInterceptor.cpp rename to libraries/ui/src/HFWebEngineRequestInterceptor.cpp diff --git a/interface/src/networking/HFWebEngineRequestInterceptor.h b/libraries/ui/src/HFWebEngineRequestInterceptor.h similarity index 100% rename from interface/src/networking/HFWebEngineRequestInterceptor.h rename to libraries/ui/src/HFWebEngineRequestInterceptor.h