Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / mediasource / MediaSource.cpp
index 83f4365..2580e8a 100644 (file)
@@ -89,7 +89,7 @@ const AtomicString& MediaSource::endedKeyword()
 
 MediaSource* MediaSource::create(ExecutionContext* context)
 {
-    MediaSource* mediaSource(adoptRefCountedGarbageCollectedWillBeNoop(new MediaSource(context)));
+    MediaSource* mediaSource = new MediaSource(context);
     mediaSource->suspendIfNeeded();
     return mediaSource;
 }
@@ -104,7 +104,6 @@ MediaSource::MediaSource(ExecutionContext* context)
     , m_isAddedToRegistry(false)
 {
     WTF_LOG(Media, "MediaSource::MediaSource %p", this);
-    ScriptWrappable::init(this);
 }
 
 MediaSource::~MediaSource()
@@ -156,7 +155,7 @@ SourceBuffer* MediaSource::addSourceBuffer(const String& type, ExceptionState& e
     SourceBuffer* buffer = SourceBuffer::create(webSourceBuffer.release(), this, m_asyncEventQueue.get());
     // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
     m_sourceBuffers->add(buffer);
-    m_activeSourceBuffers->add(buffer);
+
     // 7. Return the new object to the caller.
     return buffer;
 }
@@ -481,6 +480,28 @@ bool MediaSource::isOpen() const
     return readyState() == openKeyword();
 }
 
+void MediaSource::setSourceBufferActive(SourceBuffer* sourceBuffer)
+{
+    ASSERT(!m_activeSourceBuffers->contains(sourceBuffer));
+
+    // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#widl-MediaSource-activeSourceBuffers
+    // SourceBuffer objects in SourceBuffer.activeSourceBuffers must appear in
+    // the same order as they appear in SourceBuffer.sourceBuffers.
+    // SourceBuffer transitions to active are not guaranteed to occur in the
+    // same order as buffers in |m_sourceBuffers|, so this method needs to
+    // insert |sourceBuffer| into |m_activeSourceBuffers|.
+    size_t indexInSourceBuffers = m_sourceBuffers->find(sourceBuffer);
+    ASSERT(indexInSourceBuffers != kNotFound);
+
+    size_t insertPosition = 0;
+    while (insertPosition < m_activeSourceBuffers->length()
+        && m_sourceBuffers->find(m_activeSourceBuffers->item(insertPosition)) < indexInSourceBuffers) {
+        ++insertPosition;
+    }
+
+    m_activeSourceBuffers->insert(insertPosition, sourceBuffer);
+}
+
 bool MediaSource::isClosed() const
 {
     return readyState() == closedKeyword();