1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_WebVTTLoadListener_h
7 #define mozilla_dom_WebVTTLoadListener_h
9 #include "nsIWebVTTListener.h"
10 #include "nsIStreamListener.h"
11 #include "nsIChannelEventSink.h"
12 #include "nsIInterfaceRequestor.h"
14 #include "nsCycleCollectionParticipant.h"
16 class nsIWebVTTParserWrapper
;
18 namespace mozilla::dom
{
20 class HTMLTrackElement
;
22 class WebVTTListener final
: public nsIWebVTTListener
,
23 public nsIStreamListener
,
24 public nsIChannelEventSink
,
25 public nsIInterfaceRequestor
{
26 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27 NS_DECL_NSIWEBVTTLISTENER
28 NS_DECL_NSIREQUESTOBSERVER
29 NS_DECL_NSISTREAMLISTENER
30 NS_DECL_NSICHANNELEVENTSINK
31 NS_DECL_NSIINTERFACEREQUESTOR
33 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(WebVTTListener
, nsIStreamListener
)
36 explicit WebVTTListener(HTMLTrackElement
* aElement
);
39 * Loads the WebVTTListener. Must call this in order for the listener to be
40 * ready to parse data that is passed to it.
42 nsresult
LoadResource();
45 * When this listener is not going to be used anymore, its owner should take
46 * a responsibility to call `Cancel()` to prevent this listener making any
47 * changes for the track element.
49 bool IsCanceled() const;
55 // List of error codes returned from the WebVTT parser that we care about.
56 enum ErrorCodes
{ BadSignature
= 0 };
57 static nsresult
ParseChunk(nsIInputStream
* aInStream
, void* aClosure
,
58 const char* aFromSegment
, uint32_t aToOffset
,
59 uint32_t aCount
, uint32_t* aWriteCount
);
61 RefPtr
<HTMLTrackElement
> mElement
;
62 nsCOMPtr
<nsIWebVTTParserWrapper
> mParserWrapper
;
63 nsresult mParserWrapperError
;
67 } // namespace mozilla::dom
69 #endif // mozilla_dom_WebVTTListener_h