summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-02-25 15:00:59 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-28 15:21:26 +0100
commit970ccc7f1e7890f4ac49b761678274823576aca5 (patch)
treebb8e0ea602b3c8aac9c5967ba8bd0ecb8dc4f0a6 /src
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 <michael.bruning@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/content_browser_client_qt.cpp10
-rw-r--r--src/core/content_browser_client_qt.h3
-rw-r--r--src/core/core_gyp_generator.pro2
-rw-r--r--src/core/resource_dispatcher_host_delegate_qt.cpp128
-rw-r--r--src/core/resource_dispatcher_host_delegate_qt.h81
-rw-r--r--src/core/web_contents_adapter_client.h1
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h1
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp17
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h3
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h1
-rw-r--r--src/webenginewidgets/webenginewidgets.pro4
11 files changed, 248 insertions, 3 deletions
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp
index 7e06aed6..99862235 100644
--- a/src/core/content_browser_client_qt.cpp
+++ b/src/core/content_browser_client_qt.cpp
@@ -44,8 +44,9 @@
#include "base/message_loop/message_loop.h"
#include "base/threading/thread_restrictions.h"
#include "content/public/browser/browser_main_parts.h"
-#include "content/public/common/main_function_params.h"
#include "content/public/browser/child_process_security_policy.h"
+#include "content/public/browser/resource_dispatcher_host.h"
+#include "content/public/common/main_function_params.h"
#include "content/public/common/url_constants.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
@@ -53,6 +54,7 @@
#include "browser_context_qt.h"
#include "dev_tools_http_handler_delegate_qt.h"
+#include "resource_dispatcher_host_delegate_qt.h"
#include "web_contents_view_qt.h"
#include <QGuiApplication>
@@ -288,6 +290,12 @@ void ContentBrowserClientQt::RenderProcessHostCreated(content::RenderProcessHost
content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(host->GetID(), chrome::kFileScheme);
}
+void ContentBrowserClientQt::ResourceDispatcherHostCreated()
+{
+ m_resourceDispatcherHostDelegate.reset(new ResourceDispatcherHostDelegateQt);
+ content::ResourceDispatcherHost::Get()->SetDelegate(m_resourceDispatcherHostDelegate.get());
+}
+
gfx::GLShareGroup *ContentBrowserClientQt::GetInProcessGpuShareGroup()
{
if (!m_shareGroupQtQuick)
diff --git a/src/core/content_browser_client_qt.h b/src/core/content_browser_client_qt.h
index b97eaa5e..c8afc633 100644
--- a/src/core/content_browser_client_qt.h
+++ b/src/core/content_browser_client_qt.h
@@ -68,6 +68,7 @@ class GLShareGroup;
class BrowserContextQt;
class BrowserMainPartsQt;
class DevToolsHttpHandlerDelegateQt;
+class ResourceDispatcherHostDelegateQt;
class ShareGroupQtQuick;
class ContentBrowserClientQt : public content::ContentBrowserClient {
@@ -79,6 +80,7 @@ public:
virtual content::WebContentsViewPort* OverrideCreateWebContentsView(content::WebContents* , content::RenderViewHostDelegateView**) Q_DECL_OVERRIDE;
virtual content::BrowserMainParts* CreateBrowserMainParts(const content::MainFunctionParams&) Q_DECL_OVERRIDE;
virtual void RenderProcessHostCreated(content::RenderProcessHost* host) Q_DECL_OVERRIDE;
+ virtual void ResourceDispatcherHostCreated() Q_DECL_OVERRIDE;
virtual gfx::GLShareGroup* GetInProcessGpuShareGroup() Q_DECL_OVERRIDE;
BrowserContextQt* browser_context();
@@ -90,6 +92,7 @@ public:
private:
BrowserMainPartsQt* m_browserMainParts;
scoped_ptr<DevToolsHttpHandlerDelegateQt> m_devtools;
+ scoped_ptr<ResourceDispatcherHostDelegateQt> m_resourceDispatcherHostDelegate;
scoped_refptr<ShareGroupQtQuick> m_shareGroupQtQuick;
};
diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro
index bf7cce9f..7b0e36e0 100644
--- a/src/core/core_gyp_generator.pro
+++ b/src/core/core_gyp_generator.pro
@@ -52,6 +52,7 @@ SOURCES = \
renderer/qt_render_view_observer.cpp \
resource_bundle_qt.cpp \
resource_context_qt.cpp \
+ resource_dispatcher_host_delegate_qt.cpp \
stream_video_node.cpp \
url_request_context_getter_qt.cpp \
web_contents_adapter.cpp \
@@ -87,6 +88,7 @@ HEADERS = \
renderer/content_renderer_client_qt.h \
renderer/qt_render_view_observer.h \
resource_context_qt.h \
+ resource_dispatcher_host_delegate_qt.h \
stream_video_node.h \
url_request_context_getter_qt.h \
web_contents_adapter.h \
diff --git a/src/core/resource_dispatcher_host_delegate_qt.cpp b/src/core/resource_dispatcher_host_delegate_qt.cpp
new file mode 100644
index 00000000..3e650afb
--- /dev/null
+++ b/src/core/resource_dispatcher_host_delegate_qt.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "resource_dispatcher_host_delegate_qt.h"
+
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/resource_dispatcher_host.h"
+#include "content/public/browser/resource_request_info.h"
+#include "net/url_request/url_request.h"
+
+#include "type_conversion.h"
+#include "web_contents_view_qt.h"
+
+ResourceDispatcherHostLoginDelegateQt::ResourceDispatcherHostLoginDelegateQt(net::AuthChallengeInfo *authInfo, net::URLRequest *request)
+ : m_request(request)
+{
+ Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ content::ResourceRequestInfo::ForRequest(request)->GetAssociatedRenderView(&m_renderProcessId, &m_renderViewId);
+
+ m_url = toQt(request->url());
+ m_realm = QString::fromStdString(authInfo->realm);
+ m_isProxy = authInfo->is_proxy;
+ m_host = QString::fromStdString(authInfo->challenger.ToString());
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&ResourceDispatcherHostLoginDelegateQt::triggerDialog, this));
+}
+
+ResourceDispatcherHostLoginDelegateQt::~ResourceDispatcherHostLoginDelegateQt()
+{
+ // We must have called ClearLoginDelegateForRequest if we didn't receive an OnRequestCancelled.
+ Q_ASSERT(!m_request);
+}
+
+void ResourceDispatcherHostLoginDelegateQt::OnRequestCancelled()
+{
+ m_request = 0;
+}
+
+void ResourceDispatcherHostLoginDelegateQt::triggerDialog()
+{
+ Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ content::RenderViewHost* renderViewHost = content::RenderViewHost::FromID(m_renderProcessId, m_renderViewId);
+ content::WebContents *webContents = content::WebContents::FromRenderViewHost(renderViewHost);
+ WebContentsAdapterClient *client = WebContentsViewQt::from(webContents->GetView())->client();
+
+ // The widgets API will ask for credentials synchronouly, keep it simple for now.
+ // We'll have to figure out a mechanism to keep a ref to the ResourceDispatcherHostLoginDelegateQt
+ // to avoid crashing in the OnRequestCancelled case if we want to allow the credentials to
+ // come back asynchronously in the QtQuick API.
+ QString user, password;
+ client->authenticationRequired(m_url , m_realm , m_isProxy , m_host, &user, &password);
+
+ bool success = !user.isEmpty() || !password.isEmpty();
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&ResourceDispatcherHostLoginDelegateQt::sendAuthToRequester, this, success, user, password));
+}
+
+void ResourceDispatcherHostLoginDelegateQt::sendAuthToRequester(bool success, const QString &user, const QString &password)
+{
+ Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ if (!m_request)
+ return;
+
+ if (success)
+ m_request->SetAuth(net::AuthCredentials(toString16(user), toString16(password)));
+ else
+ m_request->CancelAuth();
+ content::ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(m_request);
+
+ m_request = 0;
+}
+
+bool ResourceDispatcherHostDelegateQt::AcceptAuthRequest(net::URLRequest *, net::AuthChallengeInfo *)
+{
+ return true;
+}
+
+content::ResourceDispatcherHostLoginDelegate *ResourceDispatcherHostDelegateQt::CreateLoginDelegate(net::AuthChallengeInfo *authInfo, net::URLRequest *request)
+{
+ // ResourceDispatcherHostLoginDelegateQt is ref-counted and will be released after we called ClearLoginDelegateForRequest.
+ return new ResourceDispatcherHostLoginDelegateQt(authInfo, request);
+}
diff --git a/src/core/resource_dispatcher_host_delegate_qt.h b/src/core/resource_dispatcher_host_delegate_qt.h
new file mode 100644
index 00000000..1b584912
--- /dev/null
+++ b/src/core/resource_dispatcher_host_delegate_qt.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H
+#define RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H
+
+#include "content/public/browser/resource_dispatcher_host_delegate.h"
+#include "content/public/browser/resource_dispatcher_host_login_delegate.h"
+
+#include "web_contents_adapter_client.h"
+
+class ResourceDispatcherHostLoginDelegateQt : public content::ResourceDispatcherHostLoginDelegate {
+public:
+ ResourceDispatcherHostLoginDelegateQt(net::AuthChallengeInfo *authInfo, net::URLRequest *request);
+ ~ResourceDispatcherHostLoginDelegateQt();
+
+ // ResourceDispatcherHostLoginDelegate implementation
+ virtual void OnRequestCancelled();
+
+private:
+ void triggerDialog();
+ void sendAuthToRequester(bool success, const QString &user, const QString &password);
+
+ QUrl m_url;
+ QString m_realm;
+ bool m_isProxy;
+ QString m_host;
+
+ int m_renderProcessId;
+ int m_renderViewId;
+
+ // The request that wants login data.
+ // Must only be accessed on the IO thread.
+ net::URLRequest *m_request;
+};
+
+class ResourceDispatcherHostDelegateQt : public content::ResourceDispatcherHostDelegate {
+public:
+ virtual bool AcceptAuthRequest(net::URLRequest *request, net::AuthChallengeInfo *authInfo) Q_DECL_OVERRIDE;
+ virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(net::AuthChallengeInfo *authInfo, net::URLRequest *request) Q_DECL_OVERRIDE;
+};
+
+#endif // RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index f56e31a7..e436fd61 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -139,6 +139,7 @@ public:
virtual void didFindText(quint64 requestId, int matchCount) = 0;
virtual void passOnFocus(bool reverse) = 0;
virtual void javaScriptConsoleMessage(int level, const QString& message, int lineNumber, const QString& sourceID) = 0;
+ virtual void authenticationRequired(const QUrl &requestUrl, const QString &realm, bool isProxy, const QString &challengingHost, QString *outUser, QString *outPassword) = 0;
};
#endif // WEB_CONTENTS_ADAPTER_CLIENT_H
diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
index 5c75f778..7fed546d 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -145,6 +145,7 @@ public:
virtual void didFindText(quint64, int) Q_DECL_OVERRIDE { }
virtual void passOnFocus(bool reverse) Q_DECL_OVERRIDE;
virtual void javaScriptConsoleMessage(int level, const QString& message, int lineNumber, const QString& sourceID) Q_DECL_OVERRIDE;
+ virtual void authenticationRequired(const QUrl&, const QString&, bool, const QString&, QString*, QString*) Q_DECL_OVERRIDE { }
void setDevicePixelRatio(qreal);
void adoptWebContents(WebContentsAdapter *webContents);
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 83f77b4b..4c4243cc 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>
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 96ffeda3..04db9975 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 773df00d..42f66cd0 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 86367d77..a871586a 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()