Skip to content

Commit 1e11faa

Browse files
committed
Plugins::WebBrowser: QWebEngineProfile must be destruct
1 parent f5ccf0c commit 1e11faa

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

Plugins/WebBrowser/FrmWebBrowser.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#endif
1717
#include <QLoggingCategory>
1818

19-
static QScopedPointer<QWebEngineProfile> g_profile;
2019
static Q_LOGGING_CATEGORY(log, "WebBrowser.Browser")
2120
CFrmWebBrowser::CFrmWebBrowser(CParameterWebBrowser *pPara, QWidget *parent)
2221
: QWidget{parent}
@@ -309,40 +308,42 @@ void CFrmWebBrowser::SetConnect(CFrmWebView* pWeb)
309308

310309
QWebEngineProfile* CFrmWebBrowser::GetProfile(bool offTheRecord)
311310
{
312-
if (!offTheRecord && !g_profile) {
311+
if(offTheRecord)
312+
return QWebEngineProfile::defaultProfile();
313+
if(m_profile)
314+
return m_profile.get();
313315

314316
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
315-
const QString name = "io.github.KangLin.RabbitRemoteControl."
316-
+ QLatin1StringView(qWebEngineChromiumVersion());
317-
QWebEngineProfileBuilder profileBuilder;
318-
g_profile.reset(profileBuilder.createProfile(name));
317+
const QString name = "io.github.KangLin.RabbitRemoteControl."
318+
+ QLatin1StringView(qWebEngineChromiumVersion());
319+
QWebEngineProfileBuilder profileBuilder;
320+
m_profile.reset(profileBuilder.createProfile(name));
319321
#else
320-
const QString name = "io.github.KangLin.RabbitRemoteControl";
321-
g_profile.reset(new QWebEngineProfile(name));
322+
const QString name = "io.github.KangLin.RabbitRemoteControl";
323+
g_profile.reset(new QWebEngineProfile(name));
322324
#endif
323-
if(!g_profile)
324-
return QWebEngineProfile::defaultProfile();
325-
326-
g_profile->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
327-
g_profile->settings()->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, true);
328-
g_profile->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
329-
g_profile->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, false);
330-
g_profile->settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, true);
331-
g_profile->settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
332-
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
333-
g_profile->settings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false);
334-
#endif
335-
bool check = connect(g_profile.get(), &QWebEngineProfile::downloadRequested,
336-
&m_DownloadManager, &CFrmDownloadManager::slotDownloadRequested);
337-
Q_ASSERT(check);
338-
qDebug(log) << "User agent:" << g_profile->httpUserAgent()
339-
<< "Persistent path:" << g_profile->persistentStoragePath()
340-
<< "Cache path:" << g_profile->cachePath()
341-
<< "Storage name:" << g_profile->storageName()
342-
<< "Is off the Record:" << g_profile->isOffTheRecord()
343-
<< "Download:" << g_profile->downloadPath();
344-
}
345-
return offTheRecord ? QWebEngineProfile::defaultProfile() : g_profile.get();
325+
if(!m_profile)
326+
return QWebEngineProfile::defaultProfile();
327+
328+
m_profile->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
329+
m_profile->settings()->setAttribute(QWebEngineSettings::DnsPrefetchEnabled, true);
330+
m_profile->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
331+
m_profile->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, false);
332+
m_profile->settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, true);
333+
m_profile->settings()->setAttribute(QWebEngineSettings::FullScreenSupportEnabled, true);
334+
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
335+
m_profile->settings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false);
336+
#endif
337+
bool check = connect(m_profile.get(), &QWebEngineProfile::downloadRequested,
338+
&m_DownloadManager, &CFrmDownloadManager::slotDownloadRequested);
339+
Q_ASSERT(check);
340+
qDebug(log) << "User agent:" << m_profile->httpUserAgent()
341+
<< "Persistent path:" << m_profile->persistentStoragePath()
342+
<< "Cache path:" << m_profile->cachePath()
343+
<< "Storage name:" << m_profile->storageName()
344+
<< "Is off the Record:" << m_profile->isOffTheRecord()
345+
<< "Download:" << m_profile->downloadPath();
346+
return m_profile.get();
346347
}
347348

348349
CFrmWebView *CFrmWebBrowser::CreateWebView(bool offTheRecord)

Plugins/WebBrowser/FrmWebBrowser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ private Q_SLOTS:
8080
QLineEdit* m_pUrlLineEdit;
8181
QProgressBar* m_pProgressBar;
8282
QTabWidget* m_pTab;
83+
QScopedPointer<QWebEngineProfile> m_profile;
8384
CFrmDownloadManager m_DownloadManager;
8485
QString m_szFindText;
8586
};

0 commit comments

Comments
 (0)