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_textencoder_h_
|
|
|
|
#define mozilla_dom_textencoder_h_
|
|
|
|
|
2012-12-21 16:15:43 -08:00
|
|
|
#include "mozilla/dom/TextEncoderBase.h"
|
2012-09-28 03:19:18 -07:00
|
|
|
#include "mozilla/dom/TextEncoderBinding.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2012-12-21 16:15:43 -08:00
|
|
|
class TextEncoder MOZ_FINAL
|
2013-02-14 12:36:50 -08:00
|
|
|
: public nsWrapperCache, public TextEncoderBase
|
2012-09-28 03:19:18 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-02-14 12:36:50 -08:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(TextEncoder)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(TextEncoder)
|
2012-09-28 03:19:18 -07:00
|
|
|
|
|
|
|
// The WebIDL constructor.
|
|
|
|
static already_AddRefed<TextEncoder>
|
2012-12-03 08:07:49 -08:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2012-10-24 19:03:21 -07:00
|
|
|
const nsAString& aEncoding,
|
2012-09-28 03:19:18 -07:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2012-12-03 08:07:49 -08:00
|
|
|
nsRefPtr<TextEncoder> txtEncoder = new TextEncoder(aGlobal.Get());
|
2012-09-28 03:19:18 -07:00
|
|
|
txtEncoder->Init(aEncoding, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return txtEncoder.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextEncoder(nsISupports* aGlobal)
|
|
|
|
: mGlobal(aGlobal)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aGlobal);
|
|
|
|
SetIsDOMBinding();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~TextEncoder()
|
|
|
|
{}
|
|
|
|
|
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 TextEncoderBinding::Wrap(aCx, aScope, this);
|
2012-09-28 03:19:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports*
|
|
|
|
GetParentObject()
|
|
|
|
{
|
|
|
|
return mGlobal;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* Encode(JSContext* aCx,
|
|
|
|
const nsAString& aString,
|
|
|
|
const TextEncodeOptions& aOptions,
|
2012-12-21 16:15:43 -08:00
|
|
|
ErrorResult& aRv) {
|
|
|
|
return TextEncoderBase::Encode(aCx, aString, aOptions.mStream, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual JSObject*
|
|
|
|
CreateUint8Array(JSContext* aCx, char* aBuf, uint32_t aLen) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return Uint8Array::Create(aCx, this, aLen,
|
|
|
|
reinterpret_cast<uint8_t*>(aBuf));
|
|
|
|
}
|
|
|
|
|
2012-09-28 03:19:18 -07:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mGlobal;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // dom
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_textencoder_h_
|