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. */
|
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
#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
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(MozNDEFRecord)
|
2013-11-08 15:10:23 -08:00
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MozNDEFRecord)
|
2013-11-08 15:10:23 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2014-02-12 01:21:09 -08:00
|
|
|
tmp->DropData();
|
2013-11-08 15:10:23 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(MozNDEFRecord)
|
2013-11-08 15:10:23 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(MozNDEFRecord)
|
2013-11-08 15:10:23 -08:00
|
|
|
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
|
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(MozNDEFRecord)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(MozNDEFRecord)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MozNDEFRecord)
|
2013-11-06 09:53:19 -08:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-11-08 15:10:23 -08:00
|
|
|
void
|
2014-01-28 16:20:17 -08:00
|
|
|
MozNDEFRecord::HoldData()
|
2013-11-08 15:10:23 -08:00
|
|
|
{
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-28 16:20:17 -08:00
|
|
|
MozNDEFRecord::DropData()
|
2013-11-08 15:10:23 -08:00
|
|
|
{
|
|
|
|
if (mType) {
|
|
|
|
mType = nullptr;
|
|
|
|
}
|
|
|
|
if (mId) {
|
|
|
|
mId = nullptr;
|
|
|
|
}
|
|
|
|
if (mPayload) {
|
|
|
|
mPayload = nullptr;
|
|
|
|
}
|
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
|
2013-11-06 09:53:19 -08:00
|
|
|
/* static */
|
2014-01-28 16:20:17 -08:00
|
|
|
already_AddRefed<MozNDEFRecord>
|
|
|
|
MozNDEFRecord::Constructor(const GlobalObject& aGlobal,
|
2014-02-19 23:08:46 -08:00
|
|
|
uint8_t aTnf,
|
|
|
|
const Optional<Uint8Array>& aType,
|
|
|
|
const Optional<Uint8Array>& aId,
|
|
|
|
const Optional<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
|
|
|
|
2014-06-16 11:08:00 -07:00
|
|
|
nsRefPtr<MozNDEFRecord> ndefrecord = new MozNDEFRecord(aGlobal.Context(),
|
2013-11-08 15:10:23 -08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
MozNDEFRecord::MozNDEFRecord(JSContext* aCx, nsPIDOMWindow* aWindow,
|
2014-02-19 23:08:46 -08:00
|
|
|
uint8_t aTnf,
|
|
|
|
const Optional<Uint8Array>& aType,
|
|
|
|
const Optional<Uint8Array>& aId,
|
|
|
|
const Optional<Uint8Array>& aPayload)
|
2013-11-06 09:53:19 -08:00
|
|
|
: mTnf(aTnf)
|
|
|
|
{
|
2013-11-08 15:10:23 -08:00
|
|
|
mWindow = aWindow; // For GetParentObject()
|
|
|
|
|
2014-02-19 23:08:46 -08:00
|
|
|
if (aType.WasPassed()) {
|
2014-06-03 04:05:46 -07:00
|
|
|
aType.Value().ComputeLengthAndData();
|
2014-02-19 23:08:46 -08:00
|
|
|
mType = Uint8Array::Create(aCx, this, aType.Value().Length(), aType.Value().Data());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aId.WasPassed()) {
|
2014-06-03 04:05:46 -07:00
|
|
|
aId.Value().ComputeLengthAndData();
|
2014-02-19 23:08:46 -08:00
|
|
|
mId = Uint8Array::Create(aCx, this, aId.Value().Length(), aId.Value().Data());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aPayload.WasPassed()) {
|
2014-06-03 04:05:46 -07:00
|
|
|
aPayload.Value().ComputeLengthAndData();
|
2014-02-19 23:08:46 -08:00
|
|
|
mPayload = Uint8Array::Create(aCx, this, aPayload.Value().Length(), aPayload.Value().Data());
|
|
|
|
}
|
2013-11-08 15:10:23 -08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-28 16:20:17 -08:00
|
|
|
MozNDEFRecord::~MozNDEFRecord()
|
2013-11-06 09:53:19 -08:00
|
|
|
{
|
2013-11-08 15:10:23 -08:00
|
|
|
DropData();
|
2013-11-06 09:53:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
MozNDEFRecord::WrapObject(JSContext* aCx)
|
2013-11-06 09:53:19 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return MozNDEFRecordBinding::Wrap(aCx, this);
|
2013-11-06 09:53:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|