Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "modules/mediasource/TrackDefault.h" | |
| 7 | |
| 8 #include "bindings/core/v8/ExceptionState.h" | |
| 9 #include "core/dom/ExceptionCode.h" | |
| 10 #include "core/html/track/AudioTrack.h" | |
| 11 #include "core/html/track/TextTrack.h" | |
| 12 #include "core/html/track/VideoTrack.h" | |
| 13 | |
| 14 // BIG TODO: start with fixing '': is it a valid trackdefault kind? is it a | |
| 15 // valid audio/video/text track kind? And fix the negative layout test to not | |
| 16 // test kinds one at a time, but in bulk. And add more tests... | |
| 17 | |
| 18 namespace blink { | |
| 19 | |
| 20 const AtomicString& TrackDefault::audioKeyword() | |
| 21 { | |
| 22 DEFINE_STATIC_LOCAL(const AtomicString, audio, ("audio", AtomicString::Const ructFromLiteral)); | |
| 23 return audio; | |
| 24 } | |
| 25 | |
| 26 const AtomicString& TrackDefault::videoKeyword() | |
| 27 { | |
| 28 DEFINE_STATIC_LOCAL(const AtomicString, video, ("video", AtomicString::Const ructFromLiteral)); | |
| 29 return video; | |
| 30 } | |
| 31 | |
| 32 const AtomicString& TrackDefault::textKeyword() | |
| 33 { | |
| 34 DEFINE_STATIC_LOCAL(const AtomicString, text, ("text", AtomicString::Constru ctFromLiteral)); | |
| 35 return text; | |
| 36 } | |
| 37 | |
| 38 TrackDefault::TrackDefault(const AtomicString& type, const String& language, con st String& label, const Vector<String>& kinds, const String& byteStreamTrackID, ExceptionState& exceptionState) | |
| 39 { | |
| 40 // Per 06 Oct 2014 Editor's Draft | |
| 41 // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source. html#idl-def-TrackDefault | |
| 42 // When this method is invoked, the user agent must run the following steps: | |
| 43 // 1. if |language| is not an empty string or |language| is not a BCP 47 | |
| 44 // language tag, then throw an INVALID_ACCESS_ERR and abort these steps. | |
| 45 // FIXME: Implement BCP 47 language tag validation, and confirm spec logic | |
| 46 // for this step should be s/or/and/. | |
| 47 | |
| 48 if (type == audioKeyword()) { | |
| 49 // 2.1. If |type| equals "audio": | |
| 50 // If any string in |kinds| contains a value that is not listed as | |
| 51 // applying to audio in the kind categories table, then throw an | |
| 52 // INVALID_ACCESS_ERR and abort these steps. | |
| 53 for (size_t i = 0; i < kinds.size(); ++i) { | |
| 54 if (!AudioTrack::isValidKindKeyword(kinds[i])) { | |
| 55 exceptionState.throwDOMException(InvalidAccessError, "Invalid au dio track default kind at index " + String::number(i)); | |
|
philipj_slow
2014/11/01 23:10:22
Wouldn't it be more useful to print the kind which
wolenetz
2014/11/03 21:21:56
I was replicating other similar exceptions in Blin
| |
| 56 return; | |
| 57 } | |
| 58 } | |
| 59 } else if (type == videoKeyword()) { | |
| 60 // 2.2. If |type| equals "video": | |
| 61 // If any string in |kinds| contains a value that is not listed as | |
| 62 // applying to video in the kind categories table, then throw an | |
| 63 // INVALID_ACCESS_ERR and abort these steps. | |
| 64 for (size_t i = 0; i < kinds.size(); ++i) { | |
| 65 if (!VideoTrack::isValidKindKeyword(kinds[i])) { | |
| 66 exceptionState.throwDOMException(InvalidAccessError, "Invalid vi deo track default kind at index " + String::number(i)); | |
| 67 return; | |
| 68 } | |
| 69 } | |
| 70 } else { | |
| 71 ASSERT(type == textKeyword()); | |
| 72 // 2.3. If |type| equals "text": | |
| 73 // If any string in |kinds| contains a value that is not listed in the | |
| 74 // text track kind list, then throw an INVALID_ACCESS_ERR and abort | |
| 75 // these steps. | |
| 76 for (size_t i = 0; i < kinds.size(); ++i) { | |
| 77 if (!TextTrack::isValidKindKeyword(kinds[i])) { | |
| 78 exceptionState.throwDOMException(InvalidAccessError, "Invalid te xt track default kind at index " + String::number(i)); | |
| 79 return; | |
| 80 } | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 // 3. Set the type attribute on this new object to |type|. | |
| 85 m_type = type; | |
| 86 | |
| 87 // 4. Set the language attribute on this new object to |language|. | |
| 88 m_language = language; | |
| 89 | |
| 90 // 5. Set the label attribute on this new object to |label|. | |
| 91 m_label = label; | |
| 92 | |
| 93 // 6. Set the kinds attribute on this new object to |kinds|. | |
| 94 m_kinds = kinds; | |
| 95 | |
| 96 // 7. Set the byteStreamTrackID attribute on this new object to | |
| 97 // |byteStreamTrackID|. | |
| 98 m_byteStreamTrackID = byteStreamTrackID; | |
| 99 } | |
| 100 | |
| 101 } // namespace blink | |
| OLD | NEW |