path: root/src/webenginewidgets
diff options
authorJocelyn Turcotte <>2014-02-25 15:00:59 +0100
committerThe Qt Project <>2014-02-28 15:21:26 +0100
commit970ccc7f1e7890f4ac49b761678274823576aca5 (patch)
treebb8e0ea602b3c8aac9c5967ba8bd0ecb8dc4f0a6 /src/webenginewidgets
parent0fb2109e9a14857f76d12c45beaac7fc9640487e (diff)
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 <>
Diffstat (limited to 'src/webenginewidgets')
4 files changed, 23 insertions, 2 deletions
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 <QMessageBox>
#include <QStandardPaths>
#include <QUrl>
+#include <private/qauthenticator_p.h>
@@ -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
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/ b/src/webenginewidgets/
index 86367d771..a871586ae 100644
--- a/src/webenginewidgets/
+++ b/src/webenginewidgets/
@@ -3,8 +3,8 @@ TARGET = QtWebEngineWidgets
# For our export macros
-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()