1 | /* |
2 | * Copyright (C) 2011, 2014 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE 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 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(VIDEO_TRACK) |
29 | |
30 | #include "CachedResourceClient.h" |
31 | #include "CachedResourceHandle.h" |
32 | #include "Timer.h" |
33 | #include "WebVTTParser.h" |
34 | #include <memory> |
35 | |
36 | namespace WebCore { |
37 | |
38 | class CachedTextTrack; |
39 | class Document; |
40 | class HTMLTrackElement; |
41 | class TextTrackLoader; |
42 | class ScriptExecutionContext; |
43 | |
44 | class TextTrackLoaderClient { |
45 | public: |
46 | virtual ~TextTrackLoaderClient() = default; |
47 | |
48 | virtual void newCuesAvailable(TextTrackLoader&) = 0; |
49 | virtual void cueLoadingCompleted(TextTrackLoader&, bool loadingFailed) = 0; |
50 | virtual void newRegionsAvailable(TextTrackLoader&) = 0; |
51 | virtual void newStyleSheetsAvailable(TextTrackLoader&) = 0; |
52 | }; |
53 | |
54 | class TextTrackLoader : public CachedResourceClient, private WebVTTParserClient { |
55 | WTF_MAKE_NONCOPYABLE(TextTrackLoader); |
56 | WTF_MAKE_FAST_ALLOCATED; |
57 | public: |
58 | TextTrackLoader(TextTrackLoaderClient&, ScriptExecutionContext*); |
59 | virtual ~TextTrackLoader(); |
60 | |
61 | bool load(const URL&, HTMLTrackElement&); |
62 | void cancelLoad(); |
63 | void getNewCues(Vector<RefPtr<TextTrackCue>>& outputCues); |
64 | void getNewRegions(Vector<RefPtr<VTTRegion>>& outputRegions); |
65 | Vector<String> getNewStyleSheets(); |
66 | private: |
67 | |
68 | // CachedResourceClient |
69 | void notifyFinished(CachedResource&) override; |
70 | void deprecatedDidReceiveCachedResource(CachedResource&) override; |
71 | |
72 | // WebVTTParserClient |
73 | void newCuesParsed() override; |
74 | void newRegionsParsed() override; |
75 | void newStyleSheetsParsed() final; |
76 | void fileFailedToParse() override; |
77 | |
78 | void processNewCueData(CachedResource&); |
79 | void cueLoadTimerFired(); |
80 | void corsPolicyPreventedLoad(); |
81 | |
82 | enum State { Idle, Loading, Finished, Failed }; |
83 | |
84 | TextTrackLoaderClient& m_client; |
85 | std::unique_ptr<WebVTTParser> m_cueParser; |
86 | CachedResourceHandle<CachedTextTrack> m_resource; |
87 | ScriptExecutionContext* m_scriptExecutionContext; |
88 | Timer m_cueLoadTimer; |
89 | State m_state; |
90 | unsigned m_parseOffset; |
91 | bool m_newCuesAvailable; |
92 | }; |
93 | |
94 | } // namespace WebCore |
95 | |
96 | #endif // ENABLE(VIDEO_TRACK) |
97 | |