Bug 1115468 - Some attrubites of MozNFCTag are null. r=dimi
authorYoshi Huang <allstars.chh@mozilla.com>
Fri, 26 Dec 2014 11:50:12 +0800
changeset 247389 99305902e4e6c2ff40fd848bed8108594ac8438a
parent 247388 9220c29104dac347138b7f03f11b352b6f4f5290
child 247390 9598ec9b1574368401f53ecdd87dc8a929d97f11
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)
reviewersdimi
bugs1115468
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 1115468 - Some attrubites of MozNFCTag are null. r=dimi From bf11cb363f58cce8eff86c6234930a94834b3c11 Mon Sep 17 00:00:00 2001 --- dom/nfc/NfcContentHelper.js | 40 ++++++++++++++++++++++++++++------------ dom/nfc/nsINfcContentHelper.idl | 23 +++++++++++++++++------ dom/nfc/nsNfc.js | 38 ++++++++++++++++++++------------------ 3 files changed, 65 insertions(+), 36 deletions(-)
dom/nfc/NfcContentHelper.js
dom/nfc/nsINfcContentHelper.idl
dom/nfc/nsNfc.js
--- a/dom/nfc/NfcContentHelper.js
+++ b/dom/nfc/NfcContentHelper.js
@@ -296,23 +296,32 @@ NfcContentHelper.prototype = {
             break;
           case NFC.PEER_EVENT_FOUND:
             this.eventListener.notifyPeerFound(result.sessionToken);
             break;
           case NFC.PEER_EVENT_LOST:
             this.eventListener.notifyPeerLost(result.sessionToken);
             break;
           case NFC.TAG_EVENT_FOUND:
-            let event = new NfcTagEvent(result.techList,
-                                        result.tagType,
-                                        result.maxNDEFSize,
-                                        result.isReadOnly,
-                                        result.isFormatable);
+            let ndefInfo = null;
+            if (result.tagType !== undefined &&
+                result.maxNDEFSize !== undefined &&
+                result.isReadOnly !== undefined &&
+                result.isFormatable !== undefined) {
+              ndefInfo = new TagNDEFInfo(result.tagType,
+                                         result.maxNDEFSize,
+                                         result.isReadOnly,
+                                         result.isFormatable);
+            }
 
-            this.eventListener.notifyTagFound(result.sessionToken, event, result.records);
+            let tagInfo = new TagInfo(result.techList);
+            this.eventListener.notifyTagFound(result.sessionToken,
+                                              tagInfo,
+                                              ndefInfo,
+                                              result.records);
             break;
           case NFC.TAG_EVENT_LOST:
             this.eventListener.notifyTagLost(result.sessionToken);
             break;
           case NFC.RF_EVENT_STATE_CHANGE:
             this._rfState = result.rfState;
             this.eventListener.notifyRFStateChange(this._rfState);
             break;
@@ -382,28 +391,35 @@ NfcContentHelper.prototype = {
     delete this._requestMap[requestId];
 
     // Privilaged status API. Always fire success to avoid using exposed props.
     // The receiver must check the boolean mapped status code to handle.
     callback.notifySuccessWithBoolean(!result.errorMsg);
   },
 };
 
-function NfcTagEvent(techList, tagType, maxNDEFSize, isReadOnly, isFormatable) {
-  this.techList = techList;
+function TagNDEFInfo(tagType, maxNDEFSize, isReadOnly, isFormatable) {
   this.tagType = tagType;
   this.maxNDEFSize = maxNDEFSize;
   this.isReadOnly = isReadOnly;
   this.isFormatable = isFormatable;
 }
-NfcTagEvent.prototype = {
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsINfcTagEvent]),
+TagNDEFInfo.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsITagNDEFInfo]),
 
-  techList: null,
   tagType: null,
   maxNDEFSize: 0,
   isReadOnly: false,
   isFormatable: false
 };
 
+function TagInfo(techList) {
+  this.techList = techList;
+}
+TagInfo.prototype = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsITagInfo]),
+
+  techList: null,
+};
+
 if (NFC_ENABLED) {
   this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NfcContentHelper]);
 }
--- a/dom/nfc/nsINfcContentHelper.idl
+++ b/dom/nfc/nsINfcContentHelper.idl
@@ -2,46 +2,57 @@
  * 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(9b43bdda-52f4-4712-b28c-ad7cba736e14)]
-interface nsINfcTagEvent : nsISupports
+[scriptable, uuid(30d77baf-50ed-4a6b-ab75-25bade40977a)]
+interface nsITagInfo : nsISupports
 {
+  /**
+   * Array of technolgies supported. See NFCTechType in MozNFCTag.webidl
+   */
   readonly attribute nsIVariant techList;
+};
 
+[scriptable, uuid(74d70ebb-557f-4ac8-8296-7885961cd1dc)]
+interface nsITagNDEFInfo : nsISupports
+{
   // one of NFCTagType defined in MozNFCTag.webidl.
   readonly attribute DOMString tagType;
 
   readonly attribute long maxNDEFSize;
 
   readonly attribute boolean isReadOnly;
 
   readonly attribute boolean isFormatable;
 };
 
-[scriptable, uuid(fcbd98d6-3d04-4657-bd64-1164e311b399)]
+[scriptable, uuid(be09c440-8385-4210-bb7b-7d3333ec3d43)]
 interface nsINfcEventListener : nsISupports
 {
   /**
    * Callback function used to notify tagfound.
    *
    * @param sessionToken
    *        SessionToken received from parent process
-   * @param event
-   *        nsINfcTagFoundEvent received from parent process.
+   * @param tagInfo
+   *        nsITagInfo received from parent process.
+   * @param ndefInfo
+   *        nsITagNDEFInfo received from parent process, could be null if the
+   *        tag is not formated as NDEF.
    * @param ndefRecords
    *        NDEF records pre-read during tag-discovered.
    */
   void notifyTagFound(in DOMString sessionToken,
-                      in nsINfcTagEvent event,
+                      in nsITagInfo tagInfo,
+                      in nsITagNDEFInfo ndefInfo,
                       in nsIVariant ndefRecords);
 
   /**
    * Callback function used to notify taglost.
    *
    * @param sessionToken
    *        SessionToken received from parent process
    */
--- a/dom/nfc/nsNfc.js
+++ b/dom/nfc/nsNfc.js
@@ -87,46 +87,48 @@ NfcCallback.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
                                          Ci.nsIObserver,
                                          Ci.nsINfcRequestCallback]),
 };
 
 /**
  * Implementation of NFCTag.
  *
- * @param window  global window object.
+ * @param window        global window object.
  * @param sessionToken  session token received from parent process.
- * @parem event   type of nsINfcTagEvent received from parent process.
+ * @param tagInfo       type of nsITagInfo received from parent process.
+ * @parem ndefInfo      type of nsITagNDEFInfo received from parent process.
  */
-function MozNFCTagImpl(window, sessionToken, event) {
+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 = event.techList;
-  this.type = event.tagType || null;
-  this.maxNDEFSize = event.maxNDEFSize || null;
-  this.isReadOnly = event.isReadOnly || null;
-  this.isFormatable = event.isFormatable || null;
-  this.canBeMadeReadOnly = this.type ?
-                             (this.type == "type1" || this.type == "type2" ||
-                              this.type == "mifare_classic") :
-                             null;
+  this.techList = tagInfo.techList;
+
+  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,
   type: null,
-  maxNDEFSize: 0,
-  isReadOnly: false,
-  isFormatable: false,
-  canBeMadeReadOnly: false,
+  maxNDEFSize: null,
+  isReadOnly: null,
+  isFormatable: null,
+  canBeMadeReadOnly: null,
   isLost: false,
 
   // NFCTag interface:
   readNDEF: function readNDEF() {
     if (this.isLost) {
       throw new this._window.DOMError("InvalidStateError", "NFCTag object is invalid");
     }
 
@@ -360,17 +362,17 @@ MozNFCImpl.prototype = {
     if (eventType !== "peerready") {
       return;
     }
 
     let appId = this._window.document.nodePrincipal.appId;
     this._nfcContentHelper.unregisterTargetForPeerReady(appId);
   },
 
-  notifyTagFound: function notifyTagFound(sessionToken, event, records) {
+  notifyTagFound: function notifyTagFound(sessionToken, tagInfo, ndefInfo, records) {
     if (this.hasDeadWrapper()) {
       dump("this._window or this.__DOM_IMPL__ is a dead wrapper.");
       return;
     }
 
     if (!this.eventService.hasListenersFor(this.__DOM_IMPL__, "tagfound")) {
       debug("ontagfound is not registered.");
       return;
@@ -378,17 +380,17 @@ MozNFCImpl.prototype = {
 
     if (!this.checkPermissions(["nfc"])) {
       return;
     }
 
     this.eventService.addSystemEventListener(this._window, "visibilitychange",
       this, /* useCapture */false);
 
-    let tagImpl = new MozNFCTagImpl(this._window, sessionToken, event);
+    let tagImpl = new MozNFCTagImpl(this._window, sessionToken, tagInfo, ndefInfo);
     let tag = this._window.MozNFCTag._create(this._window, tagImpl);
     this.nfcTag = tag;
 
     let length = records ? records.length : 0;
     let ndefRecords = records ? [] : null;
     for (let i = 0; i < length; i++) {
       let record = records[i];
       ndefRecords.push(new this._window.MozNDEFRecord({tnf: record.tnf,