mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-04 00:20:48 +02:00
fixed webview mobile view
This commit is contained in:
parent
70d2d69557
commit
d1bf3e4bf2
9 changed files with 139 additions and 15 deletions
|
@ -33,6 +33,10 @@ ScrollingWindow {
|
||||||
addressBar.text = webview.url
|
addressBar.text = webview.url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setProfile(profile) {
|
||||||
|
webview.profile = profile;
|
||||||
|
}
|
||||||
|
|
||||||
function showPermissionsBar(){
|
function showPermissionsBar(){
|
||||||
permissionsContainer.visible=true;
|
permissionsContainer.visible=true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,10 +70,10 @@ Item {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: keyboardEnabled && keyboardRaised ? parent.height - keyboard.height : parent.height
|
height: keyboardEnabled && keyboardRaised ? parent.height - keyboard.height : parent.height
|
||||||
|
|
||||||
//profile: HFWebEngineProfile {
|
profile: HFWebEngineProfile {
|
||||||
//id: webviewProfile
|
id: webviewProfile
|
||||||
//storageName: "qmlWebEngine"
|
storageName: "qmlWebEngine"
|
||||||
//}
|
}
|
||||||
|
|
||||||
property string userScriptUrl: ""
|
property string userScriptUrl: ""
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ Item {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var newWindow = component.createObject();
|
var newWindow = component.createObject();
|
||||||
//newWindow.setProfile(webview.profile);
|
newWindow.setProfile(webview.profile);
|
||||||
request.openIn(newWindow.webView);
|
request.openIn(newWindow.webView);
|
||||||
newWindow.eventBridge = web.eventBridge;
|
newWindow.eventBridge = web.eventBridge;
|
||||||
stackRoot.push(newWindow);
|
stackRoot.push(newWindow);
|
||||||
|
|
BIN
interface/resources/qml/controls/.#TabletWebView.qml
Normal file
BIN
interface/resources/qml/controls/.#TabletWebView.qml
Normal file
Binary file not shown.
|
@ -6,6 +6,7 @@ import "../controls-uit" as HiFiControls
|
||||||
import "../styles" as HifiStyles
|
import "../styles" as HifiStyles
|
||||||
import "../styles-uit"
|
import "../styles-uit"
|
||||||
import HFWebEngineProfile 1.0
|
import HFWebEngineProfile 1.0
|
||||||
|
import HFTabletWebEngineProfile 1.0
|
||||||
import "../"
|
import "../"
|
||||||
Item {
|
Item {
|
||||||
id: web
|
id: web
|
||||||
|
@ -136,10 +137,11 @@ Item {
|
||||||
y: 0
|
y: 0
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: keyboardEnabled && keyboardRaised ? (parent.height - keyboard.height) : parent.height
|
height: keyboardEnabled && keyboardRaised ? (parent.height - keyboard.height) : parent.height
|
||||||
//profile: HFWebEngineProfile {
|
profile: HFTabletWebEngineProfile {
|
||||||
//id: webviewProfile
|
id: webviewTabletProfile
|
||||||
//storageName: "qmlWebEngine"
|
storageName: "qmlTabletWebEngine"
|
||||||
//}
|
}
|
||||||
|
|
||||||
property WebEngineView webView: root
|
property WebEngineView webView: root
|
||||||
function reloadPage() {
|
function reloadPage() {
|
||||||
root.reload();
|
root.reload();
|
||||||
|
@ -188,7 +190,7 @@ Item {
|
||||||
console.log("Web Entity JS message: " + sourceID + " " + lineNumber + " " + message);
|
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;
|
keyboardRaised = false;
|
||||||
punctuationMode = false;
|
punctuationMode = false;
|
||||||
keyboard.resetShiftMode(false);
|
keyboard.resetShiftMode(false);
|
||||||
|
console.log("[DR] -> printing user string " + root.profile.httpUserAgent);
|
||||||
// Required to support clicking on "hifi://" links
|
// Required to support clicking on "hifi://" links
|
||||||
if (WebEngineView.LoadStartedStatus == loadRequest.status) {
|
if (WebEngineView.LoadStartedStatus == loadRequest.status) {
|
||||||
var url = loadRequest.url.toString();
|
var url = loadRequest.url.toString();
|
||||||
|
@ -214,9 +216,10 @@ Item {
|
||||||
|
|
||||||
onNewViewRequested:{
|
onNewViewRequested:{
|
||||||
// desktop is not defined for web-entities
|
// desktop is not defined for web-entities
|
||||||
if (isDesktop) {
|
if (web.isDesktop) {
|
||||||
var component = Qt.createComponent("../Browser.qml");
|
var component = Qt.createComponent("../Browser.qml");
|
||||||
var newWindow = component.createObject(desktop);
|
var newWindow = component.createObject(desktop);
|
||||||
|
newWindow.setProfile(root.profile);
|
||||||
request.openIn(newWindow.webView);
|
request.openIn(newWindow.webView);
|
||||||
} else {
|
} else {
|
||||||
var component = Qt.createComponent("../TabletBrowser.qml");
|
var component = Qt.createComponent("../TabletBrowser.qml");
|
||||||
|
@ -228,7 +231,7 @@ Item {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var newWindow = component.createObject();
|
var newWindow = component.createObject();
|
||||||
//newWindow.setProfile(root.profile);
|
newWindow.setProfile(root.profile);
|
||||||
request.openIn(newWindow.webView);
|
request.openIn(newWindow.webView);
|
||||||
newWindow.eventBridge = web.eventBridge;
|
newWindow.eventBridge = web.eventBridge;
|
||||||
stackRoot.push(newWindow);
|
stackRoot.push(newWindow);
|
||||||
|
@ -250,7 +253,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
stackRoot.isDesktop = (typeof desktop !== "undefined");
|
web.isDesktop = (typeof desktop !== "undefined");
|
||||||
address = url;
|
address = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,7 @@
|
||||||
#include "LODManager.h"
|
#include "LODManager.h"
|
||||||
#include "ModelPackager.h"
|
#include "ModelPackager.h"
|
||||||
#include "networking/HFWebEngineProfile.h"
|
#include "networking/HFWebEngineProfile.h"
|
||||||
|
#include "networking/HFTabletWebEngineProfile.h"
|
||||||
#include "scripting/TestScriptingInterface.h"
|
#include "scripting/TestScriptingInterface.h"
|
||||||
#include "scripting/AccountScriptingInterface.h"
|
#include "scripting/AccountScriptingInterface.h"
|
||||||
#include "scripting/AssetMappingsScriptingInterface.h"
|
#include "scripting/AssetMappingsScriptingInterface.h"
|
||||||
|
@ -1931,6 +1932,7 @@ void Application::initializeUi() {
|
||||||
qmlRegisterType<Preference>("Hifi", 1, 0, "Preference");
|
qmlRegisterType<Preference>("Hifi", 1, 0, "Preference");
|
||||||
|
|
||||||
qmlRegisterType<HFWebEngineProfile>("HFWebEngineProfile", 1, 0, "HFWebEngineProfile");
|
qmlRegisterType<HFWebEngineProfile>("HFWebEngineProfile", 1, 0, "HFWebEngineProfile");
|
||||||
|
qmlRegisterType<HFTabletWebEngineProfile>("HFTabletWebEngineProfile", 1, 0, "HFTabletWebEngineProfile");
|
||||||
|
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
offscreenUi->create(_glWidget->qglContext());
|
offscreenUi->create(_glWidget->qglContext());
|
||||||
|
|
26
interface/src/networking/HFTabletWebEngineProfile.cpp
Normal file
26
interface/src/networking/HFTabletWebEngineProfile.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
23
interface/src/networking/HFTabletWebEngineProfile.h
Normal file
23
interface/src/networking/HFTabletWebEngineProfile.h
Normal file
|
@ -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 <QtWebEngine/QQuickWebEngineProfile>
|
||||||
|
|
||||||
|
class HFTabletWebEngineProfile : public QQuickWebEngineProfile {
|
||||||
|
public:
|
||||||
|
HFTabletWebEngineProfile(QObject* parent = Q_NULLPTR);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_HFTabletWebEngineProfile_h
|
|
@ -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 <QtCore/QDebug>
|
||||||
|
#include <AccountManager.h>
|
||||||
|
|
||||||
|
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<AccountManager>();
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
|
@ -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 <QWebEngineUrlRequestInterceptor>
|
||||||
|
|
||||||
|
class HFTabletWebEngineRequestInterceptor : public QWebEngineUrlRequestInterceptor {
|
||||||
|
public:
|
||||||
|
HFTabletWebEngineRequestInterceptor(QObject* parent) : QWebEngineUrlRequestInterceptor(parent) {};
|
||||||
|
|
||||||
|
virtual void interceptRequest(QWebEngineUrlRequestInfo& info) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_HFWebEngineRequestInterceptor_h
|
Loading…
Reference in a new issue