1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Fixed crash when downloading from SSL secured site

If your download is opening in new empty tab, teh download manager will
close it. If the new tab was secured, network manager was trying to set
SSL configuration to already deleted page, thus leading to crash.
This commit is contained in:
nowrep 2011-11-08 15:20:53 +01:00
parent f8feb86351
commit 895942842d
9 changed files with 61 additions and 37 deletions

View File

@ -1152,7 +1152,7 @@ void QupZilla::savePage()
QNetworkRequest request(weView()->url());
DownloadManager* dManager = mApp->downManager();
dManager->download(request, false);
dManager->download(request, weView()->webPage(), false);
}
void QupZilla::printPage()

View File

@ -25,7 +25,7 @@
#include "downloadmanager.h"
#include "globalfunctions.h"
DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog)
DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog, WebPage* page)
: QObject()
, m_lastDownloadPath(lastDownloadPath)
, m_downloadPath(downloadPath)
@ -36,6 +36,7 @@ DownloadFileHelper::DownloadFileHelper(const QString &lastDownloadPath, const QS
, m_listWidget(0)
, m_iconProvider(new QFileIconProvider)
, m_manager(0)
, m_webPage(page)
{
}
@ -60,19 +61,16 @@ void DownloadFileHelper::handleUnsupportedContent(QNetworkReply* reply, bool ask
m_fileIcon = m_iconProvider->icon(tempInfo).pixmap(30, 30);
QString mimeType = m_iconProvider->type(tempInfo);
//Get Download Page and Close Empty Tab
QNetworkRequest request = m_reply->request();
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
WebPage* webPage = (WebPage*)(v.value<void*>());
if (webPage) {
if (!webPage->mainFrame()->url().isEmpty()) {
m_downloadPage = webPage->mainFrame()->url();
// Close Empty Tab
if (m_webPage) {
if (!m_webPage->mainFrame()->url().isEmpty()) {
m_downloadPage = m_webPage->mainFrame()->url();
}
else if (webPage->history()->canGoBack()) {
m_downloadPage = webPage->history()->backItem().url();
else if (m_webPage->history()->canGoBack()) {
m_downloadPage = m_webPage->history()->backItem().url();
}
else if (webPage->history()->count() == 0) {
webPage->getView()->closeTab();
else if (m_webPage->history()->count() == 0) {
m_webPage->getView()->closeTab();
}
}

View File

@ -30,11 +30,12 @@
class DownloadItem;
class DownloadManager;
class WebPage;
class DownloadFileHelper : public QObject
{
Q_OBJECT
public:
explicit DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog);
explicit DownloadFileHelper(const QString &lastDownloadPath, const QString &downloadPath, bool useNativeDialog, WebPage* page);
~DownloadFileHelper();
void setListWidget(QListWidget* tw) { m_listWidget = tw; }
@ -68,6 +69,7 @@ private:
QListWidget* m_listWidget;
QFileIconProvider* m_iconProvider;
DownloadManager* m_manager;
WebPage* m_webPage;
};
#endif // DOWNLOADFILEHELPER_H

View File

@ -166,18 +166,26 @@ void DownloadManager::clearList()
qDeleteAll(items);
}
void DownloadManager::download(const QNetworkRequest &request, bool askWhatToDo)
void DownloadManager::download(const QNetworkRequest &request, WebPage* page, bool askWhatToDo)
{
handleUnsupportedContent(m_networkManager->get(request), askWhatToDo);
// Clearing web page info from request
QNetworkRequest req = request;
req.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), 0);
req.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101), 0);
req.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 102), 0);
handleUnsupportedContent(m_networkManager->get(req), page, askWhatToDo);
}
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo)
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, WebPage* page, bool askWhatToDo)
{
if (reply->url().scheme() == "qupzilla") {
return;
}
DownloadFileHelper* h = new DownloadFileHelper(m_lastDownloadPath, m_downloadPath, m_useNativeDialog);
reply->setProperty("downReply", true);
DownloadFileHelper* h = new DownloadFileHelper(m_lastDownloadPath, m_downloadPath, m_useNativeDialog, page);
connect(h, SIGNAL(itemCreated(QListWidgetItem*, DownloadItem*)), this, SLOT(itemCreated(QListWidgetItem*, DownloadItem*)));
h->setDownloadManager(this);

View File

@ -43,6 +43,7 @@ class DownloadManager;
class DownloadItem;
class EcWin7;
class NetworkManager;
class WebPage;
class DownloadManager : public QWidget
{
Q_OBJECT
@ -53,8 +54,8 @@ public:
void loadSettings();
void download(const QNetworkRequest &request, bool askWhatToDo = true);
void handleUnsupportedContent(QNetworkReply* reply, bool askWhatToDo = true);
void download(const QNetworkRequest &request, WebPage* page, bool askWhatToDo = true);
void handleUnsupportedContent(QNetworkReply* reply, WebPage* page, bool askWhatToDo = true);
bool canClose();
void setLastDownloadPath(const QString &lastPath) { m_lastDownloadPath = lastPath; }

View File

@ -77,6 +77,10 @@ void NetworkManager::loadSettings()
void NetworkManager::setSSLConfiguration(QNetworkReply* reply)
{
if (reply->property("downReply").toBool()) {
return;
}
if (!reply->sslConfiguration().isNull()) {
QSslCertificate cert = reply->sslConfiguration().peerCertificate();
if (!cert.isValid()) {
@ -92,7 +96,7 @@ void NetworkManager::setSSLConfiguration(QNetworkReply* reply)
return;
}
if (webView->url().host() == reply->url().host()) {
if (webView->url().host() == reply->url().host()) {
webPage->setSSLCertificate(cert);
}
}
@ -105,6 +109,10 @@ void NetworkManager::sslError(QNetworkReply* reply, QList<QSslError> errors)
return;
}
if (reply->property("downReply").toBool()) {
return;
}
QNetworkRequest request = reply->request();
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
WebPage* webPage = (WebPage*)(v.value<void*>());

View File

@ -97,7 +97,7 @@ void WebPage::handleUnsupportedContent(QNetworkReply* reply)
case QNetworkReply::NoError:
if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) {
DownloadManager* dManager = mApp->downManager();
dManager->handleUnsupportedContent(reply);
dManager->handleUnsupportedContent(reply, this);
return;
}
break;
@ -164,11 +164,14 @@ QString WebPage::userAgentForUrl(const QUrl &url) const
void WebPage::populateNetworkRequest(QNetworkRequest &request)
{
QVariant variant = qVariantFromValue((void*) this);
QPointer<WebPage> pagePointer = this;
QPointer<WebView> webViewPointer = m_view;
QVariant variant = qVariantFromValue((void*) pagePointer);
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), variant);
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101), m_lastRequestType);
variant = qVariantFromValue((void*) m_view);
variant = qVariantFromValue((void*) webViewPointer);
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 102), variant);
}

View File

@ -663,7 +663,7 @@ void WebView::downloadImageToDisk()
if (QAction* action = qobject_cast<QAction*>(sender())) {
DownloadManager* dManager = mApp->downManager();
QNetworkRequest request(action->data().toUrl());
dManager->download(request, false);
dManager->download(request, m_page, false);
}
}
@ -696,14 +696,14 @@ void WebView::downloadLinkToDisk()
if (QAction* action = qobject_cast<QAction*>(sender())) {
QNetworkRequest request(action->data().toUrl());
DownloadManager* dManager = mApp->downManager();
dManager->download(request, false);
dManager->download(request, m_page, false);
}
}
void WebView::downloadRequested(const QNetworkRequest &request)
{
DownloadManager* dManager = mApp->downManager();
dManager->download(request);
dManager->download(request, m_page);
}
void WebView::bookmarkLink()
@ -792,7 +792,7 @@ void WebView::closeTab()
}
else {
m_wantsClose = true;
QTimer::singleShot(20, this, SLOT(closeTab()));
QTimer::singleShot(100, this, SLOT(closeTab()));
}
}
@ -832,6 +832,7 @@ void WebView::load(const QUrl &url)
QUrl WebView::url() const
{
return QWebView::url();
QUrl ur = QWebView::url();
if (ur.isEmpty() && !m_aboutToLoadUrl.isEmpty()) {
return m_aboutToLoadUrl;

View File

@ -69,6 +69,16 @@ public:
static bool isUrlValid(const QUrl &url);
int tabIndex() const;
signals:
void showUrl(QUrl url);
void siteIconChanged();
void wantsCloseTab(int index);
void changed();
void ipChanged(QString ip);
void showNotification(QWidget* notif);
void viewportResized(QSize size);
void rssChanged(bool state);
public slots:
void stop();
void back();
@ -152,15 +162,8 @@ private:
QList<QTouchEvent::TouchPoint> m_touchPoints;
//QTimer* m_loadingTimer;
signals:
void showUrl(QUrl url);
void siteIconChanged();
void wantsCloseTab(int index);
void changed();
void ipChanged(QString ip);
void showNotification(QWidget* notif);
void viewportResized(QSize size);
void rssChanged(bool state);
// static QList<WebView*> s_deletedPointers;
// static bool isPointerValid(WebView* pointer);
};
#endif // WEBVIEW_H