summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/web_contents_adapter.cpp6
-rw-r--r--src/core/web_contents_adapter.h1
-rw-r--r--src/core/web_contents_adapter_client.h1
-rw-r--r--src/core/web_contents_delegate_qt.cpp9
-rw-r--r--src/core/web_contents_delegate_qt.h1
-rw-r--r--src/webengine/api/qquickwebenginetestsupport_p.h1
-rw-r--r--src/webengine/api/qquickwebengineview.cpp11
-rw-r--r--src/webengine/api/qquickwebengineview_p.h1
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h1
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp11
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h1
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h1
-rw-r--r--src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc5
13 files changed, 50 insertions, 0 deletions
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 2b2512fc3..92c831f94 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -576,6 +576,12 @@ void WebContentsAdapter::selectAll()
d->webContents->SelectAll();
}
+void WebContentsAdapter::requestClose()
+{
+ Q_D(WebContentsAdapter);
+ d->webContents->DispatchBeforeUnload(false);
+}
+
void WebContentsAdapter::navigateToIndex(int offset)
{
Q_D(WebContentsAdapter);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index ecb084e56..54bec9adf 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -128,6 +128,7 @@ public:
void inspectElementAt(const QPoint &location);
bool hasInspector() const;
void exitFullScreen();
+ void requestClose();
void wasShown();
void wasHidden();
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 2b9b62229..6b203fc90 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -208,6 +208,7 @@ public:
virtual void unhandledKeyEvent(QKeyEvent *event) = 0;
virtual void adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect & initialGeometry) = 0;
virtual void close() = 0;
+ virtual void windowCloseRejected() = 0;
virtual bool contextMenuRequested(const WebEngineContextMenuData&) = 0;
virtual void navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) = 0;
virtual void requestFullScreen(bool) = 0;
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index 1c37f62df..497910a9c 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -390,4 +390,13 @@ void WebContentsDelegateQt::MoveValidationMessage(content::WebContents *web_cont
m_viewClient->moveValidationMessage(toQt(anchor_in_root_view));
}
+void WebContentsDelegateQt::BeforeUnloadFired(content::WebContents *tab, bool proceed, bool *proceed_to_fire_unload)
+{
+ Q_UNUSED(tab);
+ Q_ASSERT(proceed_to_fire_unload);
+ *proceed_to_fire_unload = proceed;
+ if (!proceed)
+ m_viewClient->windowCloseRejected();
+}
+
} // namespace QtWebEngineCore
diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h
index 14421d060..abdf75fe5 100644
--- a/src/core/web_contents_delegate_qt.h
+++ b/src/core/web_contents_delegate_qt.h
@@ -91,6 +91,7 @@ public:
virtual void ShowValidationMessage(content::WebContents *web_contents, const gfx::Rect &anchor_in_root_view, const base::string16 &main_text, const base::string16 &sub_text) Q_DECL_OVERRIDE;
virtual void HideValidationMessage(content::WebContents *web_contents) Q_DECL_OVERRIDE;
virtual void MoveValidationMessage(content::WebContents *web_contents, const gfx::Rect &anchor_in_root_view) Q_DECL_OVERRIDE;
+ void BeforeUnloadFired(content::WebContents* tab, bool proceed, bool* proceed_to_fire_unload) Q_DECL_OVERRIDE;
// WebContentsObserver overrides
virtual void RenderFrameDeleted(content::RenderFrameHost *render_frame_host) Q_DECL_OVERRIDE;
diff --git a/src/webengine/api/qquickwebenginetestsupport_p.h b/src/webengine/api/qquickwebenginetestsupport_p.h
index 9690e538d..d4b50ac2d 100644
--- a/src/webengine/api/qquickwebenginetestsupport_p.h
+++ b/src/webengine/api/qquickwebenginetestsupport_p.h
@@ -80,6 +80,7 @@ public:
Q_SIGNALS:
void validationMessageShown(const QString &mainText, const QString &subText);
+ void windowCloseRejected();
private:
QScopedPointer<QQuickWebEngineErrorPage> m_errorPage;
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 96a80a940..3a05477a1 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -508,6 +508,14 @@ void QQuickWebEngineViewPrivate::close()
emit q->windowCloseRequested();
}
+void QQuickWebEngineViewPrivate::windowCloseRejected()
+{
+#ifdef ENABLE_QML_TESTSUPPORT_API
+ if (m_testSupport)
+ Q_EMIT m_testSupport->windowCloseRejected();
+#endif
+}
+
void QQuickWebEngineViewPrivate::requestFullScreen(bool fullScreen)
{
Q_Q(QQuickWebEngineView);
@@ -1298,6 +1306,9 @@ void QQuickWebEngineView::triggerWebAction(WebAction action)
case ExitFullScreen:
d->adapter->exitFullScreen();
break;
+ case RequestClose:
+ d->adapter->requestClose();
+ break;
default:
Q_UNREACHABLE();
}
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index 6efb2b6f9..d1d8dacbb 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -226,6 +226,7 @@ public:
InspectElement,
ExitFullScreen,
+ RequestClose,
WebActionCount
};
diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
index 0140111b9..271ab63be 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -143,6 +143,7 @@ public:
virtual void unhandledKeyEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
virtual void adoptNewWindow(QtWebEngineCore::WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &) Q_DECL_OVERRIDE;
virtual void close() Q_DECL_OVERRIDE;
+ virtual void windowCloseRejected() Q_DECL_OVERRIDE;
virtual void requestFullScreen(bool) Q_DECL_OVERRIDE;
virtual bool isFullScreen() const Q_DECL_OVERRIDE;
virtual bool contextMenuRequested(const QtWebEngineCore::WebEngineContextMenuData &) Q_DECL_OVERRIDE;
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 5d91b3b7f..bb0917918 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -224,6 +224,11 @@ void QWebEnginePagePrivate::close()
Q_EMIT q->windowCloseRequested();
}
+void QWebEnginePagePrivate::windowCloseRejected()
+{
+ // Do nothing for now.
+}
+
void QWebEnginePagePrivate::didRunJavaScript(quint64 requestId, const QVariant& result)
{
m_callbacks.invoke(requestId, result);
@@ -639,6 +644,9 @@ QAction *QWebEnginePage::action(WebAction action) const
case ExitFullScreen:
text = tr("Exit Full Screen Mode");
break;
+ case RequestClose:
+ text = tr("Close Page");
+ break;
default:
break;
}
@@ -809,6 +817,9 @@ void QWebEnginePage::triggerAction(WebAction action, bool)
case ExitFullScreen:
d->adapter->exitFullScreen();
break;
+ case RequestClose:
+ d->adapter->requestClose();
+ break;
default:
Q_UNREACHABLE();
}
diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
index 90fa62f97..4b5e6456d 100644
--- a/src/webenginewidgets/api/qwebenginepage.h
+++ b/src/webenginewidgets/api/qwebenginepage.h
@@ -108,6 +108,7 @@ public:
InspectElement,
ExitFullScreen,
+ RequestClose,
WebActionCount
};
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index 8d9bc2517..f5c01ce1b 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -95,6 +95,7 @@ public:
virtual void unhandledKeyEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
virtual void adoptNewWindow(QtWebEngineCore::WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &initialGeometry) Q_DECL_OVERRIDE;
virtual void close() Q_DECL_OVERRIDE;
+ virtual void windowCloseRejected() Q_DECL_OVERRIDE;
virtual bool contextMenuRequested(const QtWebEngineCore::WebEngineContextMenuData &data) Q_DECL_OVERRIDE;
virtual void navigationRequested(int navigationType, const QUrl &url, int &navigationRequestAction, bool isMainFrame) Q_DECL_OVERRIDE;
virtual void requestFullScreen(bool) Q_DECL_OVERRIDE;
diff --git a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
index 4a7545c14..b7b3bf022 100644
--- a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
@@ -119,6 +119,9 @@
\value InspectElement Trigger any attached Web Inspector to inspect the highlighed element.
(Added in Qt 5.6)
\value ExitFullScreen Exit the fullscreen mode. (Added in Qt 5.6)
+ \value RequestClose Request to close the web page. If defined, the \c{window.onbeforeunload}
+ handler is run, and the user can confirm or reject to close the page. If the close
+ request is confirmed, \c windowCloseRequested is emitted. (Added in Qt 5.6)
\omitvalue WebActionCount
@@ -482,6 +485,8 @@
This signal is emitted whenever the page requests the web browser window to be closed,
for example through the JavaScript \c{window.close()} call.
+
+ \sa QWebEnginePage::RequestClose
*/
/*!