Skip to content

Commit

Permalink
use hardened replacement for topLevelWidgets in interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhendricks committed Mar 3, 2022
1 parent 87b268e commit c529134
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions src/Misc/URLInterceptor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/************************************************************************
**
** Copyright (C) 2020-2021 Kevin B. Hendricks, Stratford, ON, Canada
** Copyright (C) 2020-2022 Kevin B. Hendricks, Stratford, ON, Canada
**
** This file is part of Sigil.
**
Expand Down Expand Up @@ -84,25 +84,28 @@ void URLInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
QString usercssfolder = Utility::DefinePrefsDir() + "/";
QString sourcefolder = sourceurl.toLocalFile();
DBG qDebug() << "sourcefolder: " << sourcefolder;
const QWidgetList topwidgets = qApp->topLevelWidgets();
foreach(QWidget* widget, topwidgets) {
MainWindow * mw = qobject_cast<MainWindow *>(widget);
if (mw) {
QSharedPointer<Book> book = mw->GetCurrentBook();
if (!book.isNull()) {
QString path_to_book = book->GetFolderKeeper()->GetFullPathToMainFolder() + "/";
DBG qDebug() << "path_to_book: " << path_to_book;
QString path_to_mathjax = mw->GetMathJaxFolder();
if (sourcefolder.startsWith(path_to_book)) {
bookfolder = path_to_book;
mathjaxfolder = path_to_mathjax;
DBG qDebug() << "mainwin: " << mw;
DBG qDebug() << "book: " << bookfolder;
DBG qDebug() << "mathjax: " << mathjaxfolder;
DBG qDebug() << "usercss: " << usercssfolder;
DBG qDebug() << "party: " << info.firstPartyUrl();
DBG qDebug() << "source: " << sourcefolder;
break;
// create a topLevelWidgets equivalent to screen out stale QWidgets more safely
const QWidgetList all_widgets = QApplication::allWidgets();
foreach(QWidget* w, all_widgets) {
if (w && w->isWindow() && w->windowType() != Qt::Desktop) {
MainWindow * mw = qobject_cast<MainWindow *>(w);
if (mw) {
QSharedPointer<Book> book = mw->GetCurrentBook();
if (!book.isNull()) {
QString path_to_book = book->GetFolderKeeper()->GetFullPathToMainFolder() + "/";
DBG qDebug() << "path_to_book: " << path_to_book;
QString path_to_mathjax = mw->GetMathJaxFolder();
if (sourcefolder.startsWith(path_to_book)) {
bookfolder = path_to_book;
mathjaxfolder = path_to_mathjax;
DBG qDebug() << "mainwin: " << mw;
DBG qDebug() << "book: " << bookfolder;
DBG qDebug() << "mathjax: " << mathjaxfolder;
DBG qDebug() << "usercss: " << usercssfolder;
DBG qDebug() << "party: " << info.firstPartyUrl();
DBG qDebug() << "source: " << sourcefolder;
break;
}
}
}
}
Expand Down

0 comments on commit c529134

Please sign in to comment.