Source/WebCore/ChangeLog

 12011-10-17 Eric Carlson <eric.carlson@apple.com>
 2
 3 Use the new cached cue loader
 4 https://bugs.webkit.org/show_bug.cgi?id=70269
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 No new tests, no functionality changed.
 9
 10 * CMakeLists.txt: Remove CueParser.cpp/h and CueParserPrivate.h.
 11 * GNUmakefile.list.am: Ditto.
 12 * WebCore.gypi: Ditto.
 13 * WebCore.xcodeproj/project.pbxproj: Ditto.
 14
 15 * html/HTMLMediaElement.cpp:
 16 (WebCore::HTMLMediaElement::loadTextTracks):
 17 (WebCore::HTMLMediaElement::textTrackReadyStateChanged): New, not implemented yet.
 18 (WebCore::HTMLMediaElement::textTrackModeChanged): Ditto.
 19 (WebCore::HTMLMediaElement::textTrackCreated): Ditto.
 20 (WebCore::HTMLMediaElement::textTrackAddCues): Ditto.
 21 (WebCore::HTMLMediaElement::textTrackRemoveCues): Ditto.
 22 (WebCore::HTMLMediaElement::textTrackAddCue): Ditto.
 23 (WebCore::HTMLMediaElement::textTrackRemoveCue): Ditto.
 24 * html/HTMLMediaElement.h:
 25
 26 * html/HTMLTrackElement.cpp:
 27 (WebCore::HTMLTrackElement::load): Update for interface change
 28 (WebCore::HTMLTrackElement::textTrackLoadingCompleted): New, dispatch 'load' or 'error' event.
 29 * html/HTMLTrackElement.h:
 30
 31 * html/LoadableTextTrack.cpp:
 32 (WebCore::LoadableTextTrack::LoadableTextTrack): Add TextTrackClient and TextTrackLoadingClient
 33 parameters.
 34 (WebCore::LoadableTextTrack::load): Make url parameter KURL instead of String. Create the
 35 cue loader, trigger the load.
 36 (WebCore::LoadableTextTrack::newCuesAvailable): New callback from the loader. Not implemented yet.
 37 (WebCore::LoadableTextTrack::cueLoadingStarted): Ditto.
 38 (WebCore::LoadableTextTrack::cueLoadingCompleted): Ditto.
 39 * html/LoadableTextTrack.h:
 40
 41 * html/MutableTextTrack.cpp:
 42 (WebCore::MutableTextTrack::MutableTextTrack): Add TextTrackClient parameter.
 43 * html/MutableTextTrack.h:
 44 (WebCore::MutableTextTrack::create):
 45
 46 * html/TextTrack.cpp:
 47 (WebCore::TextTrack::TextTrack): Add TextTrackClient parameter.
 48 (WebCore::TextTrack::~TextTrack): Tell the client to remove all cues, forget the client.
 49 (WebCore::TextTrack::setReadyState): Tell client about ready state change.
 50 (WebCore::TextTrack::setMode): Tell client about mode change.
 51 * html/TextTrack.h:
 52 (WebCore::TextTrackClient::textTrackAddCues): New client interface.
 53 (WebCore::TextTrackClient::textTrackRemoveCues): Ditto.
 54 (WebCore::TextTrackClient::textTrackAddCue): Ditto.
 55 (WebCore::TextTrackClient::textTrackRemoveCue): Ditto.
 56 (WebCore::TextTrack::create):
 57 (WebCore::TextTrack::trackType): New.
 58 (WebCore::TextTrack::client): Ditto.
 59 (WebCore::TextTrack::setClient): Ditto.
 60
 61 * html/track/CueParser.cpp: Removed.
 62 * html/track/CueParser.h: Removed.
 63 * html/track/CueParserPrivate.h: Removed.
 64
 65 * html/track/WebVTTParser.cpp:
 66 (WebCore::WebVTTParser::fileIdentifierMaximumLength): New, return length of WebVTT file
 67 magic number.
 68 (WebCore::WebVTTParser::hasRequiredFileIdentifier): Update to use constants instead of hard
 69 coded lengths.
 70 (WebCore::WebVTTParser::WebVTTParser): Initialize "m_client" in the initilization list
 71 instead of setting it in the constructor.
 72 (WebCore::WebVTTParser::getNewCues): Renamed from fetchParsedCues.
 73 * html/track/WebVTTParser.h:
 74 (WebCore::WebVTTParser::create): Take a WebVTTParserClient* instead of a CueParserPrivateClient*.
 75
 76 * loader/CueLoader.cpp:
 77 (WebCore::CueLoader::CueLoader):
 78 (WebCore::CueLoader::~CueLoader): Remove client.
 79 (WebCore::CueLoader::cueLoadTimerFired): Tell client about new clues and/or that the load
 80 has finished.
 81 (WebCore::CueLoader::processNewCueData): Process newly loaded data.
 82 (WebCore::CueLoader::didReceiveData): Ditto.
 83 (WebCore::CueLoader::notifyFinished): Do final processing as necessary, prime the timer
 84 to call client.
 85 (WebCore::CueLoader::load): Create resource loader, initiate loading.
 86 (WebCore::CueLoader::newCuesParsed): Prime timer to tell client about newly parsed cues.
 87 (WebCore::CueLoader::getNewCues): Get new cues from parser.
 88 * loader/CueLoader.h:
 89 (WebCore::CueLoader::create):
 90
1912011-10-17 Ojan Vafai <ojan@chromium.org>
292
393 Unreviewed, rolling out r97662.
97710

Source/WebCore/CMakeLists.txt

@@IF (ENABLE_VIDEO_TRACK)
20522052 html/TextTrack.cpp
20532053 html/TextTrackCue.cpp
20542054 html/TextTrackCueList.cpp
2055  html/track/CueParser.cpp
20562055 html/track/WebVTTParser.cpp
20572056 html/track/WebVTTTokenizer.cpp
20582057 loader/CueLoader.cpp
97637

Source/WebCore/GNUmakefile.list.am

@@webcore_sources += \
19391939 Source/WebCore/html/TimeInputType.h \
19401940 Source/WebCore/html/TimeRanges.cpp \
19411941 Source/WebCore/html/TimeRanges.h \
1942  Source/WebCore/html/track/CueParser.h \
1943  Source/WebCore/html/track/CueParser.cpp \
1944  Source/WebCore/html/track/CueParserPrivate.h \
19451942 Source/WebCore/html/track/WebVTTParser.cpp \
19461943 Source/WebCore/html/track/WebVTTParser.h \
19471944 Source/WebCore/html/track/WebVTTToken.h \
97637

Source/WebCore/WebCore.gypi

57385738 'html/shadow/SliderThumbElement.h',
57395739 'html/shadow/TextControlInnerElements.cpp',
57405740 'html/shadow/TextControlInnerElements.h',
5741  'html/track/CueParser.cpp',
5742  'html/track/CueParser.h',
5743  'html/track/CueParserPrivate.h',
57445741 'html/track/WebVTTParser.cpp',
57455742 'html/track/WebVTTParser.h',
57465743 'html/track/WebVTTToken.h',
97637

Source/WebCore/WebCore.xcodeproj/project.pbxproj

41434143 B1AD4E6B13A12A0B00846B27 /* TextTrackCueList.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E5A13A12A0B00846B27 /* TextTrackCueList.h */; };
41444144 B1AD4E7313A12A4600846B27 /* CueLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1AD4E7113A12A4600846B27 /* CueLoader.cpp */; };
41454145 B1AD4E7413A12A4600846B27 /* CueLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E7213A12A4600846B27 /* CueLoader.h */; };
4146  B1AD4E7B13A12A7200846B27 /* CueParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1AD4E7813A12A7200846B27 /* CueParser.cpp */; };
4147  B1AD4E7C13A12A7200846B27 /* CueParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E7913A12A7200846B27 /* CueParser.h */; };
4148  B1AD4E7D13A12A7200846B27 /* CueParserPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E7A13A12A7200846B27 /* CueParserPrivate.h */; };
41494146 B1D5ECB5134B58DA0087C78F /* CallbackFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = B1D5ECB4134B58DA0087C78F /* CallbackFunction.h */; };
41504147 B1E5457A1346291F0092A545 /* LocalMediaStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1E545711346291F0092A545 /* LocalMediaStream.cpp */; };
41514148 B1E5457B1346291F0092A545 /* LocalMediaStream.h in Headers */ = {isa = PBXBuildFile; fileRef = B1E545721346291F0092A545 /* LocalMediaStream.h */; };

70897086 06E81EEB0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalCurrentGraphicsContext.mm; sourceTree = "<group>"; };
70907087 0709FC4D1025DEE30059CDBA /* AccessibilitySlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilitySlider.h; sourceTree = "<group>"; };
70917088 070DD8F50F01868000727DEB /* mediaControls.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mediaControls.css; sourceTree = "<group>"; };
 7089 0735EE690F40C5E4004A2604 /* MediaPlayerProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPlayerProxy.h; sourceTree = "<group>"; };
70927090 0753860014489E9800B78452 /* CachedCues.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedCues.cpp; sourceTree = "<group>"; };
70937091 0753860114489E9800B78452 /* CachedCues.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedCues.h; sourceTree = "<group>"; };
7094  0735EE690F40C5E4004A2604 /* MediaPlayerProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPlayerProxy.h; sourceTree = "<group>"; };
70957092 076F0D0912B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaPlayerPrivateAVFoundation.cpp; sourceTree = "<group>"; };
70967093 076F0D0A12B8192700C26AA4 /* MediaPlayerPrivateAVFoundation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPlayerPrivateAVFoundation.h; sourceTree = "<group>"; };
70977094 079F5E4B0F3BEBEA005E0782 /* MediaPlayerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPlayerPrivate.h; sourceTree = "<group>"; };

1123611233 B1AD4E5A13A12A0B00846B27 /* TextTrackCueList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackCueList.h; sourceTree = "<group>"; };
1123711234 B1AD4E7113A12A4600846B27 /* CueLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CueLoader.cpp; path = loader/CueLoader.cpp; sourceTree = SOURCE_ROOT; };
1123811235 B1AD4E7213A12A4600846B27 /* CueLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CueLoader.h; path = loader/CueLoader.h; sourceTree = SOURCE_ROOT; };
11239  B1AD4E7813A12A7200846B27 /* CueParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CueParser.cpp; sourceTree = "<group>"; };
11240  B1AD4E7913A12A7200846B27 /* CueParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CueParser.h; sourceTree = "<group>"; };
11241  B1AD4E7A13A12A7200846B27 /* CueParserPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CueParserPrivate.h; sourceTree = "<group>"; };
1124211236 B1D5ECB4134B58DA0087C78F /* CallbackFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallbackFunction.h; sourceTree = "<group>"; };
1124311237 B1E545711346291F0092A545 /* LocalMediaStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LocalMediaStream.cpp; sourceTree = "<group>"; };
1124411238 B1E545721346291F0092A545 /* LocalMediaStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalMediaStream.h; sourceTree = "<group>"; };

1847818472 B1AD4E7713A12A7200846B27 /* track */ = {
1847918473 isa = PBXGroup;
1848018474 children = (
18481  B1AD4E7813A12A7200846B27 /* CueParser.cpp */,
18482  B1AD4E7913A12A7200846B27 /* CueParser.h */,
18483  B1AD4E7A13A12A7200846B27 /* CueParserPrivate.h */,
1848418475 5D21A80013ECE5DF00BB7064 /* WebVTTParser.cpp */,
1848518476 5D21A80113ECE5DF00BB7064 /* WebVTTParser.h */,
1848618477 B10B697D140C174000BC1C26 /* WebVTTToken.h */,

2187721868 501BA9E21393CEA000F7ACEB /* CSSWrapShapes.h in Headers */,
2187821869 B1AD4E5D13A12A0B00846B27 /* CueIndex.h in Headers */,
2187921870 B1AD4E7413A12A4600846B27 /* CueLoader.h in Headers */,
21880  B1AD4E7C13A12A7200846B27 /* CueParser.h in Headers */,
21881  B1AD4E7D13A12A7200846B27 /* CueParserPrivate.h in Headers */,
2188221871 93F1992F08245E59001E9ABC /* Cursor.h in Headers */,
2188321872 BC2272A20E82E87C00E7F975 /* CursorData.h in Headers */,
2188421873 BC2272AD0E82E8F300E7F975 /* CursorList.h in Headers */,

2520525194 50E566D6139E38C500214433 /* CSSWrapShapes.cpp in Sources */,
2520625195 B1AD4E5C13A12A0B00846B27 /* CueIndex.cpp in Sources */,
2520725196 B1AD4E7313A12A4600846B27 /* CueLoader.cpp in Sources */,
25208  B1AD4E7B13A12A7200846B27 /* CueParser.cpp in Sources */,
2520925197 E11AF15111B9A1A300805103 /* Cursor.cpp in Sources */,
2521025198 93F19A2608245E59001E9ABC /* CursorMac.mm in Sources */,
2521125199 62CD32591157E57C0063B0A7 /* CustomEvent.cpp in Sources */,
97637

Source/WebCore/html/HTMLMediaElement.cpp

@@void HTMLMediaElement::loadTextTracks()
847847 for (Node* node = firstChild(); node; node = node->nextSibling()) {
848848 if (node->hasTagName(trackTag)) {
849849 HTMLTrackElement* track = static_cast<HTMLTrackElement*>(node);
850  track->load(ActiveDOMObject::scriptExecutionContext());
 850 track->load(ActiveDOMObject::scriptExecutionContext(), this);
851851 }
852852 }
853853}
 854
 855void HTMLMediaElement::textTrackReadyStateChanged(TextTrack*)
 856{
 857 // FIXME(62885): Implement.
 858}
 859
 860void HTMLMediaElement::textTrackModeChanged(TextTrack*)
 861{
 862 // FIXME(62885): Implement.
 863}
 864
 865void HTMLMediaElement::textTrackCreated(TextTrack*)
 866{
 867 // FIXME(62885): Implement.
 868}
 869
 870void HTMLMediaElement::textTrackAddCues(TextTrack*, const TextTrackCueList*)
 871{
 872 // FIXME(62885): Implement.
 873}
 874
 875void HTMLMediaElement::textTrackRemoveCues(TextTrack*, const TextTrackCueList*)
 876{
 877 // FIXME(62885): Implement.
 878}
 879
 880void HTMLMediaElement::textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue>)
 881{
 882 // FIXME(62885): Implement.
 883}
 884
 885void HTMLMediaElement::textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue>)
 886{
 887 // FIXME(62885): Implement.
 888}
 889
854890#endif
855891
856892bool HTMLMediaElement::isSafeToLoadURL(const KURL& url, InvalidSourceAction actionIfInvalid)
97560

Source/WebCore/html/HTMLMediaElement.h

3737#include "MediaPlayerProxy.h"
3838#endif
3939
 40#if ENABLE(VIDEO_TRACK)
 41#include "TextTrack.h"
 42#endif
 43
4044namespace WebCore {
4145
4246#if ENABLE(WEB_AUDIO)

@@class Widget;
5862// But it can't be until the Chromium WebMediaPlayerClientImpl class is fixed so it
5963// no longer depends on typecasting a MediaPlayerClient to an HTMLMediaElement.
6064
61 class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, private MediaCanStartListener, private ActiveDOMObject {
 65class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, private MediaCanStartListener, private ActiveDOMObject
 66#if ENABLE(VIDEO_TRACK)
 67 , private TextTrackClient
 68#endif
 69{
6270public:
6371 MediaPlayer* player() const { return m_player.get(); }
6472

@@private:
339347
340348#if ENABLE(VIDEO_TRACK)
341349 void loadTextTracks();
 350
 351 // TextTrackClient
 352 virtual void textTrackReadyStateChanged(TextTrack*);
 353 virtual void textTrackModeChanged(TextTrack*);
 354 virtual void textTrackCreated(TextTrack*);
 355 virtual void textTrackAddCues(TextTrack*, const TextTrackCueList*);
 356 virtual void textTrackRemoveCues(TextTrack*, const TextTrackCueList*);
 357 virtual void textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue>);
 358 virtual void textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue>);
342359#endif
343360
344361 // These "internal" functions do not check user gesture restrictions.
97560

Source/WebCore/html/HTMLTrackElement.cpp

2828#if ENABLE(VIDEO_TRACK)
2929#include "HTMLTrackElement.h"
3030
 31#include "Event.h"
3132#include "HTMLMediaElement.h"
3233#include "HTMLNames.h"
3334#include "Logging.h"

@@bool HTMLTrackElement::isURLAttribute(At
129130 return attribute->name() == srcAttr;
130131}
131132
132 void HTMLTrackElement::load(ScriptExecutionContext* context)
 133void HTMLTrackElement::load(ScriptExecutionContext* context, TextTrackClient* trackClient)
133134{
134  m_track = LoadableTextTrack::create(kind(), label(), srclang(), isDefault());
 135 m_track = LoadableTextTrack::create(trackClient, this, kind(), label(), srclang(), isDefault());
135136
136137 if (hasAttribute(srcAttr))
137138 m_track->load(getNonEmptyURLAttribute(srcAttr), context);
138139}
139140
 141void HTMLTrackElement::textTrackLoadingCompleted(LoadableTextTrack*, bool loadingFailed)
 142{
 143 ExceptionCode ec = 0;
 144 dispatchEvent(Event::create(loadingFailed ? eventNames().errorEvent : eventNames().loadEvent, false, false), ec);
 145}
 146
140147}
141148
142149#endif
97560

Source/WebCore/html/HTMLTrackElement.h

3333
3434namespace WebCore {
3535
36 class HTMLTrackElement : public HTMLElement {
 36class HTMLTrackElement : public HTMLElement, private TextTrackLoadingClient {
3737public:
3838 static PassRefPtr<HTMLTrackElement> create(const QualifiedName&, Document*);
3939

@@public:
4949 void setLabel(const String&);
5050 void setIsDefault(bool);
5151
52  void load(ScriptExecutionContext*);
 52 void load(ScriptExecutionContext*, TextTrackClient*);
5353
5454private:
 55
 56 // TextTrackLoadingClient
 57 virtual void textTrackLoadingCompleted(LoadableTextTrack*, bool);
 58
5559 HTMLTrackElement(const QualifiedName&, Document*);
5660 virtual ~HTMLTrackElement();
5761
97560

Source/WebCore/html/LoadableTextTrack.cpp

3131
3232namespace WebCore {
3333
34 LoadableTextTrack::LoadableTextTrack(const String& kind, const String& label, const String& language, bool isDefault)
35  : TextTrack(kind, label, language)
 34LoadableTextTrack::LoadableTextTrack(TextTrackClient* trackClient, TextTrackLoadingClient* loadingClient, const String& kind, const String& label, const String& language, bool isDefault)
 35 : TextTrack(trackClient, kind, label, language, TextTrack::LoadableTextTrack)
 36 , m_loadingClient(loadingClient)
3637 , m_isDefault(isDefault)
3738{
3839}

@@LoadableTextTrack::~LoadableTextTrack()
4142{
4243}
4344
44 void LoadableTextTrack::load(const String& url, ScriptExecutionContext* context)
 45void LoadableTextTrack::load(const KURL& url, ScriptExecutionContext* context)
4546{
46  return m_parser.load(url, context, this);
 47 if (!m_cueLoader)
 48 m_cueLoader = CueLoader::create(this, context);
 49 m_cueLoader->load(url);
4750}
4851
49 bool LoadableTextTrack::supportsType(const String& url)
 52void LoadableTextTrack::newCuesAvailable(CueLoader* loader)
5053{
51  return m_parser.supportsType(url);
52 }
 54 ASSERT_UNUSED(loader, m_cueLoader == loader);
5355
54 void LoadableTextTrack::newCuesParsed()
55 {
56  // FIXME(62883): Fetch new cues from parser and temporarily store to give to CueLoaderClient when fetchNewCuesFromLoader is called.
 56 // FIXME(62885): Implement.
5757}
5858
59 void LoadableTextTrack::trackLoadStarted()
 59void LoadableTextTrack::cueLoadingStarted(CueLoader* loader)
6060{
 61 ASSERT_UNUSED(loader, m_cueLoader == loader);
 62
6163 setReadyState(TextTrack::Loading);
6264}
6365
64 void LoadableTextTrack::trackLoadError()
 66void LoadableTextTrack::cueLoadingCompleted(CueLoader* loader, bool)
6567{
66  setReadyState(TextTrack::Error);
67 }
 68 ASSERT_UNUSED(loader, m_cueLoader == loader);
6869
69 void LoadableTextTrack::trackLoadCompleted()
70 {
71  setReadyState(TextTrack::Loaded);
72 }
73 
74 void LoadableTextTrack::newCuesLoaded()
75 {
76  // FIXME(62885): Tell the client to fetch the latest cues.
77 }
78 
79 void LoadableTextTrack::fetchNewestCues(Vector<TextTrackCue*>&)
80 {
8170 // FIXME(62885): Implement.
8271}
8372
97560

Source/WebCore/html/LoadableTextTrack.h

2929#if ENABLE(VIDEO_TRACK)
3030
3131#include "CueLoader.h"
32 #include "CueParser.h"
3332#include "TextTrack.h"
34 #include "TextTrackCueList.h"
3533#include <wtf/PassRefPtr.h>
3634#include <wtf/Vector.h>
3735
3836namespace WebCore {
3937
 38class HTMLTrackElement;
 39class LoadableTextTrack;
4040class ScriptExecutionContext;
41 class TextTrack;
42 class TextTrackCue;
4341
44 class LoadableTextTrack : public TextTrack, public CueParserClient, public CueLoader {
 42class TextTrackLoadingClient {
4543public:
46  static PassRefPtr<LoadableTextTrack> create(const String& kind, const String& label, const String& language, bool isDefault)
 44 virtual ~TextTrackLoadingClient() { }
 45
 46 virtual void textTrackLoadingCompleted(LoadableTextTrack*, bool /* loadingFailed */) = 0;
 47};
 48
 49class LoadableTextTrack : public TextTrack, private CueLoaderClient {
 50public:
 51 static PassRefPtr<LoadableTextTrack> create(TextTrackClient* trackClient, TextTrackLoadingClient* loadingClient, const String& kind, const String& label, const String& language, bool isDefault)
4752 {
48  return adoptRef(new LoadableTextTrack(kind, label, language, isDefault));
 53 return adoptRef(new LoadableTextTrack(trackClient, loadingClient, kind, label, language, isDefault));
4954 }
5055 virtual ~LoadableTextTrack();
5156
52  void load(const String&, ScriptExecutionContext*);
 57 void load(const KURL&, ScriptExecutionContext*);
5358 bool supportsType(const String&);
5459
55  virtual void newCuesParsed();
56  virtual void trackLoadStarted();
57  virtual void trackLoadError();
58  virtual void trackLoadCompleted();
59 
60  virtual void newCuesLoaded();
61  virtual void fetchNewestCues(Vector<TextTrackCue*>&);
62 
6360private:
64  LoadableTextTrack(const String& kind, const String& label, const String& language, bool isDefault);
 61 // CueLoaderClient
 62 virtual bool shouldLoadCues(CueLoader*) { return true; }
 63 virtual void newCuesAvailable(CueLoader*);
 64 virtual void cueLoadingStarted(CueLoader*);
 65 virtual void cueLoadingCompleted(CueLoader*, bool loadingFailed);
6566
66  CueParser m_parser;
 67 LoadableTextTrack(TextTrackClient*, TextTrackLoadingClient*, const String& kind, const String& label, const String& language, bool isDefault);
6768
 69 OwnPtr<CueLoader> m_cueLoader;
 70 TextTrackLoadingClient* m_loadingClient;
6871 bool m_isDefault;
6972};
7073} // namespace WebCore
97560

Source/WebCore/html/MutableTextTrack.cpp

3434
3535namespace WebCore {
3636
37 MutableTextTrack::MutableTextTrack(const String& kind, const String& label, const String& language)
38  : TextTrack(kind, label, language)
 37MutableTextTrack::MutableTextTrack(TextTrackClient* trackClient, const String& kind, const String& label, const String& language)
 38 : TextTrack(trackClient, kind, label, language, TextTrack::MutableTextTrack)
3939{
4040}
4141
97560

Source/WebCore/html/MutableTextTrack.h

@@namespace WebCore {
3737
3838class TextTrackCue;
3939
40 class MutableTextTrack : public TextTrack, public CueLoader {
 40class MutableTextTrack : public TextTrack {
4141public:
42  static PassRefPtr<MutableTextTrack> create(const String& kind, const String& label, const String& language)
 42 static PassRefPtr<MutableTextTrack> create(TextTrackClient* trackClient, const String& kind, const String& label = emptyString(), const String& language = emptyString())
4343 {
44  return adoptRef(new MutableTextTrack(kind, label, language));
 44 return adoptRef(new MutableTextTrack(trackClient, kind, label, language));
4545 }
4646 virtual ~MutableTextTrack() { }
4747

@@public:
5252 virtual void fetchNewestCues(Vector<TextTrackCue*>&);
5353
5454private:
55  MutableTextTrack(const String& kind, const String& label, const String& language);
 55 MutableTextTrack(TextTrackClient*, const String& kind, const String& label, const String& language);
5656};
5757
5858} // namespace WebCore
97560

Source/WebCore/html/TextTrack.cpp

3838
3939namespace WebCore {
4040
41 TextTrack::TextTrack(const String& kind, const String& label, const String& language)
 41TextTrack::TextTrack(TextTrackClient* client, const String& kind, const String& label, const String& language, Type trackType)
4242 : m_kind(kind)
4343 , m_label(label)
4444 , m_language(language)
4545 , m_readyState(TextTrack::None)
4646 , m_mode(TextTrack::Showing)
 47 , m_client(client)
 48 , m_type(trackType)
4749{
4850}
4951
5052TextTrack::~TextTrack()
5153{
 54 if (m_client)
 55 m_client->textTrackRemoveCues(this, m_cues.get());
 56 setClient(0);
5257}
5358
5459String TextTrack::kind() const

@@TextTrack::ReadyState TextTrack::readySt
7479void TextTrack::setReadyState(ReadyState state)
7580{
7681 m_readyState = state;
 82 if (m_client)
 83 m_client->textTrackReadyStateChanged(this);
7784}
7885
7986TextTrack::Mode TextTrack::mode() const

@@void TextTrack::setMode(unsigned short m
8592{
8693 // 4.8.10.12.5 On setting the mode, if the new value is not either 0, 1, or 2,
8794 // the user agent must throw an INVALID_ACCESS_ERR exception.
88  if (mode == TextTrack::Off || mode == TextTrack::Hidden || mode == TextTrack::Showing)
 95 if (mode == TextTrack::Off || mode == TextTrack::Hidden || mode == TextTrack::Showing) {
8996 m_mode = static_cast<Mode>(mode);
90  else
 97 if (m_client)
 98 m_client->textTrackModeChanged(this);
 99 } else
91100 ec = INVALID_ACCESS_ERR;
92101}
93102
97560

Source/WebCore/html/TextTrack.h

3636namespace WebCore {
3737
3838class TextTrack;
 39class TextTrackCue;
3940class TextTrackCueList;
4041
4142class TextTrackClient {
4243public:
4344 virtual ~TextTrackClient() { }
44  virtual void textTrackReadyStateChanged(TextTrack*) { }
45  virtual void textTrackModeChanged(TextTrack*) { }
46  virtual void textTrackCreated(TextTrack*) { }
 45 virtual void textTrackReadyStateChanged(TextTrack*) = 0;
 46 virtual void textTrackModeChanged(TextTrack*) = 0;
 47 virtual void textTrackCreated(TextTrack*) = 0;
 48 virtual void textTrackAddCues(TextTrack*, const TextTrackCueList*) = 0;
 49 virtual void textTrackRemoveCues(TextTrack*, const TextTrackCueList*) = 0;
 50 virtual void textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue>) = 0;
 51 virtual void textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue>) = 0;
4752};
4853
4954class TextTrack : public RefCounted<TextTrack> {
5055public:
51  static PassRefPtr<TextTrack> create(const String& kind, const String& label, const String& language)
 56 static PassRefPtr<TextTrack> create(TextTrackClient* client, const String& kind, const String& label, const String& language)
5257 {
53  return adoptRef(new TextTrack(kind, label, language));
 58 return adoptRef(new TextTrack(client, kind, label, language, BaseTextTrack));
5459 }
5560 virtual ~TextTrack();
5661

@@public:
5863 String label() const;
5964 String language() const;
6065
61  enum ReadyState { None, Loading, Loaded, Error };
 66 enum ReadyState { None = 0, Loading = 1, Loaded = 2, Error = 3 };
6267 ReadyState readyState() const;
6368
6469 enum Mode { Off = 0, Hidden = 1, Showing = 2 };

@@public:
7176 void readyStateChanged();
7277 void modeChanged();
7378
 79 enum Type { BaseTextTrack, MutableTextTrack, LoadableTextTrack };
 80 Type trackType() { return m_type; }
 81
 82 TextTrackClient* client() { return m_client; }
 83 void setClient(TextTrackClient* client) { m_client = client; }
 84
7485protected:
75  TextTrack(const String& kind, const String& label, const String& language);
 86 TextTrack(TextTrackClient*, const String& kind, const String& label, const String& language, Type trackType);
7687
7788 void setReadyState(ReadyState);
7889

@@private:
8495 String m_language;
8596 TextTrack::ReadyState m_readyState;
8697 TextTrack::Mode m_mode;
87 
 98 TextTrackClient* m_client;
 99 Type m_type;
88100};
89101
90102} // namespace WebCore
97560

Source/WebCore/html/track/CueParser.cpp

1 /*
2  * Copyright (C) 2011 Google 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 are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  * * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "config.h"
32 
33 #if ENABLE(VIDEO_TRACK)
34 
35 #include "CueParser.h"
36 
37 #include "ResourceRequest.h"
38 #include "ResourceResponse.h"
39 #include "ThreadableLoader.h"
40 
41 namespace WebCore {
42 
43 CueParser::CueParser()
44 {
45  // FIXME(62893): Implement.
46 }
47 
48 CueParser::~CueParser()
49 {
50  if (m_loader)
51  m_loader->cancel();
52  m_loader = 0;
53 }
54 
55 void CueParser::load(const String& url, ScriptExecutionContext* context, CueParserClient* client)
56 {
57  ResourceRequest request(url);
58 
59  ThreadableLoaderOptions options;
60  options.sendLoadCallbacks = SendCallbacks;
61  options.crossOriginRequestPolicy = AllowCrossOriginRequests;
62 
63  m_client = client;
64  m_scriptExecutionContext = context;
65 
66  m_loader = ThreadableLoader::create(context, this, request, options);
67 }
68 
69 bool CueParser::supportsType(const String&)
70 {
71  // FIXME(62893): check against a list of supported types
72  return false;
73 }
74 
75 void CueParser::didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse& response)
76 {
77  if (response.mimeType() == "text/vtt")
78  createWebVTTParser();
79 }
80 
81 void CueParser::didReceiveData(const char* data, int length)
82 {
83  // If mime type from didReceiveResponse was not informative, sniff file content.
84  if (!m_private && WebVTTParser::hasRequiredFileIdentifier(data, length))
85  createWebVTTParser();
86 
87  if (m_private)
88  m_private->parseBytes(data, length);
89 }
90 
91 void CueParser::didFinishLoading(unsigned long, double)
92 {
93  m_client->trackLoadCompleted();
94 }
95 
96 void CueParser::didFail(const ResourceError&)
97 {
98  m_client->trackLoadError();
99 }
100 
101 void CueParser::fetchParsedCues(Vector<RefPtr<TextTrackCue> >&)
102 {
103  // FIXME(62893): Implement.
104 }
105 
106 void CueParser::newCuesParsed()
107 {
108  m_client->newCuesParsed();
109 }
110 
111 void CueParser::createWebVTTParser()
112 {
113  if (!m_private) {
114  m_private = WebVTTParser::create(this, m_scriptExecutionContext);
115  m_client->trackLoadStarted();
116  }
117 }
118 
119 } // namespace WebCore
120 
121 #endif
97572

Source/WebCore/html/track/CueParser.h

1 /*
2  * Copyright (C) 2011 Google 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 are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  * * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef CueParser_h
32 #define CueParser_h
33 
34 #if ENABLE(VIDEO_TRACK)
35 
36 #include "ThreadableLoader.h"
37 #include "ThreadableLoaderClient.h"
38 #include "WebVTTParser.h"
39 #include <wtf/RefCounted.h>
40 #include <wtf/Vector.h>
41 #include <wtf/text/WTFString.h>
42 
43 namespace WebCore {
44 
45 class ScriptExecutionContext;
46 class TextTrackCue;
47 
48 class CueParserClient {
49 public:
50  virtual ~CueParserClient() { }
51 
52  virtual void newCuesParsed() = 0;
53  virtual void trackLoadStarted() = 0;
54  virtual void trackLoadError() = 0;
55  virtual void trackLoadCompleted() = 0;
56 };
57 
58 class CueParser : public ThreadableLoaderClient, CueParserPrivateClient {
59 public:
60  CueParser();
61  virtual ~CueParser();
62 
63  virtual void didReceiveResponse(unsigned long, const ResourceResponse&);
64  virtual void didReceiveData(const char*, int);
65  virtual void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/);
66  virtual void didFail(const ResourceError&);
67 
68  void load(const String&, ScriptExecutionContext*, CueParserClient*);
69  bool supportsType(const String&);
70 
71  void fetchParsedCues(Vector<RefPtr<TextTrackCue> >&);
72  void newCuesParsed();
73 
74 protected:
75  ScriptExecutionContext* m_scriptExecutionContext;
76 
77 private:
78  void createWebVTTParser();
79 
80  RefPtr<ThreadableLoader> m_loader;
81  OwnPtr<CueParserPrivateInterface> m_private;
82  CueParserClient* m_client;
83 };
84 
85 } // namespace WebCore
86 
87 #endif
88 #endif
97572

Source/WebCore/html/track/CueParserPrivate.h

1 /*
2  * Copyright (C) 2011 Google 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 are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  * * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef CueParserPrivate_h
32 #define CueParsePrivate_h
33 
34 #if ENABLE(VIDEO_TRACK)
35 
36 #include "TextTrackCue.h"
37 #include <wtf/Forward.h>
38 #include <wtf/Noncopyable.h>
39 #include <wtf/Vector.h>
40 
41 namespace WebCore {
42 
43 class CueParserPrivateClient {
44 public:
45  virtual ~CueParserPrivateClient() { }
46 
47  virtual void newCuesParsed() = 0;
48 };
49 
50 class CueParserPrivateInterface {
51  WTF_MAKE_NONCOPYABLE(CueParserPrivateInterface); WTF_MAKE_FAST_ALLOCATED;
52 public:
53  virtual ~CueParserPrivateInterface() { }
54 
55  // Input data to the parser to parse.
56  virtual void parseBytes(const char*, unsigned) = 0;
57 
58  // Transfers ownership of last parsed cues to caller.
59  virtual void fetchParsedCues(Vector<RefPtr<TextTrackCue> >&) = 0;
60 
61 protected:
62  CueParserPrivateInterface() { }
63 };
64 
65 } // namespace WebCore
66 
67 #endif
68 #endif
97572

Source/WebCore/html/track/WebVTTParser.cpp

4242
4343namespace WebCore {
4444
 45const int secondsPerHour = 3600;
 46const int secondsPerMinute = 60;
 47const double malformedTime = -1;
 48const unsigned bomLength = 3;
 49const unsigned fileIdentiferLength = 6;
 50
 51unsigned WebVTTParser::fileIdentifierMaximumLength()
 52{
 53 return bomLength + fileIdentiferLength;
 54}
 55
 56inline bool hasLongWebVTTIdentifier(String line)
 57{
 58 // If line is more than six characters ...
 59 if (line.length() < fileIdentiferLength)
 60 return false;
 61
 62 // but the first six characters do not exactly equal "WEBVTT" ...
 63 if (line.substring(0, fileIdentiferLength) != "WEBVTT")
 64 return false;
 65
 66 // or the seventh character is neither a space nor a tab character, then abort.
 67 if (line[fileIdentiferLength] != ' ' && line[fileIdentiferLength] != '\t')
 68 return false;
 69
 70 return true;
 71}
 72
4573bool WebVTTParser::hasRequiredFileIdentifier(const char* data, unsigned length)
4674{
4775 // A WebVTT file identifier consists of an optional BOM character,
4876 // the string "WEBVTT" followed by an optional space or tab character,
4977 // and any number of characters that are not line terminators ...
5078 unsigned position = 0;
51  if (length >= 3 && data[0] == '\xEF' && data[1] == '\xBB' && data[2] == '\xBF')
52  position += 3;
 79 if (length >= bomLength && data[0] == '\xEF' && data[1] == '\xBB' && data[2] == '\xBF')
 80 position += bomLength;
5381 String line = collectNextLine(data, length, &position);
54 
55  if (line.length() < 6)
 82
 83 if (line.length() < fileIdentiferLength)
5684 return false;
57  if (line.length() == 6 && line != "WEBVTT")
 85 if (line.length() == fileIdentiferLength && line != "WEBVTT")
5886 return false;
59 
60  // If line is more than six characters
61  // but the first six characters do not exactly equal "WEBVTT",
62  // or the seventh character is neither a space nor a tab character, then abort.
63  if (line.length() > 6 && (line.substring(0, 6) != "WEBVTT"
64  || (line[6] != ' ' && line[6] != '\t')))
 87 if (!hasLongWebVTTIdentifier(line))
6588 return false;
 89
6690 return true;
6791}
6892

@@String WebVTTParser::collectWord(const S
82106 return string.toString();
83107}
84108
85 WebVTTParser::WebVTTParser(CueParserPrivateClient* client, ScriptExecutionContext* context)
 109WebVTTParser::WebVTTParser(WebVTTParserClient* client, ScriptExecutionContext* context)
86110 : m_scriptExecutionContext(context)
87111 , m_state(Initial)
88112 , m_tokenizer(WebVTTTokenizer::create())
 113 , m_client(client)
89114{
90  m_client = client;
91115}
92116
93 void WebVTTParser::fetchParsedCues(Vector<RefPtr<TextTrackCue> >& outputCues)
 117void WebVTTParser::getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues)
94118{
95119 outputCues = m_cuelist;
96120 m_cuelist.clear();
97560

Source/WebCore/html/track/WebVTTParser.h

3333
3434#if ENABLE(VIDEO_TRACK)
3535
36 #include "CueParserPrivate.h"
3736#include "Document.h"
3837#include "DocumentFragment.h"
3938#include "HTMLNames.h"
 39#include "TextTrackCue.h"
4040#include "WebVTTTokenizer.h"
4141#include <wtf/PassOwnPtr.h>
4242#include <wtf/text/StringBuilder.h>

@@namespace WebCore {
4545
4646using namespace HTMLNames;
4747
48 static const int secondsPerHour = 3600;
49 static const int secondsPerMinute = 60;
50 static const double malformedTime = -1;
 48class WebVTTParserClient {
 49public:
 50 virtual ~WebVTTParserClient() { }
 51
 52 virtual void newCuesParsed() = 0;
 53};
5154
52 class WebVTTParser : public CueParserPrivateInterface {
 55class WebVTTParser {
5356public:
5457 virtual ~WebVTTParser() { }
5558
5659 enum ParseState { Initial, Header, Id, TimingsAndSettings, CueText, BadCue };
5760
58  static PassOwnPtr<WebVTTParser> create(CueParserPrivateClient* client, ScriptExecutionContext* context)
 61 static PassOwnPtr<WebVTTParser> create(WebVTTParserClient* client, ScriptExecutionContext* context)
5962 {
6063 return adoptPtr(new WebVTTParser(client, context));
6164 }
6265
 66 static unsigned fileIdentifierMaximumLength();
6367 static bool hasRequiredFileIdentifier(const char* data, unsigned length);
6468
6569 static inline bool isRecognizedTag(const AtomicString& tagName)

@@public:
7983 static String collectDigits(const String&, unsigned*);
8084 static String collectWord(const String&, unsigned*);
8185
82  virtual void fetchParsedCues(Vector<RefPtr<TextTrackCue> >&);
83 
 86 // Input data to the parser to parse.
8487 virtual void parseBytes(const char* data, unsigned length);
8588
 89 // Transfers ownership of last parsed cues to caller.
 90 virtual void getNewCues(Vector<RefPtr<TextTrackCue> >&);
 91
8692protected:
87  WebVTTParser(CueParserPrivateClient*, ScriptExecutionContext*);
 93 WebVTTParser(WebVTTParserClient*, ScriptExecutionContext*);
8894
8995 ScriptExecutionContext* m_scriptExecutionContext;
9096 ParseState m_state;

@@private:
116122 RefPtr<DocumentFragment> m_attachmentRoot;
117123 RefPtr<ContainerNode> m_currentNode;
118124
119  CueParserPrivateClient* m_client;
 125 WebVTTParserClient* m_client;
120126
121127 Vector<RefPtr<TextTrackCue> > m_cuelist;
122128};
97560

Source/WebCore/loader/CueLoader.cpp

2929
3030#include "CueLoader.h"
3131
 32#include "CachedCues.h"
 33#include "CachedResourceLoader.h"
 34#include "Document.h"
 35#include "Logging.h"
 36#include "ResourceHandle.h"
 37#include "SharedBuffer.h"
 38#include "WebVTTParser.h"
 39
3240namespace WebCore {
 41
 42CueLoader::CueLoader(CueLoaderClient* client, ScriptExecutionContext* context)
 43 : m_client(client)
 44 , m_scriptExecutionContext(context)
 45 , m_cueLoadTimer(this, &CueLoader::cueLoadTimerFired)
 46 , m_state(Idle)
 47 , m_parseOffset(0)
 48 , m_newCuesAvailable(false)
 49{
 50}
 51
 52CueLoader::~CueLoader()
 53{
 54 if (m_cachedCueData)
 55 m_cachedCueData->removeClient(this);
 56}
 57
 58void CueLoader::cueLoadTimerFired(Timer<CueLoader>* timer)
 59{
 60 ASSERT_UNUSED(timer, timer == &m_cueLoadTimer);
 61
 62 if (m_newCuesAvailable) {
 63 m_newCuesAvailable = false;
 64 m_client->newCuesAvailable(this);
 65 }
 66
 67 if (m_state >= Finished)
 68 m_client->cueLoadingCompleted(this, m_state == Failed);
 69}
 70
 71void CueLoader::processNewCueData(CachedResource* resource)
 72{
 73 ASSERT(m_cachedCueData == resource);
 74
 75 if (m_state == Failed || !resource->data())
 76 return;
 77
 78 SharedBuffer* buffer = resource->data();
 79 if (m_parseOffset == buffer->size())
 80 return;
 81
 82 const char* data;
 83 unsigned length;
 84
 85 if (!m_cueParser) {
 86 if (resource->response().mimeType() == "text/vtt")
 87 m_cueParser = WebVTTParser::create(this, m_scriptExecutionContext);
 88 else {
 89 // Don't proceed until we have enough data to check for the WebVTT magic identifier.
 90 unsigned identifierLength = WebVTTParser::fileIdentifierMaximumLength();
 91 if (buffer->size() < identifierLength)
 92 return;
 93
 94 Vector<char> identifier;
 95 unsigned offset = 0;
 96 while (offset < identifierLength && (length = buffer->getSomeData(data, offset))) {
 97 if (length > identifierLength)
 98 length = identifierLength;
 99 identifier.append(data, length);
 100 offset += length;
 101 }
 102
 103 if (!WebVTTParser::hasRequiredFileIdentifier(identifier.data(), identifier.size())) {
 104 LOG(Media, "CueLoader::didReceiveData - file \"%s\" does not have WebVTT magic header",
 105 resource->response().url().string().utf8().data());
 106 m_state = Failed;
 107 m_cueLoadTimer.startOneShot(0);
 108 return;
 109 }
 110
 111 m_cueParser = WebVTTParser::create(this, m_scriptExecutionContext);
 112 }
 113 }
 114
 115 ASSERT(m_cueParser);
 116
 117 while ((length = buffer->getSomeData(data, m_parseOffset))) {
 118 m_cueParser->parseBytes(data, length);
 119 m_parseOffset += length;
 120 }
 121
 122}
 123
 124void CueLoader::didReceiveData(CachedResource* resource)
 125{
 126 ASSERT(m_cachedCueData == resource);
 127
 128 if (!resource->data())
 129 return;
 130
 131 processNewCueData(resource);
 132}
 133
 134void CueLoader::notifyFinished(CachedResource* resource)
 135{
 136 ASSERT(m_cachedCueData == resource);
 137
 138 processNewCueData(resource);
 139
 140 m_state = resource->errorOccurred() ? Failed : Finished;
 141
 142 if (!m_cueLoadTimer.isActive())
 143 m_cueLoadTimer.startOneShot(0);
 144
 145 m_cachedCueData->removeClient(this);
 146 m_cachedCueData = 0;
 147}
 148
 149bool CueLoader::load(const KURL& url)
 150{
 151 if (!m_client->shouldLoadCues(this))
 152 return false;
 153
 154 if (m_cachedCueData) {
 155 m_cachedCueData->removeClient(this);
 156 m_cachedCueData = 0;
 157 }
 158
 159 ASSERT(m_scriptExecutionContext->isDocument());
 160 Document* document = static_cast<Document*>(m_scriptExecutionContext);
 161
 162 ResourceRequest cueRequest(document->completeURL(url));
 163 CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
 164 m_cachedCueData = static_cast<CachedCues*>(cachedResourceLoader->requestCues(cueRequest));
 165 if (m_cachedCueData)
 166 m_cachedCueData->addClient(this);
 167
 168 m_client->cueLoadingStarted(this);
 169
 170 return true;
 171}
 172
 173void CueLoader::newCuesParsed()
 174{
 175 if (m_cueLoadTimer.isActive())
 176 return;
 177
 178 m_newCuesAvailable = true;
 179 m_cueLoadTimer.startOneShot(0);
 180}
33181
34 void CueLoader::setCueLoaderClient(CueLoaderClient* client)
 182void CueLoader::getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues)
35183{
36  m_client = client;
 184 ASSERT(m_cueParser);
 185 if (m_cueParser)
 186 m_cueParser->getNewCues(outputCues);
37187}
38188
39189}
97560

Source/WebCore/loader/CueLoader.h

11/*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
33 *
44 * Redistribution and use in source and binary forms, with or without
55 * modification, are permitted provided that the following conditions

1010 * notice, this list of conditions and the following disclaimer in the
1111 * documentation and/or other materials provided with the distribution.
1212 *
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.
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
2424 */
2525
2626#ifndef CueLoader_h

2828
2929#if ENABLE(VIDEO_TRACK)
3030
31 #include <wtf/Vector.h>
 31#include "CachedCues.h"
 32#include "CachedResourceClient.h"
 33#include "CachedResourceHandle.h"
 34#include "Document.h"
 35#include "Timer.h"
 36#include "WebVTTParser.h"
 37#include <wtf/OwnPtr.h>
3238
3339namespace WebCore {
3440
3541class CueLoader;
36 class TextTrackCue;
37 class TextTrackCueList;
 42class ScriptExecutionContext;
3843
39 // Listener to CueLoader.
4044class CueLoaderClient {
4145public:
4246 virtual ~CueLoaderClient() { }
43 
44  // Queries CueLoader for newest cues.
45  virtual void fetchNewCuesFromLoader(CueLoader*) = 0;
46  virtual void removeCuesFromIndex(const TextTrackCueList*) = 0;
 47
 48 virtual bool shouldLoadCues(CueLoader*) = 0;
 49 virtual void newCuesAvailable(CueLoader*) = 0;
 50 virtual void cueLoadingStarted(CueLoader*) = 0;
 51 virtual void cueLoadingCompleted(CueLoader*, bool loadingFailed) = 0;
4752};
4853
49 class CueLoader {
 54class CueLoader : public CachedResourceClient, private WebVTTParserClient {
 55 WTF_MAKE_NONCOPYABLE(CueLoader);
 56 WTF_MAKE_FAST_ALLOCATED;
5057public:
51  virtual ~CueLoader() { }
52 
53  void setCueLoaderClient(CueLoaderClient*);
54 
55  // Informs client that new cues have been loaded.
56  virtual void newCuesLoaded() = 0;
57 
58  // Transfers ownership of currently loaded cues.
59  virtual void fetchNewestCues(Vector<TextTrackCue*>& cues) = 0;
 58 static PassOwnPtr<CueLoader> create(CueLoaderClient* client, ScriptExecutionContext* context)
 59 {
 60 return adoptPtr(new CueLoader(client, context));
 61 }
 62 virtual ~CueLoader();
 63
 64 bool load(const KURL&);
 65 void getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues);
 66
 67private:
 68
 69 // CachedResourceClient
 70 virtual void notifyFinished(CachedResource*);
 71 virtual void didReceiveData(CachedResource*);
 72
 73 // WebVTTParserClient
 74 virtual void newCuesParsed();
 75
 76 CueLoader(CueLoaderClient*, ScriptExecutionContext*);
 77
 78 void processNewCueData(CachedResource*);
 79 void cueLoadTimerFired(Timer<CueLoader>*);
6080
61 protected:
 81 enum State { Idle, Loading, Finished, Failed };
 82
6283 CueLoaderClient* m_client;
 84 OwnPtr<WebVTTParser> m_cueParser;
 85 CachedResourceHandle<CachedCues> m_cachedCueData;
 86 ScriptExecutionContext* m_scriptExecutionContext;
 87 Timer<CueLoader> m_cueLoadTimer;
 88 State m_state;
 89 unsigned m_parseOffset;
 90 bool m_newCuesAvailable;
6391};
6492
65 }
 93} // namespace WebCore
6694
6795#endif
6896#endif
97572