Bug 1115465 - Add id attribute to NFCTag. r=smaug, dimi

From 152d8835dedf6592d274478bac369530f98c3935 Mon Sep 17 00:00:00 2001
---
 dom/nfc/NfcContentHelper.js        |  6 ++++--
 dom/nfc/gonk/NfcGonkMessage.h      |  2 +-
 dom/nfc/gonk/NfcMessageHandler.cpp | 17 +++++++++++------
 dom/nfc/gonk/NfcOptions.h          |  1 +
 dom/nfc/gonk/NfcService.cpp        |  5 +++++
 dom/nfc/nsINfcContentHelper.idl    |  4 +++-
 dom/nfc/nsNfc.js                   |  2 ++
 dom/webidl/MozNFCTag.webidl        |  5 +++++
 dom/webidl/NfcOptions.webidl       |  1 +
 9 files changed, 33 insertions(+), 10 deletions(-)
This commit is contained in:
Yoshi Huang 2014-12-26 16:07:45 +08:00
parent 5f7c596617
commit 424c8aeb97
9 changed files with 33 additions and 10 deletions

View File

@ -312,7 +312,7 @@ NfcContentHelper.prototype = {
result.isFormatable);
}
let tagInfo = new TagInfo(result.techList);
let tagInfo = new TagInfo(result.techList, result.tagId);
this.eventListener.notifyTagFound(result.sessionToken,
tagInfo,
ndefInfo,
@ -411,13 +411,15 @@ TagNDEFInfo.prototype = {
isFormatable: false
};
function TagInfo(techList) {
function TagInfo(techList, tagId) {
this.techList = techList;
this.tagId = tagId;
}
TagInfo.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsITagInfo]),
techList: null,
tagId: null,
};
if (NFC_ENABLED) {

View File

@ -8,7 +8,7 @@
namespace mozilla {
#define NFCD_MAJOR_VERSION 1
#define NFCD_MINOR_VERSION 18
#define NFCD_MINOR_VERSION 19
enum NfcRequest {
ChangeRFStateReq = 0,

View File

@ -254,8 +254,8 @@ NfcMessageHandler::InitializeNotification(const Parcel& aParcel, EventOptions& a
if (aOptions.mMajorVersion != NFCD_MAJOR_VERSION ||
aOptions.mMinorVersion != NFCD_MINOR_VERSION) {
NMH_LOG("NFCD version mismatched. majorVersion: %d, minorVersion: %d",
aOptions.mMajorVersion, aOptions.mMinorVersion);
NMH_LOG("NFCD version mismatched. majorVersion: %d, minorVersion: %d",
aOptions.mMajorVersion, aOptions.mMinorVersion);
}
return true;
@ -267,9 +267,14 @@ NfcMessageHandler::TechDiscoveredNotification(const Parcel& aParcel, EventOption
aOptions.mType = NS_ConvertUTF8toUTF16(kTechDiscoveredNotification);
aOptions.mSessionId = aParcel.readInt32();
aOptions.mIsP2P = aParcel.readInt32();
int32_t techCount = aParcel.readInt32();
aOptions.mTechList.AppendElements(
static_cast<const uint8_t*>(aParcel.readInplace(techCount)), techCount);
static_cast<const uint8_t*>(aParcel.readInplace(techCount)), techCount);
int32_t idCount = aParcel.readInt32();
aOptions.mTagId.AppendElements(
static_cast<const uint8_t*>(aParcel.readInplace(idCount)), idCount);
int32_t ndefMsgCount = aParcel.readInt32();
if (ndefMsgCount != 0) {
@ -327,15 +332,15 @@ NfcMessageHandler::ReadNDEFMessage(const Parcel& aParcel, EventOptions& aOptions
int32_t typeLength = aParcel.readInt32();
record.mType.AppendElements(
static_cast<const uint8_t*>(aParcel.readInplace(typeLength)), typeLength);
static_cast<const uint8_t*>(aParcel.readInplace(typeLength)), typeLength);
int32_t idLength = aParcel.readInt32();
record.mId.AppendElements(
static_cast<const uint8_t*>(aParcel.readInplace(idLength)), idLength);
static_cast<const uint8_t*>(aParcel.readInplace(idLength)), idLength);
int32_t payloadLength = aParcel.readInt32();
record.mPayload.AppendElements(
static_cast<const uint8_t*>(aParcel.readInplace(payloadLength)), payloadLength);
static_cast<const uint8_t*>(aParcel.readInplace(payloadLength)), payloadLength);
aOptions.mRecords.AppendElement(record);
}

View File

@ -99,6 +99,7 @@ struct EventOptions
int32_t mMajorVersion;
int32_t mMinorVersion;
nsTArray<uint8_t> mTechList;
nsTArray<uint8_t> mTagId;
int32_t mIsP2P;
nsTArray<NDEFRecordStruct> mRecords;
int32_t mTagType;

View File

@ -132,6 +132,11 @@ public:
}
}
if (mEvent.mTagId.Length() > 0) {
event.mTagId.Construct();
event.mTagId.Value().Init(Uint8Array::Create(cx, mEvent.mTagId.Length(), mEvent.mTagId.Elements()));
}
if (mEvent.mRecords.Length() > 0) {
int length = mEvent.mRecords.Length();
event.mRecords.Construct();

View File

@ -7,13 +7,15 @@
interface nsIVariant;
interface nsIDOMWindow;
[scriptable, uuid(30d77baf-50ed-4a6b-ab75-25bade40977a)]
[scriptable, uuid(a694c7e8-10dd-416e-a3d9-433edf40647e)]
interface nsITagInfo : nsISupports
{
/**
* Array of technolgies supported. See NFCTechType in MozNFCTag.webidl
*/
readonly attribute nsIVariant techList;
readonly attribute nsIVariant tagId; // Uint8Array
};
[scriptable, uuid(74d70ebb-557f-4ac8-8296-7885961cd1dc)]

View File

@ -104,6 +104,7 @@ function MozNFCTagImpl(window, sessionToken, tagInfo, ndefInfo) {
this._window = window;
this.session = sessionToken;
this.techList = tagInfo.techList;
this.id = Cu.cloneInto(tagInfo.tagId, window);
if (ndefInfo) {
this.type = ndefInfo.tagType;
@ -119,6 +120,7 @@ MozNFCTagImpl.prototype = {
_window: null,
session: null,
techList: null,
id: null,
type: null,
maxNDEFSize: null,
isReadOnly: null,

View File

@ -39,6 +39,11 @@ interface MozNFCTag {
*/
[Cached, Pure] readonly attribute sequence<NFCTechType>? techList;
/**
* The identifier of this tag.
*/
[Pure, Constant] readonly attribute Uint8Array? id;
/**
* The type of this tag, null if unknown.
*/

View File

@ -37,6 +37,7 @@ dictionary NfcEventOptions
boolean isP2P;
sequence<NFCTechType> techList;
Uint8Array tagId;
sequence<MozNDEFRecordOptions> records;
NFCTagType tagType;