Title: [254387] trunk
Revision
254387
Author
jer.no...@apple.com
Date
2020-01-10 18:32:00 -0800 (Fri, 10 Jan 2020)

Log Message

[iOS] Audio from non-frontmost tab continues when app is backgrounded
https://bugs.webkit.org/show_bug.cgi?id=206101
<rdar://problem/58089916>

Reviewed by Eric Carlson.

Source/WebKit:

Tests: WKWebViewPausePlayingAudioTests.InWindow
       WKWebViewPausePlayingAudioTests.OutOfWindow

The ApplicationStateTracker will only send notifications about application state to
WebPageProxies when those proxies' views are actually in-window. Add a separate application
state observer strictly for media which fires only when application state notifications are
received while the view is not in-window.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentView.mm:
(-[WKContentView _commonInitializationWithProcessPool:configuration:]):
(-[WKContentView _applicationDidEnterBackground:]):
(-[WKContentView _applicationWillEnterForeground:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::applicationDidEnterBackgroundForMedia):
(WebKit::WebPageProxy::applicationWillEnterForegroundForMedia):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::applicationDidEnterBackgroundForMedia):
(WebKit::WebPage::applicationWillEnterForegroundForMedia):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/ios/WKWebViewPausePlayingAudioTests.mm: Added.
(TestWebKitAPI::autoplayingConfiguration):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/platform/ipad/TestExpectations (254386 => 254387)


--- trunk/LayoutTests/platform/ipad/TestExpectations	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/LayoutTests/platform/ipad/TestExpectations	2020-01-11 02:32:00 UTC (rev 254387)
@@ -54,12 +54,6 @@
 fast/scrolling/ios/body-overflow-hidden-height-100-percent-zoomed-2.html [ Skip ]
 fast/scrolling/ios/body-overflow-hidden-height-100-percent-zoomed-1.html [ Skip ]
 
-# <rdar://problem/51918994> [ iPad Sim ] Layout test media/video-concurrent-visible-playback.html is a flaky timeout
-media/video-concurrent-visible-playback.html [ Pass Timeout ]
-
-# <rdar://problem/51920910> [ iPad Sim ] Layout test media/video-object-fit-change.html is a flaky timeout
-media/video-concurrent-visible-playback.html [ Pass Timeout ]
-
 # <rdar://problem/52914585> (Layout Test fast/forms/file/file-input-reset-using-open-panel.html is Failing)
 fast/forms/file/file-input-reset-using-open-panel.html [ ImageOnlyFailure ]
 

Modified: trunk/Source/WebKit/ChangeLog (254386 => 254387)


--- trunk/Source/WebKit/ChangeLog	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/Source/WebKit/ChangeLog	2020-01-11 02:32:00 UTC (rev 254387)
@@ -1,3 +1,33 @@
+2020-01-10  Jer Noble  <jer.no...@apple.com>
+
+        [iOS] Audio from non-frontmost tab continues when app is backgrounded
+        https://bugs.webkit.org/show_bug.cgi?id=206101
+        <rdar://problem/58089916>
+
+        Reviewed by Eric Carlson.
+
+        Tests: WKWebViewPausePlayingAudioTests.InWindow
+               WKWebViewPausePlayingAudioTests.OutOfWindow
+
+        The ApplicationStateTracker will only send notifications about application state to 
+        WebPageProxies when those proxies' views are actually in-window. Add a separate application
+        state observer strictly for media which fires only when application state notifications are
+        received while the view is not in-window.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WKContentView.mm:
+        (-[WKContentView _commonInitializationWithProcessPool:configuration:]):
+        (-[WKContentView _applicationDidEnterBackground:]):
+        (-[WKContentView _applicationWillEnterForeground:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::applicationDidEnterBackgroundForMedia):
+        (WebKit::WebPageProxy::applicationWillEnterForegroundForMedia):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::applicationDidEnterBackgroundForMedia):
+        (WebKit::WebPage::applicationWillEnterForegroundForMedia):
+
 2020-01-10  Simon Fraser  <simon.fra...@apple.com>
 
         Introduce ENABLE_META_VIEWPORT and use it in some WK2 code

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (254386 => 254387)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2020-01-11 02:32:00 UTC (rev 254387)
@@ -759,6 +759,8 @@
     bool lastObservedStateWasBackground() const { return m_lastObservedStateWasBackground; }
     void applicationWillResignActive();
     void applicationDidBecomeActive();
+    void applicationDidEnterBackgroundForMedia();
+    void applicationWillEnterForegroundForMedia();
     void commitPotentialTapFailed();
     void didNotHandleTapAsClick(const WebCore::IntPoint&);
     void didCompleteSyntheticClick();

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.mm (254386 => 254387)


--- trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2020-01-11 02:32:00 UTC (rev 254387)
@@ -203,6 +203,8 @@
 
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:[UIApplication sharedApplication]];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:[UIApplication sharedApplication]];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:[UIApplication sharedApplication]];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:[UIApplication sharedApplication]];
 
 #if USE(UIKIT_KEYBOARD_ADDITIONS)
     if (WebCore::IOSApplication::isEvernote() && !linkedOnOrAfter(WebKit::SDKVersion::FirstWhereWKContentViewDoesNotOverrideKeyCommands))
@@ -718,6 +720,18 @@
     _page->applicationDidBecomeActive();
 }
 
+- (void)_applicationDidEnterBackground:(NSNotification*)notification
+{
+    if (!self.window)
+        _page->applicationDidEnterBackgroundForMedia();
+}
+
+- (void)_applicationWillEnterForeground:(NSNotification*)notification
+{
+    if (!self.window)
+        _page->applicationWillEnterForegroundForMedia();
+}
+
 @end
 
 #pragma mark Printing

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (254386 => 254387)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2020-01-11 02:32:00 UTC (rev 254387)
@@ -696,6 +696,22 @@
     m_process->send(Messages::WebPage::ApplicationWillResignActive(), m_webPageID);
 }
 
+void WebPageProxy::applicationDidEnterBackgroundForMedia()
+{
+    bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
+    RELEASE_LOG_IF_ALLOWED(ViewState, "applicationWillEnterForegroundForMedia: isSuspendedUnderLock? %d", isSuspendedUnderLock);
+
+    m_process->send(Messages::WebPage::ApplicationDidEnterBackgroundForMedia(isSuspendedUnderLock), m_webPageID);
+}
+
+void WebPageProxy::applicationWillEnterForegroundForMedia()
+{
+    bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
+    RELEASE_LOG_IF_ALLOWED(ViewState, "applicationDidEnterBackgroundForMedia: isSuspendedUnderLock? %d", isSuspendedUnderLock);
+
+    m_process->send(Messages::WebPage::ApplicationWillEnterForegroundForMedia(isSuspendedUnderLock), m_webPageID);
+}
+
 void WebPageProxy::applicationDidBecomeActive()
 {
 #if HAVE(AVKIT)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (254386 => 254387)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-01-11 02:32:00 UTC (rev 254387)
@@ -977,6 +977,8 @@
     void applicationDidFinishSnapshottingAfterEnteringBackground();
     void applicationWillEnterForeground(bool isSuspendedUnderLock);
     void applicationDidBecomeActive();
+    void applicationDidEnterBackgroundForMedia(bool isSuspendedUnderLock);
+    void applicationWillEnterForegroundForMedia(bool isSuspendedUnderLock);
     void didFinishContentChangeObserving(WKContentChange);
 
     bool platformPrefersTextLegibilityBasedZoomScaling() const;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (254386 => 254387)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2020-01-11 02:32:00 UTC (rev 254387)
@@ -99,6 +99,8 @@
     ApplicationDidFinishSnapshottingAfterEnteringBackground()
     ApplicationWillEnterForeground(bool isSuspendedUnderLock)
     ApplicationDidBecomeActive()
+    ApplicationDidEnterBackgroundForMedia(bool isSuspendedUnderLock)
+    ApplicationWillEnterForegroundForMedia(bool isSuspendedUnderLock)
     ContentSizeCategoryDidChange(String contentSizeCategory)
     GetSelectionContext(WebKit::CallbackID callbackID)
     SetAllowsMediaDocumentInlinePlayback(bool allows)

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (254386 => 254387)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-01-11 02:32:00 UTC (rev 254387)
@@ -3596,6 +3596,16 @@
         m_page->applicationDidBecomeActive();
 }
 
+void WebPage::applicationDidEnterBackgroundForMedia(bool isSuspendedUnderLock)
+{
+    [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationDidEnterBackgroundNotification object:nil userInfo:@{@"isSuspendedUnderLock": @(isSuspendedUnderLock)}];
+}
+
+void WebPage::applicationWillEnterForegroundForMedia(bool isSuspendedUnderLock)
+{
+    [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationWillEnterForegroundNotification object:nil userInfo:@{@"isSuspendedUnderLock": @(isSuspendedUnderLock)}];
+}
+
 static inline void adjustVelocityDataForBoundedScale(VelocityData& velocityData, double exposedRectScale, double minimumScale, double maximumScale)
 {
     if (velocityData.scaleChangeRate) {

Modified: trunk/Tools/ChangeLog (254386 => 254387)


--- trunk/Tools/ChangeLog	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/Tools/ChangeLog	2020-01-11 02:32:00 UTC (rev 254387)
@@ -1,3 +1,16 @@
+2020-01-10  Jer Noble  <jer.no...@apple.com>
+
+        [iOS] Audio from non-frontmost tab continues when app is backgrounded
+        https://bugs.webkit.org/show_bug.cgi?id=206101
+        <rdar://problem/58089916>
+
+        Reviewed by Eric Carlson.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/ios/WKWebViewPausePlayingAudioTests.mm: Added.
+        (TestWebKitAPI::autoplayingConfiguration):
+        (TestWebKitAPI::TEST):
+
 2020-01-10  Jonathan Bedard  <jbed...@apple.com>
 
         Python3: Support Source/WebKit/Scripts/webkit

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (254386 => 254387)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-01-11 01:52:56 UTC (rev 254386)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-01-11 02:32:00 UTC (rev 254387)
@@ -901,6 +901,7 @@
 		CD0BD0A61F79924D001AB2CF /* ContextMenuImgWithVideo.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD0BD0A51F799220001AB2CF /* ContextMenuImgWithVideo.mm */; };
 		CD0BD0A81F79982D001AB2CF /* ContextMenuImgWithVideo.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */; };
 		CD227E44211A4D5D00D285AF /* PreferredAudioBufferSize.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD227E43211A4D5D00D285AF /* PreferredAudioBufferSize.mm */; };
+		CD27A1C123C661ED006E11DD /* WKWebViewPausePlayingAudioTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD27A1C023C661ED006E11DD /* WKWebViewPausePlayingAudioTests.mm */; };
 		CD2D0D1A213465560018C784 /* NowPlaying.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD2D0D19213465560018C784 /* NowPlaying.mm */; };
 		CD3065E02165682E00E895DF /* VideoQualityDisplayCompositing.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD3065DF2165682E00E895DF /* VideoQualityDisplayCompositing.mm */; };
 		CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */; };
@@ -2415,6 +2416,7 @@
 		CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = ContextMenuImgWithVideo.html; sourceTree = "<group>"; };
 		CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = "<group>"; };
 		CD227E43211A4D5D00D285AF /* PreferredAudioBufferSize.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PreferredAudioBufferSize.mm; sourceTree = "<group>"; };
+		CD27A1C023C661ED006E11DD /* WKWebViewPausePlayingAudioTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewPausePlayingAudioTests.mm; sourceTree = "<group>"; };
 		CD2D0D19213465560018C784 /* NowPlaying.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NowPlaying.mm; sourceTree = "<group>"; };
 		CD3065DF2165682E00E895DF /* VideoQualityDisplayCompositing.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoQualityDisplayCompositing.mm; sourceTree = "<group>"; };
 		CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "video-with-muted-audio-and-webaudio.html"; sourceTree = "<group>"; };
@@ -3221,6 +3223,7 @@
 				F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */,
 				514958BD1F7427AC00E87BAD /* WKWebViewAutofillTests.mm */,
 				1CACADA0230620AD0007D54C /* WKWebViewOpaque.mm */,
+				CD27A1C023C661ED006E11DD /* WKWebViewPausePlayingAudioTests.mm */,
 			);
 			path = ios;
 			sourceTree = "<group>";
@@ -4851,6 +4854,7 @@
 				2D2BEB2D22324E5F005544CA /* RequestTextInputContext.mm in Sources */,
 				7C83E0C41D0A654200FEBCF3 /* RequiresUserActionForPlayback.mm in Sources */,
 				7CCE7F0E1A411AE600447C4C /* ResizeReversePaginatedWebView.cpp in Sources */,
+				CD27A1C123C661ED006E11DD /* WKWebViewPausePlayingAudioTests.mm in Sources */,
 				7CCE7F0F1A411AE600447C4C /* ResizeWindowAfterCrash.cpp in Sources */,
 				5CB7AFDC23C4529700E49CF3 /* ResourceLoadDelegate.mm in Sources */,
 				51C8E1A51F26AF4C00BF731B /* ResourceLoadStatistics.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewPausePlayingAudioTests.mm (0 => 254387)


--- trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewPausePlayingAudioTests.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/WKWebViewPausePlayingAudioTests.mm	2020-01-11 02:32:00 UTC (rev 254387)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+
+namespace TestWebKitAPI {
+
+static RetainPtr<WKWebViewConfiguration> autoplayingConfiguration()
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+    configuration.get().allowsInlineMediaPlayback = YES;
+    configuration.get()._inlineMediaPlaybackRequiresPlaysInlineAttribute = NO;
+    return configuration;
+}
+
+TEST(WKWebViewPausePlayingAudioTests, InWindow)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:autoplayingConfiguration().get() addToWindow:YES]);
+
+    bool isPlaying = false;
+    [webView performAfterReceivingMessage:@"playing" action:[&] { isPlaying = true; }];
+
+    [webView synchronouslyLoadTestPageNamed:@"video-with-audio"];
+    [webView objectByEvaluatingJavaScript:@"document.querySelector('video').addEventListener('pause', paused)"];
+    Util::run(&isPlaying);
+
+    bool isPaused = false;
+    [webView performAfterReceivingMessage:@"paused" action:[&] { isPaused = true; }];
+
+    [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification object:UIApplication.sharedApplication userInfo:@{@"isSuspendedUnderLock": @NO }];
+    [NSNotificationCenter.defaultCenter postNotificationName:UISceneDidEnterBackgroundNotification object:webView.get().window.windowScene];
+    Util::run(&isPaused);
+
+    [webView objectByEvaluatingJavaScript:@"document.querySelector('video').addEventListener('play', playing)"];
+
+    isPlaying = false;
+    [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationWillEnterForegroundNotification object:UIApplication.sharedApplication userInfo:@{@"isSuspendedUnderLock": @NO }];
+    [NSNotificationCenter.defaultCenter postNotificationName:UISceneWillEnterForegroundNotification object:webView.get().window.windowScene];
+    Util::run(&isPlaying);
+}
+
+TEST(WKWebViewPausePlayingAudioTests, OutOfWindow)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) configuration:autoplayingConfiguration().get() addToWindow:YES]);
+
+    bool isPlaying = false;
+    [webView performAfterReceivingMessage:@"playing" action:[&] { isPlaying = true; }];
+
+    [webView synchronouslyLoadTestPageNamed:@"video-with-audio"];
+    Util::run(&isPlaying);
+
+    bool isHidden = false;
+    [webView performAfterReceivingMessage:@"hidden" action:[&] { isHidden = true; }];
+    [webView objectByEvaluatingJavaScript:@"document.addEventListener('visibilitychange', event => { if (document.hidden) window.webkit.messageHandlers.testHandler.postMessage('hidden') })"];
+
+    [webView removeFromSuperview];
+    Util::run(&isHidden);
+
+    bool isPaused = false;
+    [webView objectByEvaluatingJavaScript:@"document.querySelector('video').addEventListener('pause', paused)"];
+    [webView performAfterReceivingMessage:@"paused" action:[&] { isPaused = true; }];
+
+    [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidEnterBackgroundNotification object:UIApplication.sharedApplication userInfo:@{@"isSuspendedUnderLock": @NO }];
+    [NSNotificationCenter.defaultCenter postNotificationName:UISceneDidEnterBackgroundNotification object:webView.get().window.windowScene];
+    Util::run(&isPaused);
+
+    [webView objectByEvaluatingJavaScript:@"document.querySelector('video').addEventListener('play', playing)"];
+
+    isPlaying = false;
+    [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationWillEnterForegroundNotification object:UIApplication.sharedApplication userInfo:@{@"isSuspendedUnderLock": @NO }];
+    [NSNotificationCenter.defaultCenter postNotificationName:UISceneWillEnterForegroundNotification object:webView.get().window.windowScene];
+
+    Util::run(&isPlaying);
+}
+
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to