mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 13:24:02 +02:00
Restore the stop functionality for a browser view when it's being destroyed
This commit is contained in:
parent
575520fe30
commit
8e42bb8c87
4 changed files with 32 additions and 56 deletions
|
@ -21,6 +21,7 @@ Item {
|
||||||
signal newViewRequestedCallback(var request)
|
signal newViewRequestedCallback(var request)
|
||||||
signal loadingChangedCallback(var loadRequest)
|
signal loadingChangedCallback(var loadRequest)
|
||||||
|
|
||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
||||||
property bool interactive: false
|
property bool interactive: false
|
||||||
|
@ -29,6 +30,10 @@ Item {
|
||||||
id: hifi
|
id: hifi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stop() {
|
||||||
|
webViewCore.stop();
|
||||||
|
}
|
||||||
|
|
||||||
function unfocus() {
|
function unfocus() {
|
||||||
webViewCore.runJavaScript("if (document.activeElement) document.activeElement.blur();", function(result) {
|
webViewCore.runJavaScript("if (document.activeElement) document.activeElement.blur();", function(result) {
|
||||||
console.log('unfocus completed: ', result);
|
console.log('unfocus completed: ', result);
|
||||||
|
|
|
@ -21,6 +21,10 @@ Item {
|
||||||
property bool passwordField: false
|
property bool passwordField: false
|
||||||
property alias flickable: webroot.interactive
|
property alias flickable: webroot.interactive
|
||||||
|
|
||||||
|
function stop() {
|
||||||
|
webroot.stop();
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME - Keyboard HMD only: Make Interface either set keyboardRaised property directly in OffscreenQmlSurface
|
// FIXME - Keyboard HMD only: Make Interface either set keyboardRaised property directly in OffscreenQmlSurface
|
||||||
// or provide HMDinfo object to QML in RenderableWebEntityItem and do the following.
|
// or provide HMDinfo object to QML in RenderableWebEntityItem and do the following.
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -318,8 +318,10 @@ bool WebEntityRenderer::buildWebSurface(const TypedEntityPointer& entity) {
|
||||||
|
|
||||||
void WebEntityRenderer::destroyWebSurface() {
|
void WebEntityRenderer::destroyWebSurface() {
|
||||||
QSharedPointer<OffscreenQmlSurface> webSurface;
|
QSharedPointer<OffscreenQmlSurface> webSurface;
|
||||||
|
ContentType contentType{ ContentType::NoContent };
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
webSurface.swap(_webSurface);
|
webSurface.swap(_webSurface);
|
||||||
|
std::swap(contentType, _contentType);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (webSurface) {
|
if (webSurface) {
|
||||||
|
@ -328,12 +330,9 @@ void WebEntityRenderer::destroyWebSurface() {
|
||||||
|
|
||||||
// Fix for crash in QtWebEngineCore when rapidly switching domains
|
// Fix for crash in QtWebEngineCore when rapidly switching domains
|
||||||
// Call stop on the QWebEngineView before destroying OffscreenQMLSurface.
|
// Call stop on the QWebEngineView before destroying OffscreenQMLSurface.
|
||||||
if (rootItem) {
|
if (rootItem && contentType == ContentType::HtmlContent) {
|
||||||
QObject* obj = rootItem->findChild<QObject*>("webEngineView");
|
// stop loading
|
||||||
if (obj) {
|
QMetaObject::invokeMethod(rootItem, "stop");
|
||||||
// stop loading
|
|
||||||
QMetaObject::invokeMethod(obj, "stop");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
webSurface->pause();
|
webSurface->pause();
|
||||||
|
|
|
@ -45,19 +45,15 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
namespace gl {
|
namespace gl {
|
||||||
extern void initModuleGl();
|
extern void initModuleGl();
|
||||||
}
|
}
|
||||||
|
|
||||||
class QTestItem : public QQuickItem {
|
class QTestItem : public QQuickItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QTestItem(QQuickItem* parent = nullptr) : QQuickItem(parent) {
|
QTestItem(QQuickItem* parent = nullptr) : QQuickItem(parent) { qDebug() << __FUNCTION__; }
|
||||||
qDebug() << __FUNCTION__;
|
|
||||||
}
|
|
||||||
|
|
||||||
~QTestItem() {
|
~QTestItem() { qDebug() << __FUNCTION__; }
|
||||||
qDebug() << __FUNCTION__;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QUrl getTestResource(const QString& relativePath) {
|
QUrl getTestResource(const QString& relativePath) {
|
||||||
|
@ -71,7 +67,6 @@ QUrl getTestResource(const QString& relativePath) {
|
||||||
return QUrl::fromLocalFile(dir + relativePath);
|
return QUrl::fromLocalFile(dir + relativePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define DIVISIONS_X 5
|
#define DIVISIONS_X 5
|
||||||
#define DIVISIONS_Y 5
|
#define DIVISIONS_Y 5
|
||||||
|
|
||||||
|
@ -164,61 +159,41 @@ void TestWindow::resizeWindow(const QSize& size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static const int DEFAULT_MAX_FPS = 10;
|
static const int DEFAULT_MAX_FPS = 10;
|
||||||
static const int YOUTUBE_MAX_FPS = 30;
|
|
||||||
static const QString CONTROL_URL{ "/qml/controls/WebEntityView.qml" };
|
static const QString CONTROL_URL{ "/qml/controls/WebEntityView.qml" };
|
||||||
static const char* URL_PROPERTY{ "url" };
|
static const char* URL_PROPERTY{ "url" };
|
||||||
|
|
||||||
QString getSourceUrl() {
|
QString getSourceUrl(bool video) {
|
||||||
static const std::vector<QString> SOURCE_URLS{
|
static const std::vector<QString> SOURCE_URLS{
|
||||||
"https://www.reddit.com/wiki/random",
|
"https://www.reddit.com/wiki/random",
|
||||||
"https://en.wikipedia.org/wiki/Wikipedia:Random",
|
"https://en.wikipedia.org/wiki/Wikipedia:Random",
|
||||||
"https://slashdot.org/",
|
"https://slashdot.org/",
|
||||||
//"https://www.youtube.com/watch?v=gDXwhHm4GhM",
|
|
||||||
//"https://www.youtube.com/watch?v=Ch_hoYPPeGc",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto index = rand() % SOURCE_URLS.size();
|
static const std::vector<QString> VIDEO_SOURCE_URLS{
|
||||||
return SOURCE_URLS[index];
|
"https://www.youtube.com/watch?v=gDXwhHm4GhM",
|
||||||
|
"https://www.youtube.com/watch?v=Ch_hoYPPeGc",
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto& sourceUrls = video ? VIDEO_SOURCE_URLS : SOURCE_URLS;
|
||||||
|
auto index = rand() % sourceUrls.size();
|
||||||
|
return sourceUrls[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CACHE_WEBVIEWS 0
|
void TestWindow::buildSurface(QmlInfo& qmlInfo, bool video) {
|
||||||
|
|
||||||
#if CACHE_WEBVIEWS
|
|
||||||
static std::list<QmlPtr> _cache;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
hifi::qml::QmlContextObjectCallback callback = [](QQmlContext* context, QQuickItem* item) {
|
|
||||||
item->setProperty(URL_PROPERTY, getSourceUrl());
|
|
||||||
};
|
|
||||||
|
|
||||||
void TestWindow::buildSurface(QmlInfo& qmlInfo, bool allowVideo) {
|
|
||||||
++_surfaceCount;
|
++_surfaceCount;
|
||||||
auto lifetimeSecs = (uint32_t)(5.0f + (randFloat() * 10.0f));
|
auto lifetimeSecs = (uint32_t)(5.0f + (randFloat() * 10.0f));
|
||||||
auto lifetimeUsecs = (USECS_PER_SECOND * lifetimeSecs);
|
auto lifetimeUsecs = (USECS_PER_SECOND * lifetimeSecs);
|
||||||
qmlInfo.lifetime = lifetimeUsecs + usecTimestampNow();
|
qmlInfo.lifetime = lifetimeUsecs + usecTimestampNow();
|
||||||
qmlInfo.texture = 0;
|
qmlInfo.texture = 0;
|
||||||
#if CACHE_WEBVIEWS
|
|
||||||
if (_cache.empty()) {
|
|
||||||
_cache.emplace_back(new hifi::qml::OffscreenSurface());
|
|
||||||
auto& surface = _cache.back();
|
|
||||||
surface->load(getTestResource(CONTROL_URL));
|
|
||||||
surface->setMaxFps(DEFAULT_MAX_FPS);
|
|
||||||
}
|
|
||||||
qmlInfo.surface = _cache.front();
|
|
||||||
_cache.pop_front();
|
|
||||||
#else
|
|
||||||
qmlInfo.surface.reset(new hifi::qml::OffscreenSurface());
|
qmlInfo.surface.reset(new hifi::qml::OffscreenSurface());
|
||||||
qmlInfo.surface->load(getTestResource(CONTROL_URL));
|
qmlInfo.surface->load(getTestResource(CONTROL_URL), [video](QQmlContext* context, QQuickItem* item) {
|
||||||
|
item->setProperty(URL_PROPERTY, getSourceUrl(video));
|
||||||
|
});
|
||||||
qmlInfo.surface->setMaxFps(DEFAULT_MAX_FPS);
|
qmlInfo.surface->setMaxFps(DEFAULT_MAX_FPS);
|
||||||
#endif
|
|
||||||
|
|
||||||
qmlInfo.surface->resize(_qmlSize);
|
qmlInfo.surface->resize(_qmlSize);
|
||||||
auto url = allowVideo ? "https://www.youtube.com/watch?v=gDXwhHm4GhM" : getSourceUrl();
|
|
||||||
qmlInfo.surface->getRootItem()->setProperty(URL_PROPERTY, url);
|
|
||||||
qmlInfo.surface->resume();
|
qmlInfo.surface->resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestWindow::destroySurface(QmlInfo& qmlInfo) {
|
void TestWindow::destroySurface(QmlInfo& qmlInfo) {
|
||||||
auto& surface = qmlInfo.surface;
|
auto& surface = qmlInfo.surface;
|
||||||
auto webView = surface->getRootItem();
|
auto webView = surface->getRootItem();
|
||||||
|
@ -228,9 +203,6 @@ void TestWindow::destroySurface(QmlInfo& qmlInfo) {
|
||||||
webView->setProperty(URL_PROPERTY, "about:blank");
|
webView->setProperty(URL_PROPERTY, "about:blank");
|
||||||
}
|
}
|
||||||
surface->pause();
|
surface->pause();
|
||||||
#if CACHE_WEBVIEWS
|
|
||||||
_cache.push_back(surface);
|
|
||||||
#endif
|
|
||||||
surface.reset();
|
surface.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +268,6 @@ void TestWindow::draw() {
|
||||||
_glf.glViewport(0, 0, size.width(), size.height());
|
_glf.glViewport(0, 0, size.width(), size.height());
|
||||||
_glf.glClearColor(1, 0, 0, 1);
|
_glf.glClearColor(1, 0, 0, 1);
|
||||||
_glf.glClear(GL_COLOR_BUFFER_BIT);
|
_glf.glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
for (uint32_t x = 0; x < DIVISIONS_X; ++x) {
|
for (uint32_t x = 0; x < DIVISIONS_X; ++x) {
|
||||||
for (uint32_t y = 0; y < DIVISIONS_Y; ++y) {
|
for (uint32_t y = 0; y < DIVISIONS_Y; ++y) {
|
||||||
auto& qmlInfo = _surfaces[x][y];
|
auto& qmlInfo = _surfaces[x][y];
|
||||||
|
@ -313,8 +284,6 @@ void TestWindow::draw() {
|
||||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_glf.glFlush();
|
|
||||||
|
|
||||||
_glContext.swapBuffers(this);
|
_glContext.swapBuffers(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,8 +294,7 @@ void TestWindow::resizeEvent(QResizeEvent* ev) {
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
TestWindow window;
|
TestWindow window;
|
||||||
app.exec();
|
return app.exec();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "main.moc"
|
#include "main.moc"
|
||||||
|
|
Loading…
Reference in a new issue