diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2015-08-26 10:43:05 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-09-06 19:26:52 +0000 |
commit | 691d4a008d90b7d69a7b4b05404475dae204848f (patch) | |
tree | 0a2144ae62ffaee5dc1788a5d6c1b9ce9ac52d12 /src/core/resource_dispatcher_host_delegate_qt.cpp | |
parent | 6ef0a365124d435314113837dc77fa07b02ff86b (diff) |
Add AuthenticationDialogController
The new controller makes possible to handle authentication requests
asynchronously. This is essential for the authentication support in the
QtQuick API.
Change-Id: Ib60b58448a60e817e64477529ec4bfd1535b3d19
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/core/resource_dispatcher_host_delegate_qt.cpp')
-rw-r--r-- | src/core/resource_dispatcher_host_delegate_qt.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/src/core/resource_dispatcher_host_delegate_qt.cpp b/src/core/resource_dispatcher_host_delegate_qt.cpp index 43d3d98ef..b63ecd5c7 100644 --- a/src/core/resource_dispatcher_host_delegate_qt.cpp +++ b/src/core/resource_dispatcher_host_delegate_qt.cpp @@ -46,22 +46,20 @@ #include "content/public/browser/resource_request_info.h" #include "net/url_request/url_request.h" +#include "authentication_dialog_controller.h" +#include "authentication_dialog_controller_p.h" #include "type_conversion.h" #include "web_contents_view_qt.h" namespace QtWebEngineCore { ResourceDispatcherHostLoginDelegateQt::ResourceDispatcherHostLoginDelegateQt(net::AuthChallengeInfo *authInfo, net::URLRequest *request) - : m_request(request) + : m_authInfo(authInfo) + , m_request(request) { Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); content::ResourceRequestInfo::GetRenderFrameForRequest(request, &m_renderProcessId, &m_renderFrameId); - 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)); @@ -69,13 +67,34 @@ ResourceDispatcherHostLoginDelegateQt::ResourceDispatcherHostLoginDelegateQt(net ResourceDispatcherHostLoginDelegateQt::~ResourceDispatcherHostLoginDelegateQt() { + Q_ASSERT(m_dialogController.isNull()); // We must have called ClearLoginDelegateForRequest if we didn't receive an OnRequestCancelled. Q_ASSERT(!m_request); } void ResourceDispatcherHostLoginDelegateQt::OnRequestCancelled() { - m_request = 0; + destroy(); +} + +QUrl ResourceDispatcherHostLoginDelegateQt::url() const +{ + return toQt(m_request->url()); +} + +QString ResourceDispatcherHostLoginDelegateQt::realm() const +{ + return QString::fromStdString(m_authInfo->realm); +} + +QString ResourceDispatcherHostLoginDelegateQt::host() const +{ + return QString::fromStdString(m_authInfo->challenger.ToString()); +} + +bool ResourceDispatcherHostLoginDelegateQt::isProxy() const +{ + return m_authInfo->is_proxy; } void ResourceDispatcherHostLoginDelegateQt::triggerDialog() @@ -85,16 +104,9 @@ void ResourceDispatcherHostLoginDelegateQt::triggerDialog() content::WebContentsImpl *webContents = static_cast<content::WebContentsImpl *>(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; - bool success = client->authenticationRequired(m_url , m_realm , m_isProxy , m_host, &user, &password); - - content::BrowserThread::PostTask( - content::BrowserThread::IO, FROM_HERE, - base::Bind(&ResourceDispatcherHostLoginDelegateQt::sendAuthToRequester, this, success, user, password)); + AuthenticationDialogControllerPrivate *dialogControllerData = new AuthenticationDialogControllerPrivate(this); + m_dialogController.reset(new AuthenticationDialogController(dialogControllerData)); + client->authenticationRequired(m_dialogController); } void ResourceDispatcherHostLoginDelegateQt::sendAuthToRequester(bool success, const QString &user, const QString &password) @@ -109,6 +121,12 @@ void ResourceDispatcherHostLoginDelegateQt::sendAuthToRequester(bool success, co m_request->CancelAuth(); content::ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(m_request); + destroy(); +} + +void ResourceDispatcherHostLoginDelegateQt::destroy() +{ + m_dialogController.reset(); m_request = 0; } |