mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
feature:webengineprofile use non off record profile
This commit is contained in:
parent
da406e1e02
commit
e84b5aa861
|
@ -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 )
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue