texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Gavin D. Smith
Date: Wed, 30 Nov 2022 13:36:38 -0500 (EST)

branch: old/qt-info
commit 6486a1d928583f50b74a128d46beaef97b5b5d04
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Thu Apr 11 12:39:53 2019 +0100

    call wc_init from profile scripts
---
 js/docbrowser/mainwindow.cpp | 30 ++++++------------------------
 js/docbrowser/mainwindow.h   |  1 -
 2 files changed, 6 insertions(+), 25 deletions(-)

diff --git a/js/docbrowser/mainwindow.cpp b/js/docbrowser/mainwindow.cpp
index 70a67c10a7..7dd87405f9 100644
--- a/js/docbrowser/mainwindow.cpp
+++ b/js/docbrowser/mainwindow.cpp
@@ -38,9 +38,6 @@ MainWindow::MainWindow(QWidget *parent) :
 
     ui->webEngineView->setPage(page);
 
-    connect(ui->webEngineView->page(), &QWebEnginePage::loadFinished,
-            this, &MainWindow::inject_qwebchannel);
-
     ui->webEngineView->page()->load(QUrl(QString("file:") + this->datadir +
                                     "/test/hello/index.html"));
 }
@@ -73,27 +70,6 @@ MainWindow::setup_channel()
     channel->registerObject(QStringLiteral("core"), core);
 }
 
-/* Load info.js and qwebchannel.js into the current page. */
-void
-MainWindow::inject_qwebchannel(bool finished_ok)
-{
-    if (!finished_ok || ui->webEngineView->url() == QUrl("about:blank"))
-      return;
-
-    qDebug() << "injecting into page" << ui->webEngineView->url();
-
-
-    auto *page = ui->webEngineView->page();
-
-    /* Run the code, and only after that has finished, run the init
-       function.  Qt uses an asynchronous callback system for this.  Check if 
-       wc_init is defined because this slot is activated even for 
"about:blank",
-       the default page. */
-    page->runJavaScript(
-                  "if (typeof wc_init == 'function') { wc_init(); }",
-                   0 );
-}
-
 QString
 MainWindow::inject_js_file (const QString &filename, QWebEngineProfile 
*profile)
 {
@@ -162,6 +138,12 @@ MainWindow::setup_profile (QWebEngineProfile *profile)
     profile->scripts()->insert(s);
     /* This needs to run after the <head> element is accessible, but before
        the DOMContentLoaded event handlers in info.js fire. */
+
+    QWebEngineScript s2;
+    s2.setSourceCode("if (typeof wc_init == 'function') { wc_init(); }");
+    s2.setInjectionPoint(QWebEngineScript::DocumentCreation);
+    s2.setWorldId(QWebEngineScript::MainWorld);
+    profile->scripts()->insert(s2);
 }
 
 
diff --git a/js/docbrowser/mainwindow.h b/js/docbrowser/mainwindow.h
index c535a26afe..464fd82a67 100644
--- a/js/docbrowser/mainwindow.h
+++ b/js/docbrowser/mainwindow.h
@@ -38,7 +38,6 @@ private:
     char *datadir;
 
     void quit();
-    void inject_qwebchannel(bool ok);
     QString inject_js_file(const QString &filename, QWebEngineProfile 
*profile);
     void setup_profile(QWebEngineProfile *profile);
     void setup_channel();



reply via email to

[Prev in Thread] Current Thread [Next in Thread]