summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-04-30 15:14:45 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-05-13 10:30:56 +0200
commit196ec015caf7634fd1924a9f9e532e230a9b342a (patch)
treeb627b99bf4dda4809d07a39c1ba7b80775ff40f9
parent44126b97f447294570a1d3a1f94a12ef565e467e (diff)
Add NavigateOnDrop settings
Some applications want this to avoid users navigating away from their app content. [ChangeLog][Settings] NavigateOnDropEnabled added, enabled by default. Change-Id: I2cc370f60ef42c708042cbc2503207f8254cf932 Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
-rw-r--r--src/core/api/qwebenginesettings.h3
-rw-r--r--src/core/doc/src/qwebenginesettings_lgpl.qdoc5
-rw-r--r--src/core/web_engine_settings.cpp4
-rw-r--r--src/webenginequick/api/qquickwebenginesettings.cpp24
-rw-r--r--src/webenginequick/api/qquickwebenginesettings_p.h6
-rw-r--r--tests/auto/quick/publicapi/tst_publicapi.cpp2
-rw-r--r--tests/auto/widgets/qwebengineview/BLACKLIST3
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp36
8 files changed, 74 insertions, 9 deletions
diff --git a/src/core/api/qwebenginesettings.h b/src/core/api/qwebenginesettings.h
index ff1935616..de3fdd855 100644
--- a/src/core/api/qwebenginesettings.h
+++ b/src/core/api/qwebenginesettings.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -95,6 +95,7 @@ public:
JavascriptCanPaste,
DnsPrefetchEnabled,
PdfViewerEnabled,
+ NavigateOnDropEnabled,
};
enum FontSize {
diff --git a/src/core/doc/src/qwebenginesettings_lgpl.qdoc b/src/core/doc/src/qwebenginesettings_lgpl.qdoc
index 0fe3620c7..9baeafaaf 100644
--- a/src/core/doc/src/qwebenginesettings_lgpl.qdoc
+++ b/src/core/doc/src/qwebenginesettings_lgpl.qdoc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2015 The Qt Company Ltd.
+ Copyright (C) 2022 The Qt Company Ltd.
Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
@@ -180,6 +180,9 @@
\value PdfViewerEnabled Specifies that PDF documents will be opened in the internal PDF viewer
instead of being downloaded.
Enabled by default. (Added in Qt 5.13)
+ \value NavigateOnDropEnabled Specifies that navigations can be triggered by dropping URLs on
+ the view.
+ Enabled by default. (Added in Qt 6.4)
*/
/*!
diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp
index cfffc87ed..1a0461897 100644
--- a/src/core/web_engine_settings.cpp
+++ b/src/core/web_engine_settings.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -297,6 +297,7 @@ void WebEngineSettings::initDefaults()
#else
s_defaultAttributes.insert(QWebEngineSettings::PdfViewerEnabled, false);
#endif
+ s_defaultAttributes.insert(QWebEngineSettings::NavigateOnDropEnabled, true);
}
if (s_defaultFontFamilies.isEmpty()) {
@@ -403,6 +404,7 @@ void WebEngineSettings::applySettingsToWebPreferences(blink::web_pref::WebPrefer
}
prefs->dom_paste_enabled = testAttribute(QWebEngineSettings::JavascriptCanPaste);
prefs->dns_prefetching_enabled = testAttribute(QWebEngineSettings::DnsPrefetchEnabled);
+ prefs->navigate_on_drag_drop = testAttribute(QWebEngineSettings::NavigateOnDropEnabled);
// Fonts settings.
prefs->standard_font_family_map[blink::web_pref::kCommonScript] =
diff --git a/src/webenginequick/api/qquickwebenginesettings.cpp b/src/webenginequick/api/qquickwebenginesettings.cpp
index f453fc746..bfec872f9 100644
--- a/src/webenginequick/api/qquickwebenginesettings.cpp
+++ b/src/webenginequick/api/qquickwebenginesettings.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -455,6 +455,20 @@ bool QQuickWebEngineSettings::pdfViewerEnabled() const
}
/*!
+ \qmlproperty bool WebEngineSettings::navigateOnDropEnabled
+ \since QtWebEngine 6.4
+
+ Specifies that navigations can be triggered by dropping URLs on
+ the view.
+
+ Enabled by default.
+*/
+bool QQuickWebEngineSettings::navigateOnDropEnabled() const
+{
+ return d_ptr->testAttribute(QWebEngineSettings::NavigateOnDropEnabled);
+}
+
+/*!
\qmlproperty string WebEngineSettings::defaultTextEncoding
\since QtWebEngine 1.2
@@ -729,6 +743,14 @@ void QQuickWebEngineSettings::setPdfViewerEnabled(bool on)
Q_EMIT pdfViewerEnabledChanged();
}
+void QQuickWebEngineSettings::setNavigateOnDropEnabled(bool on)
+{
+ bool wasOn = d_ptr->testAttribute(QWebEngineSettings::NavigateOnDropEnabled);
+ d_ptr->setAttribute(QWebEngineSettings::NavigateOnDropEnabled, on);
+ if (wasOn != on)
+ Q_EMIT navigateOnDropEnabledChanged();
+}
+
void QQuickWebEngineSettings::setUnknownUrlSchemePolicy(QQuickWebEngineSettings::UnknownUrlSchemePolicy policy)
{
QWebEngineSettings::UnknownUrlSchemePolicy oldPolicy = d_ptr->unknownUrlSchemePolicy();
diff --git a/src/webenginequick/api/qquickwebenginesettings_p.h b/src/webenginequick/api/qquickwebenginesettings_p.h
index 3f540fa12..ea2164f95 100644
--- a/src/webenginequick/api/qquickwebenginesettings_p.h
+++ b/src/webenginequick/api/qquickwebenginesettings_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -92,6 +92,7 @@ class Q_WEBENGINEQUICK_PRIVATE_EXPORT QQuickWebEngineSettings : public QObject {
Q_PROPERTY(bool javascriptCanPaste READ javascriptCanPaste WRITE setJavascriptCanPaste NOTIFY javascriptCanPasteChanged REVISION(1,6) FINAL)
Q_PROPERTY(bool dnsPrefetchEnabled READ dnsPrefetchEnabled WRITE setDnsPrefetchEnabled NOTIFY dnsPrefetchEnabledChanged REVISION(1,7) FINAL)
Q_PROPERTY(bool pdfViewerEnabled READ pdfViewerEnabled WRITE setPdfViewerEnabled NOTIFY pdfViewerEnabledChanged REVISION(1,8) FINAL)
+ Q_PROPERTY(bool navigateOnDropEnabled READ navigateOnDropEnabled WRITE setNavigateOnDropEnabled NOTIFY navigateOnDropEnabledChanged REVISION(6,4) FINAL)
QML_NAMED_ELEMENT(WebEngineSettings)
QML_ADDED_IN_VERSION(1, 1)
QML_EXTRA_VERSION(2, 0)
@@ -138,6 +139,7 @@ public:
bool javascriptCanPaste() const;
bool dnsPrefetchEnabled() const;
bool pdfViewerEnabled() const;
+ bool navigateOnDropEnabled() const;
void setAutoLoadImages(bool on);
void setJavascriptEnabled(bool on);
@@ -170,6 +172,7 @@ public:
void setJavascriptCanPaste(bool on);
void setDnsPrefetchEnabled(bool on);
void setPdfViewerEnabled(bool on);
+ void setNavigateOnDropEnabled(bool on);
signals:
void autoLoadImagesChanged();
@@ -203,6 +206,7 @@ signals:
Q_REVISION(1,6) void javascriptCanPasteChanged();
Q_REVISION(1,7) void dnsPrefetchEnabledChanged();
Q_REVISION(1,8) void pdfViewerEnabledChanged();
+ Q_REVISION(6,4) void navigateOnDropEnabledChanged();
private:
explicit QQuickWebEngineSettings(QQuickWebEngineSettings *parentSettings = nullptr);
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index c22176265..edec675f6 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -426,6 +426,8 @@ static const QStringList expectedAPI = QStringList()
<< "QQuickWebEngineSettings.localContentCanAccessRemoteUrlsChanged() --> void"
<< "QQuickWebEngineSettings.localStorageEnabled --> bool"
<< "QQuickWebEngineSettings.localStorageEnabledChanged() --> void"
+ << "QQuickWebEngineSettings.navigateOnDropEnabled --> bool"
+ << "QQuickWebEngineSettings.navigateOnDropEnabledChanged() --> void"
<< "QQuickWebEngineSettings.pdfViewerEnabled --> bool"
<< "QQuickWebEngineSettings.pdfViewerEnabledChanged() --> void"
<< "QQuickWebEngineSettings.playbackRequiresUserGesture --> bool"
diff --git a/tests/auto/widgets/qwebengineview/BLACKLIST b/tests/auto/widgets/qwebengineview/BLACKLIST
index 4bc678d10..ebdf37ea4 100644
--- a/tests/auto/widgets/qwebengineview/BLACKLIST
+++ b/tests/auto/widgets/qwebengineview/BLACKLIST
@@ -15,3 +15,6 @@ b2qt arm
[navigateOnDrop:file]
windows
+
+[navigateOnDrop:file_no_navigate]
+windows
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index 74ac24deb..921b0c52f 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -3519,16 +3519,21 @@ void tst_QWebEngineView::inspectElement()
void tst_QWebEngineView::navigateOnDrop_data()
{
QTest::addColumn<QUrl>("url");
- QTest::newRow("file") << QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).absoluteFilePath("resources/dummy.html"));
- QTest::newRow("qrc") << QUrl("qrc:///resources/dummy.html");
+ QTest::addColumn<bool>("navigateOnDrop");
+ QTest::newRow("file") << QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).absoluteFilePath("resources/dummy.html")) << true;
+ QTest::newRow("qrc") << QUrl("qrc:///resources/dummy.html") << true;
+ QTest::newRow("file_no_navigate") << QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).absoluteFilePath("resources/dummy.html")) << false;
+ QTest::newRow("qrc_no_navigate") << QUrl("qrc:///resources/dummy.html") << false;
}
void tst_QWebEngineView::navigateOnDrop()
{
QFETCH(QUrl, url);
+ QFETCH(bool, navigateOnDrop);
struct WebEngineView : QWebEngineView {
QWebEngineView* createWindow(QWebEnginePage::WebWindowType /* type */) override { return this; }
} view;
+ view.page()->settings()->setAttribute(QWebEngineSettings::NavigateOnDropEnabled, navigateOnDrop);
view.resize(640, 480);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3545,9 +3550,32 @@ void tst_QWebEngineView::navigateOnDrop()
};
sendEvents();
+ if (navigateOnDrop) {
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QVERIFY(loadSpy.last().first().toBool());
+ QCOMPARE(view.url(), url);
+ } else {
+ QTest::qWait(500);
+ QCOMPARE(loadSpy.size(), 0);
+ QVERIFY(view.url() != url);
+ }
+
+ // Check dynamically changing the setting
+ loadSpy.clear();
+ view.page()->settings()->setAttribute(QWebEngineSettings::NavigateOnDropEnabled, !navigateOnDrop);
+ view.setUrl(QUrl("about:blank"));
QTRY_COMPARE(loadSpy.count(), 1);
- QVERIFY(loadSpy.first().first().toBool());
- QCOMPARE(view.url(), url);
+
+ sendEvents();
+ if (!navigateOnDrop) {
+ QTRY_COMPARE(loadSpy.count(), 2);
+ QVERIFY(loadSpy.last().first().toBool());
+ QCOMPARE(view.url(), url);
+ } else {
+ QTest::qWait(500);
+ QCOMPARE(loadSpy.size(), 1);
+ QVERIFY(view.url() != url);
+ }
}
QTEST_MAIN(tst_QWebEngineView)