3fdc1527951a5bd3b07838ff4c6f38c3e5d4c6d5
[gentoo.git] / kde-apps / messagelib / files / messagelib-18.12.3-qtwebengine-5.12.3.patch
1 From 9f0ce086c6a4e487cee1f01acb15290ebff19ac3 Mon Sep 17 00:00:00 2001
2 From: Jonathan Marten <jjm@keelhaul.me.uk>
3 Date: Tue, 12 Mar 2019 08:47:43 +0000
4 Subject: Move management of QWebEngineProfile to WebEnginePage
5
6 To avoid a crash on KMail quit or viewer window close, caused by the
7 MailWebEnginePage being deleted while its QWebEngineProfile is still
8 active.  Simplified management of the profile by handling its creation
9 and deletion within WebEnginePage.
10
11 Deprecate the 2-argument WebEnginePage constructor which allows an
12 already allocated profile to be used.  This constructor is used by
13 Akregator which specifies the global profile; it will be changed to
14 use a private profile instead.
15
16 Differential Revision: https://phabricator.kde.org/D19559
17 ---
18  .../src/viewer/webengine/mailwebenginepage.cpp     | 10 -------
19  .../src/viewer/webengine/mailwebenginepage.h       |  3 +-
20  .../src/viewer/webengine/mailwebengineview.cpp     |  3 +-
21  webengineviewer/src/webenginepage.cpp              | 22 ++++++++++----
22  webengineviewer/src/webenginepage.h                | 35 ++++++++++++++++++++--
23  5 files changed, 52 insertions(+), 21 deletions(-)
24
25 diff --git a/messageviewer/src/viewer/webengine/mailwebenginepage.cpp b/messageviewer/src/viewer/webengine/mailwebenginepage.cpp
26 index cd91494..f3790b9 100644
27 --- a/messageviewer/src/viewer/webengine/mailwebenginepage.cpp
28 +++ b/messageviewer/src/viewer/webengine/mailwebenginepage.cpp
29 @@ -29,16 +29,6 @@ MailWebEnginePage::MailWebEnginePage(QObject *parent)
30      initialize();
31  }
32  
33 -MailWebEnginePage::MailWebEnginePage(QWebEngineProfile *profile, QObject *parent)
34 -    : WebEngineViewer::WebEnginePage(profile, parent)
35 -{
36 -    initialize();
37 -}
38 -
39 -MailWebEnginePage::~MailWebEnginePage()
40 -{
41 -}
42 -
43  void MailWebEnginePage::initialize()
44  {
45      settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
46 diff --git a/messageviewer/src/viewer/webengine/mailwebenginepage.h b/messageviewer/src/viewer/webengine/mailwebenginepage.h
47 index 7f8e6eb..d581efd 100644
48 --- a/messageviewer/src/viewer/webengine/mailwebenginepage.h
49 +++ b/messageviewer/src/viewer/webengine/mailwebenginepage.h
50 @@ -28,8 +28,7 @@ class MESSAGEVIEWER_EXPORT MailWebEnginePage : public WebEngineViewer::WebEngine
51      Q_OBJECT
52  public:
53      explicit MailWebEnginePage(QObject *parent = nullptr);
54 -    explicit MailWebEnginePage(QWebEngineProfile *profile, QObject *parent = nullptr);
55 -    ~MailWebEnginePage();
56 +    virtual ~MailWebEnginePage() = default;
57  
58      void setPrintElementBackground(bool printElementBackground);
59  
60 diff --git a/messageviewer/src/viewer/webengine/mailwebengineview.cpp b/messageviewer/src/viewer/webengine/mailwebengineview.cpp
61 index 0685a8d..09224cf 100644
62 --- a/messageviewer/src/viewer/webengine/mailwebengineview.cpp
63 +++ b/messageviewer/src/viewer/webengine/mailwebengineview.cpp
64 @@ -34,7 +34,6 @@
65  #include <QContextMenuEvent>
66  #include <WebEngineViewer/WebHitTest>
67  
68 -#include <QWebEngineProfile>
69  #include <QPrinter>
70  
71  #include <WebEngineViewer/WebHitTestResult>
72 @@ -81,7 +80,7 @@ MailWebEngineView::MailWebEngineView(KActionCollection *ac, QWidget *parent)
73      : WebEngineViewer::WebEngineView(parent)
74      , d(new MessageViewer::MailWebEngineViewPrivate)
75  {
76 -    d->mPageEngine = new MailWebEnginePage(new QWebEngineProfile(this), this);
77 +    d->mPageEngine = new MailWebEnginePage(this);
78      setPage(d->mPageEngine);
79      d->mWebViewAccessKey = new WebEngineViewer::WebEngineAccessKey(this, this);
80      d->mWebViewAccessKey->setActionCollection(ac);
81 diff --git a/webengineviewer/src/webenginepage.cpp b/webengineviewer/src/webenginepage.cpp
82 index 447ac26..2fcb6c2 100644
83 --- a/webengineviewer/src/webenginepage.cpp
84 +++ b/webengineviewer/src/webenginepage.cpp
85 @@ -33,8 +33,24 @@
86  using namespace WebEngineViewer;
87  
88  WebEnginePage::WebEnginePage(QObject *parent)
89 -    : QWebEnginePage(parent)
90 +    : QWebEnginePage(new QWebEngineProfile, parent)
91  {
92 +    // Create a private (off the record) QWebEngineProfile here to isolate the
93 +    // browsing settings, and adopt it as a child so that it will be deleted
94 +    // when we are destroyed.  The profile must remain active for as long as
95 +    // any QWebEnginePage's belonging to it exist, see the API documentation
96 +    // of QWebEnginePage::QWebEnginePage(QWebEngineProfile *, QObject *).
97 +    // Deleting it as our child on destruction is safe.
98 +    //
99 +    // Do not try to save a line of code by setting the parent on construction:
100 +    //
101 +    //    WebEnginePage::WebEnginePage(QObject *parent)
102 +    //      : QWebEnginePage(new QWebEngineProfile(this), parent)
103 +    //
104 +    // because the QWebEngineProfile constructor will call out to the QWebEnginePage
105 +    // and crash because the QWebEnginePage is not fully constructed yet.
106 +    profile()->setParent(this);
107 +
108      init();
109  }
110  
111 @@ -44,10 +60,6 @@ WebEnginePage::WebEnginePage(QWebEngineProfile *profile, QObject *parent)
112      init();
113  }
114  
115 -WebEnginePage::~WebEnginePage()
116 -{
117 -}
118 -
119  void WebEnginePage::init()
120  {
121      connect(profile(), &QWebEngineProfile::downloadRequested, this, &WebEnginePage::saveHtml);
122 diff --git a/webengineviewer/src/webenginepage.h b/webengineviewer/src/webenginepage.h
123 index be38368..95c7c76 100644
124 --- a/webengineviewer/src/webenginepage.h
125 +++ b/webengineviewer/src/webenginepage.h
126 @@ -31,10 +31,41 @@ class WEBENGINEVIEWER_EXPORT WebEnginePage : public QWebEnginePage
127  {
128      Q_OBJECT
129  public:
130 +    /**
131 +     * Constructor.
132 +     *
133 +     * A private QWebEngineProfile, only applying to this QWebEnginePage,
134 +     * will be created to implement browser settings.  It can be accessed via
135 +     * @c profile(), but it should not be shared or reused unless care is
136 +     * taken that the profile is not deleted until all of the QWebEnginePage's
137 +     * belonging to it are deleted first.
138 +     *
139 +     * @param parent The parent object
140 +     **/
141      explicit WebEnginePage(QObject *parent = nullptr);
142 -    explicit WebEnginePage(QWebEngineProfile *profile, QObject *parent = nullptr);
143  
144 -    ~WebEnginePage() override;
145 +    /**
146 +     * Constructor.
147 +     *
148 +     * The specified QWebEngineProfile will be used.  See the description of
149 +     * @c WebEnginePage(QObject *) and the API documentation of QWebEnginePage
150 +     * for caution regarding the lifetime of the profile.
151 +     *
152 +     * @param profile The profile to be used
153 +     * @param parent The parent object
154 +     * @deprecated Use the single argument constructor, which creates and uses
155 +     * a private profile.
156 +     **/
157 +#ifndef WEBENGINEVIEWER_NO_DEPRECATED
158 +    explicit WEBENGINEVIEWER_DEPRECATED WebEnginePage(QWebEngineProfile *profile, QObject *parent = nullptr);
159 +#endif
160 +
161 +    /**
162 +     * Destructor.  If there is a private QWebEngineProfile then it will also
163 +     * be destroyed.
164 +     **/
165 +    virtual ~WebEnginePage() override = default;
166 +
167      WebEngineViewer::WebHitTest *hitTestContent(const QPoint &pos);
168  
169      void saveHtml(QWebEngineDownloadItem *download);
170 -- 
171 cgit v1.1
172