TextDecoderStream.h (2126B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef DOM_ENCODING_TEXTDECODERSTREAM_H_ 8 #define DOM_ENCODING_TEXTDECODERSTREAM_H_ 9 10 #include "js/TypeDecls.h" 11 #include "mozilla/Attributes.h" 12 #include "mozilla/ErrorResult.h" 13 #include "mozilla/dom/BindingDeclarations.h" 14 #include "mozilla/dom/TextDecoder.h" 15 #include "nsCycleCollectionParticipant.h" 16 #include "nsWrapperCache.h" 17 18 class nsIGlobalObject; 19 20 namespace mozilla { 21 22 class Decoder; 23 class Encoding; 24 25 namespace dom { 26 27 class ReadableStream; 28 class WritableStream; 29 struct TextDecoderOptions; 30 class TransformStream; 31 32 } // namespace dom 33 34 } // namespace mozilla 35 36 namespace mozilla::dom { 37 38 class TextDecoderStream final : public nsISupports, 39 public nsWrapperCache, 40 public TextDecoderCommon { 41 public: 42 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 43 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(TextDecoderStream) 44 45 public: 46 TextDecoderStream(nsISupports* aGlobal, const Encoding& aEncoding, 47 bool aFatal, bool aIgnoreBOM, TransformStream& aStream); 48 49 nsISupports* GetParentObject() const { return mGlobal; } 50 51 JSObject* WrapObject(JSContext* aCx, 52 JS::Handle<JSObject*> aGivenProto) override; 53 54 mozilla::Decoder* Decoder() { return mDecoder.get(); } 55 56 // TODO: Mark as MOZ_CAN_RUN_SCRIPT when IDL constructors can be (bug 1749042) 57 MOZ_CAN_RUN_SCRIPT_BOUNDARY static already_AddRefed<TextDecoderStream> 58 Constructor(const GlobalObject& aGlobal, const nsAString& aLabel, 59 const TextDecoderOptions& aOptions, ErrorResult& aRv); 60 61 ReadableStream* Readable() const; 62 63 WritableStream* Writable() const; 64 65 private: 66 ~TextDecoderStream(); 67 68 nsCOMPtr<nsISupports> mGlobal; 69 RefPtr<TransformStream> mStream; 70 }; 71 72 } // namespace mozilla::dom 73 74 #endif // DOM_ENCODING_TEXTDECODERSTREAM_H_