From a0f0879087a8799cb619b36c2dd9032d991016e6 Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Fri, 10 Mar 2017 18:16:38 -0800 Subject: [PATCH 1/9] added file type filter and interceptor --- interface/resources/qml/controls/WebView.qml | 4 +- interface/resources/qml/hifi/Desktop.qml | 4 +- interface/src/Application.cpp | 2 + interface/src/networking/FileTypeProfile.cpp | 26 +++++++++ interface/src/networking/FileTypeProfile.h | 25 ++++++++ .../networking/FileTypeRequestInterceptor.cpp | 22 +++++++ .../networking/FileTypeRequestInterceptor.h | 26 +++++++++ .../HFWebEngineRequestInterceptor.cpp | 27 +-------- interface/src/networking/RequestFilters.cpp | 58 +++++++++++++++++++ interface/src/networking/RequestFilters.h | 28 +++++++++ 10 files changed, 194 insertions(+), 28 deletions(-) create mode 100644 interface/src/networking/FileTypeProfile.cpp create mode 100644 interface/src/networking/FileTypeProfile.h create mode 100644 interface/src/networking/FileTypeRequestInterceptor.cpp create mode 100644 interface/src/networking/FileTypeRequestInterceptor.h create mode 100644 interface/src/networking/RequestFilters.cpp create mode 100644 interface/src/networking/RequestFilters.h diff --git a/interface/resources/qml/controls/WebView.qml b/interface/resources/qml/controls/WebView.qml index a3badd7e1f..d3e1d97d1a 100644 --- a/interface/resources/qml/controls/WebView.qml +++ b/interface/resources/qml/controls/WebView.qml @@ -2,7 +2,7 @@ import QtQuick 2.5 import QtWebEngine 1.1 import QtWebChannel 1.0 import "../controls-uit" as HiFiControls -import HFWebEngineProfile 1.0 +import FileTypeProfile 1.0 Item { property alias url: root.url @@ -36,7 +36,7 @@ Item { width: parent.width height: keyboardEnabled && keyboardRaised ? parent.height - keyboard.height : parent.height - profile: HFWebEngineProfile { + profile: FileTypeProfile { id: webviewProfile storageName: "qmlWebEngine" } diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index 7857eda3c2..cd66b014a4 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -2,7 +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 FileTypeProfile 1.0 import "../desktop" as OriginalDesktop import ".." @@ -27,7 +27,7 @@ OriginalDesktop.Desktop { property alias toolWindow: toolWindow ToolWindow { id: toolWindow } - property var browserProfile: HFWebEngineProfile { + property var browserProfile: FileTypeProfile { id: webviewProfile storageName: "qmlWebEngine" } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e19eea0a2e..aa33b66962 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -142,6 +142,7 @@ #include "ModelPackager.h" #include "networking/HFWebEngineProfile.h" #include "networking/HFTabletWebEngineProfile.h" +#include "networking/FileTypeProfile.h" #include "scripting/TestScriptingInterface.h" #include "scripting/AccountScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h" @@ -1934,6 +1935,7 @@ void Application::initializeUi() { qmlRegisterType("HFWebEngineProfile", 1, 0, "HFWebEngineProfile"); qmlRegisterType("HFTabletWebEngineProfile", 1, 0, "HFTabletWebEngineProfile"); + qmlRegisterType("FileTypeProfile", 1, 0, "FileTypeProfile"); auto offscreenUi = DependencyManager::get(); offscreenUi->create(_glWidget->qglContext()); diff --git a/interface/src/networking/FileTypeProfile.cpp b/interface/src/networking/FileTypeProfile.cpp new file mode 100644 index 0000000000..2048751e5d --- /dev/null +++ b/interface/src/networking/FileTypeProfile.cpp @@ -0,0 +1,26 @@ +// +// FileTypeProfile.cpp +// interface/src/networking +// +// Created by Kunal Gosar on 2017-03-10. +// Copyright 2017 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 "FileTypeProfile.h" + +#include "FileTypeRequestInterceptor.h" + +static const QString QML_WEB_ENGINE_STORAGE_NAME = "qmlWebEngine"; + +FileTypeProfile::FileTypeProfile(QObject* parent) : + QQuickWebEngineProfile(parent) +{ + static const QString WEB_ENGINE_USER_AGENT = "Chrome/48.0 (HighFidelityInterface)"; + setHttpUserAgent(WEB_ENGINE_USER_AGENT); + + auto requestInterceptor = new FileTypeRequestInterceptor(this); + setRequestInterceptor(requestInterceptor); +} \ No newline at end of file diff --git a/interface/src/networking/FileTypeProfile.h b/interface/src/networking/FileTypeProfile.h new file mode 100644 index 0000000000..99ed5d4b79 --- /dev/null +++ b/interface/src/networking/FileTypeProfile.h @@ -0,0 +1,25 @@ +// +// FileTypeProfile.h +// interface/src/networking +// +// Created by Kunal Gosar on 2017-03-10. +// Copyright 2017 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_FileTypeProfile_h +#define hifi_FileTypeProfile_h + +#include + +class FileTypeProfile : public QQuickWebEngineProfile { +public: + FileTypeProfile(QObject* parent = Q_NULLPTR); +}; + + +#endif // hifi_FileTypeProfile_h \ No newline at end of file diff --git a/interface/src/networking/FileTypeRequestInterceptor.cpp b/interface/src/networking/FileTypeRequestInterceptor.cpp new file mode 100644 index 0000000000..2dac5db194 --- /dev/null +++ b/interface/src/networking/FileTypeRequestInterceptor.cpp @@ -0,0 +1,22 @@ +// +// FileTypeRequestInterceptor.cpp +// interface/src/networking +// +// Created by Kunal Gosar on 2017-03-10. +// Copyright 2017 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 "FileTypeRequestInterceptor.h" + +#include + +#include "RequestFilters.h" + +void FileTypeRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { + RequestFilters* filter = new RequestFilters; + filter->interceptHFWebEngineRequest(info); + filter->interceptFileType(info); +} diff --git a/interface/src/networking/FileTypeRequestInterceptor.h b/interface/src/networking/FileTypeRequestInterceptor.h new file mode 100644 index 0000000000..c39c860b7c --- /dev/null +++ b/interface/src/networking/FileTypeRequestInterceptor.h @@ -0,0 +1,26 @@ +// +// FileTypeRequestInterceptor.h +// interface/src/networking +// +// Created by Kunal Gosar on 2017-03-10. +// Copyright 2017 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_FileTypeRequestInterceptor_h +#define hifi_FileTypeRequestInterceptor_h + +#include + +class FileTypeRequestInterceptor : public QWebEngineUrlRequestInterceptor { +public: + FileTypeRequestInterceptor(QObject* parent) : QWebEngineUrlRequestInterceptor(parent) {}; + + virtual void interceptRequest(QWebEngineUrlRequestInfo& info) override; +}; + +#endif // hifi_FileTypeRequestInterceptor_h \ No newline at end of file diff --git a/interface/src/networking/HFWebEngineRequestInterceptor.cpp b/interface/src/networking/HFWebEngineRequestInterceptor.cpp index f6b0914f08..400d547d92 100644 --- a/interface/src/networking/HFWebEngineRequestInterceptor.cpp +++ b/interface/src/networking/HFWebEngineRequestInterceptor.cpp @@ -15,30 +15,9 @@ #include #include - -bool isAuthableHighFidelityURL(const QUrl& url) { - static const QStringList HF_HOSTS = { - "highfidelity.com", "highfidelity.io", - "metaverse.highfidelity.com", "metaverse.highfidelity.io" - }; - const auto& scheme = url.scheme(); - const auto& host = url.host(); - - return (scheme == "https" && HF_HOSTS.contains(host)) || - ((scheme == NetworkingConstants::METAVERSE_SERVER_URL.scheme()) && (host == NetworkingConstants::METAVERSE_SERVER_URL.host())); -} +#include "RequestFilters.h" void HFWebEngineRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { - // check if this is a request to a highfidelity URL - if (isAuthableHighFidelityURL(info.requestUrl())) { - // if we have an access token, add it to the right HTTP header for authorization - auto accountManager = DependencyManager::get(); - - 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()); - } - } + RequestFilters* filter = new RequestFilters; + filter->interceptHFWebEngineRequest(info); } diff --git a/interface/src/networking/RequestFilters.cpp b/interface/src/networking/RequestFilters.cpp new file mode 100644 index 0000000000..65845504c0 --- /dev/null +++ b/interface/src/networking/RequestFilters.cpp @@ -0,0 +1,58 @@ +// +// RequestFilters.cpp +// interface/src/networking +// +// Created by Kunal Gosar on 2017-03-10. +// Copyright 2017 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 "RequestFilters.h" + +#include + +#include + +bool isAuthableHighFidelityURL(const QUrl& url) { + static const QStringList HF_HOSTS = { + "highfidelity.com", "highfidelity.io", + "metaverse.highfidelity.com", "metaverse.highfidelity.io" + }; + + return url.scheme() == "https" && HF_HOSTS.contains(url.host()); +} + +bool isJavaScriptFile(const QString filename) { + return filename.contains(".js", Qt::CaseInsensitive); +} + +bool isEntityFile(const QString filename) { + return filename.contains(".svo.json", Qt::CaseInsensitive); +} + +void RequestFilters::interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info) { + // check if this is a request to a highfidelity URL + if (isAuthableHighFidelityURL(info.requestUrl())) { + // if we have an access token, add it to the right HTTP header for authorization + auto accountManager = DependencyManager::get(); + + 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()); + } + } +} + +void RequestFilters::interceptFileType(QWebEngineUrlRequestInfo& info) { + QString filename = info.requestUrl().fileName(); + + if (isJavaScriptFile(filename) || isEntityFile(filename)) { + static const QString CONTENT_HEADER = "Content-Type"; + static const QString HEADER_VALUE = "text/plain"; + info.setHttpHeader(CONTENT_HEADER.toLocal8Bit(), HEADER_VALUE.toLocal8Bit()); + } +} \ No newline at end of file diff --git a/interface/src/networking/RequestFilters.h b/interface/src/networking/RequestFilters.h new file mode 100644 index 0000000000..ab20a267e0 --- /dev/null +++ b/interface/src/networking/RequestFilters.h @@ -0,0 +1,28 @@ +// +// RequestFilters.h +// interface/src/networking +// +// Created by Kunal Gosar on 2017-03-10. +// Copyright 2017 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_RequestFilters_h +#define hifi_RequestFilters_h + +#include +#include + +class RequestFilters : public QObject { + Q_OBJECT + +public: + void interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info); + void interceptFileType(QWebEngineUrlRequestInfo& info); +}; + +#endif // hifi_RequestFilters_h \ No newline at end of file From 9b758dbdba32d31e1ecda5f08b202c37b2463d84 Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Fri, 10 Mar 2017 18:45:25 -0800 Subject: [PATCH 2/9] updated headers --- interface/src/networking/RequestFilters.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/interface/src/networking/RequestFilters.cpp b/interface/src/networking/RequestFilters.cpp index 65845504c0..5a29b58da9 100644 --- a/interface/src/networking/RequestFilters.cpp +++ b/interface/src/networking/RequestFilters.cpp @@ -51,8 +51,11 @@ void RequestFilters::interceptFileType(QWebEngineUrlRequestInfo& info) { QString filename = info.requestUrl().fileName(); if (isJavaScriptFile(filename) || isEntityFile(filename)) { - static const QString CONTENT_HEADER = "Content-Type"; - static const QString HEADER_VALUE = "text/plain"; - info.setHttpHeader(CONTENT_HEADER.toLocal8Bit(), HEADER_VALUE.toLocal8Bit()); + static const QString CONTENT_HEADER = "Accept"; + static const QString TYPE_VALUE = "text/html"; + info.setHttpHeader(CONTENT_HEADER.toLocal8Bit(), TYPE_VALUE.toLocal8Bit()); + static const QString CONTENT_DISPOSITION = "Content-Disposition"; + static const QString DISPOSITION_VALUE = "inline"; + info.setHttpHeader(CONTENT_DISPOSITION.toLocal8Bit(), DISPOSITION_VALUE.toLocal8Bit()); } } \ No newline at end of file From 19ab7526d35f9863e84d8602d9141779986c8030 Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Thu, 16 Mar 2017 17:54:42 -0700 Subject: [PATCH 3/9] apply profile to relevant entities --- interface/resources/qml/Browser.qml | 6 ++++++ .../resources/qml/controls/WebEntityView.qml | 20 +++++++++++++++++++ interface/resources/qml/controls/WebView.qml | 6 ++++-- interface/resources/qml/hifi/Desktop.qml | 4 ++-- interface/src/networking/FileTypeProfile.cpp | 2 +- interface/src/networking/FileTypeProfile.h | 2 +- .../networking/FileTypeRequestInterceptor.h | 2 +- interface/src/networking/RequestFilters.cpp | 8 ++------ interface/src/networking/RequestFilters.h | 2 +- .../src/RenderableWebEntityItem.cpp | 2 +- 10 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 interface/resources/qml/controls/WebEntityView.qml diff --git a/interface/resources/qml/Browser.qml b/interface/resources/qml/Browser.qml index c4e0c85642..47fb610469 100644 --- a/interface/resources/qml/Browser.qml +++ b/interface/resources/qml/Browser.qml @@ -2,6 +2,7 @@ import QtQuick 2.5 import QtQuick.Controls 1.2 import QtWebChannel 1.0 import QtWebEngine 1.2 +import FileTypeProfile 1.0 import "controls-uit" import "styles" as HifiStyles @@ -216,6 +217,11 @@ ScrollingWindow { WebChannel.id: "eventBridgeWrapper" property var eventBridge; } + + profile: FileTypeProfile { + id: webviewProfile + storageName: "qmlWebEngine" + } webChannel.registeredObjects: [eventBridgeWrapper] diff --git a/interface/resources/qml/controls/WebEntityView.qml b/interface/resources/qml/controls/WebEntityView.qml new file mode 100644 index 0000000000..961ebffb38 --- /dev/null +++ b/interface/resources/qml/controls/WebEntityView.qml @@ -0,0 +1,20 @@ +// +// WebEntityView.qml +// +// Created by Kunal Gosar on 16 March 2017 +// Copyright 2017 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 +// + +import QtQuick 2.5 +import "." +import FileTypeProfile 1.0 + +WebView { + viewProfile: FileTypeProfile { + id: webviewProfile + storageName: "qmlWebEngine" + } +} diff --git a/interface/resources/qml/controls/WebView.qml b/interface/resources/qml/controls/WebView.qml index d3e1d97d1a..8c73eddcc2 100644 --- a/interface/resources/qml/controls/WebView.qml +++ b/interface/resources/qml/controls/WebView.qml @@ -2,7 +2,7 @@ import QtQuick 2.5 import QtWebEngine 1.1 import QtWebChannel 1.0 import "../controls-uit" as HiFiControls -import FileTypeProfile 1.0 +import HFWebEngineProfile 1.0 Item { property alias url: root.url @@ -27,6 +27,8 @@ Item { WebChannel.id: "eventBridgeWrapper" property var eventBridge; } + + property alias viewProfile: root.profile WebEngineView { id: root @@ -36,7 +38,7 @@ Item { width: parent.width height: keyboardEnabled && keyboardRaised ? parent.height - keyboard.height : parent.height - profile: FileTypeProfile { + profile: HFWebEngineProfile { id: webviewProfile storageName: "qmlWebEngine" } diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index cd66b014a4..7857eda3c2 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -2,7 +2,7 @@ import QtQuick 2.5 import QtQuick.Controls 1.4 import QtWebEngine 1.1; import Qt.labs.settings 1.0 -import FileTypeProfile 1.0 +import HFWebEngineProfile 1.0 import "../desktop" as OriginalDesktop import ".." @@ -27,7 +27,7 @@ OriginalDesktop.Desktop { property alias toolWindow: toolWindow ToolWindow { id: toolWindow } - property var browserProfile: FileTypeProfile { + property var browserProfile: HFWebEngineProfile { id: webviewProfile storageName: "qmlWebEngine" } diff --git a/interface/src/networking/FileTypeProfile.cpp b/interface/src/networking/FileTypeProfile.cpp index 2048751e5d..6fcd8df669 100644 --- a/interface/src/networking/FileTypeProfile.cpp +++ b/interface/src/networking/FileTypeProfile.cpp @@ -23,4 +23,4 @@ FileTypeProfile::FileTypeProfile(QObject* parent) : auto requestInterceptor = new FileTypeRequestInterceptor(this); setRequestInterceptor(requestInterceptor); -} \ No newline at end of file +} diff --git a/interface/src/networking/FileTypeProfile.h b/interface/src/networking/FileTypeProfile.h index 99ed5d4b79..f922fd66de 100644 --- a/interface/src/networking/FileTypeProfile.h +++ b/interface/src/networking/FileTypeProfile.h @@ -22,4 +22,4 @@ public: }; -#endif // hifi_FileTypeProfile_h \ No newline at end of file +#endif // hifi_FileTypeProfile_h diff --git a/interface/src/networking/FileTypeRequestInterceptor.h b/interface/src/networking/FileTypeRequestInterceptor.h index c39c860b7c..be971daf7a 100644 --- a/interface/src/networking/FileTypeRequestInterceptor.h +++ b/interface/src/networking/FileTypeRequestInterceptor.h @@ -23,4 +23,4 @@ public: virtual void interceptRequest(QWebEngineUrlRequestInfo& info) override; }; -#endif // hifi_FileTypeRequestInterceptor_h \ No newline at end of file +#endif // hifi_FileTypeRequestInterceptor_h diff --git a/interface/src/networking/RequestFilters.cpp b/interface/src/networking/RequestFilters.cpp index 5a29b58da9..0f59258b66 100644 --- a/interface/src/networking/RequestFilters.cpp +++ b/interface/src/networking/RequestFilters.cpp @@ -49,13 +49,9 @@ void RequestFilters::interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info) void RequestFilters::interceptFileType(QWebEngineUrlRequestInfo& info) { QString filename = info.requestUrl().fileName(); - if (isJavaScriptFile(filename) || isEntityFile(filename)) { static const QString CONTENT_HEADER = "Accept"; - static const QString TYPE_VALUE = "text/html"; + static const QString TYPE_VALUE = "text/plain"; info.setHttpHeader(CONTENT_HEADER.toLocal8Bit(), TYPE_VALUE.toLocal8Bit()); - static const QString CONTENT_DISPOSITION = "Content-Disposition"; - static const QString DISPOSITION_VALUE = "inline"; - info.setHttpHeader(CONTENT_DISPOSITION.toLocal8Bit(), DISPOSITION_VALUE.toLocal8Bit()); } -} \ No newline at end of file +} diff --git a/interface/src/networking/RequestFilters.h b/interface/src/networking/RequestFilters.h index ab20a267e0..d61208a22d 100644 --- a/interface/src/networking/RequestFilters.h +++ b/interface/src/networking/RequestFilters.h @@ -25,4 +25,4 @@ public: void interceptFileType(QWebEngineUrlRequestInfo& info); }; -#endif // hifi_RequestFilters_h \ No newline at end of file +#endif // hifi_RequestFilters_h diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index c4ae0db1aa..109c4cbfe9 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -266,7 +266,7 @@ void RenderableWebEntityItem::loadSourceURL() { _webSurface->setMaxFps(DEFAULT_MAX_FPS); } - _webSurface->load("WebView.qml", [&](QQmlContext* context, QObject* obj) { + _webSurface->load("WebEntityView.qml", [&](QQmlContext* context, QObject* obj) { context->setContextProperty("eventBridgeJavaScriptToInject", QVariant(_javaScriptToInject)); }); From 9d0667cb3150a99e636cc5706f9dc9cca434c8a4 Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Fri, 17 Mar 2017 15:22:36 -0700 Subject: [PATCH 4/9] add url tag to web entities --- interface/resources/qml/controls/WebEntityView.qml | 2 ++ interface/resources/qml/controls/WebView.qml | 5 ++++- interface/src/Application.cpp | 5 ++++- interface/src/networking/FileTypeRequestInterceptor.cpp | 5 ++--- interface/src/networking/HFWebEngineRequestInterceptor.cpp | 3 +-- interface/src/networking/RequestFilters.cpp | 6 +++--- interface/src/networking/RequestFilters.h | 4 ++-- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/interface/resources/qml/controls/WebEntityView.qml b/interface/resources/qml/controls/WebEntityView.qml index 961ebffb38..821954bf7b 100644 --- a/interface/resources/qml/controls/WebEntityView.qml +++ b/interface/resources/qml/controls/WebEntityView.qml @@ -17,4 +17,6 @@ WebView { id: webviewProfile storageName: "qmlWebEngine" } + + urlTag: "?noDowload=true"; } diff --git a/interface/resources/qml/controls/WebView.qml b/interface/resources/qml/controls/WebView.qml index 8c73eddcc2..dc62721ace 100644 --- a/interface/resources/qml/controls/WebView.qml +++ b/interface/resources/qml/controls/WebView.qml @@ -10,6 +10,7 @@ Item { property alias eventBridge: eventBridgeWrapper.eventBridge property alias canGoBack: root.canGoBack; property var goBack: root.goBack; + property alias urlTag: root.urlTag property bool keyboardEnabled: true // FIXME - Keyboard HMD only: Default to false property bool keyboardRaised: false property bool punctuationMode: false @@ -68,6 +69,8 @@ Item { injectionPoint: WebEngineScript.DocumentReady // DOM ready but page load may not be finished. worldId: WebEngineScript.MainWorld } + + property string urlTag: "?noDowload=false"; userScripts: [ createGlobalEventBridge, raiseAndLowerKeyboard, userScript ] @@ -95,7 +98,7 @@ Item { // Required to support clicking on "hifi://" links if (WebEngineView.LoadStartedStatus == loadRequest.status) { - var url = loadRequest.url.toString(); + var url = loadRequest.url.toString() + urlTag; if (urlHandler.canHandleUrl(url)) { if (urlHandler.handleUrl(url)) { root.stop(); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index aa33b66962..eee9253c76 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -219,6 +219,7 @@ static const QString FST_EXTENSION = ".fst"; static const QString FBX_EXTENSION = ".fbx"; static const QString OBJ_EXTENSION = ".obj"; static const QString AVA_JSON_EXTENSION = ".ava.json"; +static const QString WEB_VIEW_TAG = "?noDowload=true"; static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f; @@ -2607,7 +2608,7 @@ bool Application::event(QEvent* event) { QFileOpenEvent* fileEvent = static_cast(event); QUrl url = fileEvent->url(); - + if (!url.isEmpty()) { QString urlString = url.toString(); @@ -5549,6 +5550,8 @@ bool Application::canAcceptURL(const QString& urlString) const { QUrl url(urlString); if (urlString.startsWith(HIFI_URL_SCHEME)) { return true; + } else if (urlString.endsWith(WEB_VIEW_TAG)) { + return false; } QHashIterator i(_acceptedExtensions); QString lowerPath = url.path().toLower(); diff --git a/interface/src/networking/FileTypeRequestInterceptor.cpp b/interface/src/networking/FileTypeRequestInterceptor.cpp index 2dac5db194..91bacd46a6 100644 --- a/interface/src/networking/FileTypeRequestInterceptor.cpp +++ b/interface/src/networking/FileTypeRequestInterceptor.cpp @@ -16,7 +16,6 @@ #include "RequestFilters.h" void FileTypeRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { - RequestFilters* filter = new RequestFilters; - filter->interceptHFWebEngineRequest(info); - filter->interceptFileType(info); + RequestFilters::interceptHFWebEngineRequest(info); + RequestFilters::interceptFileType(info); } diff --git a/interface/src/networking/HFWebEngineRequestInterceptor.cpp b/interface/src/networking/HFWebEngineRequestInterceptor.cpp index 400d547d92..546edcf95c 100644 --- a/interface/src/networking/HFWebEngineRequestInterceptor.cpp +++ b/interface/src/networking/HFWebEngineRequestInterceptor.cpp @@ -18,6 +18,5 @@ #include "RequestFilters.h" void HFWebEngineRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { - RequestFilters* filter = new RequestFilters; - filter->interceptHFWebEngineRequest(info); + RequestFilters::interceptHFWebEngineRequest(info); } diff --git a/interface/src/networking/RequestFilters.cpp b/interface/src/networking/RequestFilters.cpp index 0f59258b66..39ed5117ac 100644 --- a/interface/src/networking/RequestFilters.cpp +++ b/interface/src/networking/RequestFilters.cpp @@ -15,7 +15,7 @@ #include -bool isAuthableHighFidelityURL(const QUrl& url) { +bool static isAuthableHighFidelityURL(const QUrl& url) { static const QStringList HF_HOSTS = { "highfidelity.com", "highfidelity.io", "metaverse.highfidelity.com", "metaverse.highfidelity.io" @@ -24,11 +24,11 @@ bool isAuthableHighFidelityURL(const QUrl& url) { return url.scheme() == "https" && HF_HOSTS.contains(url.host()); } -bool isJavaScriptFile(const QString filename) { +bool static isJavaScriptFile(const QString filename) { return filename.contains(".js", Qt::CaseInsensitive); } -bool isEntityFile(const QString filename) { +bool static isEntityFile(const QString filename) { return filename.contains(".svo.json", Qt::CaseInsensitive); } diff --git a/interface/src/networking/RequestFilters.h b/interface/src/networking/RequestFilters.h index d61208a22d..0d7d66e155 100644 --- a/interface/src/networking/RequestFilters.h +++ b/interface/src/networking/RequestFilters.h @@ -21,8 +21,8 @@ class RequestFilters : public QObject { Q_OBJECT public: - void interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info); - void interceptFileType(QWebEngineUrlRequestInfo& info); + static void interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info); + static void interceptFileType(QWebEngineUrlRequestInfo& info); }; #endif // hifi_RequestFilters_h From 3b88553699e62d33ed4eb3a5a4dd97b4ab623dc1 Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Fri, 17 Mar 2017 15:33:42 -0700 Subject: [PATCH 5/9] check scripts --- interface/src/networking/RequestFilters.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/interface/src/networking/RequestFilters.cpp b/interface/src/networking/RequestFilters.cpp index 39ed5117ac..894ed9fdd2 100644 --- a/interface/src/networking/RequestFilters.cpp +++ b/interface/src/networking/RequestFilters.cpp @@ -24,14 +24,10 @@ bool static isAuthableHighFidelityURL(const QUrl& url) { return url.scheme() == "https" && HF_HOSTS.contains(url.host()); } -bool static isJavaScriptFile(const QString filename) { +bool static isScript(const QString filename) { return filename.contains(".js", Qt::CaseInsensitive); } -bool static isEntityFile(const QString filename) { - return filename.contains(".svo.json", Qt::CaseInsensitive); -} - void RequestFilters::interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info) { // check if this is a request to a highfidelity URL if (isAuthableHighFidelityURL(info.requestUrl())) { @@ -49,9 +45,9 @@ void RequestFilters::interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info) void RequestFilters::interceptFileType(QWebEngineUrlRequestInfo& info) { QString filename = info.requestUrl().fileName(); - if (isJavaScriptFile(filename) || isEntityFile(filename)) { + if (isScript(filename)) { static const QString CONTENT_HEADER = "Accept"; - static const QString TYPE_VALUE = "text/plain"; + static const QString TYPE_VALUE = "text/plain,text/html"; info.setHttpHeader(CONTENT_HEADER.toLocal8Bit(), TYPE_VALUE.toLocal8Bit()); } } From 8e4229b2119dc789c1c90f91fe9e4ac56512634a Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Fri, 17 Mar 2017 15:44:46 -0700 Subject: [PATCH 6/9] dont redirect people from webentity --- interface/src/Application.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index eee9253c76..2901de23b3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5548,10 +5548,10 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri bool Application::canAcceptURL(const QString& urlString) const { QUrl url(urlString); - if (urlString.startsWith(HIFI_URL_SCHEME)) { - return true; - } else if (urlString.endsWith(WEB_VIEW_TAG)) { + if (urlString.endsWith(WEB_VIEW_TAG)) { return false; + } else if (urlString.startsWith(HIFI_URL_SCHEME)) { + return true; } QHashIterator i(_acceptedExtensions); QString lowerPath = url.path().toLower(); From e5c075f107b95000b1cca4a5e0d7163b7e5e6271 Mon Sep 17 00:00:00 2001 From: Kunal Gosar Date: Fri, 24 Mar 2017 00:10:53 -0700 Subject: [PATCH 7/9] fix typo and namespace --- .../resources/qml/controls/WebEntityView.qml | 2 +- interface/resources/qml/controls/WebView.qml | 2 +- interface/src/Application.cpp | 2 +- interface/src/networking/RequestFilters.cpp | 22 +++++++++++-------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/interface/resources/qml/controls/WebEntityView.qml b/interface/resources/qml/controls/WebEntityView.qml index 821954bf7b..4b4c8fe46f 100644 --- a/interface/resources/qml/controls/WebEntityView.qml +++ b/interface/resources/qml/controls/WebEntityView.qml @@ -18,5 +18,5 @@ WebView { storageName: "qmlWebEngine" } - urlTag: "?noDowload=true"; + urlTag: "?noDownload=true"; } diff --git a/interface/resources/qml/controls/WebView.qml b/interface/resources/qml/controls/WebView.qml index dc62721ace..b904dd5d55 100644 --- a/interface/resources/qml/controls/WebView.qml +++ b/interface/resources/qml/controls/WebView.qml @@ -70,7 +70,7 @@ Item { worldId: WebEngineScript.MainWorld } - property string urlTag: "?noDowload=false"; + property string urlTag: "?noDownload=false"; userScripts: [ createGlobalEventBridge, raiseAndLowerKeyboard, userScript ] diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2901de23b3..f0897176af 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -219,7 +219,7 @@ static const QString FST_EXTENSION = ".fst"; static const QString FBX_EXTENSION = ".fbx"; static const QString OBJ_EXTENSION = ".obj"; static const QString AVA_JSON_EXTENSION = ".ava.json"; -static const QString WEB_VIEW_TAG = "?noDowload=true"; +static const QString WEB_VIEW_TAG = "?noDownload=true"; static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f; diff --git a/interface/src/networking/RequestFilters.cpp b/interface/src/networking/RequestFilters.cpp index 894ed9fdd2..abf9575bdc 100644 --- a/interface/src/networking/RequestFilters.cpp +++ b/interface/src/networking/RequestFilters.cpp @@ -15,17 +15,21 @@ #include -bool static isAuthableHighFidelityURL(const QUrl& url) { - static const QStringList HF_HOSTS = { - "highfidelity.com", "highfidelity.io", - "metaverse.highfidelity.com", "metaverse.highfidelity.io" - }; +namespace { - return url.scheme() == "https" && HF_HOSTS.contains(url.host()); -} + bool isAuthableHighFidelityURL(const QUrl& url) { + static const QStringList HF_HOSTS = { + "highfidelity.com", "highfidelity.io", + "metaverse.highfidelity.com", "metaverse.highfidelity.io" + }; + + return url.scheme() == "https" && HF_HOSTS.contains(url.host()); + } + + bool isScript(const QString filename) { + return filename.contains(".js", Qt::CaseInsensitive); + } -bool static isScript(const QString filename) { - return filename.contains(".js", Qt::CaseInsensitive); } void RequestFilters::interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info) { From cc81bcab663dcc3698da8a0cd036afb98047b756 Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Tue, 4 Apr 2017 11:58:38 -0700 Subject: [PATCH 8/9] updating url check from hifi master --- .../HFWebEngineRequestInterceptor.cpp | 1 - interface/src/networking/RequestFilters.cpp | 18 +++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/interface/src/networking/HFWebEngineRequestInterceptor.cpp b/interface/src/networking/HFWebEngineRequestInterceptor.cpp index 546edcf95c..59897d427f 100644 --- a/interface/src/networking/HFWebEngineRequestInterceptor.cpp +++ b/interface/src/networking/HFWebEngineRequestInterceptor.cpp @@ -10,7 +10,6 @@ // #include "HFWebEngineRequestInterceptor.h" -#include "NetworkingConstants.h" #include diff --git a/interface/src/networking/RequestFilters.cpp b/interface/src/networking/RequestFilters.cpp index abf9575bdc..4e08080df0 100644 --- a/interface/src/networking/RequestFilters.cpp +++ b/interface/src/networking/RequestFilters.cpp @@ -10,6 +10,7 @@ // #include "RequestFilters.h" +#include "NetworkingConstants.h" #include @@ -17,14 +18,17 @@ namespace { - bool isAuthableHighFidelityURL(const QUrl& url) { - static const QStringList HF_HOSTS = { - "highfidelity.com", "highfidelity.io", - "metaverse.highfidelity.com", "metaverse.highfidelity.io" - }; + bool isAuthableHighFidelityURL(const QUrl& url) { + static const QStringList HF_HOSTS = { + "highfidelity.com", "highfidelity.io", + "metaverse.highfidelity.com", "metaverse.highfidelity.io" + }; + const auto& scheme = url.scheme(); + const auto& host = url.host(); - return url.scheme() == "https" && HF_HOSTS.contains(url.host()); - } + return (scheme == "https" && HF_HOSTS.contains(host)) || + ((scheme == NetworkingConstants::METAVERSE_SERVER_URL.scheme()) && (host == NetworkingConstants::METAVERSE_SERVER_URL.host())); + } bool isScript(const QString filename) { return filename.contains(".js", Qt::CaseInsensitive); From 8749428ede5203c5f7e383a2d339b646a061dbf3 Mon Sep 17 00:00:00 2001 From: kunalgosar Date: Tue, 4 Apr 2017 13:51:34 -0700 Subject: [PATCH 9/9] dont assume no query tags --- interface/resources/qml/controls/WebEntityView.qml | 2 +- interface/resources/qml/controls/WebView.qml | 5 +++-- interface/src/Application.cpp | 10 ++++++---- interface/src/networking/RequestFilters.cpp | 8 ++++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/interface/resources/qml/controls/WebEntityView.qml b/interface/resources/qml/controls/WebEntityView.qml index 4b4c8fe46f..a3d5fe903b 100644 --- a/interface/resources/qml/controls/WebEntityView.qml +++ b/interface/resources/qml/controls/WebEntityView.qml @@ -18,5 +18,5 @@ WebView { storageName: "qmlWebEngine" } - urlTag: "?noDownload=true"; + urlTag: "noDownload=true"; } diff --git a/interface/resources/qml/controls/WebView.qml b/interface/resources/qml/controls/WebView.qml index b904dd5d55..52f277520f 100644 --- a/interface/resources/qml/controls/WebView.qml +++ b/interface/resources/qml/controls/WebView.qml @@ -70,7 +70,7 @@ Item { worldId: WebEngineScript.MainWorld } - property string urlTag: "?noDownload=false"; + property string urlTag: "noDownload=false"; userScripts: [ createGlobalEventBridge, raiseAndLowerKeyboard, userScript ] @@ -98,7 +98,8 @@ Item { // Required to support clicking on "hifi://" links if (WebEngineView.LoadStartedStatus == loadRequest.status) { - var url = loadRequest.url.toString() + urlTag; + var url = loadRequest.url.toString(); + url = (url.indexOf("?") >= 0) ? url + urlTag : url + "?" + urlTag; if (urlHandler.canHandleUrl(url)) { if (urlHandler.handleUrl(url)) { root.stop(); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f0897176af..dec6850497 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -219,7 +219,7 @@ static const QString FST_EXTENSION = ".fst"; static const QString FBX_EXTENSION = ".fbx"; static const QString OBJ_EXTENSION = ".obj"; static const QString AVA_JSON_EXTENSION = ".ava.json"; -static const QString WEB_VIEW_TAG = "?noDownload=true"; +static const QString WEB_VIEW_TAG = "noDownload=true"; static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f; @@ -2608,7 +2608,7 @@ bool Application::event(QEvent* event) { QFileOpenEvent* fileEvent = static_cast(event); QUrl url = fileEvent->url(); - + if (!url.isEmpty()) { QString urlString = url.toString(); @@ -5548,7 +5548,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri bool Application::canAcceptURL(const QString& urlString) const { QUrl url(urlString); - if (urlString.endsWith(WEB_VIEW_TAG)) { + if (url.query().contains(WEB_VIEW_TAG)) { return false; } else if (urlString.startsWith(HIFI_URL_SCHEME)) { return true; @@ -5658,7 +5658,9 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { QUrl scriptURL { scriptFilenameOrURL }; if (scriptURL.host().endsWith(MARKETPLACE_CDN_HOSTNAME)) { - shortName = shortName.mid(shortName.lastIndexOf('/') + 1); + int startIndex = shortName.lastIndexOf('/') + 1; + int endIndex = shortName.lastIndexOf('?'); + shortName = shortName.mid(startIndex, endIndex - startIndex); } QString message = "Would you like to run this script:\n" + shortName; diff --git a/interface/src/networking/RequestFilters.cpp b/interface/src/networking/RequestFilters.cpp index 4e08080df0..fedde94f15 100644 --- a/interface/src/networking/RequestFilters.cpp +++ b/interface/src/networking/RequestFilters.cpp @@ -31,7 +31,11 @@ namespace { } bool isScript(const QString filename) { - return filename.contains(".js", Qt::CaseInsensitive); + return filename.endsWith(".js", Qt::CaseInsensitive); + } + + bool isJSON(const QString filename) { + return filename.endsWith(".json", Qt::CaseInsensitive); } } @@ -53,7 +57,7 @@ void RequestFilters::interceptHFWebEngineRequest(QWebEngineUrlRequestInfo& info) void RequestFilters::interceptFileType(QWebEngineUrlRequestInfo& info) { QString filename = info.requestUrl().fileName(); - if (isScript(filename)) { + if (isScript(filename) || isJSON(filename)) { static const QString CONTENT_HEADER = "Accept"; static const QString TYPE_VALUE = "text/plain,text/html"; info.setHttpHeader(CONTENT_HEADER.toLocal8Bit(), TYPE_VALUE.toLocal8Bit());