Commit 70173a82 authored by Laurent Montel's avatar Laurent Montel 😁

Fix Bug 368498 - Kmail does not open links with target="_blank"

FIXED-IN: 5.4.0
BUG: 368498
parent ae04a1a6
......@@ -23,9 +23,9 @@ set(libwebengineviewer_webengine_SRCS
webenginescript.cpp
webengineview.cpp
webenginemanagescript.cpp
webengineprintmessagebox.cpp
webengineexporthtmlpagejob.cpp
webenginenavigationrequestinterceptor.cpp
)
set(libwebengineviewer_interceptor_SRCS
......
/*
Copyright (C) 2016 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "webenginenavigationrequestinterceptor.h"
#include "webenginepage.h"
using namespace WebEngineViewer;
WebEngineNavigationRequestInterceptor::WebEngineNavigationRequestInterceptor(QWebEnginePage *page)
: QWebEnginePage(page),
mTargetPage(page)
{
}
WebEngineNavigationRequestInterceptor::~WebEngineNavigationRequestInterceptor()
{
}
bool WebEngineNavigationRequestInterceptor::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{
Q_UNUSED(isMainFrame);
WebEnginePage *page = qobject_cast<WebEnginePage *>(mTargetPage);
if (type == NavigationTypeLinkClicked && page) {
Q_EMIT page->urlClicked(url);
return false;
}
return false;
}
/*
Copyright (C) 2016 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef WEBENGINENAVIGATIONREQUESTINTERCEPTOR_H
#define WEBENGINENAVIGATIONREQUESTINTERCEPTOR_H
#include <QWebEnginePage>
namespace WebEngineViewer
{
class WebEnginePage;
class WebEngineNavigationRequestInterceptor : public QWebEnginePage
{
Q_OBJECT
public:
explicit WebEngineNavigationRequestInterceptor(QWebEnginePage *page);
~WebEngineNavigationRequestInterceptor();
protected:
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) Q_DECL_OVERRIDE;
private:
QWebEnginePage *mTargetPage;
};
}
#endif // WEBENGINENAVIGATIONREQUESTINTERCEPTOR_H
......@@ -18,6 +18,7 @@
*/
#include "webengineview.h"
#include "webenginenavigationrequestinterceptor.h"
#include "webenginemanagescript.h"
#include "webengineviewer_debug.h"
#include "../config-webengineviewer.h"
......@@ -33,13 +34,26 @@ class WebEngineViewer::WebEngineViewPrivate
public:
WebEngineViewPrivate()
: mSavedRelativePosition(-1),
mCurrentWidget(Q_NULLPTR)
mCurrentWidget(Q_NULLPTR),
mWebEngineNavigatorInterceptor(Q_NULLPTR),
mWebEngineNavigatorInterceptorView(Q_NULLPTR)
{
}
~WebEngineViewPrivate()
{
delete mWebEngineNavigatorInterceptor;
mWebEngineNavigatorInterceptor = Q_NULLPTR;
delete mWebEngineNavigatorInterceptorView;
mWebEngineNavigatorInterceptorView = Q_NULLPTR;
}
qreal mSavedRelativePosition;
QWidget *mCurrentWidget;
WebEngineManageScript *mManagerScript;
WebEngineNavigationRequestInterceptor *mWebEngineNavigatorInterceptor;
WebEngineView *mWebEngineNavigatorInterceptorView;
};
WebEngineView::WebEngineView(QWidget *parent)
......@@ -195,7 +209,13 @@ bool WebEngineView::eventFilter(QObject *obj, QEvent *event)
QWebEngineView *WebEngineView::createWindow(QWebEnginePage::WebWindowType type)
{
Q_UNUSED(type);
return Q_NULLPTR;
delete d->mWebEngineNavigatorInterceptor;
delete d->mWebEngineNavigatorInterceptorView;
d->mWebEngineNavigatorInterceptorView = new WebEngineView();
d->mWebEngineNavigatorInterceptor = new WebEngineNavigationRequestInterceptor(this->page());
d->mWebEngineNavigatorInterceptorView->setPage(d->mWebEngineNavigatorInterceptor);
return d->mWebEngineNavigatorInterceptorView;
}
void WebEngineView::clearRelativePosition()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment