From d8fcefcddefad4aa54ef34228abfbcf10491a448 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Tue, 23 Nov 2021 20:04:35 +0000 Subject: [PATCH] Bug 1740516 - Fire pageshow for an iframe before the pageshow for its parent window when coming out of BFCache with session history in parent. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D131891 --- docshell/base/BrowsingContext.cpp | 21 +++-- .../test/mochitest/file_bug1740516_1.html | 29 +++++++ .../mochitest/file_bug1740516_1_inner.html | 15 ++++ .../test/mochitest/file_bug1740516_2.html | 11 +++ docshell/test/mochitest/mochitest.ini | 5 ++ docshell/test/mochitest/test_bug1740516.html | 76 +++++++++++++++++++ 6 files changed, 151 insertions(+), 6 deletions(-) create mode 100644 docshell/test/mochitest/file_bug1740516_1.html create mode 100644 docshell/test/mochitest/file_bug1740516_1_inner.html create mode 100644 docshell/test/mochitest/file_bug1740516_2.html create mode 100644 docshell/test/mochitest/test_bug1740516.html diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index 492246ef394b..8025adb2d19f 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -2910,12 +2910,21 @@ void BrowsingContext::DidSet(FieldIndex) { nsDocShell::Cast(mDocShell)->MaybeDisconnectChildListenersOnPageHide(); } - PreOrderWalk([&](BrowsingContext* aContext) { - nsCOMPtr shell = aContext->GetDocShell(); - if (shell) { - nsDocShell::Cast(shell)->FirePageHideShowNonRecursive(!isInBFCache); - } - }); + if (isInBFCache) { + PreOrderWalk([&](BrowsingContext* aContext) { + nsCOMPtr shell = aContext->GetDocShell(); + if (shell) { + nsDocShell::Cast(shell)->FirePageHideShowNonRecursive(false); + } + }); + } else { + PostOrderWalk([&](BrowsingContext* aContext) { + nsCOMPtr shell = aContext->GetDocShell(); + if (shell) { + nsDocShell::Cast(shell)->FirePageHideShowNonRecursive(true); + } + }); + } if (isInBFCache) { PreOrderWalk([&](BrowsingContext* aContext) { diff --git a/docshell/test/mochitest/file_bug1740516_1.html b/docshell/test/mochitest/file_bug1740516_1.html new file mode 100644 index 000000000000..cf3a54027bd3 --- /dev/null +++ b/docshell/test/mochitest/file_bug1740516_1.html @@ -0,0 +1,29 @@ + + + + + + + + + + diff --git a/docshell/test/mochitest/file_bug1740516_1_inner.html b/docshell/test/mochitest/file_bug1740516_1_inner.html new file mode 100644 index 000000000000..159c6bde5aec --- /dev/null +++ b/docshell/test/mochitest/file_bug1740516_1_inner.html @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/docshell/test/mochitest/file_bug1740516_2.html b/docshell/test/mochitest/file_bug1740516_2.html new file mode 100644 index 000000000000..2dc714feef0c --- /dev/null +++ b/docshell/test/mochitest/file_bug1740516_2.html @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/docshell/test/mochitest/mochitest.ini b/docshell/test/mochitest/mochitest.ini index 1501867d613e..c65697074052 100644 --- a/docshell/test/mochitest/mochitest.ini +++ b/docshell/test/mochitest/mochitest.ini @@ -112,6 +112,11 @@ support-files = file_bug675587.html [test_bug1729662.html] support-files = file_bug1729662.html +[test_bug1740516.html] +support-files = + file_bug1740516_1.html + file_bug1740516_1_inner.html + file_bug1740516_2.html [test_close_onpagehide_by_history_back.html] [test_close_onpagehide_by_window_close.html] [test_compressed_multipart.html] diff --git a/docshell/test/mochitest/test_bug1740516.html b/docshell/test/mochitest/test_bug1740516.html new file mode 100644 index 000000000000..dba7e8c2aa96 --- /dev/null +++ b/docshell/test/mochitest/test_bug1740516.html @@ -0,0 +1,76 @@ + + + + + Test pageshow event order for iframe + + + + + +

+ +

+
+