diff options
author | Yigit Akcay <yigit.akcay@qt.io> | 2023-02-15 20:43:25 +0100 |
---|---|---|
committer | Yigit Akcay <yigit.akcay@qt.io> | 2023-03-10 17:13:32 +0100 |
commit | 5e257fb57a211f95556ec387fe6f262a60cbb6fe (patch) | |
tree | 330abbb7f84f8664fbd44b80d573265da4cc2bcb /src/core/api/qwebengineprofile.cpp | |
parent | 28a2cfe4116f7218b33df811b79536c0593ddda6 (diff) | |
download | qtwebengine-5e257fb57a211f95556ec387fe6f262a60cbb6fe.tar.gz |
QWebEngineUrlResponseInterceptor: Implement new URL response interceptor
This patch adds the QWebEngineUrlResponseInterceptor abstract class,
which, when implemented, allows a user to intercept response headers and
modify them in any way they like.
A response interceptor can be set via
QWebEngineProfile::setUrlResponseInterceptor(),
QQuickWebEngineProfile::setUrlResponseInterceptor() or
QWebEnginePage::setUrlResponseInterceptor().
Also, the QWebEngineUrlResponseInfo class is implemented, which contains
the request and response data to be used with the response interceptor.
If a response interceptor is set in the profile and page, the one in the
profile takes precedence.
Fixes: QTBUG-61071
Change-Id: I484d14373ff597b1d531541c066f0102bae28c72
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src/core/api/qwebengineprofile.cpp')
-rw-r--r-- | src/core/api/qwebengineprofile.cpp | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/core/api/qwebengineprofile.cpp b/src/core/api/qwebengineprofile.cpp index ab873e345..3a4c899d9 100644 --- a/src/core/api/qwebengineprofile.cpp +++ b/src/core/api/qwebengineprofile.cpp @@ -62,9 +62,12 @@ using QtWebEngineCore::ProfileAdapter; The default profile can be accessed by defaultProfile(). It is a built-in profile that all web pages not specifically created with another profile belong to. - Implementing the QWebEngineUrlRequestInterceptor interface and registering the interceptor on a - profile by setUrlRequestInterceptor() enables intercepting, blocking, and modifying URL - requests (QWebEngineUrlRequestInfo) before they reach the networking stack of Chromium. + You can implement interceptor interfaces for URL requests and responses and register them + on a profile to intercept, block, or modify URL requests before they reach the networking + stack of Chromium or response headers right after they come off the networking stack of + Chromium. For requests, implement QWebEngineUrlRequestInterceptor and register it via + setUrlRequestInterceptor(). For response headers, implement QWebEngineUrlResponseInterceptor + and register it via setUrlResponseInterceptor(). A QWebEngineUrlSchemeHandler can be registered for a profile by installUrlSchemeHandler() to add support for custom URL schemes. Requests for the scheme are then issued to @@ -603,6 +606,21 @@ void QWebEngineProfile::setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor } /*! + Registers a response interceptor singleton \a interceptor to intercept URL response headers. + + The profile does not take ownership of the pointer. + + \since 6.6 + \sa QWebEngineUrlResponseInterceptor +*/ + +void QWebEngineProfile::setUrlResponseInterceptor(QWebEngineUrlResponseInterceptor *interceptor) +{ + Q_D(QWebEngineProfile); + d->profileAdapter()->setResponseInterceptor(interceptor); +} + +/*! Clears all links from the visited links database. \sa clearVisitedLinks() |