2012-09-28 03:19:18 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_textdecoder_h_
|
|
|
|
#define mozilla_dom_textdecoder_h_
|
|
|
|
|
2012-12-21 16:15:43 -08:00
|
|
|
#include "mozilla/dom/TextDecoderBase.h"
|
2012-09-28 03:19:18 -07:00
|
|
|
#include "mozilla/dom/TextDecoderBinding.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2012-12-21 16:15:43 -08:00
|
|
|
class TextDecoder MOZ_FINAL
|
|
|
|
: public nsISupports, public nsWrapperCache, public TextDecoderBase
|
2012-09-28 03:19:18 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TextDecoder)
|
|
|
|
|
|
|
|
// The WebIDL constructor.
|
|
|
|
static already_AddRefed<TextDecoder>
|
|
|
|
Constructor(nsISupports* aGlobal,
|
|
|
|
const nsAString& aEncoding,
|
2012-12-21 16:15:43 -08:00
|
|
|
const TextDecoderOptions& aOptions,
|
2012-09-28 03:19:18 -07:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsRefPtr<TextDecoder> txtDecoder = new TextDecoder(aGlobal);
|
2012-12-21 16:15:43 -08:00
|
|
|
txtDecoder->Init(aEncoding, aOptions.mFatal, aRv);
|
2012-09-28 03:19:18 -07:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return txtDecoder.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextDecoder(nsISupports* aGlobal)
|
2012-12-21 16:15:43 -08:00
|
|
|
: mGlobal(aGlobal)
|
2012-09-28 03:19:18 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aGlobal);
|
|
|
|
SetIsDOMBinding();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~TextDecoder()
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual JSObject*
|
2012-12-21 16:15:43 -08:00
|
|
|
WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap) MOZ_OVERRIDE
|
2012-09-28 03:19:18 -07:00
|
|
|
{
|
|
|
|
return TextDecoderBinding::Wrap(aCx, aScope, this, aTriedToWrap);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports*
|
|
|
|
GetParentObject()
|
|
|
|
{
|
|
|
|
return mGlobal;
|
|
|
|
}
|
|
|
|
|
2012-12-28 16:55:32 -08:00
|
|
|
void Decode(nsAString& aOutDecodedString,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
TextDecoderBase::Decode(nullptr, 0, false,
|
|
|
|
aOutDecodedString, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Decode(const ArrayBufferView& aView,
|
2012-09-28 03:19:18 -07:00
|
|
|
const TextDecodeOptions& aOptions,
|
|
|
|
nsAString& aOutDecodedString,
|
2012-12-21 16:15:43 -08:00
|
|
|
ErrorResult& aRv) {
|
2012-12-28 16:55:32 -08:00
|
|
|
TextDecoderBase::Decode(reinterpret_cast<char*>(aView.Data()),
|
|
|
|
aView.Length(), aOptions.mStream,
|
|
|
|
aOutDecodedString, aRv);
|
2012-12-21 16:15:43 -08:00
|
|
|
}
|
2012-09-28 03:19:18 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mGlobal;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // dom
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_textdecoder_h_
|