diff --git a/interface/resources/qml/Browser.qml b/interface/resources/qml/Browser.qml index bd98e42709..c4e0c85642 100644 --- a/interface/resources/qml/Browser.qml +++ b/interface/resources/qml/Browser.qml @@ -33,6 +33,10 @@ ScrollingWindow { addressBar.text = webview.url } + function setProfile(profile) { + webview.profile = profile; + } + function showPermissionsBar(){ permissionsContainer.visible=true; } diff --git a/interface/resources/qml/TabletBrowser.qml b/interface/resources/qml/TabletBrowser.qml index 1d49d46c43..312b811928 100644 --- a/interface/resources/qml/TabletBrowser.qml +++ b/interface/resources/qml/TabletBrowser.qml @@ -70,10 +70,10 @@ Item { width: parent.width height: keyboardEnabled && keyboardRaised ? parent.height - keyboard.height : parent.height - //profile: HFWebEngineProfile { - //id: webviewProfile - //storageName: "qmlWebEngine" - //} + profile: HFWebEngineProfile { + id: webviewProfile + storageName: "qmlWebEngine" + } property string userScriptUrl: "" @@ -159,7 +159,7 @@ Item { return; } var newWindow = component.createObject(); - //newWindow.setProfile(webview.profile); + newWindow.setProfile(webview.profile); request.openIn(newWindow.webView); newWindow.eventBridge = web.eventBridge; stackRoot.push(newWindow); diff --git a/interface/resources/qml/controls/.#TabletWebView.qml b/interface/resources/qml/controls/.#TabletWebView.qml new file mode 100644 index 0000000000..ff599d4a29 Binary files /dev/null and b/interface/resources/qml/controls/.#TabletWebView.qml differ diff --git a/interface/resources/qml/controls/TabletWebView.qml b/interface/resources/qml/controls/TabletWebView.qml index 70d2539744..890215a714 100644 --- a/interface/resources/qml/controls/TabletWebView.qml +++ b/interface/resources/qml/controls/TabletWebView.qml @@ -6,6 +6,7 @@ import "../controls-uit" as HiFiControls import "../styles" as HifiStyles import "../styles-uit" import HFWebEngineProfile 1.0 +import HFTabletWebEngineProfile 1.0 import "../" Item { id: web @@ -23,7 +24,7 @@ Item { property bool isDesktop: false property WebEngineView view: root - + Row { id: buttons HifiConstants { id: hifi } @@ -136,10 +137,11 @@ Item { y: 0 width: parent.width height: keyboardEnabled && keyboardRaised ? (parent.height - keyboard.height) : parent.height - //profile: HFWebEngineProfile { - //id: webviewProfile - //storageName: "qmlWebEngine" - //} + profile: HFTabletWebEngineProfile { + id: webviewTabletProfile + storageName: "qmlTabletWebEngine" + } + property WebEngineView webView: root function reloadPage() { root.reload(); @@ -188,7 +190,7 @@ Item { console.log("Web Entity JS message: " + sourceID + " " + lineNumber + " " + message); }); - root.profile.httpUserAgent = "Mozilla/5.0 Chrome (HighFidelityInterface)" + root.profile.httpUserAgent = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36" } @@ -200,7 +202,7 @@ Item { keyboardRaised = false; punctuationMode = false; keyboard.resetShiftMode(false); - + console.log("[DR] -> printing user string " + root.profile.httpUserAgent); // Required to support clicking on "hifi://" links if (WebEngineView.LoadStartedStatus == loadRequest.status) { var url = loadRequest.url.toString(); @@ -214,9 +216,10 @@ Item { onNewViewRequested:{ // desktop is not defined for web-entities - if (isDesktop) { + if (web.isDesktop) { var component = Qt.createComponent("../Browser.qml"); var newWindow = component.createObject(desktop); + newWindow.setProfile(root.profile); request.openIn(newWindow.webView); } else { var component = Qt.createComponent("../TabletBrowser.qml"); @@ -228,7 +231,7 @@ Item { return; } var newWindow = component.createObject(); - //newWindow.setProfile(root.profile); + newWindow.setProfile(root.profile); request.openIn(newWindow.webView); newWindow.eventBridge = web.eventBridge; stackRoot.push(newWindow); @@ -250,7 +253,7 @@ Item { } Component.onCompleted: { - stackRoot.isDesktop = (typeof desktop !== "undefined"); + web.isDesktop = (typeof desktop !== "undefined"); address = url; } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 25a585ea34..ed6068ece7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -141,6 +141,7 @@ #include "LODManager.h" #include "ModelPackager.h" #include "networking/HFWebEngineProfile.h" +#include "networking/HFTabletWebEngineProfile.h" #include "scripting/TestScriptingInterface.h" #include "scripting/AccountScriptingInterface.h" #include "scripting/AssetMappingsScriptingInterface.h" @@ -1931,6 +1932,7 @@ void Application::initializeUi() { qmlRegisterType("Hifi", 1, 0, "Preference"); qmlRegisterType("HFWebEngineProfile", 1, 0, "HFWebEngineProfile"); + qmlRegisterType("HFTabletWebEngineProfile", 1, 0, "HFTabletWebEngineProfile"); auto offscreenUi = DependencyManager::get(); offscreenUi->create(_glWidget->qglContext()); diff --git a/interface/src/networking/HFTabletWebEngineProfile.cpp b/interface/src/networking/HFTabletWebEngineProfile.cpp new file mode 100644 index 0000000000..46634299bb --- /dev/null +++ b/interface/src/networking/HFTabletWebEngineProfile.cpp @@ -0,0 +1,26 @@ +// +// HFTabletWebEngineProfile.h +// interface/src/networking +// +// Created by Dante Ruiz on 2017-03-31. +// 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 "HFTabletWebEngineProfile.h" +#include "HFTabletWebEngineRequestInterceptor.h" + +static const QString QML_WEB_ENGINE_NAME = "qmlTabletWebEngine"; + +HFTabletWebEngineProfile::HFTabletWebEngineProfile(QObject* parent) : QQuickWebEngineProfile(parent) { + + static const QString WEB_ENGINE_USER_AGENT = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36"; + + setHttpUserAgent(WEB_ENGINE_USER_AGENT); + + auto requestInterceptor = new HFTabletWebEngineRequestInterceptor(this); + setRequestInterceptor(requestInterceptor); +} + diff --git a/interface/src/networking/HFTabletWebEngineProfile.h b/interface/src/networking/HFTabletWebEngineProfile.h new file mode 100644 index 0000000000..406cb1a19a --- /dev/null +++ b/interface/src/networking/HFTabletWebEngineProfile.h @@ -0,0 +1,23 @@ +// +// HFTabletWebEngineProfile.h +// interface/src/networking +// +// Created by Dante Ruiz on 2017-03-31. +// 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 +// + + +#ifndef hifi_HFTabletWebEngineProfile_h +#define hifi_HFTabletWebEngineProfile_h + +#include + +class HFTabletWebEngineProfile : public QQuickWebEngineProfile { +public: + HFTabletWebEngineProfile(QObject* parent = Q_NULLPTR); +}; + +#endif // hifi_HFTabletWebEngineProfile_h diff --git a/interface/src/networking/HFTabletWebEngineRequestInterceptor.cpp b/interface/src/networking/HFTabletWebEngineRequestInterceptor.cpp new file mode 100644 index 0000000000..7282fb5e3d --- /dev/null +++ b/interface/src/networking/HFTabletWebEngineRequestInterceptor.cpp @@ -0,0 +1,42 @@ +// +// HFTabletWebEngineRequestInterceptor.cpp +// interface/src/networking +// +// Created by Dante Ruiz on 2017-3-31. +// 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 "HFTabletWebEngineRequestInterceptor.h" +#include +#include + +bool isTabletAuthableHighFidelityURL(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()); +} + +void HFTabletWebEngineRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo& info) { + // check if this is a request to a highfidelity URL + if (isTabletAuthableHighFidelityURL(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()); + } + } + + static const QString USER_AGENT = "User-Agent"; + QString tokenString = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Mobile Safari/537.36"; + info.setHttpHeader(USER_AGENT.toLocal8Bit(), tokenString.toLocal8Bit()); +} diff --git a/interface/src/networking/HFTabletWebEngineRequestInterceptor.h b/interface/src/networking/HFTabletWebEngineRequestInterceptor.h new file mode 100644 index 0000000000..e38549937e --- /dev/null +++ b/interface/src/networking/HFTabletWebEngineRequestInterceptor.h @@ -0,0 +1,24 @@ +// +// HFTabletWebEngineRequestInterceptor.h +// interface/src/networking +// +// Created by Dante Ruiz on 2017-3-31. +// 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 +// + +#ifndef hifi_HFTabletWebEngineRequestInterceptor_h +#define hifi_HFTabletWebEngineRequestInterceptor_h + +#include + +class HFTabletWebEngineRequestInterceptor : public QWebEngineUrlRequestInterceptor { +public: + HFTabletWebEngineRequestInterceptor(QObject* parent) : QWebEngineUrlRequestInterceptor(parent) {}; + + virtual void interceptRequest(QWebEngineUrlRequestInfo& info) override; +}; + +#endif // hifi_HFWebEngineRequestInterceptor_h