From 5e257fb57a211f95556ec387fe6f262a60cbb6fe Mon Sep 17 00:00:00 2001 From: Yigit Akcay Date: Wed, 15 Feb 2023 20:43:25 +0100 Subject: QWebEngineUrlResponseInterceptor: Implement new URL response interceptor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/core/api/qwebengineprofile.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/core/api/qwebengineprofile.cpp') 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 @@ -602,6 +605,21 @@ void QWebEngineProfile::setUrlRequestInterceptor(QWebEngineUrlRequestInterceptor d->profileAdapter()->setRequestInterceptor(interceptor); } +/*! + 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. -- cgit v1.2.1