2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-11-06 21:53:19 +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/. */
|
|
|
|
|
|
|
|
/* Copyright © 2013 Deutsche Telekom, Inc. */
|
|
|
|
|
2014-01-29 04:20:17 +04:00
|
|
|
#ifndef mozilla_dom_MozNDEFRecord_h__
|
|
|
|
#define mozilla_dom_MozNDEFRecord_h__
|
2013-11-06 21:53:19 +04:00
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
2014-08-20 13:35:18 +04:00
|
|
|
#include "mozilla/dom/MozNDEFRecordBinding.h"
|
2013-11-09 03:10:23 +04:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
#include "jsfriendapi.h"
|
|
|
|
#include "js/GCAPI.h"
|
2015-01-30 10:36:42 +03:00
|
|
|
#include "nsISupports.h"
|
2013-11-09 03:10:23 +04:00
|
|
|
|
2013-11-06 21:53:19 +04:00
|
|
|
struct JSContext;
|
2015-01-30 10:36:42 +03:00
|
|
|
struct JSStructuredCloneWriter;
|
2013-11-06 21:53:19 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-08-18 10:56:12 +04:00
|
|
|
class MozNDEFRecordOptions;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class MozNDEFRecord final : public nsISupports,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsWrapperCache
|
2013-11-06 21:53:19 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2014-01-29 04:20:17 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MozNDEFRecord)
|
2013-11-06 21:53:19 +04:00
|
|
|
|
|
|
|
public:
|
2015-01-30 10:36:42 +03:00
|
|
|
MozNDEFRecord(nsISupports* aParent, TNF aTnf = TNF::Empty);
|
2013-11-06 21:53:19 +04:00
|
|
|
|
2015-01-30 10:36:42 +03:00
|
|
|
nsISupports* GetParentObject() const
|
2013-11-06 21:53:19 +04:00
|
|
|
{
|
2015-01-30 10:36:42 +03:00
|
|
|
return mParent;
|
2013-11-06 21:53:19 +04:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-06 21:53:19 +04:00
|
|
|
|
2014-01-29 04:20:17 +04:00
|
|
|
static already_AddRefed<MozNDEFRecord>
|
2014-08-18 10:56:12 +04:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const MozNDEFRecordOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
2013-11-06 21:53:19 +04:00
|
|
|
|
2015-01-29 13:16:26 +03:00
|
|
|
static already_AddRefed<MozNDEFRecord>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aURI,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2014-08-20 13:35:18 +04:00
|
|
|
TNF Tnf() const
|
2013-11-06 21:53:19 +04:00
|
|
|
{
|
|
|
|
return mTnf;
|
|
|
|
}
|
|
|
|
|
2015-01-07 13:08:21 +03:00
|
|
|
void GetType(JSContext* /* unused */, JS::MutableHandle<JSObject*> aRetVal) const
|
2013-11-09 03:10:23 +04:00
|
|
|
{
|
2014-02-20 11:08:46 +04:00
|
|
|
if (mType) {
|
2014-06-12 00:26:52 +04:00
|
|
|
JS::ExposeObjectToActiveJS(mType);
|
2014-02-20 11:08:46 +04:00
|
|
|
}
|
2015-01-07 13:08:21 +03:00
|
|
|
aRetVal.set(mType);
|
2013-11-06 21:53:19 +04:00
|
|
|
}
|
|
|
|
|
2015-01-07 13:08:21 +03:00
|
|
|
void GetId(JSContext* /* unused */, JS::MutableHandle<JSObject*> aRetVal) const
|
2013-11-06 21:53:19 +04:00
|
|
|
{
|
2014-02-20 11:08:46 +04:00
|
|
|
if (mId) {
|
2014-06-12 00:26:52 +04:00
|
|
|
JS::ExposeObjectToActiveJS(mId);
|
2014-02-20 11:08:46 +04:00
|
|
|
}
|
2015-01-07 13:08:21 +03:00
|
|
|
aRetVal.set(mId);
|
2013-11-06 21:53:19 +04:00
|
|
|
}
|
|
|
|
|
2015-01-07 13:08:21 +03:00
|
|
|
void GetPayload(JSContext* /* unused */, JS::MutableHandle<JSObject*> aRetVal) const
|
2013-11-09 03:10:23 +04:00
|
|
|
{
|
2014-02-20 11:08:46 +04:00
|
|
|
if (mPayload) {
|
2014-06-12 00:26:52 +04:00
|
|
|
JS::ExposeObjectToActiveJS(mPayload);
|
2014-02-20 11:08:46 +04:00
|
|
|
}
|
2015-01-07 13:08:21 +03:00
|
|
|
aRetVal.set(mPayload);
|
2013-11-06 21:53:19 +04:00
|
|
|
}
|
|
|
|
|
2014-11-07 09:24:34 +03:00
|
|
|
uint32_t Size() const
|
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
2015-01-21 12:37:45 +03:00
|
|
|
void GetAsURI(nsAString& aRetVal);
|
2015-01-30 10:36:42 +03:00
|
|
|
|
|
|
|
// Structured clone methods use these to clone MozNDEFRecord.
|
|
|
|
bool WriteStructuredClone(JSContext* aCx, JSStructuredCloneWriter* aWriter) const;
|
|
|
|
bool ReadStructuredClone(JSContext* aCx, JSStructuredCloneReader* aReader);
|
2015-03-10 15:44:01 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
~MozNDEFRecord();
|
|
|
|
|
2013-11-06 21:53:19 +04:00
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
MozNDEFRecord() = delete;
|
2015-01-30 10:36:42 +03:00
|
|
|
nsRefPtr<nsISupports> mParent;
|
2013-11-09 03:10:23 +04:00
|
|
|
void HoldData();
|
|
|
|
void DropData();
|
2015-03-06 11:23:21 +03:00
|
|
|
void InitType(JSContext* aCx, const Optional<Nullable<Uint8Array>>& aType);
|
2015-01-29 13:16:26 +03:00
|
|
|
void InitType(JSContext* aCx, const RTD rtd);
|
2015-01-30 10:36:42 +03:00
|
|
|
void InitType(JSContext* aCx, JSObject& aType, uint32_t aLen);
|
2015-03-06 11:23:21 +03:00
|
|
|
void InitId(JSContext* aCx, const Optional<Nullable<Uint8Array>>& aId);
|
2015-01-30 10:36:42 +03:00
|
|
|
void InitId(JSContext* aCx, JSObject& aId, uint32_t aLen);
|
2015-03-06 11:23:21 +03:00
|
|
|
void InitPayload(JSContext* aCx, const Optional<Nullable<Uint8Array>>& aPayload);
|
2015-01-29 13:16:26 +03:00
|
|
|
void InitPayload(JSContext* aCx, const nsAString& aUri);
|
2015-01-30 10:36:42 +03:00
|
|
|
void InitPayload(JSContext* aCx, JSObject& aPayload, uint32_t aLen);
|
2015-01-07 13:08:21 +03:00
|
|
|
void IncSize(uint32_t aCount);
|
|
|
|
void IncSizeForPayload(uint32_t aLen);
|
2015-01-30 10:36:42 +03:00
|
|
|
bool WriteUint8Array(JSContext* aCx, JSStructuredCloneWriter* aWriter, JSObject* aObj, uint32_t aLen) const;
|
2013-11-06 21:53:19 +04:00
|
|
|
|
2014-08-28 12:44:48 +04:00
|
|
|
static bool
|
|
|
|
ValidateTNF(const MozNDEFRecordOptions& aOptions, ErrorResult& aRv);
|
2015-01-29 13:16:26 +03:00
|
|
|
static uint32_t GetURIIdentifier(const nsCString& aUri);
|
2014-08-28 12:44:48 +04:00
|
|
|
|
2014-08-20 13:35:18 +04:00
|
|
|
TNF mTnf;
|
2013-11-09 03:10:23 +04:00
|
|
|
JS::Heap<JSObject*> mType;
|
|
|
|
JS::Heap<JSObject*> mId;
|
|
|
|
JS::Heap<JSObject*> mPayload;
|
2014-11-07 09:24:34 +03:00
|
|
|
uint32_t mSize;
|
2013-11-06 21:53:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-01-29 04:20:17 +04:00
|
|
|
#endif // mozilla_dom_MozNDEFRecord_h__
|