Add a format API to MozNFCTag

RESOLVED FIXED

Status

Firefox OS
NFC
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: allstars, Assigned: jhao)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 3 obsolete attachments)

In bug 1074611 we can know if the tag is formatable or not.
We should add a API for 'formatting NDEF' on the tag, and if the tag is not formatable this method should throw.
(Reporter)

Updated

3 years ago
Blocks: 1087925
(Reporter)

Updated

3 years ago
No longer blocks: 1087925
(Reporter)

Updated

3 years ago
Assignee: nobody → allstars.chh
(Reporter)

Updated

3 years ago
Assignee: allstars.chh → nobody
(Reporter)

Updated

3 years ago
No longer blocks: 1042851

Updated

3 years ago
Depends on: 1096821
(Assignee)

Updated

3 years ago
Assignee: nobody → jhao
(Assignee)

Comment 1

3 years ago
Created attachment 8522861 [details] [diff] [review]
Working-in-progress patch

I have imitated the api "makeReadOnly" and fill corresponding code for format(). As I am not familiar with both WebIDL and NFC, I need Dimi to help me check if I'm on the right track.
Flags: needinfo?(dlee)
Comment on attachment 8522861 [details] [diff] [review]
Working-in-progress patch

Review of attachment 8522861 [details] [diff] [review]:
-----------------------------------------------------------------

Hi Jonathan,
Looks good, thanks! I will provide nfcd for you to test later.
Once the test is complete, please find yoshi to review this patch.

::: dom/nfc/gonk/NfcGonkMessage.h
@@ +23,5 @@
>  enum NfcResponse {
>    GeneralRsp = 1000,
>    PowerRsp,
>    ReadNDEFRsp,
>  };

In this file, there is a define named NFCD_MINOR_VERSION, when the binary protocol is changed between
b2g process and nfcd, we will update it. You could increase it to 16 in this patch.

::: dom/nfc/nsINfcContentHelper.idl
@@ +77,5 @@
>  
>    nsIDOMDOMRequest readNDEF(in DOMString sessionToken);
>    nsIDOMDOMRequest writeNDEF(in nsIVariant records, in DOMString sessionToken);
>    nsIDOMDOMRequest makeReadOnly(in DOMString sessionToken);
> +  nsIDOMDOMRequest format(in DOMString sessionToken);

please also update the uuid
Attachment #8522861 - Flags: feedback+

Updated

3 years ago
Flags: needinfo?(dlee)
(Assignee)

Comment 4

3 years ago
Created attachment 8523797 [details] [diff] [review]
Add format API

I have tested with the following code in gaia/apps/system/js/nfc_handler.js

>  NfcHandler.prototype = {
>    start: function nh_start() {
>      if (window.navigator.mozNfc) {
>        window.navigator.mozNfc.onpeerready = this.handleEvent.bind(this);
>        window.navigator.mozNfc.ontagfound = function (evt) {
>          dump('ontagfound');
>          var req = evt.tag.format();
>          req.onsuccess = function () { dump('format successfully'); };
>          req.onerror = function () { dump('format error'); };
>        };
>      }
>    },

and in the log we can see the format is successful.

> I/GeckoDump(27614): format successfully
Attachment #8522861 - Attachment is obsolete: true
Attachment #8523797 - Flags: review?(allstars.chh)
Comment on attachment 8523797 [details] [diff] [review]
Add format API

Review of attachment 8523797 [details] [diff] [review]:
-----------------------------------------------------------------

Please update the patch subject.

Forward r? to smaug for WebIDL change in MozNFCTag.webidl.
Attachment #8523797 - Flags: review?(bugs)
Attachment #8523797 - Flags: review?(allstars.chh)
Attachment #8523797 - Flags: review+

Comment 6

3 years ago
Comment on attachment 8523797 [details] [diff] [review]
Add format API

Would it be useful to have a boolean attribute which tells whether the Tag is formattable?
Attachment #8523797 - Flags: review?(bugs) → review+
(Assignee)

Comment 7

3 years ago
(In reply to Olli Pettay [:smaug] from comment #6)
> Comment on attachment 8523797 [details] [diff] [review]
> Add format API
> 
> Would it be useful to have a boolean attribute which tells whether the Tag
> is formattable?

Hi Olli, I think what you proposed is already in MozNFCTag.webidl.
http://dxr.mozilla.org/mozilla-central/source/dom/webidl/MozNFCTag.webidl?from=moznfctag.webidl#62
(Assignee)

Comment 8

3 years ago
Created attachment 8524211 [details] [diff] [review]
Add format API

Add patch subject.
Attachment #8523797 - Attachment is obsolete: true
(Assignee)

Comment 9

3 years ago
Created attachment 8524230 [details] [diff] [review]
Add format API

Add "return true;" in the end of NfcMessageHandler::FormatRequest()
Attachment #8524211 - Attachment is obsolete: true
(In reply to Jonathan Hao [:jhao] from comment #7)
> 
> Hi Olli, I think what you proposed is already in MozNFCTag.webidl.
> http://dxr.mozilla.org/mozilla-central/source/dom/webidl/MozNFCTag.
> webidl?from=moznfctag.webidl#62
So it is!
(Assignee)

Updated

3 years ago
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/5f4ab7ea04cd
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
(Reporter)

Updated

3 years ago
Blocks: 1042851
You need to log in before you can comment on or make changes to this bug.