diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/content_browser_client_qt.cpp | 10 | ||||
-rw-r--r-- | src/core/content_browser_client_qt.h | 3 | ||||
-rw-r--r-- | src/core/core_gyp_generator.pro | 2 | ||||
-rw-r--r-- | src/core/resource_dispatcher_host_delegate_qt.cpp | 128 | ||||
-rw-r--r-- | src/core/resource_dispatcher_host_delegate_qt.h | 81 | ||||
-rw-r--r-- | src/core/web_contents_adapter_client.h | 1 |
6 files changed, 224 insertions, 1 deletions
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 7e06aed65..99862235f 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 b97eaa5e1..c8afc633a 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 bf7cce9fe..7b0e36e0e 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 000000000..3e650afb7 --- /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 000000000..1b584912e --- /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 f56e31a71..e436fd61d 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 |