1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWebEngine module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 //
41 // W A R N I N G
42 // -------------
43 //
44 // This file is not part of the Qt API. It exists purely as an
45 // implementation detail. This header file may change from version to
46 // version without notice, or even be removed.
47 //
48 // We mean it.
49 //
50
51 #ifndef PROFILE_ADAPTER_H
52 #define PROFILE_ADAPTER_H
53
54 #include "qtwebenginecoreglobal_p.h"
55
56 #include <QEnableSharedFromThis>
57 #include <QList>
58 #include <QPointer>
59 #include <QScopedPointer>
60 #include <QString>
61 #include <QVector>
62
63 #include "api/qwebengineclientcertificatestore.h"
64 #include "api/qwebenginecookiestore.h"
65 #include "api/qwebengineurlrequestinterceptor.h"
66 #include "api/qwebengineurlschemehandler.h"
67 #include "net/qrc_url_scheme_handler.h"
68
QT_FORWARD_DECLARE_CLASS(QObject)69 QT_FORWARD_DECLARE_CLASS(QObject)
70
71 namespace QtWebEngineCore {
72
73 class UserNotificationController;
74 class DownloadManagerDelegateQt;
75 class ProfileAdapterClient;
76 class ProfileQt;
77 class UserResourceControllerHost;
78 class VisitedLinksManagerQt;
79 class WebContentsAdapterClient;
80
81 class Q_WEBENGINECORE_PRIVATE_EXPORT ProfileAdapter : public QObject
82 {
83 public:
84 explicit ProfileAdapter(const QString &storagePrefix = QString());
85 virtual ~ProfileAdapter();
86
87 static ProfileAdapter* createDefaultProfileAdapter();
88 static ProfileAdapter* defaultProfileAdapter();
89 static QObject* globalQObjectRoot();
90
91 VisitedLinksManagerQt *visitedLinksManager();
92 DownloadManagerDelegateQt *downloadManagerDelegate();
93
94 QWebEngineCookieStore *cookieStore();
95
96 QWebEngineUrlRequestInterceptor* requestInterceptor();
97 void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor);
98
99 QList<ProfileAdapterClient*> clients() { return m_clients; }
100 void addClient(ProfileAdapterClient *adapterClient);
101 void removeClient(ProfileAdapterClient *adapterClient);
102
103 void cancelDownload(quint32 downloadId);
104 void pauseDownload(quint32 downloadId);
105 void resumeDownload(quint32 downloadId);
106 void removeDownload(quint32 downloadId);
107
108 ProfileQt *profile();
109
110 QString storageName() const { return m_name; }
111 void setStorageName(const QString &storageName);
112
113 bool isOffTheRecord() const { return m_offTheRecord; }
114 void setOffTheRecord(bool offTheRecord);
115
116 QString dataPath() const;
117 void setDataPath(const QString &path);
118
119 QString downloadPath() const { return m_downloadPath; }
120 void setDownloadPath(const QString &path);
121
122 QString cachePath() const;
123 void setCachePath(const QString &path);
124
125 QString httpCachePath() const;
126
127 QString httpUserAgent() const;
128 void setHttpUserAgent(const QString &userAgent);
129
130 void setSpellCheckLanguages(const QStringList &language);
131 QStringList spellCheckLanguages() const;
132 void setSpellCheckEnabled(bool enabled);
133 bool isSpellCheckEnabled() const;
134
135 void addWebContentsAdapterClient(WebContentsAdapterClient *client);
136 void removeWebContentsAdapterClient(WebContentsAdapterClient *client);
137
138 // KEEP IN SYNC with API or add mapping layer
139 enum HttpCacheType {
140 MemoryHttpCache = 0,
141 DiskHttpCache,
142 NoCache
143 };
144
145 enum PersistentCookiesPolicy {
146 NoPersistentCookies = 0,
147 AllowPersistentCookies,
148 ForcePersistentCookies
149 };
150
151 enum VisitedLinksPolicy {
152 DoNotTrackVisitedLinks = 0,
153 TrackVisitedLinksInMemory,
154 TrackVisitedLinksOnDisk,
155 };
156
157 enum PermissionType {
158 UnsupportedPermission = 0,
159 GeolocationPermission = 1,
160 NotificationPermission = 2,
161 AudioCapturePermission = 3,
162 VideoCapturePermission = 4,
163 ClipboardRead = 5,
164 ClipboardWrite = 6,
165 };
166
167 enum PermissionState {
168 AskPermission = 0,
169 AllowedPermission = 1,
170 DeniedPermission = 2
171 };
172
173 HttpCacheType httpCacheType() const;
174 void setHttpCacheType(ProfileAdapter::HttpCacheType);
175
176 PersistentCookiesPolicy persistentCookiesPolicy() const;
177 void setPersistentCookiesPolicy(ProfileAdapter::PersistentCookiesPolicy);
178
179 VisitedLinksPolicy visitedLinksPolicy() const;
180 void setVisitedLinksPolicy(ProfileAdapter::VisitedLinksPolicy);
181
182 int httpCacheMaxSize() const;
183 void setHttpCacheMaxSize(int maxSize);
184
185 bool trackVisitedLinks() const;
186
187 QWebEngineUrlSchemeHandler *urlSchemeHandler(const QByteArray &scheme);
188 void installUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler *handler);
189 void removeUrlScheme(const QByteArray &scheme);
190 void removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler);
191 void removeAllUrlSchemeHandlers();
192
193 const QList<QByteArray> customUrlSchemes() const;
194 UserResourceControllerHost *userResourceController();
195
196 void permissionRequestReply(const QUrl &origin, PermissionType type, PermissionState reply);
197 bool checkPermission(const QUrl &origin, PermissionType type);
198
199 QString httpAcceptLanguageWithoutQualities() const;
200 QString httpAcceptLanguage() const;
201 void setHttpAcceptLanguage(const QString &httpAcceptLanguage);
202
203 void clearHttpCache();
204
205 void setUseForGlobalCertificateVerification(bool enable = true);
206 bool isUsedForGlobalCertificateVerification() const;
207
208 #if QT_CONFIG(ssl)
209 QWebEngineClientCertificateStore *clientCertificateStore();
210 #endif
211
212 QHash<QByteArray, QWeakPointer<UserNotificationController>> &ephemeralNotifications()
213 { return m_ephemeralNotifications; }
214 QHash<QByteArray, QSharedPointer<UserNotificationController>> &persistentNotifications()
215 { return m_persistentNotifications; }
216
217 QString determineDownloadPath(const QString &downloadDirectory, const QString &suggestedFilename, const time_t &startTime);
218
219 private:
220 void updateCustomUrlSchemeHandlers();
221 void resetVisitedLinksManager();
222 bool persistVisitedLinks() const;
223
224 QString m_name;
225 bool m_offTheRecord;
226 bool m_usedForGlobalCertificateVerification = false;
227 QScopedPointer<ProfileQt> m_profile;
228 QScopedPointer<VisitedLinksManagerQt> m_visitedLinksManager;
229 QScopedPointer<DownloadManagerDelegateQt> m_downloadManagerDelegate;
230 QScopedPointer<UserResourceControllerHost> m_userResourceController;
231 QScopedPointer<QWebEngineCookieStore> m_cookieStore;
232 #if QT_CONFIG(ssl)
233 QWebEngineClientCertificateStore *m_clientCertificateStore = nullptr;
234 #endif
235 QPointer<QWebEngineUrlRequestInterceptor> m_requestInterceptor;
236
237 QString m_dataPath;
238 QString m_downloadPath;
239 QString m_cachePath;
240 QString m_httpUserAgent;
241 HttpCacheType m_httpCacheType;
242 QString m_httpAcceptLanguage;
243 PersistentCookiesPolicy m_persistentCookiesPolicy;
244 VisitedLinksPolicy m_visitedLinksPolicy;
245 QHash<QByteArray, QPointer<QWebEngineUrlSchemeHandler>> m_customUrlSchemeHandlers;
246 QHash<QByteArray, QWeakPointer<UserNotificationController>> m_ephemeralNotifications;
247 QHash<QByteArray, QSharedPointer<UserNotificationController>> m_persistentNotifications;
248
249 QList<ProfileAdapterClient*> m_clients;
250 QVector<WebContentsAdapterClient *> m_webContentsAdapterClients;
251 int m_httpCacheMaxSize;
252 QrcUrlSchemeHandler m_qrcHandler;
253
254 Q_DISABLE_COPY(ProfileAdapter)
255 };
256
257 } // namespace QtWebEngineCore
258
259 #endif // PROFILE_ADAPTER_H
260