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
|
2013-02-14 12:36:50 -08:00
|
|
|
: public nsWrapperCache, public TextDecoderBase
|
2012-09-28 03:19:18 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-02-14 12:36:50 -08:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(TextDecoder)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(TextDecoder)
|
2012-09-28 03:19:18 -07:00
|
|
|
|
|
|
|
// The WebIDL constructor.
|
|
|
|
static already_AddRefed<TextDecoder>
|
2012-12-03 08:07:49 -08:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2012-09-28 03:19:18 -07:00
|
|
|
const nsAString& aEncoding,
|
2012-12-21 16:15:43 -08:00
|
|
|
const TextDecoderOptions& aOptions,
|
2012-09-28 03:19:18 -07:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-08-22 22:17:08 -07:00
|
|
|
nsRefPtr<TextDecoder> txtDecoder = new TextDecoder(aGlobalAsSupports.Get());
|
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()
|
|
|
|
{}
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
|
2012-09-28 03:19:18 -07:00
|
|
|
{
|
2013-03-11 16:03:47 -07:00
|
|
|
return TextDecoderBinding::Wrap(aCx, aScope, this);
|
2012-09-28 03:19:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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_
|