mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:43:03 +02:00
fix tablet html loading errors
This commit is contained in:
parent
4246d89eac
commit
b969a9b1e0
2 changed files with 62 additions and 2 deletions
|
@ -795,11 +795,25 @@ void TabletProxy::loadWebScreenOnTop(const QVariant& url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabletProxy::loadWebScreenOnTop(const QVariant& url, const QString& injectJavaScriptUrl) {
|
void TabletProxy::loadWebScreenOnTop(const QVariant& url, const QString& injectJavaScriptUrl) {
|
||||||
|
bool localSafeContext = hifi::scripting::isLocalAccessSafeThread();
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "loadWebScreenOnTop", Q_ARG(QVariant, url), Q_ARG(QString, injectJavaScriptUrl));
|
QMetaObject::invokeMethod(this, "loadHTMLSourceImpl", Q_ARG(QVariant, url), Q_ARG(QString, injectJavaScriptUrl), Q_ARG(bool, localSafeContext));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadHTMLSourceImpl(url, injectJavaScriptUrl, localSafeContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TabletProxy::loadHTMLSourceImpl(const QVariant& url, const QString& injectJavaScriptUrl, bool localSafeContext) {
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
qCWarning(uiLogging) << __FUNCTION__ << "may not be called directly by scripts";
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QObject* root = nullptr;
|
QObject* root = nullptr;
|
||||||
if (!_toolbarMode && _qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
root = _qmlTabletRoot;
|
root = _qmlTabletRoot;
|
||||||
|
@ -808,22 +822,59 @@ void TabletProxy::loadWebScreenOnTop(const QVariant& url, const QString& injectJ
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root) {
|
if (root) {
|
||||||
|
if (localSafeContext) {
|
||||||
|
hifi::scripting::setLocalAccessSafeThread(true);
|
||||||
|
}
|
||||||
QMetaObject::invokeMethod(root, "loadQMLOnTop", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL)));
|
QMetaObject::invokeMethod(root, "loadQMLOnTop", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL)));
|
||||||
QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true)));
|
QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true)));
|
||||||
if (_toolbarMode && _desktopWindow) {
|
if (_toolbarMode && _desktopWindow) {
|
||||||
QMetaObject::invokeMethod(root, "setResizable", Q_ARG(const QVariant&, QVariant(false)));
|
QMetaObject::invokeMethod(root, "setResizable", Q_ARG(const QVariant&, QVariant(false)));
|
||||||
}
|
}
|
||||||
QMetaObject::invokeMethod(root, "loadWebOnTop", Q_ARG(const QVariant&, QVariant(url)), Q_ARG(const QVariant&, QVariant(injectJavaScriptUrl)));
|
QMetaObject::invokeMethod(root, "loadWebOnTop", Q_ARG(const QVariant&, QVariant(url)), Q_ARG(const QVariant&, QVariant(injectJavaScriptUrl)));
|
||||||
|
hifi::scripting::setLocalAccessSafeThread(false);
|
||||||
}
|
}
|
||||||
_state = State::Web;
|
_state = State::Web;
|
||||||
|
/*QObject* root = nullptr;
|
||||||
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
|
root = _qmlTabletRoot;
|
||||||
|
} else if (_toolbarMode && _desktopWindow) {
|
||||||
|
root = _desktopWindow->asQuickItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root) {
|
||||||
|
// BUGZ-1398: tablet access to local HTML files from client scripts
|
||||||
|
// Here we TEMPORARILY mark the main thread as allowed to load local file content,
|
||||||
|
// because the thread that originally made the call is so marked.
|
||||||
|
if (localSafeContext) {
|
||||||
|
hifi::scripting::setLocalAccessSafeThread(true);
|
||||||
|
}
|
||||||
|
QMetaObject::invokeMethod(root, "loadSource", Q_ARG(const QVariant&, path));
|
||||||
|
hifi::scripting::setLocalAccessSafeThread(false);
|
||||||
|
_state = State::QML;
|
||||||
|
_currentPathLoaded = path;
|
||||||
|
QMetaObject::invokeMethod(root, "setShown", Q_ARG(const QVariant&, QVariant(true)));
|
||||||
|
if (_toolbarMode && _desktopWindow) {
|
||||||
|
QMetaObject::invokeMethod(root, "setResizable", Q_ARG(const QVariant&, QVariant(resizable)));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
qCDebug(uiLogging) << "tablet cannot load QML because _qmlTabletRoot is null";
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaScriptUrl, bool loadOtherBase) {
|
void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaScriptUrl, bool loadOtherBase) {
|
||||||
|
bool localSafeContext = hifi::scripting::isLocalAccessSafeThread();
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "gotoWebScreen", Q_ARG(QString, url), Q_ARG(QString, injectedJavaScriptUrl), Q_ARG(bool, loadOtherBase));
|
QMetaObject::invokeMethod(this, "loadHTMLSourceImpl", Q_ARG(QString, url), Q_ARG(QString, injectedJavaScriptUrl), Q_ARG(bool, loadOtherBase), Q_ARG(bool, localSafeContext));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
loadHTMLSourceImpl(url, injectedJavaScriptUrl, loadOtherBase, localSafeContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabletProxy::loadHTMLSourceImpl(const QString& url, const QString& injectedJavaScriptUrl, bool loadOtherBase, bool localSafeContext) {
|
||||||
|
|
||||||
QObject* root = nullptr;
|
QObject* root = nullptr;
|
||||||
if (!_toolbarMode && _qmlTabletRoot) {
|
if (!_toolbarMode && _qmlTabletRoot) {
|
||||||
root = _qmlTabletRoot;
|
root = _qmlTabletRoot;
|
||||||
|
@ -832,6 +883,9 @@ void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root) {
|
if (root) {
|
||||||
|
if (localSafeContext) {
|
||||||
|
hifi::scripting::setLocalAccessSafeThread(true);
|
||||||
|
}
|
||||||
if (loadOtherBase) {
|
if (loadOtherBase) {
|
||||||
QMetaObject::invokeMethod(root, "loadTabletWebBase", Q_ARG(const QVariant&, QVariant(url)), Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl)));
|
QMetaObject::invokeMethod(root, "loadTabletWebBase", Q_ARG(const QVariant&, QVariant(url)), Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl)));
|
||||||
} else {
|
} else {
|
||||||
|
@ -841,6 +895,8 @@ void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaS
|
||||||
if (_toolbarMode && _desktopWindow) {
|
if (_toolbarMode && _desktopWindow) {
|
||||||
QMetaObject::invokeMethod(root, "setResizable", Q_ARG(const QVariant&, QVariant(false)));
|
QMetaObject::invokeMethod(root, "setResizable", Q_ARG(const QVariant&, QVariant(false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hifi::scripting::setLocalAccessSafeThread(false);
|
||||||
_state = State::Web;
|
_state = State::Web;
|
||||||
_currentPathLoaded = QVariant(url);
|
_currentPathLoaded = QVariant(url);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -298,6 +298,10 @@ public:
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void loadQMLSourceImpl(const QVariant& path, bool resizable, bool localSafeContext);
|
Q_INVOKABLE void loadQMLSourceImpl(const QVariant& path, bool resizable, bool localSafeContext);
|
||||||
|
|
||||||
|
Q_INVOKABLE void loadHTMLSourceImpl(const QVariant& url, const QString& injectJavaScriptUrl, bool localSafeContext);
|
||||||
|
|
||||||
|
Q_INVOKABLE void loadHTMLSourceImpl(const QString& url, const QString& injectedJavaScriptUrl, bool loadOtherBase, bool localSafeContext);
|
||||||
|
|
||||||
// FIXME: This currently relies on a script initializing the tablet (hence the bool denoting success);
|
// FIXME: This currently relies on a script initializing the tablet (hence the bool denoting success);
|
||||||
// it should be initialized internally so it cannot fail
|
// it should be initialized internally so it cannot fail
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue