[iOS] REGRESSION(r190434): Media continues to play when locking screen
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Oct 2015 04:13:32 +0000 (04:13 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Oct 2015 04:13:32 +0000 (04:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149822

Reviewed by Brent Fulgham.

Source/WebCore:

In MediaSessionManagerIOS.mm, both -applicationWillEnterForeground: and
-applicationDidBecomeActive: called
PlatformMediaSessionManager::applicationWillEnterForeground(), leading to the
PlatformMediaSession's m_interruptionCount becoming increasingly unbalanced.

Rename PlatformMediaSessionManager::applicationWillEnterForeground() to
applicationDidEnterForeground() to more correctly reflect when this notification will be
called. Add a new method, MediaSessionManagerIOS::applicationWillEnterForeground(bool),
whose paramater is whether the screen was locked. This allows the beginInterruption() and
endInterruption() methods to be correctly balanced.

Drive-by fix: remove the unimplemented declarations for application{will,did}Enter{Fore,Back}ground()
from PlatformMediaSession.h.

* platform/audio/PlatformMediaSession.h:
* platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::applicationDidEnterForeground):
(WebCore::PlatformMediaSessionManager::applicationWillEnterForeground): Deleted.
* platform/audio/PlatformMediaSessionManager.h:
* platform/audio/ios/MediaSessionManagerIOS.h:
* platform/audio/ios/MediaSessionManagerIOS.mm:
(WebCore::MediaSessionManageriOS::applicationDidEnterBackground):
(WebCore::MediaSessionManageriOS::applicationWillEnterForeground):
(-[WebMediaSessionHelper applicationWillEnterForeground:]):
(-[WebMediaSessionHelper applicationDidBecomeActive:]):
* testing/Internals.cpp:
(WebCore::Internals::applicationDidEnterForeground):
(WebCore::Internals::applicationWillEnterForeground): Deleted.
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit2:

Pass through isSuspendedUnderLock when notifying the WebPage that the
applicationWillEnterForeground, and pass that boolean in the userInfo of the
WebUIApplicationWillEnterForegroundNotification.

* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::applicationWillEnterForeground):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::applicationWillEnterForeground):

LayoutTests:

applicationWillEnterForeground() -> applicationDidEnterForeground().

* media/video-background-playback-expected.txt:
* media/video-background-playback.html:
* media/video-background-tab-playback-expected.txt:
* media/video-background-tab-playback.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190604 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
LayoutTests/ChangeLog
LayoutTests/media/video-background-playback-expected.txt
LayoutTests/media/video-background-playback.html
LayoutTests/media/video-background-tab-playback-expected.txt
LayoutTests/media/video-background-tab-playback.html
Source/WebCore/ChangeLog
Source/WebCore/platform/audio/PlatformMediaSession.h
Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp
Source/WebCore/platform/audio/PlatformMediaSessionManager.h
Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.h
Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index 18b6b50..9ec9736 100644 (file)
@@ -1,3 +1,17 @@
+2015-10-05  Jer Noble  <jer.noble@apple.com>
+
+        [iOS] REGRESSION(r190434): Media continues to play when locking screen
+        https://bugs.webkit.org/show_bug.cgi?id=149822
+
+        Reviewed by Brent Fulgham.
+
+        applicationWillEnterForeground() -> applicationDidEnterForeground().
+
+        * media/video-background-playback-expected.txt:
+        * media/video-background-playback.html:
+        * media/video-background-tab-playback-expected.txt:
+        * media/video-background-tab-playback.html:
+
 2015-10-05  Alex Christensen  <achristensen@webkit.org>
 
         Invalid CSS Selector for Content Blockers invalidates others
index 94bc177..eb7ff86 100644 (file)
@@ -21,7 +21,7 @@ EXPECTED (video.paused == 'true') OK
 EXPECTED (audio.paused == 'false') OK
 
 ** Simulate switch back to foreground, video should resume.
-RUN(internals.applicationWillEnterForeground())
+RUN(internals.applicationDidEnterForeground())
 
 EVENT(playing)
 
index d79b43a..e5e1cd8 100644 (file)
@@ -23,7 +23,7 @@
                     testExpected("audio.paused", false);
                     state = "foreground";
                     consoleWrite("<br>** Simulate switch back to foreground, video should resume.");
-                    run("internals.applicationWillEnterForeground()");
+                    run("internals.applicationDidEnterForeground()");
                     setTimeout(checkState, 100);
                     consoleWrite("");
                     break;
index 1a1bcf0..a7e751e 100644 (file)
@@ -16,7 +16,7 @@ RUN(testRunner.setPageVisibility('hidden'))
 EXPECTED (video.paused == 'true') OK
 
 ** Simulate switch back to foreground, video should remain paused.
-RUN(internals.applicationWillEnterForeground())
+RUN(internals.applicationDidEnterForeground())
 
 
 ** 100ms timer fired...
index beb932a..f3372a9 100644 (file)
@@ -13,7 +13,7 @@
                     testExpected("video.paused", true);
                     state = "foreground";
                     consoleWrite("<br>** Simulate switch back to foreground, video should remain paused.");
-                    run("internals.applicationWillEnterForeground()");
+                    run("internals.applicationDidEnterForeground()");
                     setTimeout(checkState, 100);
                     consoleWrite("");
                     break;
index a1e6e4a..79fbf9e 100644 (file)
@@ -1,3 +1,41 @@
+2015-10-05  Jer Noble  <jer.noble@apple.com>
+
+        [iOS] REGRESSION(r190434): Media continues to play when locking screen
+        https://bugs.webkit.org/show_bug.cgi?id=149822
+
+        Reviewed by Brent Fulgham.
+
+        In MediaSessionManagerIOS.mm, both -applicationWillEnterForeground: and
+        -applicationDidBecomeActive: called
+        PlatformMediaSessionManager::applicationWillEnterForeground(), leading to the
+        PlatformMediaSession's m_interruptionCount becoming increasingly unbalanced.
+
+        Rename PlatformMediaSessionManager::applicationWillEnterForeground() to
+        applicationDidEnterForeground() to more correctly reflect when this notification will be
+        called. Add a new method, MediaSessionManagerIOS::applicationWillEnterForeground(bool),
+        whose paramater is whether the screen was locked. This allows the beginInterruption() and
+        endInterruption() methods to be correctly balanced.
+
+        Drive-by fix: remove the unimplemented declarations for application{will,did}Enter{Fore,Back}ground()
+        from PlatformMediaSession.h.
+
+        * platform/audio/PlatformMediaSession.h:
+        * platform/audio/PlatformMediaSessionManager.cpp:
+        (WebCore::PlatformMediaSessionManager::applicationDidEnterForeground):
+        (WebCore::PlatformMediaSessionManager::applicationWillEnterForeground): Deleted.
+        * platform/audio/PlatformMediaSessionManager.h:
+        * platform/audio/ios/MediaSessionManagerIOS.h:
+        * platform/audio/ios/MediaSessionManagerIOS.mm:
+        (WebCore::MediaSessionManageriOS::applicationDidEnterBackground):
+        (WebCore::MediaSessionManageriOS::applicationWillEnterForeground):
+        (-[WebMediaSessionHelper applicationWillEnterForeground:]):
+        (-[WebMediaSessionHelper applicationDidBecomeActive:]):
+        * testing/Internals.cpp:
+        (WebCore::Internals::applicationDidEnterForeground):
+        (WebCore::Internals::applicationWillEnterForeground): Deleted.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2015-10-05  Alex Christensen  <achristensen@webkit.org>
 
         Invalid CSS Selector for Content Blockers invalidates others
index 0ad7724..a010ec6 100644 (file)
@@ -84,10 +84,6 @@ public:
     void beginInterruption(InterruptionType);
     void endInterruption(EndInterruptionFlags);
 
-    void applicationWillEnterForeground() const;
-    void applicationWillEnterBackground() const;
-    void applicationDidEnterBackground(bool isSuspendedUnderLock) const;
-
     bool clientWillBeginPlayback();
     bool clientWillPausePlayback();
 
index 54bc209..bf35c47 100644 (file)
@@ -288,9 +288,9 @@ void PlatformMediaSessionManager::applicationWillEnterBackground() const
     }
 }
 
-void PlatformMediaSessionManager::applicationWillEnterForeground() const
+void PlatformMediaSessionManager::applicationDidEnterForeground() const
 {
-    LOG(Media, "PlatformMediaSessionManager::applicationWillEnterForeground");
+    LOG(Media, "PlatformMediaSessionManager::applicationDidEnterForeground");
 
     if (!m_isApplicationInBackground)
         return;
index 27532e8..9471e09 100644 (file)
@@ -58,7 +58,7 @@ public:
     WEBCORE_EXPORT void beginInterruption(PlatformMediaSession::InterruptionType);
     WEBCORE_EXPORT void endInterruption(PlatformMediaSession::EndInterruptionFlags);
 
-    WEBCORE_EXPORT void applicationWillEnterForeground() const;
+    WEBCORE_EXPORT void applicationDidEnterForeground() const;
     WEBCORE_EXPORT void applicationWillEnterBackground() const;
 
     void stopAllMediaPlaybackForDocument(const Document*);
index dd7475a..8c223a6 100644 (file)
@@ -49,6 +49,7 @@ public:
     void externalOutputDeviceAvailableDidChange();
     virtual bool hasWirelessTargetsAvailable() override;
     void applicationDidEnterBackground(bool isSuspendedUnderLock);
+    void applicationWillEnterForeground(bool isSuspendedUnderLock);
 
 private:
     friend class PlatformMediaSessionManager;
@@ -67,6 +68,7 @@ private:
     virtual bool sessionCanLoadMedia(const PlatformMediaSession&) const override;
     
     RetainPtr<WebMediaSessionHelper> m_objcObserver;
+    bool m_isInBackground { false };
 };
 
 } // namespace WebCore
index 6bc5d8b..3abf9df 100644 (file)
@@ -252,6 +252,10 @@ void MediaSessionManageriOS::applicationDidEnterBackground(bool isSuspendedUnder
 {
     LOG(Media, "MediaSessionManageriOS::applicationDidEnterBackground");
 
+    if (m_isInBackground)
+        return;
+    m_isInBackground = true;
+
     if (!isSuspendedUnderLock)
         return;
 
@@ -262,6 +266,23 @@ void MediaSessionManageriOS::applicationDidEnterBackground(bool isSuspendedUnder
     }
 }
 
+void MediaSessionManageriOS::applicationWillEnterForeground(bool isSuspendedUnderLock)
+{
+    LOG(Media, "MediaSessionManageriOS::applicationWillEnterForeground");
+
+    if (!m_isInBackground)
+        return;
+    m_isInBackground = false;
+
+    if (!isSuspendedUnderLock)
+        return;
+
+    Vector<PlatformMediaSession*> sessions = this->sessions();
+    for (auto* session : sessions) {
+        if (restrictions(session->mediaType()) & BackgroundProcessPlaybackRestricted)
+            session->endInterruption(PlatformMediaSession::MayResumePlaying);
+    }
+}
 
 } // namespace WebCore
 
@@ -432,11 +453,13 @@ void MediaSessionManageriOS::applicationDidEnterBackground(bool isSuspendedUnder
 
     LOG(Media, "-[WebMediaSessionHelper applicationWillEnterForeground]");
 
+    BOOL isSuspendedUnderLock = [[[notification userInfo] objectForKey:@"isSuspendedUnderLock"] boolValue];
+
     WebThreadRun(^{
         if (!_callback)
             return;
 
-        _callback->applicationWillEnterForeground();
+        _callback->applicationWillEnterForeground(isSuspendedUnderLock);
     });
 }
 
@@ -453,7 +476,7 @@ void MediaSessionManageriOS::applicationDidEnterBackground(bool isSuspendedUnder
         if (!_callback)
             return;
 
-        _callback->applicationWillEnterForeground();
+        _callback->applicationDidEnterForeground();
     });
 }
 
index faa9cef..2157ac6 100644 (file)
@@ -2730,9 +2730,9 @@ void Internals::endMediaSessionInterruption(const String& flagsString)
     PlatformMediaSessionManager::sharedManager().endInterruption(flags);
 }
 
-void Internals::applicationWillEnterForeground() const
+void Internals::applicationDidEnterForeground() const
 {
-    PlatformMediaSessionManager::sharedManager().applicationWillEnterForeground();
+    PlatformMediaSessionManager::sharedManager().applicationDidEnterForeground();
 }
 
 void Internals::applicationWillEnterBackground() const
index 7f69396..71edd99 100644 (file)
@@ -388,7 +388,7 @@ public:
 #if ENABLE(VIDEO)
     void beginMediaSessionInterruption(const String&, ExceptionCode&);
     void endMediaSessionInterruption(const String&);
-    void applicationWillEnterForeground() const;
+    void applicationDidEnterForeground() const;
     void applicationWillEnterBackground() const;
     void setMediaSessionRestrictions(const String& mediaType, const String& restrictions, ExceptionCode&);
     void setMediaElementRestrictions(HTMLMediaElement*, const String& restrictions, ExceptionCode&);
index d8123d3..b379155 100644 (file)
@@ -372,7 +372,7 @@ enum MediaControlEvent {
     [Conditional=MEDIA_SESSION] DOMString mediaSessionCurrentState(MediaSession session);
     [Conditional=MEDIA_SESSION] double mediaElementPlayerVolume(HTMLMediaElement element);
     [Conditional=MEDIA_SESSION] void sendMediaControlEvent(MediaControlEvent event);
-    [Conditional=VIDEO] void applicationWillEnterForeground();
+    [Conditional=VIDEO] void applicationDidEnterForeground();
     [Conditional=VIDEO] void applicationWillEnterBackground();
     [Conditional=VIDEO, RaisesException] void setMediaSessionRestrictions(DOMString mediaType, DOMString restrictions);
     [Conditional=VIDEO, RaisesException] void setMediaElementRestrictions(HTMLMediaElement element, DOMString restrictions);
index b96ce97..9a28511 100644 (file)
@@ -1,3 +1,21 @@
+2015-10-05  Jer Noble  <jer.noble@apple.com>
+
+        [iOS] REGRESSION(r190434): Media continues to play when locking screen
+        https://bugs.webkit.org/show_bug.cgi?id=149822
+
+        Reviewed by Brent Fulgham.
+
+        Pass through isSuspendedUnderLock when notifying the WebPage that the
+        applicationWillEnterForeground, and pass that boolean in the userInfo of the
+        WebUIApplicationWillEnterForegroundNotification.
+
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::applicationWillEnterForeground):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::applicationWillEnterForeground):
+
 2015-10-05  Anders Carlsson  <andersca@apple.com>
 
         Get rid of some dead code
index 045b8eb..0a329d0 100644 (file)
@@ -621,7 +621,8 @@ void WebPageProxy::applicationDidEnterBackground()
 
 void WebPageProxy::applicationWillEnterForeground()
 {
-    m_process->send(Messages::WebPage::ApplicationWillEnterForeground(), m_pageID);
+    bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
+    m_process->send(Messages::WebPage::ApplicationWillEnterForeground(isSuspendedUnderLock), m_pageID);
 }
 
 void WebPageProxy::applicationWillResignActive()
index 283b1c4..91967e7 100644 (file)
@@ -807,7 +807,7 @@ public:
     void willStartUserTriggeredZooming();
     void applicationWillResignActive();
     void applicationDidEnterBackground(bool isSuspendedUnderLock);
-    void applicationWillEnterForeground();
+    void applicationWillEnterForeground(bool isSuspendedUnderLock);
     void applicationDidBecomeActive();
     void zoomToRect(WebCore::FloatRect, double minimumScale, double maximumScale);
     void completePendingSyntheticClickForContentChangeObserver();
index 29c2d94..56b121c 100644 (file)
@@ -87,7 +87,7 @@ messages -> WebPage LegacyReceiver {
     SetAssistedNodeSelectedIndex(uint32_t index, bool allowMultipleSelection)
     ApplicationWillResignActive()
     ApplicationDidEnterBackground(bool isSuspendedUnderLock)
-    ApplicationWillEnterForeground()
+    ApplicationWillEnterForeground(bool isSuspendedUnderLock)
     ApplicationDidBecomeActive()
     ContentSizeCategoryDidChange(String contentSizeCategory)
     ExecuteEditCommandWithCallback(String name, uint64_t callbackID)
index ad7bfa0..b30b54f 100644 (file)
@@ -2844,12 +2844,12 @@ void WebPage::applicationDidEnterBackground(bool isSuspendedUnderLock)
     m_volatilityTimer.startRepeating(std::chrono::milliseconds(200));
 }
 
-void WebPage::applicationWillEnterForeground()
+void WebPage::applicationWillEnterForeground(bool isSuspendedUnderLock)
 {
     m_volatilityTimer.stop();
     setLayerTreeStateIsFrozen(false);
 
-    [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationWillEnterForegroundNotification object:nil];
+    [[NSNotificationCenter defaultCenter] postNotificationName:WebUIApplicationWillEnterForegroundNotification object:nil userInfo:@{@"isSuspendedUnderLock": @(isSuspendedUnderLock)}];
 }
 
 void WebPage::applicationDidBecomeActive()