diff --git a/LayoutTests/platform/wpe/fast/history/page-cache-video-media-disabled-expected.txt b/LayoutTests/platform/wpe/fast/history/page-cache-video-media-disabled-expected.txt new file mode 100644 index 0000000000000..0944f83611d72 --- /dev/null +++ b/LayoutTests/platform/wpe/fast/history/page-cache-video-media-disabled-expected.txt @@ -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 + diff --git a/LayoutTests/platform/wpe/fast/history/page-cache-video-media-disabled.html b/LayoutTests/platform/wpe/fast/history/page-cache-video-media-disabled.html new file mode 100644 index 0000000000000..ddaf1768e1a3e --- /dev/null +++ b/LayoutTests/platform/wpe/fast/history/page-cache-video-media-disabled.html @@ -0,0 +1,46 @@ + + + +
+ + + + + diff --git a/LayoutTests/platform/wpe/fast/history/page-cache-video-media-enabled-expected.txt b/LayoutTests/platform/wpe/fast/history/page-cache-video-media-enabled-expected.txt new file mode 100644 index 0000000000000..991ac7ef2bbae --- /dev/null +++ b/LayoutTests/platform/wpe/fast/history/page-cache-video-media-enabled-expected.txt @@ -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 + diff --git a/LayoutTests/platform/wpe/fast/history/page-cache-video-media-enabled.html b/LayoutTests/platform/wpe/fast/history/page-cache-video-media-enabled.html new file mode 100644 index 0000000000000..32bb2495ad2da --- /dev/null +++ b/LayoutTests/platform/wpe/fast/history/page-cache-video-media-enabled.html @@ -0,0 +1,44 @@ + + + + + + + + + diff --git a/LayoutTests/platform/wpe/fast/history/resources/page-cache-helper.html b/LayoutTests/platform/wpe/fast/history/resources/page-cache-helper.html new file mode 100644 index 0000000000000..241100a9ee9f8 --- /dev/null +++ b/LayoutTests/platform/wpe/fast/history/resources/page-cache-helper.html @@ -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. + diff --git a/Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml b/Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml index 165778326c5a5..be5036d916281 100644 --- a/Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml +++ b/Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml @@ -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 diff --git a/Source/WebCore/history/BackForwardCache.cpp b/Source/WebCore/history/BackForwardCache.cpp index 9dc23543e8889..436258fff51e2 100644 --- a/Source/WebCore/history/BackForwardCache.cpp +++ b/Source/WebCore/history/BackForwardCache.cpp @@ -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" @@ -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);