Media elements are allowed to continue to load media data after navigation
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jun 2017 20:55:11 +0000 (20:55 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jun 2017 20:55:11 +0000 (20:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173179

Reviewed by Eric Carlson.

Deny media sessions the ability to load media data when suspended.

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::isSuspended):
* Modules/webaudio/AudioContext.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::isSuspended):
* html/HTMLMediaElement.h:
* platform/audio/PlatformMediaSession.cpp:
(WebCore::PlatformMediaSession::isSuspended):
* platform/audio/PlatformMediaSession.h:
(WebCore::PlatformMediaSessionClient::isSuspended):
* platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::sessionCanLoadMedia):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/Modules/webaudio/AudioContext.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/platform/audio/PlatformMediaSession.cpp
Source/WebCore/platform/audio/PlatformMediaSession.h
Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp

index 8ff5f8c..8ca233c 100644 (file)
@@ -1,3 +1,25 @@
+2017-06-09  Jer Noble  <jer.noble@apple.com>
+
+        Media elements are allowed to continue to load media data after navigation
+        https://bugs.webkit.org/show_bug.cgi?id=173179
+
+        Reviewed by Eric Carlson.
+
+        Deny media sessions the ability to load media data when suspended.  
+
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::isSuspended):
+        * Modules/webaudio/AudioContext.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::isSuspended):
+        * html/HTMLMediaElement.h:
+        * platform/audio/PlatformMediaSession.cpp:
+        (WebCore::PlatformMediaSession::isSuspended):
+        * platform/audio/PlatformMediaSession.h:
+        (WebCore::PlatformMediaSessionClient::isSuspended):
+        * platform/audio/PlatformMediaSessionManager.cpp:
+        (WebCore::PlatformMediaSessionManager::sessionCanLoadMedia):
+
 2017-06-09  Daniel Bates  <dabates@apple.com>
 
         CSP: Apply img-src directive to favicon loads
index 64727d5..8de2f23 100644 (file)
@@ -374,6 +374,11 @@ bool AudioContext::processingUserGestureForMedia() const
     return document() ? document()->processingUserGestureForMedia() : false;
 }
 
+bool AudioContext::isSuspended() const
+{
+    return !document() || document()->activeDOMObjectsAreSuspended() || document()->activeDOMObjectsAreStopped();
+}
+
 void AudioContext::visibilityStateChanged()
 {
     // Do not suspend if audio is audible.
index 77fa877..226d6f7 100644 (file)
@@ -319,6 +319,7 @@ private:
     bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const override { return false; }
     String sourceApplicationIdentifier() const override;
     bool canProduceAudio() const final { return true; }
+    bool isSuspended() const final;
     bool processingUserGestureForMedia() const final;
 
     void visibilityStateChanged() final;
index 7bdb91c..30c229e 100644 (file)
@@ -7025,6 +7025,11 @@ bool HTMLMediaElement::canProduceAudio() const
     return m_player && m_readyState >= HAVE_METADATA && hasAudio();
 }
 
+bool HTMLMediaElement::isSuspended() const
+{
+    return document().activeDOMObjectsAreSuspended() || document().activeDOMObjectsAreStopped();
+}
+
 #if ENABLE(MEDIA_SOURCE)
 size_t HTMLMediaElement::maximumSourceBufferSize(const SourceBuffer& buffer) const
 {
index 0c1ebc4..3fe6ea6 100644 (file)
@@ -825,6 +825,7 @@ private:
     bool shouldOverrideBackgroundLoadingRestriction() const override;
     bool canProduceAudio() const final;
     bool processingUserGestureForMedia() const final;
+    bool isSuspended() const final;
 
     void pageMutedStateDidChange() override;
 
index 64b0eed..72e8204 100644 (file)
@@ -299,6 +299,11 @@ bool PlatformMediaSession::isHidden() const
     return m_client.elementIsHidden();
 }
 
+bool PlatformMediaSession::isSuspended() const
+{
+    return m_client.isSuspended();
+}
+
 bool PlatformMediaSession::shouldOverrideBackgroundLoadingRestriction() const
 {
     return m_client.shouldOverrideBackgroundLoadingRestriction();
index a63b9c4..c5592fd 100644 (file)
@@ -144,6 +144,7 @@ public:
     DisplayType displayType() const;
 
     bool isHidden() const;
+    bool isSuspended() const;
 
     bool shouldOverrideBackgroundLoadingRestriction() const;
 
@@ -218,6 +219,7 @@ public:
     virtual void setShouldBufferData(bool) { }
     virtual bool elementIsHidden() const { return false; }
     virtual bool canProduceAudio() const { return false; }
+    virtual bool isSuspended() const { return false; };
 
     virtual bool shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType) const = 0;
     virtual bool shouldOverrideBackgroundLoadingRestriction() const { return false; }
index c4ff1d4..37332cc 100644 (file)
@@ -289,6 +289,8 @@ Vector<PlatformMediaSession*> PlatformMediaSessionManager::currentSessionsMatchi
     
 bool PlatformMediaSessionManager::sessionCanLoadMedia(const PlatformMediaSession& session) const
 {
+    if (session.isSuspended())
+        return false;
     return session.state() == PlatformMediaSession::Playing || !session.isHidden() || session.shouldOverrideBackgroundLoadingRestriction();
 }