Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Tests that a page with a video element does not go into the back/forward cache when back-forward-cache-with-media is disabled.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


pageshow - not from cache
PASS Page was not restored from the back/forward cache
PASS successfullyParsed is true

TEST COMPLETE

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- webkit-test-runner [ UsesBackForwardCache=true BackForwardCacheWithMediaEnabled=false ] -->
<!DOCTYPE html>
<html>
<body>
<script src="../../../../resources/js-test-pre.js"></script>
<script>
description('Tests that a page with a video element does not go into the back/forward cache when back-forward-cache-with-media is disabled.');
window.jsTestIsAsync = true;

window.addEventListener("pageshow", function(event) {
debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
if (!window.sessionStorage.pageWithVideoMediaDisabledTestStarted)
return;

delete window.sessionStorage.pageWithVideoMediaDisabledTestStarted;

if (event.persisted)
testFailed("Page did enter and was restored from the back/forward cache");
else
testPassed("Page was not restored from the back/forward cache");

finishJSTest();
}, false);

window.addEventListener("pagehide", function(event) {
debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
if (event.persisted)
testFailed("Page entered the back/forward cache.");
}, false);

window.addEventListener('load', function() {
if (window.sessionStorage.pageWithVideoMediaDisabledTestStarted)
return;

var video = document.createElement("video");
document.body.appendChild(video);

setTimeout(function() {
window.sessionStorage.pageWithVideoMediaDisabledTestStarted = true;
window.location.href = "resources/page-cache-helper.html";
}, 0);
}, false);
</script>
<script src="../../../../resources/js-test-post.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Tests that a page with a video element goes into the back/forward cache when back-forward-cache-with-media is enabled.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


pageshow - not from cache
pagehide - entering cache
pageshow - from cache
PASS Page did enter and was restored from the back/forward cache
PASS successfullyParsed is true

TEST COMPLETE

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!-- webkit-test-runner [ UsesBackForwardCache=true BackForwardCacheWithMediaEnabled=true ] -->
<!DOCTYPE html>
<html>
<body>
<script src="../../../../resources/js-test-pre.js"></script>
<script>
description('Tests that a page with a video element goes into the back/forward cache when back-forward-cache-with-media is enabled.');
window.jsTestIsAsync = true;

window.addEventListener("pageshow", function(event) {
debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
if (!window.sessionStorage.pageWithVideoMediaEnabledTestStarted)
return;

delete window.sessionStorage.pageWithVideoMediaEnabledTestStarted;

if (event.persisted)
testPassed("Page did enter and was restored from the back/forward cache");
else
testFailed("Page was not restored from the back/forward cache");

finishJSTest();
}, false);

window.addEventListener("pagehide", function(event) {
debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
}, false);

window.addEventListener('load', function() {
if (window.sessionStorage.pageWithVideoMediaEnabledTestStarted)
return;

var video = document.createElement("video");
document.body.appendChild(video);

setTimeout(function() {
window.sessionStorage.pageWithVideoMediaEnabledTestStarted = true;
window.location.href = "resources/page-cache-helper.html";
}, 0);
}, false);
</script>
<script src="../../../../resources/js-test-post.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This page should go back. If a test outputs the contents of this
page, then the test page failed to enter the page cache.
<script>
function triggerBackNavigation() {
setTimeout(function() {
history.back();
}, 0);
}

window.addEventListener("pageshow", (event) => {
if (event.persisted)
triggerBackNavigation();
});

window.addEventListener("load", function() {
triggerBackNavigation();
});
</script>
15 changes: 15 additions & 0 deletions Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,21 @@ AzimuthAngleEnabled:
"PLATFORM(COCOA)": true
default: false

BackForwardCacheWithMediaEnabled:
type: bool
status: stable
category: media
humanReadableName: "Back/Forward Cache with Media"
humanReadableDescription: "Enable back/forward cache for pages with media"
condition: PLATFORM(WPE)
defaultValue:
WebKitLegacy:
default: true
WebKit:
default: true
WebCore:
default: true

BackgroundFetchAPIEnabled:
type: bool
status: testable
Expand Down
12 changes: 12 additions & 0 deletions Source/WebCore/history/BackForwardCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "FocusController.h"
#include "FrameDestructionObserverInlines.h"
#include "FrameLoader.h"
#include "HTMLMediaElement.h"
#include "HTTPParsers.h"
#include "HistoryController.h"
#include "LocalDOMWindow.h"
Expand Down Expand Up @@ -217,6 +218,17 @@ static bool canCachePage(Page& page)
logBackForwardCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::isDisabledKey());
isCacheable = false;
}
#if PLATFORM(WPE)
if (!page.settings().backForwardCacheWithMediaEnabled()) {
bool hasMedia = false;
page.forEachMediaElement([&](HTMLMediaElement&) { hasMedia = true; });
if (hasMedia) {
PCLOG(" -Page contains media elements and back/forward cache with media is disabled"_s);
logBackForwardCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::pageContainsMediaEngineKey());
isCacheable = false;
}
}
#endif
#if ENABLE(DEVICE_ORIENTATION) && !PLATFORM(IOS_FAMILY)
if (DeviceMotionController::isActiveAt(&page)) {
PCLOG(" -Page is using DeviceMotion"_s);
Expand Down