feature:webengineprofile use non off record profile

This commit is contained in:
Xiao YiFang 2023-03-25 20:10:28 +08:00 committed by xiaoyifang
parent da406e1e02
commit e84b5aa861
5 changed files with 33 additions and 29 deletions

View file

@ -1,8 +1,9 @@
#include "articlewebpage.h"
#include "utils.hh"
#include "globalbroadcaster.h"
ArticleWebPage::ArticleWebPage(QObject *parent)
: QWebEnginePage{parent}
ArticleWebPage::ArticleWebPage( QObject * parent ):
QWebEnginePage{ GlobalBroadcaster::instance()->profile, parent }
{
}
bool ArticleWebPage::acceptNavigationRequest( const QUrl & resUrl, NavigationType type, bool isMainFrame )

View file

@ -3,6 +3,7 @@
#include <QObject>
#include <vector>
#include <QWebEngineProfile>
#include "config.hh"
struct ActiveDictIds
@ -27,6 +28,7 @@ public:
static GlobalBroadcaster * instance();
unsigned currentGroupId;
QString translateLineText{};
QWebEngineProfile * profile;
signals:
void dictionaryChanges( ActiveDictIds ad );

View file

@ -97,12 +97,11 @@ void MainWindow::changeWebEngineViewFont()
{
if( cfg.preferences.webFontFamily.isEmpty() )
{
QWebEngineProfile::defaultProfile()->settings()->resetFontFamily( QWebEngineSettings::StandardFont );
webEngineProfile->settings()->resetFontFamily( QWebEngineSettings::StandardFont );
}
else
{
QWebEngineProfile::defaultProfile()->settings()->setFontFamily( QWebEngineSettings::StandardFont,
cfg.preferences.webFontFamily );
webEngineProfile->settings()->setFontFamily( QWebEngineSettings::StandardFont, cfg.preferences.webFontFamily );
}
}
@ -154,28 +153,28 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
QThreadPool::globalInstance()->start( new InitSSLRunnable );
#endif
GlobalBroadcaster::instance()->setPreference(&cfg.preferences);
GlobalBroadcaster::instance()->setPreference( &cfg.preferences );
localSchemeHandler = new LocalSchemeHandler( articleNetMgr, this);
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "gdlookup", localSchemeHandler );
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "bword", localSchemeHandler );
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "entry", localSchemeHandler );
webEngineProfile.reset( new QWebEngineProfile( "GoldenDictProfile" ) );
GlobalBroadcaster::instance()->profile = webEngineProfile.get();
localSchemeHandler = new LocalSchemeHandler( articleNetMgr, this );
webEngineProfile->installUrlSchemeHandler( "gdlookup", localSchemeHandler );
webEngineProfile->installUrlSchemeHandler( "bword", localSchemeHandler );
webEngineProfile->installUrlSchemeHandler( "entry", localSchemeHandler );
iframeSchemeHandler = new IframeSchemeHandler( this );
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( "ifr", iframeSchemeHandler );
webEngineProfile->installUrlSchemeHandler( "ifr", iframeSchemeHandler );
QStringList localSchemes = { "gdau", "gico", "qrcx", "bres", "gdprg", "gdvideo", "gdpicture", "gdtts" };
resourceSchemeHandler = new ResourceSchemeHandler( articleNetMgr, this);
for( int i = 0; i < localSchemes.size(); i++ )
{
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler( localSchemes.at( i ).toLatin1(),
resourceSchemeHandler );
resourceSchemeHandler = new ResourceSchemeHandler( articleNetMgr, this );
for( const auto & localScheme : localSchemes ) {
webEngineProfile->installUrlSchemeHandler( localScheme.toLatin1(), resourceSchemeHandler );
}
QWebEngineProfile::defaultProfile()->setUrlRequestInterceptor( new WebUrlRequestInterceptor(this) );
webEngineProfile->setUrlRequestInterceptor( new WebUrlRequestInterceptor( this ) );
if(!cfg.preferences.hideGoldenDictHeader){
QWebEngineProfile::defaultProfile()->setHttpUserAgent(QWebEngineProfile::defaultProfile()->httpUserAgent()+" GoldenDict/WebEngine");
if( !cfg.preferences.hideGoldenDictHeader ) {
webEngineProfile->setHttpUserAgent( webEngineProfile->httpUserAgent() + " GoldenDict/WebEngine" );
}
qRegisterMetaType< Config::InputPhrase >();
@ -1416,8 +1415,7 @@ void MainWindow::setupNetworkCache( int maxSize )
return; // There is currently no cache and it is not needed.
QString const cacheDirectory = Config::getNetworkCacheDir();
if( !QDir().mkpath( cacheDirectory ) )
{
if( !QDir().mkpath( cacheDirectory ) ) {
gdWarning( "Cannot create a cache directory %s. Disabling network cache.", cacheDirectory.toUtf8().constData() );
return;
}
@ -1425,6 +1423,9 @@ void MainWindow::setupNetworkCache( int maxSize )
diskCache->setMaximumCacheSize( maxCacheSizeInBytes );
diskCache->setCacheDirectory( cacheDirectory );
articleNetMgr.setCache( diskCache );
webEngineProfile->setCachePath( cacheDirectory );
webEngineProfile->setPersistentStoragePath( cacheDirectory );
}
void MainWindow::makeDictionaries()

View file

@ -136,7 +136,7 @@ private:
History history;
DictionaryBar dictionaryBar;
vector< sptr< Dictionary::Class > > dictionaries;
QMap<std::string, sptr< Dictionary::Class > > dictMap;
QMap< std::string, sptr< Dictionary::Class > > dictMap;
/// Here we store unmuted dictionaries when the dictionary bar is active
vector< sptr< Dictionary::Class > > dictionariesUnmuted;
Instances::Groups groupInstances;
@ -145,6 +145,9 @@ private:
QNetworkAccessManager dictNetMgr; // We give dictionaries a separate manager,
// since their requests can be destroyed
// in a separate thread
QScopedPointer< QWebEngineProfile > webEngineProfile;
AudioPlayerFactory audioPlayerFactory;
WordList * wordList;

View file

@ -657,14 +657,11 @@ void Preferences::on_buttonBox_accepted()
if( prevWebFontFamily != currentFontFamily )
{
//reset to default font .
if( currentFontFamily.isEmpty() )
{
QWebEngineProfile::defaultProfile()->settings()->resetFontFamily( QWebEngineSettings::StandardFont );
if( currentFontFamily.isEmpty() ) {
GlobalBroadcaster::instance()->profile->settings()->resetFontFamily( QWebEngineSettings::StandardFont );
}
else
{
QWebEngineProfile::defaultProfile()->settings()->setFontFamily( QWebEngineSettings::StandardFont,
currentFontFamily );
else {
GlobalBroadcaster::instance()->profile->settings()->setFontFamily( QWebEngineSettings::StandardFont, currentFontFamily );
}
}
}