Bug 1094669 - Add a size attribute for MozNDEFRecord. r=smaug, dimi

From 2f518e162998b4ac911b3e10f8a7f8177fe03f59 Mon Sep 17 00:00:00 2001
---
 dom/nfc/MozNDEFRecord.cpp       | 7 +++++++
 dom/nfc/MozNDEFRecord.h         | 6 ++++++
 dom/webidl/MozNDEFRecord.webidl | 6 ++++++
 3 files changed, 19 insertions(+)
This commit is contained in:
Yoshi Huang 2014-11-07 14:24:34 +08:00
parent a00417e9d1
commit df0810a717
3 changed files with 19 additions and 0 deletions

View File

@ -131,23 +131,30 @@ MozNDEFRecord::MozNDEFRecord(JSContext* aCx, nsPIDOMWindow* aWindow,
mWindow = aWindow; // For GetParentObject()
mTnf = aOptions.mTnf;
mSize = 3; // 1(flags) + 1(type_length) + 1(payload_length)
if (aOptions.mType.WasPassed()) {
const Uint8Array& type = aOptions.mType.Value();
type.ComputeLengthAndData();
mType = Uint8Array::Create(aCx, this, type.Length(), type.Data());
mSize += type.Length();
}
if (aOptions.mId.WasPassed()) {
const Uint8Array& id = aOptions.mId.Value();
id.ComputeLengthAndData();
mId = Uint8Array::Create(aCx, this, id.Length(), id.Data());
mSize += 1 /* id_length */ + id.Length();
}
if (aOptions.mPayload.WasPassed()) {
const Uint8Array& payload = aOptions.mPayload.Value();
payload.ComputeLengthAndData();
mPayload = Uint8Array::Create(aCx, this, payload.Length(), payload.Data());
if (payload.Length() > 0xff) {
mSize += 3;
}
mSize += payload.Length();
}
HoldData();

View File

@ -83,6 +83,11 @@ public:
retval.set(mPayload);
}
uint32_t Size() const
{
return mSize;
}
private:
MozNDEFRecord() MOZ_DELETE;
nsRefPtr<nsPIDOMWindow> mWindow;
@ -96,6 +101,7 @@ private:
JS::Heap<JSObject*> mType;
JS::Heap<JSObject*> mId;
JS::Heap<JSObject*> mPayload;
uint32_t mSize;
};
} // namespace dom

View File

@ -42,6 +42,12 @@ interface MozNDEFRecord
*/
[Constant]
readonly attribute Uint8Array? payload;
/**
* Get the size of this NDEF Record.
*/
[Constant]
readonly attribute unsigned long size;
};
dictionary MozNDEFRecordOptions {