Introduce a new abstract class called AudioProducer and keep a set of AudioProducers
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Oct 2014 22:00:39 +0000 (22:00 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Oct 2014 22:00:39 +0000 (22:00 +0000)
rather than the active MediaSessions in Document
https://bugs.webkit.org/show_bug.cgi?id=138107

Reviewed by Eric Carlson.

No new tests, no behavior change.

* WebCore.xcodeproj/project.pbxproj:
Add AudioProducer.h to the project.
* dom/Document.cpp:
(WebCore::Document::addAudioProducer):
(WebCore::Document::removeAudioProducer):
(WebCore::Document::updateIsPlayingAudio):
Go through the set of AudioProducers and see if any is playing audio.
Now that this method no longer refers to MediaSessions directly, this code
does not need to be guarded by #if ENABLE(VIDEO).
(WebCore::Document::registerMediaSession): Deleted.
(WebCore::Document::unregisterMediaSession): Deleted.
* dom/Document.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::registerWithDocument):
(WebCore::HTMLMediaElement::unregisterWithDocument):
(WebCore::HTMLMediaElement::isPlayingAudio):
Return whether this element is playing audio.
* html/HTMLMediaElement.h:
* page/AudioProducer.h: Added.
(WebCore::AudioProducer::~AudioProducer):
* page/Page.cpp:
(WebCore::Page::updateIsPlayingAudio):
This is no longer guarded with #if ENABLE(VIDEO) since the Document methods it calls
are no longer guarded.
* page/Page.h:

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/page/AudioProducer.h [new file with mode: 0644]
Source/WebCore/page/Page.cpp
Source/WebCore/page/Page.h

index 5d7c9ff..bd20507 100644 (file)
@@ -1,3 +1,39 @@
+2014-10-27  Ada Chan  <adachan@apple.com>
+
+        Introduce a new abstract class called AudioProducer and keep a set of AudioProducers
+        rather than the active MediaSessions in Document
+        https://bugs.webkit.org/show_bug.cgi?id=138107
+
+        Reviewed by Eric Carlson.
+
+        No new tests, no behavior change.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Add AudioProducer.h to the project.
+        * dom/Document.cpp:
+        (WebCore::Document::addAudioProducer):
+        (WebCore::Document::removeAudioProducer):
+        (WebCore::Document::updateIsPlayingAudio):
+        Go through the set of AudioProducers and see if any is playing audio.
+        Now that this method no longer refers to MediaSessions directly, this code
+        does not need to be guarded by #if ENABLE(VIDEO).
+        (WebCore::Document::registerMediaSession): Deleted.
+        (WebCore::Document::unregisterMediaSession): Deleted.
+        * dom/Document.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::registerWithDocument):
+        (WebCore::HTMLMediaElement::unregisterWithDocument):
+        (WebCore::HTMLMediaElement::isPlayingAudio):
+        Return whether this element is playing audio.
+        * html/HTMLMediaElement.h:
+        * page/AudioProducer.h: Added.
+        (WebCore::AudioProducer::~AudioProducer):
+        * page/Page.cpp:
+        (WebCore::Page::updateIsPlayingAudio):
+        This is no longer guarded with #if ENABLE(VIDEO) since the Document methods it calls
+        are no longer guarded.
+        * page/Page.h:
+
 2014-10-28  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed comment fix from r175267.
index 9fc5f7b..c91c166 100644 (file)
                52CCA9E815E3F64C0053C77F /* DOMDOMNamedFlowCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 52CCA9E515E3F64C0053C77F /* DOMDOMNamedFlowCollection.h */; };
                52CCA9E915E3F64C0053C77F /* DOMDOMNamedFlowCollection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 52CCA9E615E3F64C0053C77F /* DOMDOMNamedFlowCollection.mm */; };
                52CCA9EA15E3F64C0053C77F /* DOMDOMNamedFlowCollectionInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 52CCA9E715E3F64C0053C77F /* DOMDOMNamedFlowCollectionInternal.h */; };
+               52E2CAFC19FF0207001EEB4F /* AudioProducer.h in Headers */ = {isa = PBXBuildFile; fileRef = 52E2CAFB19FF0207001EEB4F /* AudioProducer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                52F10865162B6DA4009AC81E /* MixedContentChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52F10862162B6D82009AC81E /* MixedContentChecker.cpp */; };
                52F10866162B6DA8009AC81E /* MixedContentChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 52F10863162B6D82009AC81E /* MixedContentChecker.h */; settings = {ATTRIBUTES = (Private, ); }; };
                52F52E1114A0134F00ACC397 /* NSScrollerImpDetails.mm in Sources */ = {isa = PBXBuildFile; fileRef = 52F52E1014A0134F00ACC397 /* NSScrollerImpDetails.mm */; };
                52CCA9E515E3F64C0053C77F /* DOMDOMNamedFlowCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDOMNamedFlowCollection.h; sourceTree = "<group>"; };
                52CCA9E615E3F64C0053C77F /* DOMDOMNamedFlowCollection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMDOMNamedFlowCollection.mm; sourceTree = "<group>"; };
                52CCA9E715E3F64C0053C77F /* DOMDOMNamedFlowCollectionInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDOMNamedFlowCollectionInternal.h; sourceTree = "<group>"; };
+               52E2CAFB19FF0207001EEB4F /* AudioProducer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioProducer.h; sourceTree = "<group>"; };
                52F10862162B6D82009AC81E /* MixedContentChecker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MixedContentChecker.cpp; sourceTree = "<group>"; };
                52F10863162B6D82009AC81E /* MixedContentChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MixedContentChecker.h; sourceTree = "<group>"; };
                52F52E1014A0134F00ACC397 /* NSScrollerImpDetails.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NSScrollerImpDetails.mm; sourceTree = "<group>"; };
                                8538F0000AD71770006A81D1 /* AbstractView.idl */,
                                BCF48CE61370D114004E87D6 /* AdjustViewSizeOrNot.h */,
                                CEDA12D6152CA1CB00D9E08D /* AlternativeTextClient.h */,
+                               52E2CAFB19FF0207001EEB4F /* AudioProducer.h */,
                                45830D4B1679B4F800ACF8C3 /* AutoscrollController.cpp */,
                                45830D4C1679B4F800ACF8C3 /* AutoscrollController.h */,
                                BC124EE40C2641CD009E2349 /* BarProp.cpp */,
                                7EE6846F12D26E3800E79415 /* ResourceRequestCFNet.h in Headers */,
                                7EE6847012D26E3800E79415 /* ResourceResponse.h in Headers */,
                                514C767F0CE923A1007EF3CD /* ResourceResponseBase.h in Headers */,
+                               52E2CAFC19FF0207001EEB4F /* AudioProducer.h in Headers */,
                                FD3160A512B026F700C1A359 /* Reverb.h in Headers */,
                                FD3160A712B026F700C1A359 /* ReverbAccumulationBuffer.h in Headers */,
                                FD3160A912B026F700C1A359 /* ReverbConvolver.h in Headers */,
index 0769046..0da0360 100644 (file)
@@ -31,6 +31,7 @@
 #include "AXObjectCache.h"
 #include "AnimationController.h"
 #include "Attr.h"
+#include "AudioProducer.h"
 #include "CDATASection.h"
 #include "CSSStyleDeclaration.h"
 #include "CSSStyleSheet.h"
 #include "MediaCanStartListener.h"
 #include "MediaQueryList.h"
 #include "MediaQueryMatcher.h"
-#include "MediaSession.h"
 #include "MouseEventWithHitTestResults.h"
 #include "NameNodeList.h"
 #include "NestingLevelIncrementer.h"
@@ -3273,24 +3273,23 @@ void Document::updateViewportUnitsOnResize()
     }
 }
 
-#if ENABLE(VIDEO)
-void Document::registerMediaSession(MediaSession& mediaSession)
+void Document::addAudioProducer(AudioProducer* audioProducer)
 {
-    m_mediaSessions.add(&mediaSession);
+    m_audioProducers.add(audioProducer);
     updateIsPlayingAudio();
 }
 
-void Document::unregisterMediaSession(MediaSession& mediaSession)
+void Document::removeAudioProducer(AudioProducer* audioProducer)
 {
-    m_mediaSessions.remove(&mediaSession);
+    m_audioProducers.remove(audioProducer);
     updateIsPlayingAudio();
 }
 
 void Document::updateIsPlayingAudio()
 {
     bool isPlayingAudio = false;
-    for (auto mediaSession : m_mediaSessions) {
-        if (mediaSession->hasMediaCharacteristics(MediaSession::MediaCharacteristicAudible) && mediaSession->state() == MediaSession::Playing) {
+    for (auto audioProducer : m_audioProducers) {
+        if (audioProducer->isPlayingAudio()) {
             isPlayingAudio = true;
             break;
         }
@@ -3304,7 +3303,6 @@ void Document::updateIsPlayingAudio()
     if (page())
         page()->updateIsPlayingAudio();
 }
-#endif
 
 void Document::styleResolverChanged(StyleResolverUpdateFlag updateFlag)
 {
index fe6591c..cd384fc 100644 (file)
@@ -67,6 +67,7 @@ namespace WebCore {
 
 class AXObjectCache;
 class Attr;
+class AudioProducer;
 class CDATASection;
 class CSSStyleDeclaration;
 class CSSStyleSheet;
@@ -122,7 +123,6 @@ class Locale;
 class MediaCanStartListener;
 class MediaQueryList;
 class MediaQueryMatcher;
-class MediaSession;
 class MouseEventWithHitTestResults;
 class NamedFlowCollection;
 class NodeFilter;
@@ -1288,12 +1288,10 @@ public:
     bool hasStyleWithViewportUnits() const { return m_hasStyleWithViewportUnits; }
     void updateViewportUnitsOnResize();
 
-#if ENABLE(VIDEO)
-    void registerMediaSession(MediaSession&);
-    void unregisterMediaSession(MediaSession&);
+    void addAudioProducer(AudioProducer*);
+    void removeAudioProducer(AudioProducer*);
     bool isPlayingAudio() const { return m_isPlayingAudio; }
     void updateIsPlayingAudio();
-#endif
 
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
@@ -1725,7 +1723,7 @@ private:
 
     bool m_hasStyleWithViewportUnits;
 
-    HashSet<MediaSession*> m_mediaSessions;
+    HashSet<AudioProducer*> m_audioProducers;
     bool m_isPlayingAudio;
 };
 
index a37dea7..72d5947 100644 (file)
@@ -443,7 +443,7 @@ void HTMLMediaElement::registerWithDocument(Document& document)
         document.registerForPageScaleFactorChangedCallbacks(this);
 #endif
 
-    document.registerMediaSession(*m_mediaSession);
+    document.addAudioProducer(this);
     addElementToDocumentMap(*this, document);
 }
 
@@ -468,7 +468,7 @@ void HTMLMediaElement::unregisterWithDocument(Document& document)
         document.unregisterForPageScaleFactorChangedCallbacks(this);
 #endif
 
-    document.unregisterMediaSession(*m_mediaSession);
+    document.removeAudioProducer(this);
     removeElementFromDocumentMap(*this, document);
 }
 
@@ -6022,6 +6022,11 @@ void HTMLMediaElement::mediaStateDidChange()
     document().updateIsPlayingAudio();
 }
 
+bool HTMLMediaElement::isPlayingAudio()
+{
+    return m_mediaSession->state() == MediaSession::Playing && hasAudio();
+}
+
 bool HTMLMediaElement::doesHaveAttribute(const AtomicString& attribute, AtomicString* value) const
 {
     QualifiedName attributeName(nullAtom, attribute, nullAtom);
index b3af007..f4c253c 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(VIDEO)
 #include "HTMLElement.h"
 #include "ActiveDOMObject.h"
+#include "AudioProducer.h"
 #include "GenericEventQueue.h"
 #include "HTMLMediaSession.h"
 #include "MediaCanStartListener.h"
@@ -94,7 +95,7 @@ class MediaStream;
 
 class HTMLMediaElement
     : public HTMLElement
-    , private MediaPlayerClient, public MediaPlayerSupportsTypeClient, private MediaCanStartListener, public ActiveDOMObject, public MediaControllerInterface , public MediaSessionClient
+    , private MediaPlayerClient, public MediaPlayerSupportsTypeClient, private MediaCanStartListener, public ActiveDOMObject, public MediaControllerInterface , public MediaSessionClient, private AudioProducer
 #if ENABLE(VIDEO_TRACK)
     , private AudioTrackClient
     , private TextTrackClient
@@ -707,6 +708,9 @@ private:
     virtual bool hasMediaCharacteristics(MediaSession::MediaCharacteristics) const override;
     virtual void mediaStateDidChange() override;
 
+    // AudioProducer overrides
+    virtual bool isPlayingAudio() override;
+
     void registerWithDocument(Document&);
     void unregisterWithDocument(Document&);
 
diff --git a/Source/WebCore/page/AudioProducer.h b/Source/WebCore/page/AudioProducer.h
new file mode 100644 (file)
index 0000000..43f01fc
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 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. ``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
+ * 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.
+ */
+
+#ifndef AudioProducer_h
+#define AudioProducer_h
+
+namespace WebCore {
+
+class AudioProducer {
+public:
+    virtual bool isPlayingAudio() = 0;
+
+protected:
+    virtual ~AudioProducer() { }
+};
+
+}
+
+#endif
index 4386427..3ada7ed 100644 (file)
@@ -1193,7 +1193,6 @@ void Page::enableLegacyPrivateBrowsing(bool privateBrowsingEnabled)
     setSessionID(privateBrowsingEnabled ? SessionID::legacyPrivateSessionID() : SessionID::defaultSessionID());
 }
 
-#if ENABLE(VIDEO)
 void Page::updateIsPlayingAudio()
 {
     bool isPlayingAudio = false;
@@ -1211,7 +1210,6 @@ void Page::updateIsPlayingAudio()
 
     chrome().client().isPlayingAudioDidChange(m_isPlayingAudio);
 }
-#endif
 
 #if !ASSERT_DISABLED
 void Page::checkSubframeCountConsistency() const
index c16c0a3..c927e21 100644 (file)
@@ -436,10 +436,8 @@ public:
     WEBCORE_EXPORT void enableLegacyPrivateBrowsing(bool privateBrowsingEnabled);
     bool usesEphemeralSession() const { return m_sessionID.isEphemeral(); }
 
-#if ENABLE(VIDEO)
     bool isPlayingAudio() const { return m_isPlayingAudio; }
     void updateIsPlayingAudio();
-#endif
 
 private:
     WEBCORE_EXPORT void initGroup();