2013-11-06 21:53:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* 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"
|
2014-08-18 18:44:50 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2013-11-09 03:10:23 +04:00
|
|
|
|
2013-11-06 21:53:19 +04:00
|
|
|
struct JSContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-08-18 10:56:12 +04:00
|
|
|
class MozNDEFRecordOptions;
|
|
|
|
|
2014-01-29 04:20:17 +04:00
|
|
|
class MozNDEFRecord MOZ_FINAL : public nsISupports,
|
2013-11-06 21:53:19 +04:00
|
|
|
public nsWrapperCache
|
|
|
|
{
|
|
|
|
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-07 13:08:21 +03:00
|
|
|
MozNDEFRecord(nsPIDOMWindow* aWindow, TNF aTnf);
|
2013-11-06 21:53:19 +04:00
|
|
|
|
2014-01-29 04:20:17 +04:00
|
|
|
~MozNDEFRecord();
|
2013-11-06 21:53:19 +04:00
|
|
|
|
|
|
|
nsIDOMWindow* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mWindow;
|
|
|
|
}
|
|
|
|
|
2014-04-09 02:27:18 +04:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_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;
|
|
|
|
}
|
|
|
|
|
2013-11-06 21:53:19 +04:00
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
MozNDEFRecord() = delete;
|
2013-11-06 21:53:19 +04:00
|
|
|
nsRefPtr<nsPIDOMWindow> mWindow;
|
2013-11-09 03:10:23 +04:00
|
|
|
void HoldData();
|
|
|
|
void DropData();
|
2015-01-07 13:08:21 +03:00
|
|
|
void InitType(JSContext* aCx, const Optional<Uint8Array>& aType);
|
2015-01-29 13:16:26 +03:00
|
|
|
void InitType(JSContext* aCx, const RTD rtd);
|
2015-01-07 13:08:21 +03:00
|
|
|
void InitId(JSContext* aCx, const Optional<Uint8Array>& aId);
|
|
|
|
void InitPayload(JSContext* aCx, const Optional<Uint8Array>& aPayload);
|
2015-01-29 13:16:26 +03:00
|
|
|
void InitPayload(JSContext* aCx, const nsAString& aUri);
|
2015-01-07 13:08:21 +03:00
|
|
|
void IncSize(uint32_t aCount);
|
|
|
|
void IncSizeForPayload(uint32_t aLen);
|
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__
|