1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

WebPage: Workaround changing webchannel world not sometimes working

Closes #2577
This commit is contained in:
David Rosca 2018-02-07 10:25:55 +01:00
parent 4caab39269
commit 7bd3b3d5af
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 21 additions and 6 deletions

View File

@ -73,8 +73,6 @@ WebPage::WebPage(QObject* parent)
, m_blockAlerts(false)
, m_secureStatus(false)
{
setupWebChannelForUrl(QUrl());
connect(this, &QWebEnginePage::loadProgress, this, &WebPage::progress);
connect(this, &QWebEnginePage::loadFinished, this, &WebPage::finished);
connect(this, &QWebEnginePage::urlChanged, this, &WebPage::urlChanged);
@ -109,6 +107,14 @@ WebPage::WebPage(QObject* parent)
}
});
}
// Workaround for changing webchannel world inside acceptNavigationRequest not working
m_setupChannelTimer = new QTimer(this);
m_setupChannelTimer->setSingleShot(true);
m_setupChannelTimer->setInterval(100);
connect(m_setupChannelTimer, &QTimer::timeout, this, [this]() {
setupWebChannelForUrl(m_channelUrl);
});
}
WebPage::~WebPage()
@ -377,10 +383,15 @@ void WebPage::setupWebChannelForUrl(const QUrl &url)
channel = new QWebChannel(this);
ExternalJsObject::setupWebChannel(channel, this);
}
int worldId = -1;
if (url.scheme() == QL1S("falkon") || url.scheme() == QL1S("extension")) {
setWebChannel(channel, UnsafeJsWorld);
worldId = UnsafeJsWorld;
} else {
setWebChannel(channel, SafeJsWorld);
worldId = SafeJsWorld;
}
if (worldId != m_channelWorldId) {
m_channelWorldId = worldId;
setWebChannel(channel, m_channelWorldId);
}
}
@ -407,8 +418,8 @@ bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::Navigatio
const bool isWeb = url.scheme() == QL1S("http") || url.scheme() == QL1S("https") || url.scheme() == QL1S("file");
const bool globalJsEnabled = mApp->webSettings()->testAttribute(QWebEngineSettings::JavascriptEnabled);
settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, isWeb ? globalJsEnabled : true);
setupWebChannelForUrl(url);
m_channelUrl = url;
m_setupChannelTimer->start();
}
emit navigationRequestAccepted(url, type, isMainFrame);
}

View File

@ -109,6 +109,10 @@ private:
QMetaObject::Connection m_contentsResizedConnection;
QUrl m_channelUrl;
int m_channelWorldId = -1;
QTimer *m_setupChannelTimer = nullptr;
friend class WebView;
};