fixing WebEntities html

This commit is contained in:
danteruiz 2019-09-12 17:12:50 -07:00
parent b969a9b1e0
commit 8491a37923
5 changed files with 47 additions and 35 deletions

View file

@ -12,20 +12,35 @@ import QtQuick 2.5
import "controls" as Controls
Controls.WebView {
Item {
id: root
anchors.fill: parent
property string url: ""
property string scriptUrl: null
// This is for JS/QML communication, which is unused in a Web3DOverlay,
// but not having this here results in spurious warnings about a
// missing signal
signal sendToScript(var message);
onUrlChanged: {
load(root.url, root.scriptUrl);
}
function onWebEventReceived(event) {
if (event.slice(0, 17) === "CLARA.IO DOWNLOAD") {
ApplicationInterface.addAssetToWorldFromURL(event.slice(18));
onScriptUrlChanged: {
if (root.item) {
root.item.scriptUrl = root.scriptUrl;
} else {
load(root.url, root.scriptUrl);
}
}
property var item: null
function load(url, scriptUrl) {
QmlSurface.load("./controls/WebView.qml", root, function(newItem) {
root.item = newItem
root.item.url = url
root.item.scriptUrl = scriptUrl
})
}
Component.onCompleted: {
eventBridge.webEventReceived.connect(onWebEventReceived);
load(root.url, root.scriptUrl);
}
}

View file

@ -24,6 +24,7 @@
#include <ui/OffscreenQmlSurface.h>
#include <ui/TabletScriptingInterface.h>
#include <EntityScriptingInterface.h>
#include <shared/LocalFileAccessGate.h>
#include "EntitiesRendererLogging.h"
#include <NetworkingConstants.h>
@ -180,14 +181,23 @@ void WebEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene
}
// This work must be done on the main thread
bool localSafeContext = entity->getLocalSafeContext();
if (!_webSurface) {
if (localSafeContext) {
::hifi::scripting::setLocalAccessSafeThread(true);
}
buildWebSurface(entity, newSourceURL);
::hifi::scripting::setLocalAccessSafeThread(false);
}
if (_webSurface) {
if (_webSurface->getRootItem()) {
if (_contentType == ContentType::HtmlContent && _sourceURL != newSourceURL) {
if (localSafeContext) {
::hifi::scripting::setLocalAccessSafeThread(true);
}
_webSurface->getRootItem()->setProperty(URL_PROPERTY, newSourceURL);
::hifi::scripting::setLocalAccessSafeThread(false);
_sourceURL = newSourceURL;
} else if (_contentType != ContentType::HtmlContent) {
_sourceURL = newSourceURL;

View file

@ -15,6 +15,7 @@
#include <ByteCountCoding.h>
#include <GeometryUtil.h>
#include <shared/LocalFileAccessGate.h>
#include "EntitiesLogging.h"
#include "EntityItemProperties.h"
@ -31,6 +32,9 @@ EntityItemPointer WebEntityItem::factory(const EntityItemID& entityID, const Ent
}
WebEntityItem::WebEntityItem(const EntityItemID& entityItemID) : EntityItem(entityItemID) {
// this initialzation of localSafeContext is reading a thread-local variable and that is depends on
// the ctor being executed on the same thread as the script, assuming it's being create by a script
_localSafeContext = hifi::scripting::isLocalAccessSafeThread();
_type = EntityTypes::Web;
}
@ -241,6 +245,12 @@ glm::u8vec3 WebEntityItem::getColor() const {
});
}
bool WebEntityItem::getLocalSafeContext() const {
return resultWithReadLock<bool>([&] {
return _localSafeContext;
});
}
void WebEntityItem::setAlpha(float alpha) {
withWriteLock([&] {
_needsRenderUpdate |= _alpha != alpha;

View file

@ -74,6 +74,8 @@ public:
void setScriptURL(const QString& value);
QString getScriptURL() const;
bool getLocalSafeContext() const;
static const uint8_t DEFAULT_MAX_FPS;
void setMaxFPS(uint8_t value);
uint8_t getMaxFPS() const;
@ -98,6 +100,7 @@ protected:
uint8_t _maxFPS;
WebInputMode _inputMode;
bool _showKeyboardFocusHighlight;
bool _localSafeContext { false };
};
#endif // hifi_WebEntityItem_h

View file

@ -834,32 +834,6 @@ void TabletProxy::loadHTMLSourceImpl(const QVariant& url, const QString& injectJ
hifi::scripting::setLocalAccessSafeThread(false);
}
_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) {