2011-10-18 Eric Carlson <eric.carlson@apple.com>
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Oct 2011 17:34:27 +0000 (17:34 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Oct 2011 17:34:27 +0000 (17:34 +0000)
        Use the new cached cue loader
        https://bugs.webkit.org/show_bug.cgi?id=70269

        Reviewed by Antti Koivisto.

        No new tests, no functionality changed.

        * CMakeLists.txt: Remove CueParser.cpp/h and CueParserPrivate.h.
        * GNUmakefile.list.am: Ditto.
        * WebCore.gypi: Ditto.
        * WebCore.xcodeproj/project.pbxproj: Ditto.

        * html/HTMLMediaElement.cpp:
        (WebCore::HTMLMediaElement::loadTextTracks):
        (WebCore::HTMLMediaElement::textTrackReadyStateChanged): New, not implemented yet.
        (WebCore::HTMLMediaElement::textTrackModeChanged): Ditto.
        (WebCore::HTMLMediaElement::textTrackCreated): Ditto.
        (WebCore::HTMLMediaElement::textTrackAddCues): Ditto.
        (WebCore::HTMLMediaElement::textTrackRemoveCues): Ditto.
        (WebCore::HTMLMediaElement::textTrackAddCue): Ditto.
        (WebCore::HTMLMediaElement::textTrackRemoveCue): Ditto.
        * html/HTMLMediaElement.h:

        * html/HTMLTrackElement.cpp:
        (WebCore::HTMLTrackElement::load): Update for interface change
        (WebCore::HTMLTrackElement::textTrackLoadingCompleted): New, dispatch 'load' or 'error' event.
        * html/HTMLTrackElement.h:

        * html/LoadableTextTrack.cpp:
        (WebCore::LoadableTextTrack::LoadableTextTrack): Add TextTrackClient and TextTrackLoadingClient
            parameters.
        (WebCore::LoadableTextTrack::load): Make url parameter KURL instead of String. Create the
            cue loader, trigger the load.
        (WebCore::LoadableTextTrack::newCuesAvailable): New callback from the loader. Not implemented yet.
        (WebCore::LoadableTextTrack::cueLoadingStarted): Ditto.
        (WebCore::LoadableTextTrack::cueLoadingCompleted): Ditto.
        * html/LoadableTextTrack.h:

        * html/MutableTextTrack.cpp:
        (WebCore::MutableTextTrack::MutableTextTrack): Add TextTrackClient parameter.
        * html/MutableTextTrack.h:
        (WebCore::MutableTextTrack::create):

        * html/TextTrack.cpp:
        (WebCore::TextTrack::TextTrack): Add TextTrackClient parameter.
        (WebCore::TextTrack::~TextTrack): Tell the client to remove all cues, forget the client.
        (WebCore::TextTrack::setReadyState): Tell client about ready state change.
        (WebCore::TextTrack::setMode): Tell client about mode change.
        * html/TextTrack.h:
        (WebCore::TextTrackClient::textTrackAddCues): New client interface.
        (WebCore::TextTrackClient::textTrackRemoveCues): Ditto.
        (WebCore::TextTrackClient::textTrackAddCue): Ditto.
        (WebCore::TextTrackClient::textTrackRemoveCue): Ditto.
        (WebCore::TextTrack::create):
        (WebCore::TextTrack::trackType): New.
        (WebCore::TextTrack::client): Ditto.
        (WebCore::TextTrack::setClient): Ditto.

        * html/track/CueParser.cpp: Removed.
        * html/track/CueParser.h: Removed.
        * html/track/CueParserPrivate.h: Removed.

        * html/track/WebVTTParser.cpp:
        (WebCore::WebVTTParser::fileIdentifierMaximumLength): New, return length of WebVTT file
            magic number.
        (WebCore::WebVTTParser::hasRequiredFileIdentifier): Update to use constants instead of hard
            coded lengths.
        (WebCore::WebVTTParser::WebVTTParser): Initialize "m_client" in the initilization list
            instead of setting it in the constructor.
        (WebCore::WebVTTParser::getNewCues): Renamed from fetchParsedCues.
        * html/track/WebVTTParser.h:
        (WebCore::WebVTTParser::create): Take a WebVTTParserClient* instead of a CueParserPrivateClient*.

        * loader/CueLoader.cpp:
        (WebCore::CueLoader::CueLoader):
        (WebCore::CueLoader::~CueLoader): Remove client.
        (WebCore::CueLoader::cueLoadTimerFired): Tell client about new clues and/or that the load
            has finished.
        (WebCore::CueLoader::processNewCueData): Process newly loaded data.
        (WebCore::CueLoader::didReceiveData): Ditto.
        (WebCore::CueLoader::notifyFinished): Do final processing as necessary, prime the timer
            to call client.
        (WebCore::CueLoader::load): Create resource loader, initiate loading.
        (WebCore::CueLoader::newCuesParsed): Prime timer to tell client about newly parsed cues.
        (WebCore::CueLoader::getNewCues): Get new cues from parser.
        * loader/CueLoader.h:
        (WebCore::CueLoader::create):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@97773 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLTrackElement.cpp
Source/WebCore/html/HTMLTrackElement.h
Source/WebCore/html/LoadableTextTrack.cpp
Source/WebCore/html/LoadableTextTrack.h
Source/WebCore/html/MutableTextTrack.cpp
Source/WebCore/html/MutableTextTrack.h
Source/WebCore/html/TextTrack.cpp
Source/WebCore/html/TextTrack.h
Source/WebCore/html/track/CueParser.cpp [deleted file]
Source/WebCore/html/track/CueParser.h [deleted file]
Source/WebCore/html/track/CueParserPrivate.h [deleted file]
Source/WebCore/html/track/WebVTTParser.cpp
Source/WebCore/html/track/WebVTTParser.h
Source/WebCore/loader/CueLoader.cpp
Source/WebCore/loader/CueLoader.h

index cab32ca..e496cf8 100644 (file)
@@ -2050,7 +2050,6 @@ IF (ENABLE_VIDEO_TRACK)
         html/TextTrack.cpp
         html/TextTrackCue.cpp
         html/TextTrackCueList.cpp
-        html/track/CueParser.cpp
         html/track/WebVTTParser.cpp
         html/track/WebVTTTokenizer.cpp
         loader/CueLoader.cpp
index 21ac5df..9c40d5e 100644 (file)
@@ -1,3 +1,93 @@
+2011-10-18  Eric Carlson  <eric.carlson@apple.com>
+
+        Use the new cached cue loader
+        https://bugs.webkit.org/show_bug.cgi?id=70269
+
+        Reviewed by Antti Koivisto.
+
+        No new tests, no functionality changed.
+
+        * CMakeLists.txt: Remove CueParser.cpp/h and CueParserPrivate.h.
+        * GNUmakefile.list.am: Ditto.
+        * WebCore.gypi: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::loadTextTracks):
+        (WebCore::HTMLMediaElement::textTrackReadyStateChanged): New, not implemented yet.
+        (WebCore::HTMLMediaElement::textTrackModeChanged): Ditto.
+        (WebCore::HTMLMediaElement::textTrackCreated): Ditto.
+        (WebCore::HTMLMediaElement::textTrackAddCues): Ditto.
+        (WebCore::HTMLMediaElement::textTrackRemoveCues): Ditto.
+        (WebCore::HTMLMediaElement::textTrackAddCue): Ditto.
+        (WebCore::HTMLMediaElement::textTrackRemoveCue): Ditto.
+        * html/HTMLMediaElement.h:
+
+        * html/HTMLTrackElement.cpp:
+        (WebCore::HTMLTrackElement::load): Update for interface change
+        (WebCore::HTMLTrackElement::textTrackLoadingCompleted): New, dispatch 'load' or 'error' event.
+        * html/HTMLTrackElement.h:
+
+        * html/LoadableTextTrack.cpp:
+        (WebCore::LoadableTextTrack::LoadableTextTrack): Add TextTrackClient and TextTrackLoadingClient
+            parameters.
+        (WebCore::LoadableTextTrack::load): Make url parameter KURL instead of String. Create the 
+            cue loader, trigger the load.
+        (WebCore::LoadableTextTrack::newCuesAvailable): New callback from the loader. Not implemented yet.
+        (WebCore::LoadableTextTrack::cueLoadingStarted): Ditto.
+        (WebCore::LoadableTextTrack::cueLoadingCompleted): Ditto.
+        * html/LoadableTextTrack.h:
+
+        * html/MutableTextTrack.cpp:
+        (WebCore::MutableTextTrack::MutableTextTrack): Add TextTrackClient parameter.
+        * html/MutableTextTrack.h:
+        (WebCore::MutableTextTrack::create):
+
+        * html/TextTrack.cpp:
+        (WebCore::TextTrack::TextTrack): Add TextTrackClient parameter.
+        (WebCore::TextTrack::~TextTrack): Tell the client to remove all cues, forget the client.
+        (WebCore::TextTrack::setReadyState): Tell client about ready state change.
+        (WebCore::TextTrack::setMode): Tell client about mode change.
+        * html/TextTrack.h:
+        (WebCore::TextTrackClient::textTrackAddCues): New client interface.
+        (WebCore::TextTrackClient::textTrackRemoveCues): Ditto.
+        (WebCore::TextTrackClient::textTrackAddCue): Ditto.
+        (WebCore::TextTrackClient::textTrackRemoveCue): Ditto.
+        (WebCore::TextTrack::create):
+        (WebCore::TextTrack::trackType): New.
+        (WebCore::TextTrack::client): Ditto.
+        (WebCore::TextTrack::setClient): Ditto.
+
+        * html/track/CueParser.cpp: Removed.
+        * html/track/CueParser.h: Removed.
+        * html/track/CueParserPrivate.h: Removed.
+
+        * html/track/WebVTTParser.cpp:
+        (WebCore::WebVTTParser::fileIdentifierMaximumLength): New, return length of WebVTT file
+            magic number.
+        (WebCore::WebVTTParser::hasRequiredFileIdentifier): Update to use constants instead of hard
+            coded lengths.
+        (WebCore::WebVTTParser::WebVTTParser): Initialize "m_client" in the initilization list
+            instead of setting it in the constructor.
+        (WebCore::WebVTTParser::getNewCues): Renamed from fetchParsedCues.
+        * html/track/WebVTTParser.h:
+        (WebCore::WebVTTParser::create): Take a WebVTTParserClient* instead of a CueParserPrivateClient*.
+
+        * loader/CueLoader.cpp:
+        (WebCore::CueLoader::CueLoader):
+        (WebCore::CueLoader::~CueLoader): Remove client.
+        (WebCore::CueLoader::cueLoadTimerFired): Tell client about new clues and/or that the load
+            has finished.
+        (WebCore::CueLoader::processNewCueData): Process newly loaded data.
+        (WebCore::CueLoader::didReceiveData): Ditto.
+        (WebCore::CueLoader::notifyFinished): Do final processing as necessary, prime the timer
+            to call client.
+        (WebCore::CueLoader::load): Create resource loader, initiate loading.
+        (WebCore::CueLoader::newCuesParsed): Prime timer to tell client about newly parsed cues.
+        (WebCore::CueLoader::getNewCues): Get new cues from parser.
+        * loader/CueLoader.h:
+        (WebCore::CueLoader::create):
+
 2011-10-18  Adam Barth  <abarth@webkit.org>
 
         Always enable ENABLE(XPATH)
index 4fb6e36..cffa083 100644 (file)
@@ -1955,9 +1955,6 @@ webcore_sources += \
        Source/WebCore/html/TimeInputType.h \
        Source/WebCore/html/TimeRanges.cpp \
        Source/WebCore/html/TimeRanges.h \
-       Source/WebCore/html/track/CueParser.h \
-       Source/WebCore/html/track/CueParser.cpp \
-       Source/WebCore/html/track/CueParserPrivate.h \
        Source/WebCore/html/track/WebVTTParser.cpp \
        Source/WebCore/html/track/WebVTTParser.h \
        Source/WebCore/html/track/WebVTTToken.h \
index 0e1debe..5a06899 100644 (file)
             'html/shadow/SliderThumbElement.h',
             'html/shadow/TextControlInnerElements.cpp',
             'html/shadow/TextControlInnerElements.h',
-            'html/track/CueParser.cpp',
-            'html/track/CueParser.h',
-            'html/track/CueParserPrivate.h',
             'html/track/WebVTTParser.cpp',
             'html/track/WebVTTParser.h',
             'html/track/WebVTTToken.h',
index 651f3a6..16a1fbb 100644 (file)
                B1AD4E6B13A12A0B00846B27 /* TextTrackCueList.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E5A13A12A0B00846B27 /* TextTrackCueList.h */; };
                B1AD4E7313A12A4600846B27 /* CueLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1AD4E7113A12A4600846B27 /* CueLoader.cpp */; };
                B1AD4E7413A12A4600846B27 /* CueLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E7213A12A4600846B27 /* CueLoader.h */; };
-               B1AD4E7B13A12A7200846B27 /* CueParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1AD4E7813A12A7200846B27 /* CueParser.cpp */; };
-               B1AD4E7C13A12A7200846B27 /* CueParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E7913A12A7200846B27 /* CueParser.h */; };
-               B1AD4E7D13A12A7200846B27 /* CueParserPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E7A13A12A7200846B27 /* CueParserPrivate.h */; };
                B1D5ECB5134B58DA0087C78F /* CallbackFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = B1D5ECB4134B58DA0087C78F /* CallbackFunction.h */; };
                B1E5457A1346291F0092A545 /* LocalMediaStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1E545711346291F0092A545 /* LocalMediaStream.cpp */; };
                B1E5457B1346291F0092A545 /* LocalMediaStream.h in Headers */ = {isa = PBXBuildFile; fileRef = B1E545721346291F0092A545 /* LocalMediaStream.h */; };
                B1AD4E5A13A12A0B00846B27 /* TextTrackCueList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackCueList.h; sourceTree = "<group>"; };
                B1AD4E7113A12A4600846B27 /* CueLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CueLoader.cpp; path = loader/CueLoader.cpp; sourceTree = SOURCE_ROOT; };
                B1AD4E7213A12A4600846B27 /* CueLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CueLoader.h; path = loader/CueLoader.h; sourceTree = SOURCE_ROOT; };
-               B1AD4E7813A12A7200846B27 /* CueParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CueParser.cpp; sourceTree = "<group>"; };
-               B1AD4E7913A12A7200846B27 /* CueParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CueParser.h; sourceTree = "<group>"; };
-               B1AD4E7A13A12A7200846B27 /* CueParserPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CueParserPrivate.h; sourceTree = "<group>"; };
                B1D5ECB4134B58DA0087C78F /* CallbackFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallbackFunction.h; sourceTree = "<group>"; };
                B1E545711346291F0092A545 /* LocalMediaStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LocalMediaStream.cpp; sourceTree = "<group>"; };
                B1E545721346291F0092A545 /* LocalMediaStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalMediaStream.h; sourceTree = "<group>"; };
                B1AD4E7713A12A7200846B27 /* track */ = {
                        isa = PBXGroup;
                        children = (
-                               B1AD4E7813A12A7200846B27 /* CueParser.cpp */,
-                               B1AD4E7913A12A7200846B27 /* CueParser.h */,
-                               B1AD4E7A13A12A7200846B27 /* CueParserPrivate.h */,
                                5D21A80013ECE5DF00BB7064 /* WebVTTParser.cpp */,
                                5D21A80113ECE5DF00BB7064 /* WebVTTParser.h */,
                                B10B697D140C174000BC1C26 /* WebVTTToken.h */,
                                501BA9E21393CEA000F7ACEB /* CSSWrapShapes.h in Headers */,
                                B1AD4E5D13A12A0B00846B27 /* CueIndex.h in Headers */,
                                B1AD4E7413A12A4600846B27 /* CueLoader.h in Headers */,
-                               B1AD4E7C13A12A7200846B27 /* CueParser.h in Headers */,
-                               B1AD4E7D13A12A7200846B27 /* CueParserPrivate.h in Headers */,
                                93F1992F08245E59001E9ABC /* Cursor.h in Headers */,
                                BC2272A20E82E87C00E7F975 /* CursorData.h in Headers */,
                                BC2272AD0E82E8F300E7F975 /* CursorList.h in Headers */,
                                50E566D6139E38C500214433 /* CSSWrapShapes.cpp in Sources */,
                                B1AD4E5C13A12A0B00846B27 /* CueIndex.cpp in Sources */,
                                B1AD4E7313A12A4600846B27 /* CueLoader.cpp in Sources */,
-                               B1AD4E7B13A12A7200846B27 /* CueParser.cpp in Sources */,
                                E11AF15111B9A1A300805103 /* Cursor.cpp in Sources */,
                                93F19A2608245E59001E9ABC /* CursorMac.mm in Sources */,
                                62CD32591157E57C0063B0A7 /* CustomEvent.cpp in Sources */,
index d23503e..67ac0f5 100644 (file)
@@ -847,10 +847,46 @@ void HTMLMediaElement::loadTextTracks()
     for (Node* node = firstChild(); node; node = node->nextSibling()) {
         if (node->hasTagName(trackTag)) {
             HTMLTrackElement* track = static_cast<HTMLTrackElement*>(node);
-            track->load(ActiveDOMObject::scriptExecutionContext());
+            track->load(ActiveDOMObject::scriptExecutionContext(), this);
         }
     }
 }
+
+void HTMLMediaElement::textTrackReadyStateChanged(TextTrack*)
+{
+    // FIXME(62885): Implement.
+}
+
+void HTMLMediaElement::textTrackModeChanged(TextTrack*)
+{
+    // FIXME(62885): Implement.
+}
+
+void HTMLMediaElement::textTrackCreated(TextTrack*)
+{
+    // FIXME(62885): Implement.
+}
+
+void HTMLMediaElement::textTrackAddCues(TextTrack*, const TextTrackCueList*) 
+{
+    // FIXME(62885): Implement.
+}
+
+void HTMLMediaElement::textTrackRemoveCues(TextTrack*, const TextTrackCueList*) 
+{
+    // FIXME(62885): Implement.
+}
+
+void HTMLMediaElement::textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue>)
+{
+    // FIXME(62885): Implement.
+}
+
+void HTMLMediaElement::textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue>)
+{
+    // FIXME(62885): Implement.
+}
+
 #endif
 
 bool HTMLMediaElement::isSafeToLoadURL(const KURL& url, InvalidSourceAction actionIfInvalid)
index b353248..77488d4 100644 (file)
 #include "MediaPlayerProxy.h"
 #endif
 
+#if ENABLE(VIDEO_TRACK)
+#include "TextTrack.h"
+#endif
+
 namespace WebCore {
 
 #if ENABLE(WEB_AUDIO)
@@ -58,7 +62,11 @@ class Widget;
 // But it can't be until the Chromium WebMediaPlayerClientImpl class is fixed so it
 // no longer depends on typecasting a MediaPlayerClient to an HTMLMediaElement.
 
-class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, private MediaCanStartListener, private ActiveDOMObject {
+class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, private MediaCanStartListener, private ActiveDOMObject
+#if ENABLE(VIDEO_TRACK)
+    , private TextTrackClient
+#endif
+{
 public:
     MediaPlayer* player() const { return m_player.get(); }
     
@@ -339,6 +347,15 @@ private:
 
 #if ENABLE(VIDEO_TRACK)
     void loadTextTracks();
+
+    // TextTrackClient
+    virtual void textTrackReadyStateChanged(TextTrack*);
+    virtual void textTrackModeChanged(TextTrack*);
+    virtual void textTrackCreated(TextTrack*);
+    virtual void textTrackAddCues(TextTrack*, const TextTrackCueList*);
+    virtual void textTrackRemoveCues(TextTrack*, const TextTrackCueList*);
+    virtual void textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue>);
+    virtual void textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue>);
 #endif
 
     // These "internal" functions do not check user gesture restrictions.
index 043f08b..b40bc4f 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(VIDEO_TRACK)
 #include "HTMLTrackElement.h"
 
+#include "Event.h"
 #include "HTMLMediaElement.h"
 #include "HTMLNames.h"
 #include "Logging.h"
@@ -129,14 +130,20 @@ bool HTMLTrackElement::isURLAttribute(Attribute* attribute) const
     return attribute->name() == srcAttr;
 }
 
-void HTMLTrackElement::load(ScriptExecutionContext* context)
+void HTMLTrackElement::load(ScriptExecutionContext* context, TextTrackClient* trackClient)
 {
-    m_track = LoadableTextTrack::create(kind(), label(), srclang(), isDefault());
+    m_track = LoadableTextTrack::create(trackClient, this, kind(), label(), srclang(), isDefault());
 
     if (hasAttribute(srcAttr))
         m_track->load(getNonEmptyURLAttribute(srcAttr), context);
 }
 
+void HTMLTrackElement::textTrackLoadingCompleted(LoadableTextTrack*, bool loadingFailed)
+{
+    ExceptionCode ec = 0;
+    dispatchEvent(Event::create(loadingFailed ? eventNames().errorEvent : eventNames().loadEvent, false, false), ec);
+}
+    
 }
 
 #endif
index 9465642..4a9e472 100644 (file)
@@ -33,7 +33,7 @@
 
 namespace WebCore {
 
-class HTMLTrackElement : public HTMLElement {
+class HTMLTrackElement : public HTMLElement, private TextTrackLoadingClient {
 public:
     static PassRefPtr<HTMLTrackElement> create(const QualifiedName&, Document*);
 
@@ -49,9 +49,13 @@ public:
     void setLabel(const String&);
     void setIsDefault(bool);
     
-    void load(ScriptExecutionContext*);
+    void load(ScriptExecutionContext*, TextTrackClient*);
 
 private:
+
+    // TextTrackLoadingClient
+    virtual void textTrackLoadingCompleted(LoadableTextTrack*, bool);
+
     HTMLTrackElement(const QualifiedName&, Document*);
     virtual ~HTMLTrackElement();
 
index 73676ab..c415c01 100644 (file)
@@ -31,8 +31,9 @@
 
 namespace WebCore {
 
-LoadableTextTrack::LoadableTextTrack(const String& kind, const String& label, const String& language, bool isDefault)
-    : TextTrack(kind, label, language)
+LoadableTextTrack::LoadableTextTrack(TextTrackClient* trackClient, TextTrackLoadingClient* loadingClient, const String& kind, const String& label, const String& language, bool isDefault)
+    : TextTrack(trackClient, kind, label, language, TextTrack::LoadableTextTrack)
+    , m_loadingClient(loadingClient)
     , m_isDefault(isDefault)
 {
 }
@@ -41,43 +42,31 @@ LoadableTextTrack::~LoadableTextTrack()
 {
 }
 
-void LoadableTextTrack::load(const String& url, ScriptExecutionContext* context)
+void LoadableTextTrack::load(const KURL& url, ScriptExecutionContext* context)
 {
-    return m_parser.load(url, context, this);
+    if (!m_cueLoader)
+        m_cueLoader = CueLoader::create(this, context);
+    m_cueLoader->load(url);
 }
 
-bool LoadableTextTrack::supportsType(const String& url)
+void LoadableTextTrack::newCuesAvailable(CueLoader* loader)
 {
-    return m_parser.supportsType(url);
-}
+    ASSERT_UNUSED(loader, m_cueLoader == loader);
 
-void LoadableTextTrack::newCuesParsed()
-{
-    // FIXME(62883): Fetch new cues from parser and temporarily store to give to CueLoaderClient when fetchNewCuesFromLoader is called.
+    // FIXME(62885): Implement.
 }
 
-void LoadableTextTrack::trackLoadStarted()
+void LoadableTextTrack::cueLoadingStarted(CueLoader* loader)
 {
+    ASSERT_UNUSED(loader, m_cueLoader == loader);
+    
     setReadyState(TextTrack::Loading);
 }
 
-void LoadableTextTrack::trackLoadError()
+void LoadableTextTrack::cueLoadingCompleted(CueLoader* loader, bool)
 {
-    setReadyState(TextTrack::Error);
-}
+    ASSERT_UNUSED(loader, m_cueLoader == loader);
 
-void LoadableTextTrack::trackLoadCompleted()
-{
-    setReadyState(TextTrack::Loaded);
-}
-
-void LoadableTextTrack::newCuesLoaded()
-{
-    // FIXME(62885): Tell the client to fetch the latest cues.
-}
-
-void LoadableTextTrack::fetchNewestCues(Vector<TextTrackCue*>&)
-{
     // FIXME(62885): Implement.
 }
 
index c55ed26..3ce79b0 100644 (file)
 #if ENABLE(VIDEO_TRACK)
 
 #include "CueLoader.h"
-#include "CueParser.h"
 #include "TextTrack.h"
-#include "TextTrackCueList.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
+class HTMLTrackElement;
+class LoadableTextTrack;
 class ScriptExecutionContext;
-class TextTrack;
-class TextTrackCue;
 
-class LoadableTextTrack : public TextTrack, public CueParserClient, public CueLoader {
+class TextTrackLoadingClient {
 public:
-    static PassRefPtr<LoadableTextTrack> create(const String& kind, const String& label, const String& language, bool isDefault)
+    virtual ~TextTrackLoadingClient() { }
+    
+    virtual void textTrackLoadingCompleted(LoadableTextTrack*, bool /* loadingFailed */) = 0;
+};
+
+class LoadableTextTrack : public TextTrack, private CueLoaderClient {
+public:
+    static PassRefPtr<LoadableTextTrack> create(TextTrackClient* trackClient, TextTrackLoadingClient* loadingClient, const String& kind, const String& label, const String& language, bool isDefault)
     {
-        return adoptRef(new LoadableTextTrack(kind, label, language, isDefault));
+        return adoptRef(new LoadableTextTrack(trackClient, loadingClient, kind, label, language, isDefault));
     }
     virtual ~LoadableTextTrack();
 
-    void load(const String&, ScriptExecutionContext*);
+    void load(const KURL&, ScriptExecutionContext*);
     bool supportsType(const String&);
 
-    virtual void newCuesParsed();
-    virtual void trackLoadStarted();
-    virtual void trackLoadError();
-    virtual void trackLoadCompleted();
-
-    virtual void newCuesLoaded();
-    virtual void fetchNewestCues(Vector<TextTrackCue*>&);
-
 private:
-    LoadableTextTrack(const String& kind, const String& label, const String& language, bool isDefault);
+    // CueLoaderClient
+    virtual bool shouldLoadCues(CueLoader*) { return true; }
+    virtual void newCuesAvailable(CueLoader*);
+    virtual void cueLoadingStarted(CueLoader*);
+    virtual void cueLoadingCompleted(CueLoader*, bool loadingFailed);
 
-    CueParser m_parser;
+    LoadableTextTrack(TextTrackClient*, TextTrackLoadingClient*, const String& kind, const String& label, const String& language, bool isDefault);
 
+    OwnPtr<CueLoader> m_cueLoader;
+    TextTrackLoadingClient* m_loadingClient;
     bool m_isDefault;
 };
 } // namespace WebCore
index 4d68354..30a2c51 100644 (file)
@@ -34,8 +34,8 @@
 
 namespace WebCore {
 
-MutableTextTrack::MutableTextTrack(const String& kind, const String& label, const String& language)
-    : TextTrack(kind, label, language)
+MutableTextTrack::MutableTextTrack(TextTrackClient* trackClient, const String& kind, const String& label, const String& language)
+    : TextTrack(trackClient, kind, label, language, TextTrack::MutableTextTrack)
 {
 }
 
index 618c272..b05c289 100644 (file)
@@ -37,11 +37,11 @@ namespace WebCore {
 
 class TextTrackCue;
 
-class MutableTextTrack : public TextTrack, public CueLoader {
+class MutableTextTrack : public TextTrack {
 public:
-    static PassRefPtr<MutableTextTrack> create(const String& kind, const String& label, const String& language)
+    static PassRefPtr<MutableTextTrack> create(TextTrackClient* trackClient, const String& kind, const String& label = emptyString(), const String& language = emptyString())
     {
-        return adoptRef(new MutableTextTrack(kind, label, language));
+        return adoptRef(new MutableTextTrack(trackClient, kind, label, language));
     }
     virtual ~MutableTextTrack() { }
 
@@ -52,7 +52,7 @@ public:
     virtual void fetchNewestCues(Vector<TextTrackCue*>&);
 
 private:
-    MutableTextTrack(const String& kind, const String& label, const String& language);
+    MutableTextTrack(TextTrackClient*, const String& kind, const String& label, const String& language);
 };
 
 } // namespace WebCore
index 301ae71..6c8ccb4 100644 (file)
 
 namespace WebCore {
 
-TextTrack::TextTrack(const String& kind, const String& label, const String& language)
+TextTrack::TextTrack(TextTrackClient* client, const String& kind, const String& label, const String& language, Type trackType)
     : m_kind(kind)
     , m_label(label)
     , m_language(language)
     , m_readyState(TextTrack::None)
     , m_mode(TextTrack::Showing)
+    , m_client(client)
+    , m_type(trackType)
 {
 }
 
 TextTrack::~TextTrack()
 {
+    if (m_client)
+        m_client->textTrackRemoveCues(this, m_cues.get());
+    setClient(0);
 }
 
 String TextTrack::kind() const
@@ -74,6 +79,8 @@ TextTrack::ReadyState TextTrack::readyState() const
 void TextTrack::setReadyState(ReadyState state)
 {
     m_readyState = state;
+    if (m_client)
+        m_client->textTrackReadyStateChanged(this);
 }
 
 TextTrack::Mode TextTrack::mode() const
@@ -85,9 +92,11 @@ void TextTrack::setMode(unsigned short mode, ExceptionCode& ec)
 {
     // 4.8.10.12.5 On setting the mode, if the new value is not either 0, 1, or 2,
     // the user agent must throw an INVALID_ACCESS_ERR exception.
-    if (mode == TextTrack::Disabled || mode == TextTrack::Hidden || mode == TextTrack::Showing)
+    if (mode == TextTrack::Disabled || mode == TextTrack::Hidden || mode == TextTrack::Showing) {
         m_mode = static_cast<Mode>(mode);
-    else
+        if (m_client)
+            m_client->textTrackModeChanged(this);
+    } else
         ec = INVALID_ACCESS_ERR;
 }
 
index 0e6c026..707ce6c 100644 (file)
 namespace WebCore {
 
 class TextTrack;
+class TextTrackCue;
 class TextTrackCueList;
 
 class TextTrackClient {
 public:
     virtual ~TextTrackClient() { }
-    virtual void textTrackReadyStateChanged(TextTrack*) { }
-    virtual void textTrackModeChanged(TextTrack*) { }
-    virtual void textTrackCreated(TextTrack*) { }
+    virtual void textTrackReadyStateChanged(TextTrack*) = 0;
+    virtual void textTrackModeChanged(TextTrack*) = 0;
+    virtual void textTrackCreated(TextTrack*) = 0;
+    virtual void textTrackAddCues(TextTrack*, const TextTrackCueList*) = 0;
+    virtual void textTrackRemoveCues(TextTrack*, const TextTrackCueList*) = 0;
+    virtual void textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue>) = 0;
+    virtual void textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue>) = 0;
 };
 
 class TextTrack : public RefCounted<TextTrack> {
 public:
-    static PassRefPtr<TextTrack> create(const String& kind, const String& label, const String& language)
+    static PassRefPtr<TextTrack> create(TextTrackClient* client, const String& kind, const String& label, const String& language)
     {
-        return adoptRef(new TextTrack(kind, label, language));
+        return adoptRef(new TextTrack(client, kind, label, language, BaseTextTrack));
     }
     virtual ~TextTrack();
 
@@ -58,7 +63,7 @@ public:
     String label() const;
     String language() const;
 
-    enum ReadyState { None, Loading, Loaded, Error };
+    enum ReadyState { None = 0, Loading = 1, Loaded = 2, Error = 3 };
     ReadyState readyState() const;
 
     enum Mode { Disabled = 0, Hidden = 1, Showing = 2 };
@@ -71,8 +76,14 @@ public:
     void readyStateChanged();
     void modeChanged();
 
+    enum Type { BaseTextTrack, MutableTextTrack, LoadableTextTrack };
+    Type trackType() { return m_type; }
+
+    TextTrackClient* client() { return m_client; }
+    void setClient(TextTrackClient* client) { m_client = client; }
+
 protected:
-    TextTrack(const String& kind, const String& label, const String& language);
+    TextTrack(TextTrackClient*, const String& kind, const String& label, const String& language, Type trackType);
 
     void setReadyState(ReadyState);
 
@@ -84,7 +95,8 @@ private:
     String m_language;
     TextTrack::ReadyState m_readyState;
     TextTrack::Mode m_mode;
-
+    TextTrackClient* m_client;
+    Type m_type; 
 };
 
 } // namespace WebCore
diff --git a/Source/WebCore/html/track/CueParser.cpp b/Source/WebCore/html/track/CueParser.cpp
deleted file mode 100644 (file)
index ec1ae85..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#if ENABLE(VIDEO_TRACK)
-
-#include "CueParser.h"
-
-#include "ResourceRequest.h"
-#include "ResourceResponse.h"
-#include "ThreadableLoader.h"
-
-namespace WebCore {
-
-CueParser::CueParser()
-{
-    // FIXME(62893): Implement.
-}
-
-CueParser::~CueParser()
-{
-    if (m_loader)
-        m_loader->cancel();
-    m_loader = 0;
-}
-
-void CueParser::load(const String& url, ScriptExecutionContext* context, CueParserClient* client)
-{
-    ResourceRequest request(url);
-
-    ThreadableLoaderOptions options;
-    options.sendLoadCallbacks = SendCallbacks;
-    options.crossOriginRequestPolicy = AllowCrossOriginRequests;
-
-    m_client = client;
-    m_scriptExecutionContext = context;
-
-    m_loader = ThreadableLoader::create(context, this, request, options);
-}
-
-bool CueParser::supportsType(const String&)
-{
-    // FIXME(62893): check against a list of supported types
-    return false;
-}
-
-void CueParser::didReceiveResponse(unsigned long /*identifier*/, const ResourceResponse& response)
-{
-    if (response.mimeType() == "text/vtt")
-        createWebVTTParser();
-}
-
-void CueParser::didReceiveData(const char* data, int length)
-{
-    // If mime type from didReceiveResponse was not informative, sniff file content.
-    if (!m_private && WebVTTParser::hasRequiredFileIdentifier(data, length))
-        createWebVTTParser();
-
-    if (m_private)
-        m_private->parseBytes(data, length);
-}
-
-void CueParser::didFinishLoading(unsigned long, double)
-{
-    m_client->trackLoadCompleted();
-}
-
-void CueParser::didFail(const ResourceError&)
-{
-    m_client->trackLoadError();
-}
-
-void CueParser::fetchParsedCues(Vector<RefPtr<TextTrackCue> >&)
-{
-    // FIXME(62893): Implement.
-}
-
-void CueParser::newCuesParsed()
-{
-    m_client->newCuesParsed();
-}
-
-void CueParser::createWebVTTParser()
-{
-    if (!m_private) {
-        m_private = WebVTTParser::create(this, m_scriptExecutionContext);
-        m_client->trackLoadStarted();
-    }
-}
-
-} // namespace WebCore
-
-#endif
diff --git a/Source/WebCore/html/track/CueParser.h b/Source/WebCore/html/track/CueParser.h
deleted file mode 100644 (file)
index d6f43a8..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef CueParser_h
-#define CueParser_h
-
-#if ENABLE(VIDEO_TRACK)
-
-#include "ThreadableLoader.h"
-#include "ThreadableLoaderClient.h"
-#include "WebVTTParser.h"
-#include <wtf/RefCounted.h>
-#include <wtf/Vector.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-
-class ScriptExecutionContext;
-class TextTrackCue;
-
-class CueParserClient {
-public:
-    virtual ~CueParserClient() { }
-
-    virtual void newCuesParsed() = 0;
-    virtual void trackLoadStarted() = 0;
-    virtual void trackLoadError() = 0;
-    virtual void trackLoadCompleted() = 0;
-};
-
-class CueParser : public ThreadableLoaderClient, CueParserPrivateClient {
-public:
-    CueParser();
-    virtual ~CueParser();
-
-    virtual void didReceiveResponse(unsigned long, const ResourceResponse&);
-    virtual void didReceiveData(const char*, int);
-    virtual void didFinishLoading(unsigned long /*identifier*/, double /*finishTime*/);
-    virtual void didFail(const ResourceError&);
-
-    void load(const String&, ScriptExecutionContext*, CueParserClient*);
-    bool supportsType(const String&);
-
-    void fetchParsedCues(Vector<RefPtr<TextTrackCue> >&);
-    void newCuesParsed();
-
-protected:
-    ScriptExecutionContext* m_scriptExecutionContext;
-
-private:
-    void createWebVTTParser();
-    RefPtr<ThreadableLoader> m_loader;
-    OwnPtr<CueParserPrivateInterface> m_private;
-    CueParserClient* m_client;
-};
-
-} // namespace WebCore
-
-#endif
-#endif
diff --git a/Source/WebCore/html/track/CueParserPrivate.h b/Source/WebCore/html/track/CueParserPrivate.h
deleted file mode 100644 (file)
index ba13266..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef CueParserPrivate_h
-#define CueParsePrivate_h
-
-#if ENABLE(VIDEO_TRACK)
-
-#include "TextTrackCue.h"
-#include <wtf/Forward.h>
-#include <wtf/Noncopyable.h>
-#include <wtf/Vector.h>
-
-namespace WebCore {
-
-class CueParserPrivateClient {
-public:
-    virtual ~CueParserPrivateClient() { }
-
-    virtual void newCuesParsed() = 0;
-};
-
-class CueParserPrivateInterface {
-    WTF_MAKE_NONCOPYABLE(CueParserPrivateInterface); WTF_MAKE_FAST_ALLOCATED;
-public:
-    virtual ~CueParserPrivateInterface() { }
-
-    // Input data to the parser to parse.
-    virtual void parseBytes(const char*, unsigned) = 0;
-
-    // Transfers ownership of last parsed cues to caller.
-    virtual void fetchParsedCues(Vector<RefPtr<TextTrackCue> >&) = 0;
-
-protected:
-    CueParserPrivateInterface() { }
-};
-
-} // namespace WebCore
-
-#endif
-#endif
index 1b258df..d82c664 100644 (file)
 
 namespace WebCore {
 
+const int secondsPerHour = 3600;
+const int secondsPerMinute = 60;
+const double malformedTime = -1;
+const unsigned bomLength = 3;
+const unsigned fileIdentiferLength = 6;
+    
+unsigned WebVTTParser::fileIdentifierMaximumLength()
+{
+    return bomLength + fileIdentiferLength;
+}
+
+inline bool hasLongWebVTTIdentifier(String line)
+{
+    // If line is more than six characters ...
+    if (line.length() < fileIdentiferLength)
+        return false;
+
+    // but the first six characters do not exactly equal "WEBVTT" ...
+    if (line.substring(0, fileIdentiferLength) != "WEBVTT")
+        return false;
+
+    // or the seventh character is neither a space nor a tab character, then abort.
+    if (line[fileIdentiferLength] != ' ' && line[fileIdentiferLength] != '\t')
+        return false;
+
+    return true;
+}
+
 bool WebVTTParser::hasRequiredFileIdentifier(const char* data, unsigned length)
 {
     // A WebVTT file identifier consists of an optional BOM character,
     // the string "WEBVTT" followed by an optional space or tab character,
     // and any number of characters that are not line terminators ...
     unsigned position = 0;
-    if (length >= 3 && data[0] == '\xEF' && data[1] == '\xBB' && data[2] == '\xBF')
-        position += 3;
+    if (length >= bomLength && data[0] == '\xEF' && data[1] == '\xBB' && data[2] == '\xBF')
+        position += bomLength;
     String line = collectNextLine(data, length, &position);
-        
-    if (line.length() < 6)
+
+    if (line.length() < fileIdentiferLength)
         return false;
-    if (line.length() == 6 && line != "WEBVTT")
+    if (line.length() == fileIdentiferLength && line != "WEBVTT")
         return false;
-
-    // If line is more than six characters
-    // but the first six characters do not exactly equal "WEBVTT",
-    // or the seventh character is neither a space nor a tab character, then abort.
-    if (line.length() > 6 && (line.substring(0, 6) != "WEBVTT"
-                              || (line[6] != ' ' && line[6] != '\t')))
+    if (!hasLongWebVTTIdentifier(line))
         return false;
+
     return true;
 }
 
@@ -82,15 +106,15 @@ String WebVTTParser::collectWord(const String& input, unsigned* position)
     return string.toString();
 }
 
-WebVTTParser::WebVTTParser(CueParserPrivateClient* client, ScriptExecutionContext* context)
+WebVTTParser::WebVTTParser(WebVTTParserClient* client, ScriptExecutionContext* context)
     : m_scriptExecutionContext(context)
     , m_state(Initial)
     , m_tokenizer(WebVTTTokenizer::create())
+    , m_client(client)
 {
-    m_client = client;
 }
 
-void WebVTTParser::fetchParsedCues(Vector<RefPtr<TextTrackCue> >& outputCues)
+void WebVTTParser::getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues)
 {
     outputCues = m_cuelist;
     m_cuelist.clear();
index 02bd8b7..244ee8f 100644 (file)
 
 #if ENABLE(VIDEO_TRACK)
 
-#include "CueParserPrivate.h"
 #include "Document.h"
 #include "DocumentFragment.h"
 #include "HTMLNames.h"
+#include "TextTrackCue.h"
 #include "WebVTTTokenizer.h"
 #include <wtf/PassOwnPtr.h>
 #include <wtf/text/StringBuilder.h>
@@ -45,21 +45,25 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-static const int secondsPerHour = 3600;
-static const int secondsPerMinute = 60;
-static const double malformedTime = -1;
+class WebVTTParserClient {
+public:
+    virtual ~WebVTTParserClient() { }
+    
+    virtual void newCuesParsed() = 0;
+};
 
-class WebVTTParser : public CueParserPrivateInterface {
+class WebVTTParser {
 public:
     virtual ~WebVTTParser() { }
     
     enum ParseState { Initial, Header, Id, TimingsAndSettings, CueText, BadCue };
 
-    static PassOwnPtr<WebVTTParser> create(CueParserPrivateClient* client, ScriptExecutionContext* context)
+    static PassOwnPtr<WebVTTParser> create(WebVTTParserClient* client, ScriptExecutionContext* context)
     {
         return adoptPtr(new WebVTTParser(client, context));
     }
     
+    static unsigned fileIdentifierMaximumLength();
     static bool hasRequiredFileIdentifier(const char* data, unsigned length);
 
     static inline bool isRecognizedTag(const AtomicString& tagName)
@@ -79,12 +83,14 @@ public:
     static String collectDigits(const String&, unsigned*);
     static String collectWord(const String&, unsigned*);
 
-    virtual void fetchParsedCues(Vector<RefPtr<TextTrackCue> >&);
-    
+    // Input data to the parser to parse.
     virtual void parseBytes(const char* data, unsigned length);
 
+    // Transfers ownership of last parsed cues to caller.
+    virtual void getNewCues(Vector<RefPtr<TextTrackCue> >&);
+
 protected:
-    WebVTTParser(CueParserPrivateClient*, ScriptExecutionContext*);
+    WebVTTParser(WebVTTParserClient*, ScriptExecutionContext*);
     
     ScriptExecutionContext* m_scriptExecutionContext;
     ParseState m_state;
@@ -116,7 +122,7 @@ private:
     RefPtr<DocumentFragment> m_attachmentRoot;
     RefPtr<ContainerNode> m_currentNode;
 
-    CueParserPrivateClient* m_client;
+    WebVTTParserClient* m_client;
 
     Vector<RefPtr<TextTrackCue> > m_cuelist;
 };
index 7eff076..5ac60de 100644 (file)
 
 #include "CueLoader.h"
 
+#include "CachedCues.h"
+#include "CachedResourceLoader.h"
+#include "Document.h"
+#include "Logging.h"
+#include "ResourceHandle.h"
+#include "SharedBuffer.h"
+#include "WebVTTParser.h"
+
 namespace WebCore {
+    
+CueLoader::CueLoader(CueLoaderClient* client, ScriptExecutionContext* context)
+    : m_client(client)
+    , m_scriptExecutionContext(context)
+    , m_cueLoadTimer(this, &CueLoader::cueLoadTimerFired)
+    , m_state(Idle)
+    , m_parseOffset(0)
+    , m_newCuesAvailable(false)
+{
+}
+
+CueLoader::~CueLoader()
+{
+    if (m_cachedCueData)
+        m_cachedCueData->removeClient(this);
+}
+
+void CueLoader::cueLoadTimerFired(Timer<CueLoader>* timer)
+{
+    ASSERT_UNUSED(timer, timer == &m_cueLoadTimer);
+    
+    if (m_newCuesAvailable) {
+        m_newCuesAvailable = false;
+        m_client->newCuesAvailable(this); 
+    }
+    
+    if (m_state >= Finished)
+        m_client->cueLoadingCompleted(this, m_state == Failed);
+}
+
+void CueLoader::processNewCueData(CachedResource* resource)
+{
+    ASSERT(m_cachedCueData == resource);
+    
+    if (m_state == Failed || !resource->data())
+        return;
+    
+    SharedBuffer* buffer = resource->data();
+    if (m_parseOffset == buffer->size())
+        return;
+
+    const char* data;
+    unsigned length;
+    
+    if (!m_cueParser) {
+        if (resource->response().mimeType() == "text/vtt")
+            m_cueParser = WebVTTParser::create(this, m_scriptExecutionContext);
+        else {
+            // Don't proceed until we have enough data to check for the WebVTT magic identifier.
+            unsigned identifierLength = WebVTTParser::fileIdentifierMaximumLength();
+            if (buffer->size() < identifierLength)
+                return;
+            
+            Vector<char> identifier;
+            unsigned offset = 0;
+            while (offset < identifierLength && (length = buffer->getSomeData(data, offset))) {
+                if (length > identifierLength)
+                    length = identifierLength;
+                identifier.append(data, length);
+                offset += length;
+            }
+            
+            if (!WebVTTParser::hasRequiredFileIdentifier(identifier.data(), identifier.size())) {
+                LOG(Media, "CueLoader::didReceiveData - file \"%s\" does not have WebVTT magic header", 
+                    resource->response().url().string().utf8().data());
+                m_state = Failed;
+                m_cueLoadTimer.startOneShot(0);
+                return;
+            }
+            
+            m_cueParser = WebVTTParser::create(this, m_scriptExecutionContext);
+        }
+    }
+    
+    ASSERT(m_cueParser);
+    
+    while ((length = buffer->getSomeData(data, m_parseOffset))) {
+        m_cueParser->parseBytes(data, length);
+        m_parseOffset += length;
+    }
+    
+}
+
+void CueLoader::didReceiveData(CachedResource* resource)
+{
+    ASSERT(m_cachedCueData == resource);
+    
+    if (!resource->data())
+        return;
+    
+    processNewCueData(resource);
+}
+
+void CueLoader::notifyFinished(CachedResource* resource)
+{
+    ASSERT(m_cachedCueData == resource);
+
+    processNewCueData(resource);
+
+    m_state = resource->errorOccurred() ? Failed : Finished;
+
+    if (!m_cueLoadTimer.isActive())
+        m_cueLoadTimer.startOneShot(0);
+    
+    m_cachedCueData->removeClient(this);
+    m_cachedCueData = 0;
+}
+
+bool CueLoader::load(const KURL& url)
+{
+    if (!m_client->shouldLoadCues(this))
+        return false;
+    
+    if (m_cachedCueData) {
+        m_cachedCueData->removeClient(this);
+        m_cachedCueData = 0;
+    }
+    
+    ASSERT(m_scriptExecutionContext->isDocument());
+    Document* document = static_cast<Document*>(m_scriptExecutionContext);
+    
+    ResourceRequest cueRequest(document->completeURL(url));
+    CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
+    m_cachedCueData = static_cast<CachedCues*>(cachedResourceLoader->requestCues(cueRequest));
+    if (m_cachedCueData)
+        m_cachedCueData->addClient(this);
+    
+    m_client->cueLoadingStarted(this);
+    
+    return true;
+}
+
+void CueLoader::newCuesParsed()
+{
+    if (m_cueLoadTimer.isActive())
+        return;
+
+    m_newCuesAvailable = true;
+    m_cueLoadTimer.startOneShot(0);
+}
 
-void CueLoader::setCueLoaderClient(CueLoaderClient* client)
+void CueLoader::getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues)
 {
-    m_client = client;
+    ASSERT(m_cueParser);
+    if (m_cueParser)
+        m_cueParser->getNewCues(outputCues);
 }
 
 }
index 7b5b248..8bf6a05 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc.  All rights reserved.
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef CueLoader_h
 
 #if ENABLE(VIDEO_TRACK)
 
-#include <wtf/Vector.h>
+#include "CachedCues.h"
+#include "CachedResourceClient.h"
+#include "CachedResourceHandle.h"
+#include "Document.h"
+#include "Timer.h"
+#include "WebVTTParser.h"
+#include <wtf/OwnPtr.h>
 
 namespace WebCore {
 
 class CueLoader;
-class TextTrackCue;
-class TextTrackCueList;
+class ScriptExecutionContext;
 
-// Listener to CueLoader.
 class CueLoaderClient {
 public:
     virtual ~CueLoaderClient() { }
-
-    // Queries CueLoader for newest cues.
-    virtual void fetchNewCuesFromLoader(CueLoader*) = 0;
-    virtual void removeCuesFromIndex(const TextTrackCueList*) = 0;
+    
+    virtual bool shouldLoadCues(CueLoader*) = 0;
+    virtual void newCuesAvailable(CueLoader*) = 0;
+    virtual void cueLoadingStarted(CueLoader*) = 0;
+    virtual void cueLoadingCompleted(CueLoader*, bool loadingFailed) = 0;
 };
 
-class CueLoader {
+class CueLoader : public CachedResourceClient, private WebVTTParserClient {
+    WTF_MAKE_NONCOPYABLE(CueLoader); 
+    WTF_MAKE_FAST_ALLOCATED;
 public:
-    virtual ~CueLoader() { }
-
-    void setCueLoaderClient(CueLoaderClient*);
-
-    // Informs client that new cues have been loaded.
-    virtual void newCuesLoaded() = 0;
+    static PassOwnPtr<CueLoader> create(CueLoaderClient* client, ScriptExecutionContext* context)
+    {
+        return adoptPtr(new CueLoader(client, context));
+    }
+    virtual ~CueLoader();
+    
+    bool load(const KURL&);
+    void getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues);
+    
+private:
 
-    // Transfers ownership of currently loaded cues.
-    virtual void fetchNewestCues(Vector<TextTrackCue*>& cues) = 0;
+    // CachedResourceClient
+    virtual void notifyFinished(CachedResource*);
+    virtual void didReceiveData(CachedResource*);
+    
+    // WebVTTParserClient
+    virtual void newCuesParsed();
+    
+    CueLoader(CueLoaderClient*, ScriptExecutionContext*);
+    
+    void processNewCueData(CachedResource*);
+    void cueLoadTimerFired(Timer<CueLoader>*);
 
-protected:
+    enum State { Idle, Loading, Finished, Failed };
+    
     CueLoaderClient* m_client;
+    OwnPtr<WebVTTParser> m_cueParser;
+    CachedResourceHandle<CachedCues> m_cachedCueData;
+    ScriptExecutionContext* m_scriptExecutionContext;
+    Timer<CueLoader> m_cueLoadTimer;
+    State m_state;
+    unsigned m_parseOffset;
+    bool m_newCuesAvailable;
 };
 
-}
+} // namespace WebCore
 
 #endif
 #endif