Changeset 97773 in webkit
- Timestamp:
- Oct 18, 2011, 10:34:27 AM (14 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 deleted
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r97771 r97773 2051 2051 html/TextTrackCue.cpp 2052 2052 html/TextTrackCueList.cpp 2053 html/track/CueParser.cpp2054 2053 html/track/WebVTTParser.cpp 2055 2054 html/track/WebVTTTokenizer.cpp -
trunk/Source/WebCore/ChangeLog
r97771 r97773 1 2011-10-18 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 Antti Koivisto. 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 1 91 2011-10-18 Adam Barth <abarth@webkit.org> 2 92 -
trunk/Source/WebCore/GNUmakefile.list.am
r97771 r97773 1956 1956 Source/WebCore/html/TimeRanges.cpp \ 1957 1957 Source/WebCore/html/TimeRanges.h \ 1958 Source/WebCore/html/track/CueParser.h \1959 Source/WebCore/html/track/CueParser.cpp \1960 Source/WebCore/html/track/CueParserPrivate.h \1961 1958 Source/WebCore/html/track/WebVTTParser.cpp \ 1962 1959 Source/WebCore/html/track/WebVTTParser.h \ -
trunk/Source/WebCore/WebCore.gypi
r97765 r97773 5742 5742 'html/shadow/TextControlInnerElements.cpp', 5743 5743 'html/shadow/TextControlInnerElements.h', 5744 'html/track/CueParser.cpp',5745 'html/track/CueParser.h',5746 'html/track/CueParserPrivate.h',5747 5744 'html/track/WebVTTParser.cpp', 5748 5745 'html/track/WebVTTParser.h', -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r97764 r97773 4146 4146 B1AD4E7313A12A4600846B27 /* CueLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1AD4E7113A12A4600846B27 /* CueLoader.cpp */; }; 4147 4147 B1AD4E7413A12A4600846B27 /* CueLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E7213A12A4600846B27 /* CueLoader.h */; }; 4148 B1AD4E7B13A12A7200846B27 /* CueParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1AD4E7813A12A7200846B27 /* CueParser.cpp */; };4149 B1AD4E7C13A12A7200846B27 /* CueParser.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E7913A12A7200846B27 /* CueParser.h */; };4150 B1AD4E7D13A12A7200846B27 /* CueParserPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = B1AD4E7A13A12A7200846B27 /* CueParserPrivate.h */; };4151 4148 B1D5ECB5134B58DA0087C78F /* CallbackFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = B1D5ECB4134B58DA0087C78F /* CallbackFunction.h */; }; 4152 4149 B1E5457A1346291F0092A545 /* LocalMediaStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B1E545711346291F0092A545 /* LocalMediaStream.cpp */; }; … … 11240 11237 B1AD4E7113A12A4600846B27 /* CueLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CueLoader.cpp; path = loader/CueLoader.cpp; sourceTree = SOURCE_ROOT; }; 11241 11238 B1AD4E7213A12A4600846B27 /* CueLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CueLoader.h; path = loader/CueLoader.h; sourceTree = SOURCE_ROOT; }; 11242 B1AD4E7813A12A7200846B27 /* CueParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CueParser.cpp; sourceTree = "<group>"; };11243 B1AD4E7913A12A7200846B27 /* CueParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CueParser.h; sourceTree = "<group>"; };11244 B1AD4E7A13A12A7200846B27 /* CueParserPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CueParserPrivate.h; sourceTree = "<group>"; };11245 11239 B1D5ECB4134B58DA0087C78F /* CallbackFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallbackFunction.h; sourceTree = "<group>"; }; 11246 11240 B1E545711346291F0092A545 /* LocalMediaStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LocalMediaStream.cpp; sourceTree = "<group>"; }; … … 18483 18477 isa = PBXGroup; 18484 18478 children = ( 18485 B1AD4E7813A12A7200846B27 /* CueParser.cpp */,18486 B1AD4E7913A12A7200846B27 /* CueParser.h */,18487 B1AD4E7A13A12A7200846B27 /* CueParserPrivate.h */,18488 18479 5D21A80013ECE5DF00BB7064 /* WebVTTParser.cpp */, 18489 18480 5D21A80113ECE5DF00BB7064 /* WebVTTParser.h */, … … 21881 21872 B1AD4E5D13A12A0B00846B27 /* CueIndex.h in Headers */, 21882 21873 B1AD4E7413A12A4600846B27 /* CueLoader.h in Headers */, 21883 B1AD4E7C13A12A7200846B27 /* CueParser.h in Headers */,21884 B1AD4E7D13A12A7200846B27 /* CueParserPrivate.h in Headers */,21885 21874 93F1992F08245E59001E9ABC /* Cursor.h in Headers */, 21886 21875 BC2272A20E82E87C00E7F975 /* CursorData.h in Headers */, … … 25209 25198 B1AD4E5C13A12A0B00846B27 /* CueIndex.cpp in Sources */, 25210 25199 B1AD4E7313A12A4600846B27 /* CueLoader.cpp in Sources */, 25211 B1AD4E7B13A12A7200846B27 /* CueParser.cpp in Sources */,25212 25200 E11AF15111B9A1A300805103 /* Cursor.cpp in Sources */, 25213 25201 93F19A2608245E59001E9ABC /* CursorMac.mm in Sources */, -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r97367 r97773 848 848 if (node->hasTagName(trackTag)) { 849 849 HTMLTrackElement* track = static_cast<HTMLTrackElement*>(node); 850 track->load(ActiveDOMObject::scriptExecutionContext() );850 track->load(ActiveDOMObject::scriptExecutionContext(), this); 851 851 } 852 852 } 853 853 } 854 855 void HTMLMediaElement::textTrackReadyStateChanged(TextTrack*) 856 { 857 // FIXME(62885): Implement. 858 } 859 860 void HTMLMediaElement::textTrackModeChanged(TextTrack*) 861 { 862 // FIXME(62885): Implement. 863 } 864 865 void HTMLMediaElement::textTrackCreated(TextTrack*) 866 { 867 // FIXME(62885): Implement. 868 } 869 870 void HTMLMediaElement::textTrackAddCues(TextTrack*, const TextTrackCueList*) 871 { 872 // FIXME(62885): Implement. 873 } 874 875 void HTMLMediaElement::textTrackRemoveCues(TextTrack*, const TextTrackCueList*) 876 { 877 // FIXME(62885): Implement. 878 } 879 880 void HTMLMediaElement::textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue>) 881 { 882 // FIXME(62885): Implement. 883 } 884 885 void HTMLMediaElement::textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue>) 886 { 887 // FIXME(62885): Implement. 888 } 889 854 890 #endif 855 891 -
trunk/Source/WebCore/html/HTMLMediaElement.h
r97100 r97773 38 38 #endif 39 39 40 #if ENABLE(VIDEO_TRACK) 41 #include "TextTrack.h" 42 #endif 43 40 44 namespace WebCore { 41 45 … … 59 63 // no longer depends on typecasting a MediaPlayerClient to an HTMLMediaElement. 60 64 61 class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, private MediaCanStartListener, private ActiveDOMObject { 65 class HTMLMediaElement : public HTMLElement, public MediaPlayerClient, private MediaCanStartListener, private ActiveDOMObject 66 #if ENABLE(VIDEO_TRACK) 67 , private TextTrackClient 68 #endif 69 { 62 70 public: 63 71 MediaPlayer* player() const { return m_player.get(); } … … 340 348 #if ENABLE(VIDEO_TRACK) 341 349 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>); 342 359 #endif 343 360 -
trunk/Source/WebCore/html/HTMLTrackElement.cpp
r95901 r97773 29 29 #include "HTMLTrackElement.h" 30 30 31 #include "Event.h" 31 32 #include "HTMLMediaElement.h" 32 33 #include "HTMLNames.h" … … 130 131 } 131 132 132 void HTMLTrackElement::load(ScriptExecutionContext* context )133 void HTMLTrackElement::load(ScriptExecutionContext* context, TextTrackClient* trackClient) 133 134 { 134 m_track = LoadableTextTrack::create( kind(), label(), srclang(), isDefault());135 m_track = LoadableTextTrack::create(trackClient, this, kind(), label(), srclang(), isDefault()); 135 136 136 137 if (hasAttribute(srcAttr)) … … 138 139 } 139 140 141 void HTMLTrackElement::textTrackLoadingCompleted(LoadableTextTrack*, bool loadingFailed) 142 { 143 ExceptionCode ec = 0; 144 dispatchEvent(Event::create(loadingFailed ? eventNames().errorEvent : eventNames().loadEvent, false, false), ec); 145 } 146 140 147 } 141 148 -
trunk/Source/WebCore/html/HTMLTrackElement.h
r95901 r97773 34 34 namespace WebCore { 35 35 36 class HTMLTrackElement : public HTMLElement {36 class HTMLTrackElement : public HTMLElement, private TextTrackLoadingClient { 37 37 public: 38 38 static PassRefPtr<HTMLTrackElement> create(const QualifiedName&, Document*); … … 50 50 void setIsDefault(bool); 51 51 52 void load(ScriptExecutionContext* );52 void load(ScriptExecutionContext*, TextTrackClient*); 53 53 54 54 private: 55 56 // TextTrackLoadingClient 57 virtual void textTrackLoadingCompleted(LoadableTextTrack*, bool); 58 55 59 HTMLTrackElement(const QualifiedName&, Document*); 56 60 virtual ~HTMLTrackElement(); -
trunk/Source/WebCore/html/LoadableTextTrack.cpp
r96914 r97773 32 32 namespace WebCore { 33 33 34 LoadableTextTrack::LoadableTextTrack(const String& kind, const String& label, const String& language, bool isDefault) 35 : TextTrack(kind, label, language) 34 LoadableTextTrack::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) 36 37 , m_isDefault(isDefault) 37 38 { … … 42 43 } 43 44 44 void LoadableTextTrack::load(const String& url, ScriptExecutionContext* context)45 void LoadableTextTrack::load(const KURL& url, ScriptExecutionContext* context) 45 46 { 46 return m_parser.load(url, context, this); 47 if (!m_cueLoader) 48 m_cueLoader = CueLoader::create(this, context); 49 m_cueLoader->load(url); 47 50 } 48 51 49 bool LoadableTextTrack::supportsType(const String& url)52 void LoadableTextTrack::newCuesAvailable(CueLoader* loader) 50 53 { 51 return m_parser.supportsType(url); 54 ASSERT_UNUSED(loader, m_cueLoader == loader); 55 56 // FIXME(62885): Implement. 52 57 } 53 58 54 void LoadableTextTrack:: newCuesParsed()59 void LoadableTextTrack::cueLoadingStarted(CueLoader* loader) 55 60 { 56 // FIXME(62883): Fetch new cues from parser and temporarily store to give to CueLoaderClient when fetchNewCuesFromLoader is called. 57 } 58 59 void LoadableTextTrack::trackLoadStarted() 60 { 61 ASSERT_UNUSED(loader, m_cueLoader == loader); 62 61 63 setReadyState(TextTrack::Loading); 62 64 } 63 65 64 void LoadableTextTrack:: trackLoadError()66 void LoadableTextTrack::cueLoadingCompleted(CueLoader* loader, bool) 65 67 { 66 setReadyState(TextTrack::Error); 67 } 68 ASSERT_UNUSED(loader, m_cueLoader == loader); 68 69 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 {81 70 // FIXME(62885): Implement. 82 71 } -
trunk/Source/WebCore/html/LoadableTextTrack.h
r95901 r97773 30 30 31 31 #include "CueLoader.h" 32 #include "CueParser.h"33 32 #include "TextTrack.h" 34 #include "TextTrackCueList.h"35 33 #include <wtf/PassRefPtr.h> 36 34 #include <wtf/Vector.h> … … 38 36 namespace WebCore { 39 37 38 class HTMLTrackElement; 39 class LoadableTextTrack; 40 40 class ScriptExecutionContext; 41 class TextTrack;42 class TextTrackCue;43 41 44 class LoadableTextTrack : public TextTrack, public CueParserClient, public CueLoader{42 class TextTrackLoadingClient { 45 43 public: 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 49 class LoadableTextTrack : public TextTrack, private CueLoaderClient { 50 public: 51 static PassRefPtr<LoadableTextTrack> create(TextTrackClient* trackClient, TextTrackLoadingClient* loadingClient, const String& kind, const String& label, const String& language, bool isDefault) 47 52 { 48 return adoptRef(new LoadableTextTrack( kind, label, language, isDefault));53 return adoptRef(new LoadableTextTrack(trackClient, loadingClient, kind, label, language, isDefault)); 49 54 } 50 55 virtual ~LoadableTextTrack(); 51 56 52 void load(const String&, ScriptExecutionContext*);57 void load(const KURL&, ScriptExecutionContext*); 53 58 bool supportsType(const String&); 54 59 55 virtual void newCuesParsed(); 56 virtual void trackLoadStarted(); 57 virtual void trackLoadError(); 58 virtual void trackLoadCompleted(); 60 private: 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); 59 66 60 virtual void newCuesLoaded(); 61 virtual void fetchNewestCues(Vector<TextTrackCue*>&); 67 LoadableTextTrack(TextTrackClient*, TextTrackLoadingClient*, const String& kind, const String& label, const String& language, bool isDefault); 62 68 63 private: 64 LoadableTextTrack(const String& kind, const String& label, const String& language, bool isDefault); 65 66 CueParser m_parser; 67 69 OwnPtr<CueLoader> m_cueLoader; 70 TextTrackLoadingClient* m_loadingClient; 68 71 bool m_isDefault; 69 72 }; -
trunk/Source/WebCore/html/MutableTextTrack.cpp
r95901 r97773 35 35 namespace WebCore { 36 36 37 MutableTextTrack::MutableTextTrack( const String& kind, const String& label, const String& language)38 : TextTrack( kind, label, language)37 MutableTextTrack::MutableTextTrack(TextTrackClient* trackClient, const String& kind, const String& label, const String& language) 38 : TextTrack(trackClient, kind, label, language, TextTrack::MutableTextTrack) 39 39 { 40 40 } -
trunk/Source/WebCore/html/MutableTextTrack.h
r95901 r97773 38 38 class TextTrackCue; 39 39 40 class MutableTextTrack : public TextTrack , public CueLoader{40 class MutableTextTrack : public TextTrack { 41 41 public: 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()) 43 43 { 44 return adoptRef(new MutableTextTrack( kind, label, language));44 return adoptRef(new MutableTextTrack(trackClient, kind, label, language)); 45 45 } 46 46 virtual ~MutableTextTrack() { } … … 53 53 54 54 private: 55 MutableTextTrack( const String& kind, const String& label, const String& language);55 MutableTextTrack(TextTrackClient*, const String& kind, const String& label, const String& language); 56 56 }; 57 57 -
trunk/Source/WebCore/html/TextTrack.cpp
r97762 r97773 39 39 namespace WebCore { 40 40 41 TextTrack::TextTrack( const String& kind, const String& label, const String& language)41 TextTrack::TextTrack(TextTrackClient* client, const String& kind, const String& label, const String& language, Type trackType) 42 42 : m_kind(kind) 43 43 , m_label(label) … … 45 45 , m_readyState(TextTrack::None) 46 46 , m_mode(TextTrack::Showing) 47 , m_client(client) 48 , m_type(trackType) 47 49 { 48 50 } … … 50 52 TextTrack::~TextTrack() 51 53 { 54 if (m_client) 55 m_client->textTrackRemoveCues(this, m_cues.get()); 56 setClient(0); 52 57 } 53 58 … … 75 80 { 76 81 m_readyState = state; 82 if (m_client) 83 m_client->textTrackReadyStateChanged(this); 77 84 } 78 85 … … 86 93 // 4.8.10.12.5 On setting the mode, if the new value is not either 0, 1, or 2, 87 94 // the user agent must throw an INVALID_ACCESS_ERR exception. 88 if (mode == TextTrack::Disabled || mode == TextTrack::Hidden || mode == TextTrack::Showing) 95 if (mode == TextTrack::Disabled || mode == TextTrack::Hidden || mode == TextTrack::Showing) { 89 96 m_mode = static_cast<Mode>(mode); 90 else 97 if (m_client) 98 m_client->textTrackModeChanged(this); 99 } else 91 100 ec = INVALID_ACCESS_ERR; 92 101 } -
trunk/Source/WebCore/html/TextTrack.h
r97762 r97773 37 37 38 38 class TextTrack; 39 class TextTrackCue; 39 40 class TextTrackCueList; 40 41 … … 42 43 public: 43 44 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; 47 52 }; 48 53 49 54 class TextTrack : public RefCounted<TextTrack> { 50 55 public: 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) 52 57 { 53 return adoptRef(new TextTrack( kind, label, language));58 return adoptRef(new TextTrack(client, kind, label, language, BaseTextTrack)); 54 59 } 55 60 virtual ~TextTrack(); … … 59 64 String language() const; 60 65 61 enum ReadyState { None , Loading, Loaded, Error};66 enum ReadyState { None = 0, Loading = 1, Loaded = 2, Error = 3 }; 62 67 ReadyState readyState() const; 63 68 … … 72 77 void modeChanged(); 73 78 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 74 85 protected: 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); 76 87 77 88 void setReadyState(ReadyState); … … 85 96 TextTrack::ReadyState m_readyState; 86 97 TextTrack::Mode m_mode; 87 98 TextTrackClient* m_client; 99 Type m_type; 88 100 }; 89 101 -
trunk/Source/WebCore/html/track/WebVTTParser.cpp
r96913 r97773 43 43 namespace WebCore { 44 44 45 const int secondsPerHour = 3600; 46 const int secondsPerMinute = 60; 47 const double malformedTime = -1; 48 const unsigned bomLength = 3; 49 const unsigned fileIdentiferLength = 6; 50 51 unsigned WebVTTParser::fileIdentifierMaximumLength() 52 { 53 return bomLength + fileIdentiferLength; 54 } 55 56 inline 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 45 73 bool WebVTTParser::hasRequiredFileIdentifier(const char* data, unsigned length) 46 74 { … … 49 77 // and any number of characters that are not line terminators ... 50 78 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; 53 81 String line = collectNextLine(data, length, &position); 54 55 if (line.length() < 6) 56 return false; 57 if (line.length() == 6 && line != "WEBVTT") 58 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'))) 65 return false; 82 83 if (line.length() < fileIdentiferLength) 84 return false; 85 if (line.length() == fileIdentiferLength && line != "WEBVTT") 86 return false; 87 if (!hasLongWebVTTIdentifier(line)) 88 return false; 89 66 90 return true; 67 91 } … … 83 107 } 84 108 85 WebVTTParser::WebVTTParser( CueParserPrivateClient* client, ScriptExecutionContext* context)109 WebVTTParser::WebVTTParser(WebVTTParserClient* client, ScriptExecutionContext* context) 86 110 : m_scriptExecutionContext(context) 87 111 , m_state(Initial) 88 112 , m_tokenizer(WebVTTTokenizer::create()) 89 { 90 m_client = client; 91 } 92 93 void WebVTTParser:: fetchParsedCues(Vector<RefPtr<TextTrackCue> >& outputCues)113 , m_client(client) 114 { 115 } 116 117 void WebVTTParser::getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues) 94 118 { 95 119 outputCues = m_cuelist; -
trunk/Source/WebCore/html/track/WebVTTParser.h
r95901 r97773 34 34 #if ENABLE(VIDEO_TRACK) 35 35 36 #include "CueParserPrivate.h"37 36 #include "Document.h" 38 37 #include "DocumentFragment.h" 39 38 #include "HTMLNames.h" 39 #include "TextTrackCue.h" 40 40 #include "WebVTTTokenizer.h" 41 41 #include <wtf/PassOwnPtr.h> … … 46 46 using namespace HTMLNames; 47 47 48 static const int secondsPerHour = 3600; 49 static const int secondsPerMinute = 60; 50 static const double malformedTime = -1; 48 class WebVTTParserClient { 49 public: 50 virtual ~WebVTTParserClient() { } 51 52 virtual void newCuesParsed() = 0; 53 }; 51 54 52 class WebVTTParser : public CueParserPrivateInterface{55 class WebVTTParser { 53 56 public: 54 57 virtual ~WebVTTParser() { } … … 56 59 enum ParseState { Initial, Header, Id, TimingsAndSettings, CueText, BadCue }; 57 60 58 static PassOwnPtr<WebVTTParser> create( CueParserPrivateClient* client, ScriptExecutionContext* context)61 static PassOwnPtr<WebVTTParser> create(WebVTTParserClient* client, ScriptExecutionContext* context) 59 62 { 60 63 return adoptPtr(new WebVTTParser(client, context)); 61 64 } 62 65 66 static unsigned fileIdentifierMaximumLength(); 63 67 static bool hasRequiredFileIdentifier(const char* data, unsigned length); 64 68 … … 80 84 static String collectWord(const String&, unsigned*); 81 85 82 virtual void fetchParsedCues(Vector<RefPtr<TextTrackCue> >&); 83 86 // Input data to the parser to parse. 84 87 virtual void parseBytes(const char* data, unsigned length); 85 88 89 // Transfers ownership of last parsed cues to caller. 90 virtual void getNewCues(Vector<RefPtr<TextTrackCue> >&); 91 86 92 protected: 87 WebVTTParser( CueParserPrivateClient*, ScriptExecutionContext*);93 WebVTTParser(WebVTTParserClient*, ScriptExecutionContext*); 88 94 89 95 ScriptExecutionContext* m_scriptExecutionContext; … … 117 123 RefPtr<ContainerNode> m_currentNode; 118 124 119 CueParserPrivateClient* m_client;125 WebVTTParserClient* m_client; 120 126 121 127 Vector<RefPtr<TextTrackCue> > m_cuelist; -
trunk/Source/WebCore/loader/CueLoader.cpp
r95901 r97773 30 30 #include "CueLoader.h" 31 31 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 32 40 namespace WebCore { 41 42 CueLoader::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 } 33 51 34 void CueLoader::setCueLoaderClient(CueLoaderClient* client)52 CueLoader::~CueLoader() 35 53 { 36 m_client = client; 54 if (m_cachedCueData) 55 m_cachedCueData->removeClient(this); 56 } 57 58 void 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 71 void 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 124 void CueLoader::didReceiveData(CachedResource* resource) 125 { 126 ASSERT(m_cachedCueData == resource); 127 128 if (!resource->data()) 129 return; 130 131 processNewCueData(resource); 132 } 133 134 void 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 149 bool 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 173 void CueLoader::newCuesParsed() 174 { 175 if (m_cueLoadTimer.isActive()) 176 return; 177 178 m_newCuesAvailable = true; 179 m_cueLoadTimer.startOneShot(0); 180 } 181 182 void CueLoader::getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues) 183 { 184 ASSERT(m_cueParser); 185 if (m_cueParser) 186 m_cueParser->getNewCues(outputCues); 37 187 } 38 188 -
trunk/Source/WebCore/loader/CueLoader.h
r97572 r97773 1 1 /* 2 * Copyright (C) 2011 Google Inc.All rights reserved.2 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 11 11 * documentation and/or other materials provided with the distribution. 12 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR17 * 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, OR20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE23 * OF THIS SOFTWARE, EVEN IF ADVISED OFTHE 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. 24 24 */ 25 25 … … 29 29 #if ENABLE(VIDEO_TRACK) 30 30 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> 32 38 33 39 namespace WebCore { 34 40 35 41 class CueLoader; 36 class TextTrackCue; 37 class TextTrackCueList; 42 class ScriptExecutionContext; 38 43 39 // Listener to CueLoader.40 44 class CueLoaderClient { 41 45 public: 42 46 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; 47 52 }; 48 53 49 class CueLoader { 54 class CueLoader : public CachedResourceClient, private WebVTTParserClient { 55 WTF_MAKE_NONCOPYABLE(CueLoader); 56 WTF_MAKE_FAST_ALLOCATED; 50 57 public: 51 virtual ~CueLoader() { } 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 67 private: 52 68 53 void setCueLoaderClient(CueLoaderClient*); 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>*); 54 80 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; 60 61 protected: 81 enum State { Idle, Loading, Finished, Failed }; 82 62 83 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; 63 91 }; 64 92 65 } 93 } // namespace WebCore 66 94 67 95 #endif
Note:
See TracChangeset
for help on using the changeset viewer.