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:
|
|
|
|
|
2014-08-18 10:56:12 +04:00
|
|
|
MozNDEFRecord(JSContext* aCx, nsPIDOMWindow* aWindow,
|
|
|
|
const MozNDEFRecordOptions& aOptions);
|
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
|
|
|
|
2014-08-20 13:35:18 +04:00
|
|
|
TNF Tnf() const
|
2013-11-06 21:53:19 +04:00
|
|
|
{
|
|
|
|
return mTnf;
|
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetType(JSContext* cx, JS::MutableHandle<JSObject*> retval) 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
|
|
|
}
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(mType);
|
2013-11-06 21:53:19 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetId(JSContext* cx, JS::MutableHandle<JSObject*> retval) 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
|
|
|
}
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(mId);
|
2013-11-06 21:53:19 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 00:26:52 +04:00
|
|
|
void GetPayload(JSContext* cx, JS::MutableHandle<JSObject*> retval) 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
|
|
|
}
|
2014-06-12 00:26:52 +04:00
|
|
|
retval.set(mPayload);
|
2013-11-06 21:53:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-01-29 04:20:17 +04:00
|
|
|
MozNDEFRecord() MOZ_DELETE;
|
2013-11-06 21:53:19 +04:00
|
|
|
nsRefPtr<nsPIDOMWindow> mWindow;
|
2013-11-09 03:10:23 +04:00
|
|
|
void HoldData();
|
|
|
|
void DropData();
|
2013-11-06 21:53:19 +04:00
|
|
|
|
2014-08-28 12:44:48 +04:00
|
|
|
static bool
|
|
|
|
ValidateTNF(const MozNDEFRecordOptions& aOptions, ErrorResult& aRv);
|
|
|
|
|
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;
|
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__
|