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 file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_textdecoder_h_
7 #define mozilla_dom_textdecoder_h_
9 #include "mozilla/dom/NonRefcountedDOMObject.h"
10 #include "mozilla/dom/TextDecoderBinding.h"
11 #include "mozilla/dom/TypedArray.h"
12 #include "nsIUnicodeDecoder.h"
20 class ArrayBufferViewOrArrayBuffer
;
22 class TextDecoder MOZ_FINAL
23 : public NonRefcountedDOMObject
26 // The WebIDL constructor.
28 Constructor(const GlobalObject
& aGlobal
,
29 const nsAString
& aEncoding
,
30 const TextDecoderOptions
& aOptions
,
33 nsAutoPtr
<TextDecoder
> txtDecoder(new TextDecoder());
34 txtDecoder
->Init(aEncoding
, aOptions
.mFatal
, aRv
);
38 return txtDecoder
.forget();
44 MOZ_COUNT_CTOR(TextDecoder
);
49 MOZ_COUNT_DTOR(TextDecoder
);
52 JSObject
* WrapObject(JSContext
* aCx
, bool* aTookOwnership
)
54 return TextDecoderBinding::Wrap(aCx
, this, aTookOwnership
);
58 * Validates provided label and throws an exception if invalid label.
60 * @param aLabel The encoding label (case insensitive) provided.
61 * @param aFatal indicates whether to throw an 'EncodingError'
62 * exception or not when decoding.
63 * @return aRv EncodingError exception else null.
65 void Init(const nsAString
& aLabel
, const bool aFatal
, ErrorResult
& aRv
);
68 * Performs initialization with a Gecko-canonical encoding name (as opposed
71 * @param aEncoding A Gecko-canonical encoding name
72 * @param aFatal indicates whether to throw an 'EncodingError'
73 * exception or not when decoding.
75 void InitWithEncoding(const nsACString
& aEncoding
, const bool aFatal
);
78 * Return the encoding name.
80 * @param aEncoding, current encoding.
82 void GetEncoding(nsAString
& aEncoding
);
85 * Decodes incoming byte stream of characters in charset indicated by
88 * The encoding algorithm state is reset if aOptions.mStream is not set.
90 * If the fatal flag is set then a decoding error will throw EncodingError.
91 * Else the decoder will return a decoded string with replacement
92 * character(s) for unidentified character(s).
94 * @param aView, incoming byte stream of characters to be decoded to
95 * to UTF-16 code points.
96 * @param aOptions, indicates if streaming or not.
97 * @param aOutDecodedString, decoded string of UTF-16 code points.
98 * @param aRv, error result.
100 void Decode(const char* aInput
, const int32_t aLength
,
101 const bool aStream
, nsAString
& aOutDecodedString
,
104 void Decode(const Optional
<ArrayBufferViewOrArrayBuffer
>& aBuffer
,
105 const TextDecodeOptions
& aOptions
,
106 nsAString
& aOutDecodedString
,
115 nsCOMPtr
<nsIUnicodeDecoder
> mDecoder
;
122 #endif // mozilla_dom_textdecoder_h_