From 970ccc7f1e7890f4ac49b761678274823576aca5 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Tue, 25 Feb 2014 15:00:59 +0100 Subject: Add HTTP and proxy authentication signals directly to QWebEnginePage This allows handling calls that would be signaled by QNetworkAccessManager in QtWebKit. This pulls QtNetwork as a dependency of the QtWebEngineWidgets module to be able to use QAuthenticator, but isn't required otherwise. Only the request URL is available in the case of HTTP authentication (no access to HTTP request headers that the QNetworkReply would allow) and only the proxy host name in the case case of proxy authentication. This keeps the API synchronous the same way, as QtWebKit did, in favor of source compatibility at the cost of requiring a modal dialog, even though the implementation doesn't require it. Change-Id: I9e021def38e6107c9e66d2de8f86bd0328d543df Reviewed-by: Michael Bruning --- src/webenginewidgets/api/qwebenginepage.cpp | 17 +++++++++++++++++ src/webenginewidgets/api/qwebenginepage.h | 3 +++ src/webenginewidgets/api/qwebenginepage_p.h | 1 + src/webenginewidgets/webenginewidgets.pro | 4 ++-- 4 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 83f77b4bd..4c4243ccc 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -42,6 +42,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -284,6 +285,22 @@ void QWebEnginePagePrivate::didFindText(quint64 requestId, int matchCount) m_callbacks.invoke(requestId, matchCount > 0); } +void QWebEnginePagePrivate::authenticationRequired(const QUrl &requestUrl, const QString &realm, bool isProxy, const QString &challengingHost, QString *outUser, QString *outPassword) +{ + Q_Q(QWebEnginePage); + QAuthenticator networkAuth; + // Detach to trigger the creation of its QAuthenticatorPrivate. + networkAuth.detach(); + QAuthenticatorPrivate::getPrivate(networkAuth)->realm = realm; + + if (isProxy) + Q_EMIT q->proxyAuthenticationRequired(requestUrl, &networkAuth, challengingHost); + else + Q_EMIT q->authenticationRequired(requestUrl, &networkAuth); + *outUser = networkAuth.user(); + *outPassword = networkAuth.password(); +} + void QWebEnginePagePrivate::updateAction(QWebEnginePage::WebAction action) const { #ifdef QT_NO_ACTION diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index 96ffeda3a..04db99750 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -542,6 +542,9 @@ Q_SIGNALS: void featurePermissionRequested(QWebEngineFrame* frame, QWebEnginePage::Feature feature); void featurePermissionRequestCanceled(QWebEngineFrame* frame, QWebEnginePage::Feature feature); + void authenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator); + void proxyAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator, const QString &proxyHost); + // Ex-QWebFrame signals void javaScriptWindowObjectCleared(); diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 773df00d4..42f66cd01 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -134,6 +134,7 @@ public: virtual void didFindText(quint64 requestId, int matchCount) Q_DECL_OVERRIDE; virtual void passOnFocus(bool reverse) Q_DECL_OVERRIDE { Q_UNUSED(reverse); }; virtual void javaScriptConsoleMessage(int level, const QString& message, int lineNumber, const QString& sourceID) Q_DECL_OVERRIDE; + virtual void authenticationRequired(const QUrl &requestUrl, const QString &realm, bool isProxy, const QString &challengingHost, QString *outUser, QString *outPassword) Q_DECL_OVERRIDE; void updateAction(QWebEnginePage::WebAction) const; void updateNavigationActions(); diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro index 86367d771..a871586ae 100644 --- a/src/webenginewidgets/webenginewidgets.pro +++ b/src/webenginewidgets/webenginewidgets.pro @@ -3,8 +3,8 @@ TARGET = QtWebEngineWidgets # For our export macros DEFINES += QT_BUILD_WEBENGINEWIDGETS_LIB -QT += widgets -QT_PRIVATE += widgets-private gui-private core-private +QT += widgets network +QT_PRIVATE += widgets-private gui-private network-private core-private # FIXME: all this should eventually be turned into QT += webenginecore macx:LIBPATH = $$getOutDir()/$$getConfigDir() -- cgit v1.2.3