2012-09-28 14:19:18 +04: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-22 04:15:43 +04:00
|
|
|
#include "mozilla/dom/TextEncoderBase.h"
|
2012-09-28 14:19:18 +04:00
|
|
|
#include "mozilla/dom/TextEncoderBinding.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2012-12-22 04:15:43 +04:00
|
|
|
class TextEncoder MOZ_FINAL
|
2013-02-15 00:36:50 +04:00
|
|
|
: public nsWrapperCache, public TextEncoderBase
|
2012-09-28 14:19:18 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-02-15 00:36:50 +04:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(TextEncoder)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(TextEncoder)
|
2012-09-28 14:19:18 +04:00
|
|
|
|
|
|
|
// The WebIDL constructor.
|
|
|
|
static already_AddRefed<TextEncoder>
|
2012-12-03 20:07:49 +04:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2012-10-25 06:03:21 +04:00
|
|
|
const nsAString& aEncoding,
|
2012-09-28 14:19:18 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-08-23 09:17:08 +04:00
|
|
|
nsRefPtr<TextEncoder> txtEncoder = new TextEncoder(aGlobal.GetAsSupports());
|
2012-09-28 14:19:18 +04: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 20:29:54 +04:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE
|
2012-09-28 14:19:18 +04:00
|
|
|
{
|
2013-03-12 03:03:47 +04:00
|
|
|
return TextEncoderBinding::Wrap(aCx, aScope, this);
|
2012-09-28 14:19:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports*
|
|
|
|
GetParentObject()
|
|
|
|
{
|
|
|
|
return mGlobal;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* Encode(JSContext* aCx,
|
2013-08-23 09:17:07 +04:00
|
|
|
JS::Handle<JSObject*> aObj,
|
2012-09-28 14:19:18 +04:00
|
|
|
const nsAString& aString,
|
|
|
|
const TextEncodeOptions& aOptions,
|
2012-12-22 04:15:43 +04:00
|
|
|
ErrorResult& aRv) {
|
2013-08-23 09:17:07 +04:00
|
|
|
return TextEncoderBase::Encode(aCx, aObj, aString, aOptions.mStream, aRv);
|
2012-12-22 04:15:43 +04:00
|
|
|
}
|
|
|
|
|
2012-09-28 14:19:18 +04:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mGlobal;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // dom
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_textencoder_h_
|