Chromium Code Reviews| Index: Source/modules/mediasource/TrackDefaultList.cpp |
| diff --git a/Source/modules/mediasource/TrackDefaultList.cpp b/Source/modules/mediasource/TrackDefaultList.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eea06e30243afcc48727e5b18fca562c89eb9301 |
| --- /dev/null |
| +++ b/Source/modules/mediasource/TrackDefaultList.cpp |
| @@ -0,0 +1,58 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| + |
| +#include "modules/mediasource/TrackDefaultList.h" |
| + |
| +#include "bindings/core/v8/ExceptionState.h" |
| +#include "core/dom/ExceptionCode.h" |
| + |
| +namespace blink { |
| + |
| +TrackDefault* TrackDefaultList::item(unsigned index) const |
| +{ |
| + // Per 18 Nov 2014 Editor's Draft |
| + // https://w3c.github.io/media-source/#trackdefaultlist |
| + // When this method is invoked, the user agent must run the following steps: |
| + // 1. If |index| is greater than or equal to the length attribute then |
| + // return undefined and abort these steps. |
| + if (index >= m_trackDefaults.size()) |
| + return 0; |
| + |
| + // 2. Return the |index|'th TrackDefault object in the list. |
| + return m_trackDefaults[index].get(); |
| +} |
| + |
| +TrackDefaultList::TrackDefaultList(const HeapVector<Member<TrackDefault>>& trackDefaults, ExceptionState& exceptionState) |
| +{ |
| + // Per 18 Nov 2014 Editor's Draft |
|
sof
2014/12/03 19:15:40
I think it would be tidier if the static factory m
philipj_slow
2014/12/04 15:29:14
I agree, m_typeAndIDToTrackDefaultMap is only used
wolenetz
2014/12/11 23:52:39
Thanks for pointing out these issues.
I'll address
|
| + // https://w3c.github.io/media-source/#trackdefaultlist |
| + // When this method is invoked, the user agent must run the following steps: |
| + // 1. If |trackDefaults| contains two or more TrackDefault objects with the |
| + // same type and the same byteStreamTrackID, then throw an |
| + // InvalidAccessError and abort these steps. |
| + // Note: This also applies when byteStreamTrackID contains an empty |
| + // string and ensures that there is only one "byteStreamTrackID |
| + // independent" default for each TrackDefaultType value. |
| + for (const auto& trackDefault : trackDefaults) { |
| + TypeAndID key = TypeAndID(trackDefault->type(), trackDefault->byteStreamTrackID()); |
| + if (!m_typeAndIDToTrackDefaultMap.add(key, trackDefault).isNewEntry) { |
| + exceptionState.throwDOMException(InvalidAccessError, "Duplicate TrackDefault type (" + key.first + ") and byteStreamTrackID (" + key.second + ")"); |
| + return; |
| + } |
| + } |
| + |
| + // 2. Store a copy of |trackDefaults| in this new object so the values can |
|
haraken
2014/12/04 11:29:51
This is a shadow copy, is it OK? I guess this need
philipj_slow
2014/12/04 15:29:14
The spec says "Store a copy of trackDefaults in th
wolenetz
2014/12/11 23:52:39
Thanks to discussion on this CL, a w3c bug (https:
|
| + // be returned by the accessor methods. |
| + m_trackDefaults = trackDefaults; |
| +} |
| + |
| +void TrackDefaultList::trace(Visitor* visitor) |
| +{ |
| + visitor->trace(m_trackDefaults); |
| + visitor->trace(m_typeAndIDToTrackDefaultMap); |
| +} |
| + |
| +} // namespace blink |