Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Unified Diff: content/browser/frame_host/render_frame_host_impl.cc

Issue 2783723002: Keep track in the browser of which frames have onunload and onbeforeunload handlers. (Closed)
Patch Set: fix content_browsertests with plznavigate and also remove now unnecessary unloadcontroller change Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/render_frame_host_impl.cc
diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc
index acb7916dafaa6adc64f982046ca89ddb0ebc838d..61cd6ca6a8bb3ef3fe4f1ea6e608e7130e4bad9c 100644
--- a/content/browser/frame_host/render_frame_host_impl.cc
+++ b/content/browser/frame_host/render_frame_host_impl.cc
@@ -378,6 +378,8 @@ RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance,
is_waiting_for_swapout_ack_(false),
render_frame_created_(false),
navigations_suspended_(false),
+ has_beforeunload_handlers_(false),
+ has_unload_handlers_(false),
is_waiting_for_beforeunload_ack_(false),
unload_ack_is_for_navigation_(false),
is_loading_(false),
@@ -751,6 +753,10 @@ bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) {
IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted,
OnDocumentOnLoadCompleted)
IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK)
+ IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnloadHandlersPresent,
+ OnBeforeUnloadHandlersPresent)
+ IPC_MESSAGE_HANDLER(FrameHostMsg_UnloadHandlersPresent,
+ OnUnloadHandlersPresent)
IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK)
IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu)
IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse,
@@ -2373,6 +2379,14 @@ void RenderFrameHostImpl::OnSetHasReceivedUserGesture() {
frame_tree_node_->OnSetHasReceivedUserGesture();
}
+void RenderFrameHostImpl::OnBeforeUnloadHandlersPresent(bool present) {
+ has_beforeunload_handlers_ = present;
+}
+
+void RenderFrameHostImpl::OnUnloadHandlersPresent(bool present) {
+ has_unload_handlers_ = present;
+}
+
#if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
void RenderFrameHostImpl::OnShowPopup(
const FrameHostMsg_ShowPopup_Params& params) {
@@ -2701,7 +2715,25 @@ void RenderFrameHostImpl::SimulateBeforeUnloadAck() {
}
bool RenderFrameHostImpl::ShouldDispatchBeforeUnload() {
- return IsRenderFrameLive();
+ if (!IsRenderFrameLive())
+ return false;
+
+ for (FrameTreeNode* node : frame_tree_->SubtreeNodes(frame_tree_node_)) {
+ if (node->current_frame_host()->has_beforeunload_handlers_)
+ return true;
+ }
+ return false;
+}
+
+bool RenderFrameHostImpl::ShouldDispatchUnload() {
+ if (!IsRenderFrameLive())
+ return false;
+
+ for (FrameTreeNode* node : frame_tree_->SubtreeNodes(frame_tree_node_)) {
+ if (node->current_frame_host()->has_unload_handlers_)
+ return true;
+ }
+ return false;
}
void RenderFrameHostImpl::UpdateOpener() {

Powered by Google App Engine
This is Rietveld 408576698