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

Scripts: Register window.external to all frames

It seems that only one QWebChannel connection per page
is supported, so we need to forward window.external to
all subframes.
This commit is contained in:
David Rosca 2015-08-31 12:28:44 +02:00
parent fa2779e6b9
commit 19f1ed6bfb
2 changed files with 16 additions and 4 deletions

View File

@ -459,7 +459,7 @@ function init()
if (window.external) { if (window.external) {
init(); init();
} else { } else {
document.addEventListener('qz_external_created', init); document.addEventListener('_qupzilla_external_created', init);
} }
</script> </script>

View File

@ -25,12 +25,24 @@ QString Scripts::setupWebChannel()
{ {
QString source = QL1S("(function() {" QString source = QL1S("(function() {"
"%1" "%1"
"new QWebChannel(qt.webChannelTransport, function(channel) {" "function registerExternal(e) {"
" window.external = channel.objects.qz_object;" " window.external = e;"
" if (window.external) {" " if (window.external) {"
" var event = new Event('qz_external_created');" " var event = new Event('_qupzilla_external_created');"
" document.dispatchEvent(event);" " document.dispatchEvent(event);"
" }" " }"
"}"
"if (self !== top) {"
" if (top.external)"
" registerExternal(top.external);"
" else"
" top.document.addEventListener('_qupzilla_external_created', function() {"
" registerExternal(top.external);"
" });"
" return;"
"}"
"new QWebChannel(qt.webChannelTransport, function(channel) {"
" registerExternal(channel.objects.qz_object);"
"});" "});"
"})()"); "})()");