| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | 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, | 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 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 | 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 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 | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef TextTrackLoader_h | 26 #ifndef TextTrackLoader_h |
| 27 #define TextTrackLoader_h | 27 #define TextTrackLoader_h |
| 28 | 28 |
| 29 #include "core/fetch/ResourceClient.h" | 29 #include "core/fetch/RawResource.h" |
| 30 #include "core/fetch/ResourcePtr.h" | 30 #include "core/fetch/ResourcePtr.h" |
| 31 #include "core/fetch/TextTrackResource.h" | 31 #include "core/fetch/TextTrackResource.h" |
| 32 #include "core/html/track/WebVTTParser.h" | 32 #include "core/html/track/WebVTTParser.h" |
| 33 #include "platform/Timer.h" | 33 #include "platform/Timer.h" |
| 34 #include "wtf/OwnPtr.h" | 34 #include "wtf/OwnPtr.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 class Document; | 38 class Document; |
| 39 class TextTrackLoader; | 39 class TextTrackLoader; |
| 40 | 40 |
| 41 class TextTrackLoaderClient { | 41 class TextTrackLoaderClient { |
| 42 public: | 42 public: |
| 43 virtual ~TextTrackLoaderClient() { } | 43 virtual ~TextTrackLoaderClient() { } |
| 44 | 44 |
| 45 virtual bool shouldLoadCues(TextTrackLoader*) = 0; | 45 virtual bool shouldLoadCues(TextTrackLoader*) = 0; |
| 46 virtual void newCuesAvailable(TextTrackLoader*) = 0; | 46 virtual void newCuesAvailable(TextTrackLoader*) = 0; |
| 47 virtual void cueLoadingStarted(TextTrackLoader*) = 0; | 47 virtual void cueLoadingStarted(TextTrackLoader*) = 0; |
| 48 virtual void cueLoadingCompleted(TextTrackLoader*, bool loadingFailed) = 0; | 48 virtual void cueLoadingCompleted(TextTrackLoader*, bool loadingFailed) = 0; |
| 49 virtual void newRegionsAvailable(TextTrackLoader*) = 0; | 49 virtual void newRegionsAvailable(TextTrackLoader*) = 0; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class TextTrackLoader : public ResourceClient, private WebVTTParserClient { | 52 class TextTrackLoader : public RawResourceClient, private WebVTTParserClient { |
| 53 WTF_MAKE_NONCOPYABLE(TextTrackLoader); | 53 WTF_MAKE_NONCOPYABLE(TextTrackLoader); |
| 54 WTF_MAKE_FAST_ALLOCATED; | 54 WTF_MAKE_FAST_ALLOCATED; |
| 55 public: | 55 public: |
| 56 static PassOwnPtr<TextTrackLoader> create(TextTrackLoaderClient* client, Doc
ument& document) | 56 static PassOwnPtr<TextTrackLoader> create(TextTrackLoaderClient* client, Doc
ument& document) |
| 57 { | 57 { |
| 58 return adoptPtr(new TextTrackLoader(client, document)); | 58 return adoptPtr(new TextTrackLoader(client, document)); |
| 59 } | 59 } |
| 60 virtual ~TextTrackLoader(); | 60 virtual ~TextTrackLoader(); |
| 61 | 61 |
| 62 bool load(const KURL&, const String& crossOriginMode); | 62 bool load(const KURL&, const String& crossOriginMode); |
| 63 void cancelLoad(); | 63 void cancelLoad(); |
| 64 | 64 |
| 65 enum State { Idle, Loading, Finished, Failed }; | 65 enum State { Idle, Loading, Finished, Failed }; |
| 66 State loadState() { return m_state; } | 66 State loadState() { return m_state; } |
| 67 | 67 |
| 68 void getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues); | 68 void getNewCues(Vector<RefPtr<TextTrackCue> >& outputCues); |
| 69 void getNewRegions(Vector<RefPtr<TextTrackRegion> >& outputRegions); | 69 void getNewRegions(Vector<RefPtr<TextTrackRegion> >& outputRegions); |
| 70 private: | 70 private: |
| 71 | 71 |
| 72 // ResourceClient | 72 // RawResourceClient |
| 73 virtual void notifyFinished(Resource*); | 73 virtual void dataReceived(Resource*, const char* data, int length) OVERRIDE; |
| 74 virtual void deprecatedDidReceiveResource(Resource*); | 74 virtual void notifyFinished(Resource*) OVERRIDE; |
| 75 | 75 |
| 76 // WebVTTParserClient | 76 // WebVTTParserClient |
| 77 virtual void newCuesParsed(); | 77 virtual void newCuesParsed() OVERRIDE; |
| 78 virtual void newRegionsParsed(); | 78 virtual void newRegionsParsed() OVERRIDE; |
| 79 virtual void fileFailedToParse(); | 79 virtual void fileFailedToParse() OVERRIDE; |
| 80 | 80 |
| 81 TextTrackLoader(TextTrackLoaderClient*, Document&); | 81 TextTrackLoader(TextTrackLoaderClient*, Document&); |
| 82 | 82 |
| 83 void processNewCueData(Resource*); | 83 void processNewCueData(Resource*); |
| 84 void cueLoadTimerFired(Timer<TextTrackLoader>*); | 84 void cueLoadTimerFired(Timer<TextTrackLoader>*); |
| 85 void corsPolicyPreventedLoad(); | 85 void corsPolicyPreventedLoad(); |
| 86 | 86 |
| 87 TextTrackLoaderClient* m_client; | 87 TextTrackLoaderClient* m_client; |
| 88 OwnPtr<WebVTTParser> m_cueParser; | 88 OwnPtr<WebVTTParser> m_cueParser; |
| 89 ResourcePtr<TextTrackResource> m_cachedCueData; | 89 ResourcePtr<TextTrackResource> m_cachedCueData; |
| 90 // FIXME: Remove this pointer and get the Document from m_client. | 90 // FIXME: Remove this pointer and get the Document from m_client. |
| 91 Document& m_document; | 91 Document& m_document; |
| 92 Timer<TextTrackLoader> m_cueLoadTimer; | 92 Timer<TextTrackLoader> m_cueLoadTimer; |
| 93 String m_crossOriginMode; | 93 String m_crossOriginMode; |
| 94 State m_state; | 94 State m_state; |
| 95 unsigned m_parseOffset; | 95 unsigned m_parseOffset; |
| 96 bool m_newCuesAvailable; | 96 bool m_newCuesAvailable; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 } // namespace WebCore | 99 } // namespace WebCore |
| 100 | 100 |
| 101 #endif | 101 #endif |
| OLD | NEW |