1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "core/html/track/InbandTextTrack.h"
28
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
30 #include "core/html/HTMLMediaElement.h"
31 #include "core/html/track/vtt/VTTCue.h"
32 #include "platform/Logging.h"
33 #include "public/platform/WebInbandTextTrack.h"
34 #include "public/platform/WebString.h"
35 #include <math.h>
36
37 using blink::WebInbandTextTrack;
38 using blink::WebString;
39
40 namespace blink {
41
create(WebInbandTextTrack * webTrack)42 PassRefPtrWillBeRawPtr<InbandTextTrack> InbandTextTrack::create(WebInbandTextTrack* webTrack)
43 {
44 return adoptRefWillBeNoop(new InbandTextTrack(webTrack));
45 }
46
InbandTextTrack(WebInbandTextTrack * webTrack)47 InbandTextTrack::InbandTextTrack(WebInbandTextTrack* webTrack)
48 : TextTrack(emptyAtom, webTrack->label(), webTrack->language(), webTrack->id(), InBand)
49 , m_webTrack(webTrack)
50 {
51 m_webTrack->setClient(this);
52
53 switch (m_webTrack->kind()) {
54 case WebInbandTextTrack::KindSubtitles:
55 setKind(TextTrack::subtitlesKeyword());
56 break;
57 case WebInbandTextTrack::KindCaptions:
58 setKind(TextTrack::captionsKeyword());
59 break;
60 case WebInbandTextTrack::KindDescriptions:
61 setKind(TextTrack::descriptionsKeyword());
62 break;
63 case WebInbandTextTrack::KindChapters:
64 setKind(TextTrack::chaptersKeyword());
65 break;
66 case WebInbandTextTrack::KindMetadata:
67 setKind(TextTrack::metadataKeyword());
68 break;
69 case WebInbandTextTrack::KindNone:
70 default:
71 ASSERT_NOT_REACHED();
72 break;
73 }
74 }
75
~InbandTextTrack()76 InbandTextTrack::~InbandTextTrack()
77 {
78 #if ENABLE(OILPAN)
79 if (m_webTrack)
80 m_webTrack->setClient(0);
81 #else
82 // Make sure m_webTrack was cleared by trackRemoved() before destruction.
83 ASSERT(!m_webTrack);
84 #endif
85 }
86
inbandTrackIndex()87 size_t InbandTextTrack::inbandTrackIndex()
88 {
89 ASSERT(m_webTrack);
90 return m_webTrack->textTrackIndex();
91 }
92
setTrackList(TextTrackList * trackList)93 void InbandTextTrack::setTrackList(TextTrackList* trackList)
94 {
95 TextTrack::setTrackList(trackList);
96 if (trackList)
97 return;
98
99 ASSERT(m_webTrack);
100 m_webTrack->setClient(0);
101 m_webTrack = 0;
102 }
103
addWebVTTCue(double start,double end,const WebString & id,const WebString & content,const WebString & settings)104 void InbandTextTrack::addWebVTTCue(double start, double end, const WebString& id, const WebString& content, const WebString& settings)
105 {
106 HTMLMediaElement* owner = mediaElement();
107 ASSERT(owner);
108 RefPtrWillBeRawPtr<VTTCue> cue = VTTCue::create(owner->document(), start, end, content);
109 cue->setId(id);
110 cue->parseSettings(settings);
111 addCue(cue);
112 }
113
114 } // namespace blink
115