From 4439a1d57f9f5a3f2955939c3c8b31c558816d63 Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 15 Dec 2011 17:43:06 +0100 Subject: [PATCH] [Fix:] Crash when opening js dialog from locationbar and closing tab - how to reproduce: 1. write javascript:alert("test"); to locationbar and hit enter 2. alert will show up 3. close tab 4. app will most likely crash --- src/navigation/locationbar.cpp | 14 +++++++++----- src/navigation/locationbar.h | 3 +++ src/webview/tabbar.cpp | 2 ++ src/webview/webtab.cpp | 1 + src/webview/webview.h | 3 ++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/navigation/locationbar.cpp b/src/navigation/locationbar.cpp index 8b556877b..8e7a74f0d 100644 --- a/src/navigation/locationbar.cpp +++ b/src/navigation/locationbar.cpp @@ -123,7 +123,7 @@ void LocationBar::urlEnter() } m_webView->setFocus(); - m_webView->load(urlToLoad); + emit loadUrl(urlToLoad); } void LocationBar::textEdit() @@ -247,8 +247,10 @@ void LocationBar::dropEvent(QDropEvent* event) QUrl dropUrl = event->mimeData()->urls().at(0); if (WebView::isUrlValid(dropUrl)) { setText(dropUrl.toString()); - p_QupZilla->loadAddress(dropUrl); - QLineEdit::focusOutEvent(new QFocusEvent(QFocusEvent::FocusOut)); + + m_webView->setFocus(); + emit loadUrl(dropUrl); + return; } } @@ -256,8 +258,10 @@ void LocationBar::dropEvent(QDropEvent* event) QUrl dropUrl = QUrl(event->mimeData()->text().trimmed()); if (WebView::isUrlValid(dropUrl)) { setText(dropUrl.toString()); - p_QupZilla->loadAddress(dropUrl); - QLineEdit::focusOutEvent(new QFocusEvent(QFocusEvent::FocusOut)); + + m_webView->setFocus(); + emit loadUrl(dropUrl); + return; } diff --git a/src/navigation/locationbar.h b/src/navigation/locationbar.h index 749e67080..fe0abf506 100644 --- a/src/navigation/locationbar.h +++ b/src/navigation/locationbar.h @@ -53,6 +53,9 @@ public: void setWebView(WebView* view) { m_webView = view; } +signals: + void loadUrl(const QUrl &url); + public slots: void showUrl(const QUrl &url, bool empty = true); diff --git a/src/webview/tabbar.cpp b/src/webview/tabbar.cpp index 1d150c5dd..3608d6d2f 100644 --- a/src/webview/tabbar.cpp +++ b/src/webview/tabbar.cpp @@ -316,6 +316,7 @@ void TabBar::mouseDoubleClickEvent(QMouseEvent* event) m_tabWidget->addView(QUrl(), tr("New tab"), TabWidget::NewTab, true); return; } + QTabBar::mouseDoubleClickEvent(event); } @@ -335,5 +336,6 @@ void TabBar::mouseReleaseEvent(QMouseEvent* event) m_tabWidget->addView(QUrl(), tr("New tab"), TabWidget::NewSelectedTab, true); return; } + QTabBar::mouseReleaseEvent(event); } diff --git a/src/webview/webtab.cpp b/src/webview/webtab.cpp index 85a8c5ab4..404fb90ec 100644 --- a/src/webview/webtab.cpp +++ b/src/webview/webtab.cpp @@ -47,6 +47,7 @@ WebTab::WebTab(QupZilla* mainClass, LocationBar* locationBar) connect(m_view.data(), SIGNAL(showUrl(QUrl)), m_locationBar.data(), SLOT(showUrl(QUrl))); connect(m_view.data(), SIGNAL(rssChanged(bool)), m_locationBar.data(), SLOT(showRSSIcon(bool))); connect(m_view.data()->webPage(), SIGNAL(privacyChanged(bool)), m_locationBar.data(), SLOT(setPrivacy(bool))); + connect(m_locationBar.data(), SIGNAL(loadUrl(QUrl)), m_view.data(), SLOT(load(QUrl))); } void WebTab::showNotification(QWidget* notif) diff --git a/src/webview/webview.h b/src/webview/webview.h index ec3a84dec..5808edbb6 100644 --- a/src/webview/webview.h +++ b/src/webview/webview.h @@ -47,7 +47,6 @@ public: int getLoading() { return m_progress; } void zoomReset(); - void load(const QUrl &url); QUrl url() const; QString title() const; void reload(); @@ -80,6 +79,8 @@ signals: void rssChanged(bool state); public slots: + void load(const QUrl &url); + void stop(); void back(); void forward();