summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill Burtsev <kirill.burtsev@qt.io>2019-04-10 18:27:31 +0200
committerKirill Burtsev <kirill.burtsev@qt.io>2019-04-23 14:09:11 +0000
commit5f81848067f2142b7c78d6ca758c9efc5c1ab1d8 (patch)
tree7f03ce8097c3b5fcf175b8c4e4df7a5b60ae4f46
parentc6fb532d81f405b2456c382aa0b29eef8866f993 (diff)
Simple browser example: create off-the-record profile in a lazy manner
Do not create multiple profiles immediately on start. Allows to start and run browser with default profile with 'single-process' flag. Change-Id: Idea7da8167152f718a3c2d4086ad4216d8e1b722 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
-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 /^\}/