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

AbstractButtonInterface: Use WebView property instead of WebPage

WebView of a tab will not change while WebPage may.

This also fixes crash when WebPage of WebView is changed. It can happen
eg. when opening new tab from page with target=_blank.

Closes #2537
This commit is contained in:
David Rosca 2018-01-07 09:53:01 +01:00
parent f87c6897a0
commit 6806fa5405
9 changed files with 41 additions and 41 deletions

View File

@ -21,7 +21,7 @@
#include "adblocksubscription.h"
#include "mainapplication.h"
#include "browserwindow.h"
#include "webpage.h"
#include "webview.h"
#include "tabbedwebview.h"
#include "tabwidget.h"
#include "desktopnotificationsfactory.h"
@ -38,7 +38,7 @@ AdBlockIcon::AdBlockIcon(QObject *parent)
updateState();
connect(this, &AbstractButtonInterface::clicked, this, &AdBlockIcon::clicked);
connect(this, &AbstractButtonInterface::webPageChanged, this, &AdBlockIcon::webPageChanged);
connect(this, &AbstractButtonInterface::webViewChanged, this, &AdBlockIcon::webViewChanged);
connect(AdBlockManager::instance(), &AdBlockManager::enabledChanged, this, &AdBlockIcon::updateState);
connect(AdBlockManager::instance(), &AdBlockManager::blockedRequestsChanged, this, &AdBlockIcon::blockedRequestsChanged);
}
@ -75,8 +75,8 @@ void AdBlockIcon::toggleCustomFilter()
void AdBlockIcon::updateState()
{
WebPage *page = webPage();
if (!page) {
WebView *view = webView();
if (!view) {
setActive(false);
setToolTip(name());
setBadgeText(QString());
@ -88,7 +88,7 @@ void AdBlockIcon::updateState()
setBadgeText(QString());
return;
}
if (!AdBlockManager::instance()->canRunOnScheme(page->url().scheme())) {
if (!AdBlockManager::instance()->canRunOnScheme(view->url().scheme())) {
setActive(false);
setToolTip(tr("AdBlock is disabled on this site "));
setBadgeText(QString());
@ -102,11 +102,11 @@ void AdBlockIcon::updateState()
void AdBlockIcon::updateBadgeText()
{
WebPage *page = webPage();
if (!page) {
WebView *view = webView();
if (!view) {
return;
}
const int count = AdBlockManager::instance()->blockedRequestsForUrl(page->url()).count();
const int count = AdBlockManager::instance()->blockedRequestsForUrl(view->url()).count();
if (count > 0) {
setBadgeText(QString::number(count));
} else {
@ -114,39 +114,39 @@ void AdBlockIcon::updateBadgeText()
}
}
void AdBlockIcon::webPageChanged(WebPage *page)
void AdBlockIcon::webViewChanged(WebView *view)
{
updateState();
if (m_page) {
disconnect(m_page.data(), &QWebEnginePage::urlChanged, this, &AdBlockIcon::updateState);
if (m_view) {
disconnect(m_view.data(), &WebView::urlChanged, this, &AdBlockIcon::updateState);
}
m_page = page;
m_view = view;
if (m_page) {
connect(m_page.data(), &QWebEnginePage::urlChanged, this, &AdBlockIcon::updateState);
if (m_view) {
connect(m_view.data(), &WebView::urlChanged, this, &AdBlockIcon::updateState);
}
}
void AdBlockIcon::clicked(ClickController *controller)
{
WebPage *page = webPage();
if (!page) {
WebView *view = webView();
if (!view) {
return;
}
AdBlockManager* manager = AdBlockManager::instance();
AdBlockCustomList* customList = manager->customList();
const QUrl pageUrl = page->url();
const QUrl pageUrl = view->url();
QMenu menu;
menu.addAction(tr("Show AdBlock &Settings"), manager, SLOT(showDialog()));
menu.addSeparator();
if (!pageUrl.host().isEmpty() && manager->isEnabled() && manager->canRunOnScheme(pageUrl.scheme())) {
const QString host = page->url().host().contains(QLatin1String("www.")) ? pageUrl.host().mid(4) : pageUrl.host();
const QString host = view->url().host().contains(QLatin1String("www.")) ? pageUrl.host().mid(4) : pageUrl.host();
const QString hostFilter = QString("@@||%1^$document").arg(host);
const QString pageFilter = QString("@@|%1|$document").arg(pageUrl.toString());
@ -170,8 +170,8 @@ void AdBlockIcon::clicked(ClickController *controller)
void AdBlockIcon::blockedRequestsChanged(const QUrl &url)
{
WebPage *page = webPage();
if (!page || url != page->url()) {
WebView *view = webView();
if (!view || url != view->url()) {
return;
}
updateState();

View File

@ -39,11 +39,11 @@ private slots:
private:
void updateState();
void updateBadgeText();
void webPageChanged(WebPage *page);
void webViewChanged(WebView *view);
void clicked(ClickController *controller);
void blockedRequestsChanged(const QUrl &url);
QPointer<WebPage> m_page;
QPointer<WebView> m_view;
};
#endif // ADBLOCKICON_H

View File

@ -960,6 +960,8 @@ void BrowserWindow::refreshHistory()
void BrowserWindow::currentTabChanged()
{
TabbedWebView* view = weView();
m_navigationToolbar->setCurrentView(view);
if (!view) {
return;
}
@ -968,7 +970,6 @@ void BrowserWindow::currentTabChanged()
m_ipLabel->setText(view->getIp());
view->setFocus();
m_navigationToolbar->setCurrentView(view);
updateLoadingActions();
// Setting correct tab order (LocationBar -> WebSearchBar -> WebView)

View File

@ -208,7 +208,7 @@ void NavigationBar::setCurrentView(TabbedWebView *view)
{
for (const WidgetData &data : qAsConst(m_widgets)) {
if (data.button) {
data.button->setWebPage(view->page());
data.button->setWebView(view);
}
}
}
@ -286,9 +286,7 @@ void NavigationBar::addToolButton(AbstractButtonInterface *button)
data.button = button;
m_widgets[data.id] = data;
if (m_window->weView()) {
data.button->setWebPage(m_window->weView()->page());
}
data.button->setWebView(m_window->weView());
reloadLayout();
}

View File

@ -98,17 +98,17 @@ void AbstractButtonInterface::setBadgeText(const QString &badgeText)
emit badgeTextChanged(m_badgeText);
}
WebPage *AbstractButtonInterface::webPage() const
WebView *AbstractButtonInterface::webView() const
{
return m_page;
return m_view;
}
void AbstractButtonInterface::setWebPage(WebPage *page)
void AbstractButtonInterface::setWebView(WebView *view)
{
if (m_page == page) {
if (m_view == view) {
return;
}
m_page = page;
emit webPageChanged(m_page);
m_view = view;
emit webViewChanged(m_view);
}

View File

@ -24,7 +24,7 @@
#include "qzcommon.h"
class WebPage;
class WebView;
class QUPZILLA_EXPORT AbstractButtonInterface : public QObject
{
@ -58,8 +58,8 @@ public:
QString badgeText() const;
void setBadgeText(const QString &badgeText);
WebPage *webPage() const;
void setWebPage(WebPage *page);
WebView *webView() const;
void setWebView(WebView *view);
signals:
void activeChanged(bool active);
@ -67,7 +67,7 @@ signals:
void toolTipChanged(const QString &toolTip);
void iconChanged(const QIcon &icon);
void badgeTextChanged(const QString &badgeText);
void webPageChanged(WebPage *page);
void webViewChanged(WebView *view);
void clicked(ClickController *controller);
private:
@ -76,5 +76,5 @@ private:
QString m_toolTip;
QIcon m_icon;
QString m_badgeText;
WebPage *m_page = nullptr;
WebView *m_view = nullptr;
};

View File

@ -165,6 +165,7 @@ void WebView::setPage(WebPage *page)
// Scrollbars must be added only after QWebEnginePage is set
WebScrollBarManager::instance()->addWebView(this);
emit pageChanged(m_page);
mApp->plugins()->emitWebPageCreated(m_page);
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -75,6 +75,7 @@ public:
static void setForceContextMenuOnMouseRelease(bool force);
signals:
void pageChanged(WebPage *page);
void focusChanged(bool);
void viewportResized(QSize);
void showNotification(QWidget*);

View File

@ -18,7 +18,6 @@
#include "gm_icon.h"
#include "gm_manager.h"
#include "webpage.h"
#include "webview.h"
GM_Icon::GM_Icon(GM_Manager *manager)
@ -44,5 +43,5 @@ QString GM_Icon::name() const
void GM_Icon::openSettings()
{
m_manager->showSettings(webPage() ? webPage()->view() : nullptr);
m_manager->showSettings(webView());
}