fix: resource scheme handler received finished signal twice,more likely to crash the webengine.

This commit is contained in:
xiaoyifang 2022-01-09 09:52:40 +08:00
parent f16107e072
commit bd6cc8b9c9
7 changed files with 40 additions and 34 deletions

View file

@ -438,8 +438,6 @@ ArticleResourceReply::ArticleResourceReply( QObject * parent,
{ {
connect( this, SIGNAL( readyReadSignal() ), connect( this, SIGNAL( readyReadSignal() ),
this, SLOT( readyReadSlot() ), Qt::QueuedConnection ); this, SLOT( readyReadSlot() ), Qt::QueuedConnection );
connect( this, SIGNAL( finishedSignal() ),
this, SLOT( finishedSlot() ), Qt::QueuedConnection );
emit readyReadSignal(); emit readyReadSignal();
@ -448,6 +446,10 @@ ArticleResourceReply::ArticleResourceReply( QObject * parent,
emit finishedSignal(); emit finishedSignal();
GD_DPRINTF( "In-place finish.\n" ); GD_DPRINTF( "In-place finish.\n" );
} }
else{
connect( this, SIGNAL( finishedSignal() ),
this, SLOT( finishedSlot() ), Qt::QueuedConnection );
}
} }
} }

View file

@ -1,20 +0,0 @@
#ifndef GICO_SCHEMAHANDLER_H
#define GICO_SCHEMAHANDLER_H
#include"article_netmgr.hh"
class GicoSchemeHandler : public QWebEngineUrlSchemeHandler
{
Q_OBJECT
public:
GicoSchemeHandler(ArticleNetworkAccessManager& articleNetMgr);
void requestStarted(QWebEngineUrlRequestJob *requestJob);
protected:
private:
ArticleNetworkAccessManager& mManager;
QMimeDatabase db;
};
#endif // GICO_SCHEMAHANDLER_H

View file

@ -247,11 +247,11 @@ DEFINES += PROGRAM_VERSION=\\\"$$VERSION\\\"
# Input # Input
HEADERS += folding.hh \ HEADERS += folding.hh \
gico_schemahandler.h \
globalbroadcaster.h \ globalbroadcaster.h \
inc_case_folding.hh \ inc_case_folding.hh \
inc_diacritic_folding.hh \ inc_diacritic_folding.hh \
mainwindow.hh \ mainwindow.hh \
resourceschemehandler.h \
sptr.hh \ sptr.hh \
dictionary.hh \ dictionary.hh \
ex.hh \ ex.hh \
@ -388,11 +388,11 @@ FORMS += groups.ui \
fulltextsearch.ui fulltextsearch.ui
SOURCES += folding.cc \ SOURCES += folding.cc \
gico_schemahandler.cpp \
globalbroadcaster.cpp \ globalbroadcaster.cpp \
main.cc \ main.cc \
dictionary.cc \ dictionary.cc \
config.cc \ config.cc \
resourceschemehandler.cpp \
sources.cc \ sources.cc \
mainwindow.cc \ mainwindow.cc \
utf8.cc \ utf8.cc \

View file

@ -48,7 +48,7 @@
#include "utils.hh" #include "utils.hh"
#include <QDesktopWidget> #include <QDesktopWidget>
#include "ui_authentication.h" #include "ui_authentication.h"
#include "gico_schemahandler.h" #include "resourceschemehandler.h"
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include "lionsupport.h" #include "lionsupport.h"
@ -146,14 +146,14 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
#endif #endif
LocalSchemeHandler *handler = new LocalSchemeHandler(articleNetMgr); localSchemeHandler = new LocalSchemeHandler(articleNetMgr);
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", handler); QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", localSchemeHandler);
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("bword", handler); QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("bword", localSchemeHandler);
QStringList localSchemes={"gdau","gico","qrcx","bres","gdprg","gdvideo","gdpicture","gdtts"}; QStringList localSchemes={"gdau","gico","qrcx","bres","gdprg","gdvideo","gdpicture","gdtts"};
GicoSchemeHandler *h=new GicoSchemeHandler(articleNetMgr); resourceSchemeHandler = new ResourceSchemeHandler(articleNetMgr);
for(int i=0;i<localSchemes.size();i++){ for(int i=0;i<localSchemes.size();i++){
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(localSchemes.at(i).toLatin1(), h); QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(localSchemes.at(i).toLatin1(), resourceSchemeHandler);
} }
wuri = new WebUrlRequestInterceptor(); wuri = new WebUrlRequestInterceptor();

View file

@ -33,6 +33,7 @@
#include "hotkeywrapper.hh" #include "hotkeywrapper.hh"
#include "weburlrequestinterceptor.h" #include "weburlrequestinterceptor.h"
#include "resourceschemehandler.h"
#ifdef HAVE_X11 #ifdef HAVE_X11
#include <fixx11h.h> #include <fixx11h.h>
#endif #endif
@ -194,6 +195,9 @@ private:
QIcon starIcon, blueStarIcon; QIcon starIcon, blueStarIcon;
LocalSchemeHandler *localSchemeHandler;
ResourceSchemeHandler *resourceSchemeHandler;
/// Applies the qt's stylesheet, given the style's name. /// Applies the qt's stylesheet, given the style's name.
void applyQtStyleSheet( QString const & displayStyle, QString const & addonStyle ); void applyQtStyleSheet( QString const & displayStyle, QString const & addonStyle );

View file

@ -1,9 +1,9 @@
#include "gico_schemahandler.h" #include "resourceschemehandler.h"
GicoSchemeHandler::GicoSchemeHandler(ArticleNetworkAccessManager& articleNetMgr):mManager(articleNetMgr){ ResourceSchemeHandler::ResourceSchemeHandler(ArticleNetworkAccessManager& articleNetMgr):mManager(articleNetMgr){
} }
void GicoSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) void ResourceSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
{ {
QUrl url = requestJob->requestUrl(); QUrl url = requestJob->requestUrl();
@ -17,7 +17,7 @@ void GicoSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
requestJob->fail(QWebEngineUrlRequestJob::UrlNotFound); requestJob->fail(QWebEngineUrlRequestJob::UrlNotFound);
return; return;
} }
qDebug() << "resource scheme handler receive finished signal:" << reply->request().url();
QMimeType mineType = db.mimeTypeForUrl(url); QMimeType mineType = db.mimeTypeForUrl(url);
QString contentType = mineType.name(); QString contentType = mineType.name();
// Reply segment // Reply segment

20
resourceschemehandler.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef RESOURCESCHEMEHANDLER_H
#define RESOURCESCHEMEHANDLER_H
#include"article_netmgr.hh"
class ResourceSchemeHandler : public QWebEngineUrlSchemeHandler
{
Q_OBJECT
public:
ResourceSchemeHandler(ArticleNetworkAccessManager& articleNetMgr);
void requestStarted(QWebEngineUrlRequestJob *requestJob);
protected:
private:
ArticleNetworkAccessManager& mManager;
QMimeDatabase db;
};
#endif // RESOURCESCHEMEHANDLER_H