MediaSource.readyState should use an IDL enum
authornael.ouedraogo@crf.canon.fr <nael.ouedraogo@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 May 2017 16:00:22 +0000 (16:00 +0000)
committernael.ouedraogo@crf.canon.fr <nael.ouedraogo@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 May 2017 16:00:22 +0000 (16:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171672

Reviewed by Eric Carlson and Chris Dumez.

MediaSource.readyState should use an IDL enum as per specification
(https://www.w3.org/TR/2016/CR-media-source-20160503/#idl-def-ReadyState).

No new tests required since no behavior change.

* Modules/mediasource/MediaSource.cpp:
(WebCore::toString):
(WebCore::MediaSource::MediaSource):
(WebCore::MediaSource::setPrivateAndOpen):
(WebCore::MediaSource::buffered):
(WebCore::MediaSource::setReadyState):
(WebCore::MediaSource::streamEndedWithError):
(WebCore::MediaSource::isOpen):
(WebCore::MediaSource::isClosed):
(WebCore::MediaSource::isEnded):
(WebCore::MediaSource::detachFromElement):
(WebCore::MediaSource::openIfInEndedState):
(WebCore::MediaSource::stop):
(WebCore::MediaSource::onReadyStateChange):
* Modules/mediasource/MediaSource.h:
* Modules/mediasource/MediaSource.idl:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/mediasource/MediaSource.cpp
Source/WebCore/Modules/mediasource/MediaSource.h
Source/WebCore/Modules/mediasource/MediaSource.idl

index d4f1001..0acb2cc 100644 (file)
@@ -1,5 +1,34 @@
 2017-05-09  Nael Ouedraogo  <nael.ouedraogo@crf.canon.fr>
 
+        MediaSource.readyState should use an IDL enum
+        https://bugs.webkit.org/show_bug.cgi?id=171672
+
+        Reviewed by Eric Carlson and Chris Dumez.
+
+        MediaSource.readyState should use an IDL enum as per specification
+        (https://www.w3.org/TR/2016/CR-media-source-20160503/#idl-def-ReadyState).
+
+        No new tests required since no behavior change.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::toString):
+        (WebCore::MediaSource::MediaSource):
+        (WebCore::MediaSource::setPrivateAndOpen):
+        (WebCore::MediaSource::buffered):
+        (WebCore::MediaSource::setReadyState):
+        (WebCore::MediaSource::streamEndedWithError):
+        (WebCore::MediaSource::isOpen):
+        (WebCore::MediaSource::isClosed):
+        (WebCore::MediaSource::isEnded):
+        (WebCore::MediaSource::detachFromElement):
+        (WebCore::MediaSource::openIfInEndedState):
+        (WebCore::MediaSource::stop):
+        (WebCore::MediaSource::onReadyStateChange):
+        * Modules/mediasource/MediaSource.h:
+        * Modules/mediasource/MediaSource.idl:
+
+2017-05-09  Nael Ouedraogo  <nael.ouedraogo@crf.canon.fr>
+
         Invalid MediaSource duration value should throw TyperError instead of InvalidStateError
         https://bugs.webkit.org/show_bug.cgi?id=171653
 
index da90913..f9f913e 100644 (file)
 
 namespace WebCore {
 
+#if !LOG_DISABLED
+static const char* toString(MediaSource::ReadyState readyState)
+{
+    switch (readyState) {
+    case MediaSource::ReadyState::Closed:
+        return "closed";
+    case MediaSource::ReadyState::Ended:
+        return "ended";
+    case MediaSource::ReadyState::Open:
+        return "open";
+    default:
+        return "(unknown)";
+    }
+}
+#endif
+
 URLRegistry* MediaSource::s_registry;
 
 void MediaSource::setRegistry(URLRegistry* registry)
@@ -71,7 +87,6 @@ MediaSource::MediaSource(ScriptExecutionContext& context)
     : ActiveDOMObject(&context)
     , m_duration(MediaTime::invalidTime())
     , m_pendingSeekTime(MediaTime::invalidTime())
-    , m_readyState(closedKeyword())
     , m_asyncEventQueue(*this)
 {
     LOG(MediaSource, "MediaSource::MediaSource %p", this);
@@ -85,24 +100,6 @@ MediaSource::~MediaSource()
     ASSERT(isClosed());
 }
 
-const AtomicString& MediaSource::openKeyword()
-{
-    static NeverDestroyed<const AtomicString> open("open", AtomicString::ConstructFromLiteral);
-    return open;
-}
-
-const AtomicString& MediaSource::closedKeyword()
-{
-    static NeverDestroyed<const AtomicString> closed("closed", AtomicString::ConstructFromLiteral);
-    return closed;
-}
-
-const AtomicString& MediaSource::endedKeyword()
-{
-    static NeverDestroyed<const AtomicString> ended("ended", AtomicString::ConstructFromLiteral);
-    return ended;
-}
-
 void MediaSource::setPrivateAndOpen(Ref<MediaSourcePrivate>&& mediaSourcePrivate)
 {
     ASSERT(!m_private);
@@ -126,7 +123,7 @@ void MediaSource::setPrivateAndOpen(Ref<MediaSourcePrivate>&& mediaSourcePrivate
 
     // 2. Set the readyState attribute to "open".
     // 3. Queue a task to fire a simple event named sourceopen at the MediaSource.
-    setReadyState(openKeyword());
+    setReadyState(ReadyState::Open);
 
     // 4. Continue the resource fetch algorithm by running the remaining "Otherwise (mode is local)" steps,
     // with these clarifications:
@@ -192,7 +189,7 @@ std::unique_ptr<PlatformTimeRanges> MediaSource::buffered() const
     m_buffered->add(MediaTime::zeroTime(), highestEndTime);
 
     // 5. For each SourceBuffer object in activeSourceBuffers run the following steps:
-    bool ended = readyState() == endedKeyword();
+    bool ended = readyState() == ReadyState::Ended;
     for (auto& sourceRanges : activeRanges) {
         // 5.1 Let source ranges equal the ranges returned by the buffered attribute on the current SourceBuffer.
         // 5.2 If readyState is "ended", then set the end time on the last range in source ranges to highest end time.
@@ -528,12 +525,10 @@ ExceptionOr<void> MediaSource::setDurationInternal(const MediaTime& duration)
     return { };
 }
 
-void MediaSource::setReadyState(const AtomicString& state)
+void MediaSource::setReadyState(ReadyState state)
 {
-    ASSERT(state == openKeyword() || state == closedKeyword() || state == endedKeyword());
-
-    AtomicString oldState = readyState();
-    LOG(MediaSource, "MediaSource::setReadyState(%p) : %s -> %s", this, oldState.string().ascii().data(), state.string().ascii().data());
+    auto oldState = readyState();
+    LOG(MediaSource, "MediaSource::setReadyState(%p) : %s -> %s", this, toString(oldState), toString(state));
 
     if (oldState == state)
         return;
@@ -572,7 +567,7 @@ void MediaSource::streamEndedWithError(std::optional<EndOfStreamError> error)
 
     // 1. Change the readyState attribute value to "ended".
     // 2. Queue a task to fire a simple event named sourceended at the MediaSource.
-    setReadyState(endedKeyword());
+    setReadyState(ReadyState::Ended);
 
     // 3.
     if (!error) {
@@ -861,17 +856,17 @@ bool MediaSource::isTypeSupported(const String& type)
 
 bool MediaSource::isOpen() const
 {
-    return readyState() == openKeyword();
+    return readyState() == ReadyState::Open;
 }
 
 bool MediaSource::isClosed() const
 {
-    return readyState() == closedKeyword();
+    return readyState() == ReadyState::Closed;
 }
 
 bool MediaSource::isEnded() const
 {
-    return readyState() == endedKeyword();
+    return readyState() == ReadyState::Ended;
 }
 
 void MediaSource::detachFromElement(HTMLMediaElement& element)
@@ -883,7 +878,7 @@ void MediaSource::detachFromElement(HTMLMediaElement& element)
 
     // 1. Set the readyState attribute to "closed".
     // 7. Queue a task to fire a simple event named sourceclose at the MediaSource.
-    setReadyState(closedKeyword());
+    setReadyState(ReadyState::Closed);
 
     // 2. Update duration to NaN.
     m_duration = MediaTime::invalidTime();
@@ -920,10 +915,10 @@ bool MediaSource::attachToElement(HTMLMediaElement& element)
 
 void MediaSource::openIfInEndedState()
 {
-    if (m_readyState != endedKeyword())
+    if (m_readyState != ReadyState::Ended)
         return;
 
-    setReadyState(openKeyword());
+    setReadyState(ReadyState::Open);
     m_private->unmarkEndOfStream();
 }
 
@@ -938,7 +933,7 @@ void MediaSource::stop()
     m_asyncEventQueue.close();
     if (m_mediaElement)
         m_mediaElement->detachMediaSource();
-    m_readyState = closedKeyword();
+    m_readyState = ReadyState::Closed;
     m_private = nullptr;
 }
 
@@ -952,7 +947,7 @@ const char* MediaSource::activeDOMObjectName() const
     return "MediaSource";
 }
 
-void MediaSource::onReadyStateChange(const AtomicString& oldState, const AtomicString& newState)
+void MediaSource::onReadyStateChange(ReadyState oldState, ReadyState newState)
 {
     for (auto& buffer : *m_sourceBuffers)
         buffer->readyStateChanged();
@@ -962,7 +957,7 @@ void MediaSource::onReadyStateChange(const AtomicString& oldState, const AtomicS
         return;
     }
 
-    if (oldState == openKeyword() && newState == endedKeyword()) {
+    if (oldState == ReadyState::Open && newState == ReadyState::Ended) {
         scheduleEvent(eventNames().sourceendedEvent);
         return;
     }
index 549319f..204287b 100644 (file)
@@ -82,7 +82,9 @@ public:
     ExceptionOr<void> setDuration(double);
     ExceptionOr<void> setDurationInternal(const MediaTime&);
     MediaTime currentTime() const;
-    const AtomicString& readyState() const { return m_readyState; }
+
+    enum class ReadyState { Closed, Open, Ended };
+    ReadyState readyState() const { return m_readyState; }
     ExceptionOr<void> endOfStream(std::optional<EndOfStreamError>);
 
     HTMLMediaElement* mediaElement() const { return m_mediaElement; }
@@ -118,11 +120,8 @@ private:
 
     URLRegistry& registry() const final;
 
-    static const AtomicString& openKeyword();
-    static const AtomicString& closedKeyword();
-    static const AtomicString& endedKeyword();
-    void setReadyState(const AtomicString&);
-    void onReadyStateChange(const AtomicString& oldState, const AtomicString& newState);
+    void setReadyState(ReadyState);
+    void onReadyStateChange(ReadyState oldState, ReadyState newState);
 
     Vector<PlatformTimeRanges> activeRanges() const;
 
@@ -147,7 +146,7 @@ private:
     HTMLMediaElement* m_mediaElement { nullptr };
     MediaTime m_duration;
     MediaTime m_pendingSeekTime;
-    AtomicString m_readyState;
+    ReadyState m_readyState { ReadyState::Closed };
     GenericEventQueue m_asyncEventQueue;
 };
 
index 5a9fef1..0fa751d 100644 (file)
@@ -33,6 +33,12 @@ enum EndOfStreamError {
     "decode"
 };
 
+enum ReadyState {
+    "closed",
+    "open",
+    "ended"
+};
+
 [
     ActiveDOMObject,
     Conditional=MEDIA_SOURCE,
@@ -51,7 +57,7 @@ enum EndOfStreamError {
     [MayThrowException] SourceBuffer addSourceBuffer(DOMString type);
     [MayThrowException] void removeSourceBuffer(SourceBuffer buffer);
 
-    readonly attribute DOMString readyState;
+    readonly attribute ReadyState readyState;
     
     [MayThrowException] void endOfStream(optional EndOfStreamError error);