summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-27 19:02:35 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-27 19:02:35 (GMT)
commit70173a8245c6f0401619f5be9cc4770451feeb21 (patch)
tree698247effe4c7364e7cbaf5730ba779b9b2290a5
parentae04a1a6cff7e600672d3d9a3acb38fe519b7f57 (diff)
Fix Bug 368498 - Kmail does not open links with target="_blank"
FIXED-IN: 5.4.0 BUG: 368498
-rw-r--r--webengineviewer/src/CMakeLists.txt2
-rw-r--r--webengineviewer/src/webenginenavigationrequestinterceptor.cpp47
-rw-r--r--webengineviewer/src/webenginenavigationrequestinterceptor.h43
-rw-r--r--webengineviewer/src/webengineview.cpp24
4 files changed, 113 insertions, 3 deletions
diff --git a/webengineviewer/src/CMakeLists.txt b/webengineviewer/src/CMakeLists.txt
index aada8bf..deca7d2 100644
--- a/webengineviewer/src/CMakeLists.txt
+++ b/webengineviewer/src/CMakeLists.txt
@@ -23,9 +23,9 @@ set(libwebengineviewer_webengine_SRCS
webenginescript.cpp
webengineview.cpp
webenginemanagescript.cpp
-
webengineprintmessagebox.cpp
webengineexporthtmlpagejob.cpp
+ webenginenavigationrequestinterceptor.cpp
)
set(libwebengineviewer_interceptor_SRCS
diff --git a/webengineviewer/src/webenginenavigationrequestinterceptor.cpp b/webengineviewer/src/webenginenavigationrequestinterceptor.cpp
new file mode 100644
index 0000000..f5d34cd
--- /dev/null
+++ b/webengineviewer/src/webenginenavigationrequestinterceptor.cpp
@@ -0,0 +1,47 @@
+/*
+ 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;
+}
+
diff --git a/webengineviewer/src/webenginenavigationrequestinterceptor.h b/webengineviewer/src/webenginenavigationrequestinterceptor.h
new file mode 100644
index 0000000..ad6e881
--- /dev/null
+++ b/webengineviewer/src/webenginenavigationrequestinterceptor.h
@@ -0,0 +1,43 @@
+/*
+ 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
diff --git a/webengineviewer/src/webengineview.cpp b/webengineviewer/src/webengineview.cpp
index 925990d..96a8e5b 100644
--- a/webengineviewer/src/webengineview.cpp
+++ b/webengineviewer/src/webengineview.cpp
@@ -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()