2013-11-06 09:53:19 -08: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. */
|
|
|
|
|
|
|
|
#include "MozNdefRecord.h"
|
|
|
|
#include "mozilla/dom/MozNdefRecordBinding.h"
|
2013-11-08 15:10:23 -08:00
|
|
|
#include "mozilla/HoldDropJSObjects.h"
|
2013-11-06 09:53:19 -08:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
2013-11-08 15:10:23 -08:00
|
|
|
|
2013-11-06 09:53:19 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-11-08 15:10:23 -08:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(MozNdefRecord)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MozNdefRecord)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(MozNdefRecord)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(MozNdefRecord)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mType)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mId)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mPayload)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2013-11-06 09:53:19 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(MozNdefRecord)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(MozNdefRecord)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MozNdefRecord)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-11-08 15:10:23 -08:00
|
|
|
void
|
|
|
|
MozNdefRecord::HoldData()
|
|
|
|
{
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MozNdefRecord::DropData()
|
|
|
|
{
|
|
|
|
if (mType) {
|
|
|
|
mType = nullptr;
|
|
|
|
}
|
|
|
|
if (mId) {
|
|
|
|
mId = nullptr;
|
|
|
|
}
|
|
|
|
if (mPayload) {
|
|
|
|
mPayload = nullptr;
|
|
|
|
}
|
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
|
2013-11-06 09:53:19 -08:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<MozNdefRecord>
|
|
|
|
MozNdefRecord::Constructor(const GlobalObject& aGlobal,
|
2013-11-08 15:10:23 -08:00
|
|
|
uint8_t aTnf, const Uint8Array& aType,
|
|
|
|
const Uint8Array& aId, const Uint8Array& aPayload,
|
2013-11-06 09:53:19 -08:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
if (!win) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-08 15:10:23 -08:00
|
|
|
|
|
|
|
nsRefPtr<MozNdefRecord> ndefrecord = new MozNdefRecord(aGlobal.GetContext(),
|
|
|
|
win, aTnf, aType, aId,
|
|
|
|
aPayload);
|
|
|
|
if (!ndefrecord) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-06 09:53:19 -08:00
|
|
|
return ndefrecord.forget();
|
|
|
|
}
|
|
|
|
|
2013-11-08 15:10:23 -08:00
|
|
|
MozNdefRecord::MozNdefRecord(JSContext* aCx, nsPIDOMWindow* aWindow,
|
|
|
|
uint8_t aTnf, const Uint8Array& aType,
|
|
|
|
const Uint8Array& aId, const Uint8Array& aPayload)
|
2013-11-06 09:53:19 -08:00
|
|
|
: mTnf(aTnf)
|
|
|
|
{
|
2013-11-08 15:10:23 -08:00
|
|
|
mWindow = aWindow; // For GetParentObject()
|
|
|
|
|
|
|
|
mType = Uint8Array::Create(aCx, this, aType.Length(), aType.Data());
|
|
|
|
mId = Uint8Array::Create(aCx, this, aId.Length(), aId.Data());
|
|
|
|
mPayload = Uint8Array::Create(aCx, this, aPayload.Length(), aPayload.Data());
|
|
|
|
|
2013-11-06 09:53:19 -08:00
|
|
|
SetIsDOMBinding();
|
2013-11-08 15:10:23 -08:00
|
|
|
HoldData();
|
2013-11-06 09:53:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
MozNdefRecord::~MozNdefRecord()
|
|
|
|
{
|
2013-11-08 15:10:23 -08:00
|
|
|
DropData();
|
2013-11-06 09:53:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
MozNdefRecord::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
|
|
|
{
|
|
|
|
return MozNdefRecordBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|