Bug 1115465 - Add id attribute to NFCTag. r=smaug, dimi
authorYoshi Huang <allstars.chh@mozilla.com>
Fri, 26 Dec 2014 16:07:45 +0800
changeset 247575 c776f112102f59e49d4cb3988c756263c23745e0
parent 247574 3c34292527f633d92f69d565b2e59d7acc42d0de
child 247576 0c6e1ca875fba763facd74d2cdc096e83f34550f
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, dimi
bugs1115465
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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(-)
dom/nfc/NfcContentHelper.js
dom/nfc/gonk/NfcGonkMessage.h
dom/nfc/gonk/NfcMessageHandler.cpp
dom/nfc/gonk/NfcOptions.h
dom/nfc/gonk/NfcService.cpp
dom/nfc/nsINfcContentHelper.idl
dom/nfc/nsNfc.js
dom/webidl/MozNFCTag.webidl
dom/webidl/NfcOptions.webidl
--- a/dom/nfc/NfcContentHelper.js
+++ b/dom/nfc/NfcContentHelper.js
@@ -307,17 +307,17 @@ NfcContentHelper.prototype = {
                 result.isReadOnly !== undefined &&
                 result.isFormatable !== undefined) {
               ndefInfo = new TagNDEFInfo(result.tagType,
                                          result.maxNDEFSize,
                                          result.isReadOnly,
                                          result.isFormatable);
             }
 
-            let tagInfo = new TagInfo(result.techList);
+            let tagInfo = new TagInfo(result.techList, result.tagId);
             this.eventListener.notifyTagFound(result.sessionToken,
                                               tagInfo,
                                               ndefInfo,
                                               result.records);
             break;
           case NFC.TAG_EVENT_LOST:
             this.eventListener.notifyTagLost(result.sessionToken);
             break;
@@ -406,20 +406,22 @@ TagNDEFInfo.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsITagNDEFInfo]),
 
   tagType: null,
   maxNDEFSize: 0,
   isReadOnly: false,
   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) {
   this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NfcContentHelper]);
 }
--- a/dom/nfc/gonk/NfcGonkMessage.h
+++ b/dom/nfc/gonk/NfcGonkMessage.h
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef NfcGonkMessage_h
 #define NfcGonkMessage_h
 
 namespace mozilla {
 
 #define NFCD_MAJOR_VERSION 1
-#define NFCD_MINOR_VERSION 18
+#define NFCD_MINOR_VERSION 19
 
 enum NfcRequest {
   ChangeRFStateReq = 0,
   ConnectReq,
   CloseReq,
   ReadNDEFReq,
   WriteNDEFReq,
   MakeReadOnlyReq,
--- a/dom/nfc/gonk/NfcMessageHandler.cpp
+++ b/dom/nfc/gonk/NfcMessageHandler.cpp
@@ -249,32 +249,37 @@ NfcMessageHandler::InitializeNotificatio
 {
   aOptions.mType = NS_ConvertUTF8toUTF16(kInitializedNotification);
   aOptions.mStatus = aParcel.readInt32();
   aOptions.mMajorVersion = aParcel.readInt32();
   aOptions.mMinorVersion = aParcel.readInt32();
 
   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;
 }
 
 bool
 NfcMessageHandler::TechDiscoveredNotification(const Parcel& aParcel, EventOptions& aOptions)
 {
   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) {
     ReadNDEFMessage(aParcel, aOptions);
   }
 
   int32_t ndefInfo = aParcel.readInt32();
   if (ndefInfo) {
@@ -322,25 +327,25 @@ NfcMessageHandler::ReadNDEFMessage(const
 
   for (int i = 0; i < recordCount; i++) {
     int32_t tnf = aParcel.readInt32();
     NDEFRecordStruct record;
     record.mTnf = static_cast<TNF>(tnf);
 
     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);
   }
 
   return true;
 }
 
 bool
--- a/dom/nfc/gonk/NfcOptions.h
+++ b/dom/nfc/gonk/NfcOptions.h
@@ -94,16 +94,17 @@ struct EventOptions
   nsString mType;
   int32_t mStatus;
   int32_t mErrorCode;
   int32_t mSessionId;
   nsString mRequestId;
   int32_t mMajorVersion;
   int32_t mMinorVersion;
   nsTArray<uint8_t> mTechList;
+  nsTArray<uint8_t> mTagId;
   int32_t mIsP2P;
   nsTArray<NDEFRecordStruct> mRecords;
   int32_t mTagType;
   int32_t mMaxNDEFSize;
   int32_t mIsReadOnly;
   int32_t mIsFormatable;
   int32_t mRfState;
 
--- a/dom/nfc/gonk/NfcService.cpp
+++ b/dom/nfc/gonk/NfcService.cpp
@@ -127,16 +127,21 @@ public:
 
       for (int i = 0; i < length; i++) {
         NFCTechType tech = static_cast<NFCTechType>(mEvent.mTechList[i]);
         MOZ_ASSERT(tech < NFCTechType::EndGuard_);
         *event.mTechList.Value().AppendElement() = tech;
       }
     }
 
+    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();
       if (!event.mRecords.Value().SetCapacity(length)) {
         return NS_ERROR_FAILURE;
       }
 
       for (int i = 0; i < length; i++) {
--- a/dom/nfc/nsINfcContentHelper.idl
+++ b/dom/nfc/nsINfcContentHelper.idl
@@ -2,23 +2,25 @@
  * 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/. */
 
 #include "nsISupports.idl"
 
 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)]
 interface nsITagNDEFInfo : nsISupports
 {
   // one of NFCTagType defined in MozNFCTag.webidl.
   readonly attribute DOMString tagType;
 
--- a/dom/nfc/nsNfc.js
+++ b/dom/nfc/nsNfc.js
@@ -99,31 +99,33 @@ NfcCallback.prototype = {
  */
 function MozNFCTagImpl(window, sessionToken, tagInfo, ndefInfo) {
   debug("In MozNFCTagImpl Constructor");
   this._nfcContentHelper = Cc["@mozilla.org/nfc/content-helper;1"]
                              .getService(Ci.nsINfcContentHelper);
   this._window = window;
   this.session = sessionToken;
   this.techList = tagInfo.techList;
+  this.id = Cu.cloneInto(tagInfo.tagId, window);
 
   if (ndefInfo) {
     this.type = ndefInfo.tagType;
     this.maxNDEFSize = ndefInfo.maxNDEFSize;
     this.isReadOnly = ndefInfo.isReadOnly;
     this.isFormatable = ndefInfo.isFormatable;
     this.canBeMadeReadOnly = this.type == "type1" || this.type == "type2" ||
                              this.type == "mifare_classic";
   }
 }
 MozNFCTagImpl.prototype = {
   _nfcContentHelper: null,
   _window: null,
   session: null,
   techList: null,
+  id: null,
   type: null,
   maxNDEFSize: null,
   isReadOnly: null,
   isFormatable: null,
   canBeMadeReadOnly: null,
   isLost: false,
 
   // NFCTag interface:
--- a/dom/webidl/MozNFCTag.webidl
+++ b/dom/webidl/MozNFCTag.webidl
@@ -35,16 +35,21 @@ enum NFCTagType {
 [JSImplementation="@mozilla.org/nfc/NFCTag;1", AvailableIn="PrivilegedApps"]
 interface MozNFCTag {
   /**
    * The supported technologies of this tag, null if unknown.
    */
   [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.
    */
   readonly attribute NFCTagType? type;
 
   /**
    * The maximum size of the NDEF supported on this tag, null if unknown.
    */
   readonly attribute long? maxNDEFSize;
--- a/dom/webidl/NfcOptions.webidl
+++ b/dom/webidl/NfcOptions.webidl
@@ -32,16 +32,17 @@ dictionary NfcEventOptions
   long sessionId;
   DOMString requestId;
 
   long majorVersion;
   long minorVersion;
 
   boolean isP2P;
   sequence<NFCTechType> techList;
+  Uint8Array tagId;
   sequence<MozNDEFRecordOptions> records;
 
   NFCTagType tagType;
   long maxNDEFSize;
   boolean isReadOnly;
   boolean isFormatable;
 
   RFState rfState;