Bug 1697266 - Update performance.navigation.type when restoring page from bfcache, r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D107709
This commit is contained in:
Olli Pettay 2021-03-10 14:51:49 +00:00
Родитель aee8b3248c
Коммит 47aebd78b8
4 изменённых файлов: 89 добавлений и 2 удалений

Просмотреть файл

@ -1212,12 +1212,25 @@ void nsDocShell::FirePageHideShowNonRecursive(bool aShow) {
mFiredUnloadEvent = false;
RefPtr<Document> doc = contentViewer->GetDocument();
if (doc) {
RefPtr<nsGlobalWindowInner> inner =
mScriptGlobal ? mScriptGlobal->GetCurrentInnerWindowInternal()
: nullptr;
if (mBrowsingContext->IsTop()) {
doc->NotifyPossibleTitleChange(false);
if (inner) {
// Now that we have found the inner window of the page restored
// from the history, we have to make sure that
// performance.navigation.type is 2.
// Traditionally this type change has been done to the top level page
// only.
inner->GetPerformance()->GetDOMTiming()->NotifyRestoreStart();
}
}
if (mScriptGlobal && mScriptGlobal->GetCurrentInnerWindowInternal()) {
mScriptGlobal->GetCurrentInnerWindowInternal()->Thaw(false);
if (inner) {
inner->Thaw(false);
}
nsCOMPtr<nsIChannel> channel = doc->GetChannel();
if (channel) {
SetCurrentURI(doc->GetDocumentURI(), channel, true, 0);

Просмотреть файл

@ -0,0 +1,25 @@
<html>
<head>
<script>
onpageshow = function() {
let bc = new BroadcastChannel("navigation_type");
bc.onmessage = function(event) {
if (event.data == "loadNewPage") {
bc.close();
location.href = location.href + "?next";
} else if (event.data == "back") {
bc.close();
history.back();
} else if (event.data == "close") {
window.close();
bc.postMessage("closed");
bc.close();
}
}
bc.postMessage({ navigationType: performance.navigation.type });
}
</script>
</head>
<body>
</body>
</html>

Просмотреть файл

@ -88,6 +88,8 @@ support-files = file_bug1536471.html
support-files = file_docshell_gotoindex.html
[test_grandchild.html]
[test_load_history_entry.html]
[test_navigation_type.html]
support-files = file_navigation_type.html
[test_not-opener.html]
[test_opener.html]
[test_popup-navigates-children.html]

Просмотреть файл

@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>performance.navigation.type</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
SimpleTest.waitForExplicitFinish();
let bc = new BroadcastChannel("navigation_type");
let pageshowCount = 0;
bc.onmessage = function(event) {
if (event.data == "closed") {
bc.close();
SimpleTest.finish();
return;
}
++pageshowCount;
if (pageshowCount == 1) {
is(event.data.navigationType, PerformanceNavigation.TYPE_NAVIGATE,
"Should have navigation type TYPE_NAVIGATE.");
bc.postMessage("loadNewPage");
} else if (pageshowCount == 2) {
is(event.data.navigationType, PerformanceNavigation.TYPE_NAVIGATE,
"Should have navigation type TYPE_NAVIGATE.");
bc.postMessage("back");
} else if (pageshowCount == 3) {
is(event.data.navigationType, PerformanceNavigation.TYPE_BACK_FORWARD ,
"Should have navigation type TYPE_BACK_FORWARD .");
bc.postMessage("close");
} else {
ok(false, "Unexpected load");
}
}
function test() {
window.open("file_navigation_type.html", "", "noopener");
}
</script>
</head>
<body onload="test()">
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>