summaryrefslogtreecommitdiffstats
path: root/examples/webenginewidgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/webenginewidgets')
-rw-r--r--examples/webenginewidgets/simplebrowser/browser.cpp13
-rw-r--r--examples/webenginewidgets/simplebrowser/browser.h2
-rw-r--r--examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc23
3 files changed, 24 insertions, 14 deletions
diff --git a/examples/webenginewidgets/simplebrowser/browser.cpp b/examples/webenginewidgets/simplebrowser/browser.cpp
index 5c6dbd35e..68458b2a4 100644
--- a/examples/webenginewidgets/simplebrowser/browser.cpp
+++ b/examples/webenginewidgets/simplebrowser/browser.cpp
@@ -51,8 +51,6 @@
#include "browser.h"
#include "browserwindow.h"
-#include <QWebEngineProfile>
-
Browser::Browser()
{
// Quit application if the download manager window is the only remaining window
@@ -61,14 +59,17 @@ Browser::Browser()
QObject::connect(
QWebEngineProfile::defaultProfile(), &QWebEngineProfile::downloadRequested,
&m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
- QObject::connect(
- &m_otrProfile, &QWebEngineProfile::downloadRequested,
- &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
}
BrowserWindow *Browser::createWindow(bool offTheRecord)
{
- auto profile = offTheRecord ? &m_otrProfile : QWebEngineProfile::defaultProfile();
+ if (offTheRecord && !m_otrProfile) {
+ m_otrProfile.reset(new QWebEngineProfile);
+ QObject::connect(
+ m_otrProfile.get(), &QWebEngineProfile::downloadRequested,
+ &m_downloadManagerWidget, &DownloadManagerWidget::downloadRequested);
+ }
+ auto profile = offTheRecord ? m_otrProfile.get() : QWebEngineProfile::defaultProfile();
auto mainWindow = new BrowserWindow(this, profile, false);
m_windows.append(mainWindow);
QObject::connect(mainWindow, &QObject::destroyed, [this, mainWindow]() {
diff --git a/examples/webenginewidgets/simplebrowser/browser.h b/examples/webenginewidgets/simplebrowser/browser.h
index fbc8465d2..4c17121df 100644
--- a/examples/webenginewidgets/simplebrowser/browser.h
+++ b/examples/webenginewidgets/simplebrowser/browser.h
@@ -73,6 +73,6 @@ public:
private:
QVector<BrowserWindow*> m_windows;
DownloadManagerWidget m_downloadManagerWidget;
- QWebEngineProfile m_otrProfile;
+ QScopedPointer<QWebEngineProfile> m_otrProfile;
};
#endif // BROWSER_H
diff --git a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
index b5ad13626..251ca5ad8 100644
--- a/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
+++ b/examples/webenginewidgets/simplebrowser/doc/src/simplebrowser.qdoc
@@ -270,7 +270,7 @@
Implementing private browsing is quite easy using \QWE. All one has
to do is to create a new \l{QWebEngineProfile} and use it in the
\l{QWebEnginePage} instead of the default profile. In the example this new
- profile is created and owned by the \c Browser object:
+ profile is owned by the \c Browser object:
\quotefromfile webenginewidgets/simplebrowser/browser.h
\skipto /^class Browser$/
@@ -285,15 +285,24 @@
\printline m_otrProfile
\printline /^\};$/
- The default constructor for \l{QWebEngineProfile} already puts it in
- \e{off-the-record} mode. All that is left to do is to pass the appropriate
- profile down to the appropriate \l QWebEnginePage objects. The \c Browser
- object will hand to each new \c BrowserWindow either the global default
- profile (see \l{QWebEngineProfile::defaultProfile}) or its own
- off-the-record profile:
+ Required profile for \e{private browsing} is created together with its
+ first window. The default constructor for \l{QWebEngineProfile} already
+ puts it in \e{off-the-record} mode.
\quotefromfile webenginewidgets/simplebrowser/browser.cpp
+
\skipto Browser::createWindow
+ \printuntil m_otrProfile.reset
+ \dots
+
+ All that is left to do is to pass the appropriate profile down to the
+ appropriate \l QWebEnginePage objects. The \c Browser object will hand to
+ each new \c BrowserWindow either the global default profile
+ (see \l{QWebEngineProfile::defaultProfile}) or one shared
+ \e{off-the-record} profile instance:
+
+ \dots
+ \skipto m_otrProfile.get
\printuntil mainWindow = new BrowserWindow
\skipto return mainWindow
\printuntil /^\}/