From 1babe6b3c89b0328c9aca4dc1bf0f61bdfde5365 Mon Sep 17 00:00:00 2001
From: Zoltan Kis The NFCRecord dictionary and
dictionary:
The kind
- property MUST return the NFCDataType
of the
+ property MUST return the NFCRecordType
of the
NDEF record.
@@ -1032,13 +1032,13 @@
- NFCDataType denotes the data types + NFCRecordType denotes the data types supported as NDEF record payload in read and send operations in this API.
-@@ -1417,6 +1417,9 @@
"tag"
,
+ If target has the value "tag"
,
then the sending should only happen if an NFC tag is
tapped, otherwise reject promise
"InvalidAccessError"
and terminate this algorithm.
"peer"
,
+ If target has the value "peer"
,
then the sending should only happen if an NFC peer is
tapped, otherwise reject promise with
"InvalidAccessError"
and terminate this algorithm.
"any"
+ If target has the value "any"
(which is the default value), then the sending should happen if
either an NFC peer or an NFC tag is tapped within
the specified timeout.
@@ -2101,10 +2104,15 @@ "SyntaxError"
,
and terminate this algorithm.
"SyntaxError"
, and terminate this algorithm.
+ - An NDEF record has a maximum payload of 2^32-1 bytes. The record - also contains information about the payload size, type, and an optional - identifier. NFC Forum standardized a small set of useful data types to be + The term NFC content is a synonym for NDEF message, + which can originate either from an NFC tag or an NFC peer. +
++ An NDEF record is a part of an NDEF message that has a + single associated type information to its payload. It is contains a + Type Name Format (TNF) field, the payload size, the payload type, an + optional identifier which is a URL, and a payload of maximum size of + 2^32-1 bytes. + The NFC Forum has standardized a small set of useful data types to be used in NDEF records, for instance text, URL, and binary data such as media. In addition, there are record types designed for more complex interactions, such as Smart Poster, and handover records.
- Part of the NDEF record is the TNF field, standing for - Type Name Format. It can take binary values representing the following + The TNF (Type Name Format) field of the NDEF record can + take binary values denoting the following NDEF record payload types:
"opaque" | -IANA media type | +IANA media type | ArrayBuffer or typed array |
Media-type as defined in [[RFC2046]] (TNF=2) | ||
Media-type as defined in [[RFC2046]] (TNF=2) with associated
- IANA media type "application/json" or
+ IANA media type> "application/json" or
"application/*-json"
|
"json" | -The IANA media type used in the NDEF record | +The IANA media type used in the NDEF record |
null or DOMString or Number or
Object
@@ -1211,7 +1214,7 @@
| ||
Media-type as defined in [[RFC2046]] (TNF=2) | "opaque" | -The IANA media type used in the NDEF record | +The IANA media type used in the NDEF record | ArrayBuffer |
||
The mapping from NDEF record types to NFCRecord
,
- as used for incoming NDEF messages described by the
- receiving NFC content algorithm is as
+ as used for incoming NDEF messages described in the
+ Receiving and parsing content section, is as
follows:
Media-type as defined in [[RFC2046]] (TNF=2) with associated
- IANA media type> "application/json" or
+ IANA media type "application/json" or
"application/*-json"
|
"json" | @@ -1252,42 +1255,34 @@
- An NFC watch is a mechanism used for listening to and filtering - Web NFC messages. It is defined in more detail in - The watch() method section. + An NFC watch is a mechanism used to watch for available + Web NFC messages fulfilling certain criteria. + It is defined in more detail in The watch() + method section.
- A Web NFC record is a special NDEF record of External Type - specific to W3C Web NFC, which indicates that the containing - NDEF message is targeted for browsing contexts using this API + A Web NFC record is an NDEF record of External Type, + specific to Web NFC. It indicates that the containing NDEF message + is targeted for browsing contexts using this API and contains information useful for handling the NDEF message with - the algorithms defined in this API. - The format of a Web NFC record is the following: + the algorithms defined in this specification. + The format of a Web NFC record is as follows:
The Web NFC Id is a URL according to
[[RFC3986]], with "https"
scheme, and an
- ASCII serialized origin optionally followed by a URL path.
- It is used for matching Web NFC content with URL patterns
+ ASCII serialized origin, optionally followed by a URL path.
+ This allows matching Web NFC content with URL patterns
specified by NFC watches.
@@ -452,13 +453,13 @@
The term Web NFC content denotes all Web NFC messages - contained in an NDEF message, identified by their Web NFC Id + contained within an NDEF message, identified by the Web NFC Id within the NDEF message. This version of the specification supports one Web NFC message per NDEF message.
As part of the NDEF record, an NDEF Id field may be - present, which is meant for applications use. According to the + present for application specific usages. According to the [[!NFC-STANDARDS]] it contains a URL with the maximum length of 256 octets. This URL is used for identifying the payload in an application specific way. Although the NDEF Id could be used for containing e.g. an @@ -467,8 +468,8 @@ record-level identification, since the message-level identification is handled by the Web NFC Id. Also, the content of the NDEF Id is also contained in the Web NFC Id, and since NFC tags are - rather small storages, this duplication is avoided in this version. - When multiple Web NFC messages will be eventually supported within a + rather small storage units, this duplication is avoided in this version. + When multiple Web NFC messages eventually will be supported within a single NDEF message, it would likely use the NDEF Id to store the same identifier for each NDEF record which is part of a given Web NFC message, which identifier will likely be an @@ -477,7 +478,7 @@
The term trusted integrity NFC content refers to an NDEF message, or an NDEF record, which can be trusted for - data integrity, i.e. the content is not changed by third party between + data integrity, i.e. the content is not changed by third parties between writing and reading.
@@ -497,16 +498,15 @@ In general, there are three groups of user scenarios for NFC:
In addition to data types standardized for NDEF records by the NFC - Forum, many commercial products, e.g. bus cards, door openers etc, use + Forum, many commercial products such as bus cards, door openers etc use different card specific data and protocol extensions which require specific - NFC chips (same vendor of card and reader) in order to work. + NFC chips (same vendor of card and reader) in order to function.
Card emulation mode capabilities also depend on the NFC chip in the device. @@ -601,64 +601,75 @@ This section shows how developers can make use of the various features of this specification.
-- var adapter = null; - var id = null; - navigator.nfc.requestAdapter().then((nfcAdapter) => { - id = adapter.watch({}, onMessage); - }; - - function onMessage(message, url) { - console.log("NDEF message received from URL " + url); - if (message[0].kind == 'empty') { - adapter.pushMessage([ - { kind: "text", type: "", data: “Initializing a passive tag”}]); - } ++ navigator.nfc.requestAdapter().then((adapter) => { + adapter.watch({}, (message, url) => { + console.log("NDEF message received from URL " + url); + if (message[0].kind == 'empty') { + adapter.pushMessage([ + { + kind: "text", + type: "", + data: "Initializing tag" + } + ]); + } + processMessage(message); + }); + }); + function processMessage(message) { message.forEach((record) => { if (record.kind == "string") { console.log(“Data is string: “ + data); } else if (record.kind == "json") { processJSON(record.data); } else if (record.kind == "url") { - console.log(“Data is URL: “ + record.data; + console.log("Data is URL: " + record.data; } else if (record.kind == "opaque") { processBinary(data); }); }; function processBinary(data) { - console.log("Binary data we know being a string: "); + console.log("Known (string) binary data: "); console.log(String.fromCharCode.apply(null, new Uint16Array(data))); }; function processJSON(data) { var obj = JSON.parse(data); - console.log("My data: " + obj.myProperty.toString()); + console.log("JSON data: " + obj.myProperty.toString()); };-+navigator.nfc.requestAdapter().then((adapter) => { - adapter.pushMessage([ - { kind: "text", type: "", data: “Data meant for peers”}]) - .then(() => { console.log("Message sent.")}) - .catch(() => {console.log("Send failed :'(, try again.")}); - }; + adapter.pushMessage([ + { + kind: "text", + type: "", + data: "Data meant for peers" + } + ]).then(() => { + console.log("Message sent.") + }).catch(() => { + console.log("Send failed :-( try again.") + }); + });navigator.nfc.requestAdapter().then((adapter) => { console.log("Awaiting game state"); - adapter.watch({ url: "*://mydomain/mygame/*"}, (message, url) => { + adapter.watch({ url: "*://mydomain/mygame/*" }, (message, url) => { console.log("Game state received from: " + url; console.log("Stored state: " + message.data); // Now do some calculations and then update the state. // ... adapter.pushMessage([ data: { level: 3, points: 4500, lives: 3 } ]) - .then(() => { console.log("We have stored your current game state.")}) - .catch(() => { console.log("Failed updating game state, try again.")}); + .then(() => { console.log("We have stored your current game state.") }) + .catch(() => { console.log("Failed updating game state, try again.") }); }; });From 768318ae40b82c964ed1cd38dde828fb7860eb23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=A8Kenneth?= <¨kenneth.r.christiansen@intel.com¨> Date: Fri, 11 Sep 2015 10:32:19 +0200 Subject: [PATCH 12/28] Factor out a sub-algorithm in accordance with Anssi --- index.html | 70 +++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/index.html b/index.html index ce8fe81..f2afb8e 100644 --- a/index.html +++ b/index.html @@ -1667,39 +1667,11 @@
"url"
, then
- execute the map URL to NDEF sub-steps, or ensure
- that the underlying platform provides equivalent values to
- ndef:
- string
,
- reject promise with
- "SyntaxError"
, and abort these steps.
- "url"
, then let ndef
+ the be result of passing record to map a URL to NDEF.
+ If this threw an exception, reject promise with that exception
+ and abort these steps.
"json"
, then
execute the map JSON to NDEF sub-steps, or ensure
@@ -1843,7 +1815,7 @@
+ To map a URL to NDEF given a record, run these steps: +
"SyntaxError"
exception and abort these steps.
+ This document defines conformance criteria that apply to a single - product: the UA that implements the interfaces it contains. + product: the UA that implements the interfaces it contains.
Implementations that use ECMAScript to implement the APIs defined in @@ -282,6 +282,14 @@ IANA media types (formerly known as MIME types) are defined in RFC2046.
++ The term queue + a task is defined in [[!HTML5]]. +
++ The term task + source is defined in [[!HTML5]]. +
The term expressed permission refers to an act by the user, e.g. via user interface or setting or host device platform features, using which @@ -1419,9 +1427,9 @@
- The NFCAdapter.pushMessage(message, options) method, - when invoked, MUST return a new promise promise and run the following - steps in parallel: + The NFCAdapter.pushMessage(message, options) + method, when invoked, MUST return a new promise promise + and run the following steps in parallel:
"web-only"
, and
+ If options.mode is "web-nfc-only"
, and
messageId is null, then skip to the next
NFC watch.
"web-only"
, and
+ Otherwise, if options.mode is "web-nfc-only"
, and
messageId is not null
, or if
options.mode is "all"
, then execute the
following sub-steps:
@@ -2483,9 +2491,11 @@ MessageCallback
+ callback with record as its first argument,
+ and messageId as its second argument. The task source
+ for the tasks queued by algorithms in this section is the
+ XXXXX task source.
"json"
, then
- execute the map JSON to NDEF sub-steps, or ensure
- that the underlying platform provides equivalent values to
- ndef:
- "string"
, or "number"
, or
- "object"
, reject promise with
- "SyntaxError"
, and abort these steps.
- "application/json"
, or any other
- IANA media type for JSON
- ("application/<type>+json"
), reject
- promise with "SyntaxError"
, and
- terminate this algorithm.
- "json"
, then let ndef
+ the be result of passing record to map a JSON object to NDEF.
+ If this threw an exception, reject promise with that exception
+ and abort these steps.
"opaque"
, then
execute the map binary to NDEF sub-steps, or ensure
@@ -1918,7 +1886,43 @@
Return ndef.
+ To map a JSON object to NDEF given a record, + run these steps: +
"TypeError"
exception and abort these steps.
+ "application/json"
, or any other
+ IANA media type for JSON
+ (starting with "application/"
and ending with
+ "+json"
), throw a "SyntaxError"
exception and
+ abort these steps.
+ "text"
, then
- execute the following steps, or make sure
- that the underlying platform provides equivalent values to
- ndef:
-
- This kind is useful when clients specifically want to write an
- NDEF Well Known Type Text record. Other options would be to
- use the value "opaque"
with an explicit
- IANA media type text type, which allows for better differentiation, e.g. when using "text/xml", or "text/vcard".
-
"string"
- or "number"
, reject promise
- with "SyntaxError"
, and abort these steps.
- "string"
- or starts with "text/"
, then
- reject promise with "SyntaxError"
,
- and abort these steps.
- In addition, UAs MAY check that
- record.type is an IANA registered media type
- for text. If not, then the UA MAY
- reject promise with "SyntaxError"
,
- terminate this algorithm.
- "en"
.
- If record.type includes a lang=
- parameter, detailing the language encoding (e.g.
- "text/plain; lang=fr"), then set language to
- the language code extracted from record.type.
- If language is not one of the language codes listed
- in the IANA language registry
- (or [[ISO-639.2]]),
- then UAs MAY reject promise with
- "SyntaxError"
, and abort these steps.
-
- Note that lang=
is not standard parameter
- to IANA media types, but it is used in this specification
- in order to maintain compatibility with NFC specifications.
-
"T"
- (value 0x54 following NFC binary encoding).
- "text"
, then let
+ ndef be the result of passing record
+ to map text to NDEF. If this threw an exception, reject
+ promise with that exception and abort these steps.
"url"
, then let ndef
the be result of passing record to map a URL to NDEF.
@@ -1706,21 +1617,15 @@
terminate this algorithm.
+ To map text to NDEF given a record, run these + steps: +
+ This kind is useful when clients specifically want to write an
+ NDEF Well Known Type Text record. Other options would be to
+ use the value "opaque"
with an explicit
+ IANA media type text type, which allows for better differentiation, e.g. when using "text/xml", or "text/vcard".
+
"SyntaxError"
exception, and abort these steps.
+
+ "text/"
, then throw a "SyntaxError"
exception,
+ and abort these steps.
+
+ In addition, UAs MAY check that
+ record.type is an IANA registered media type
+ for text.
+ If not, then the UA MAY throw a "SyntaxError"
exception,
+ and abort these steps.
+ "en"
.
+
+ If record.type includes a lang=
+ parameter, detailing the language encoding (e.g.
+ "text/plain; lang=fr"), then set language to
+ the language code extracted from record.type.
+
+ If language is not one of the language codes listed
+ in the IANA language registry
+ (or [[ISO-639.2]]), then UAs MAY throw a "SyntaxError"
+ exception, and abort these steps.
+
+
+ Note that lang=
is not standard parameter
+ to IANA media types, but it is used in this specification
+ in order to maintain compatibility with NFC specifications.
+
"T"
+ (value 0x54 following NFC binary encoding).
+ To map a URL to NDEF given a record, run these steps:
"TypeError"
exception and abort these steps.
+ Let data be the result of
+ serializing record.data
+ and if that throws, throw a "TypeError"
exception
+ and abort these steps.
typedef sequence<NFCRecord> NFCMessage;+ A Web NFC message is a valid Web NFC message if these steps + return success: +
dictionary NFCPushOptions { - NCPushTarget target; - unsigned long timeout; + NCPushTarget target = "any"; + unsigned long timeout = 10000; };
@@ -1430,19 +1437,31 @@
The NFCAdapter.pushMessage(message, options)
- method, when invoked, MUST return a new promise promise
- and run the following steps in parallel:
+ method, when invoked, MUST run the push a message algorithm.
+
+ To push a message given a message and options,
+ run the following steps:
- In future versions a list of "allowed-origins" may be
- supported.
- It is still up for discussions due to security issues. See the
-
- Security and Privacy document.
-
+ To map empty record to NDEF given a record, run
+ these steps:
+
To map text to NDEF given a record, run these
steps:
@@ -1769,7 +1722,7 @@
use the value
To map a URL to NDEF given a record, run these steps:
-
To map a JSON object to NDEF given a record,
run these steps:
-
+ To map binary data to NDEF given a record,
+ run these steps:
+
+ To create a Web NFC record, run these steps:
+
+ In future versions a list of "allowed-origins" may be
+ supported.
+ It is still up for discussions due to security issues. See the
+
+ Security and Privacy document.
+
The
@@ -2086,7 +2107,7 @@
The NFCWatchOptions.mode property tells
whether only Web NFC content or any NFC content will be
watched.
- The default value is
The
The NFC content to which clients listen can be filtered based on
@@ -2139,8 +2159,7 @@
When the
+ The concepts
+
+ task source and
+
+ queue a task are defined in [[!HTML5]].
+
The term
browsing context refers to the environment in which
@@ -286,7 +293,7 @@
The term queue
- a task is defined in [[!HTML5]].
+ a task is defined in [[!HTML5]].
The term task
@@ -933,12 +940,14 @@
mandate specific user prompting policies. The term obtain permission
is used for acquiring trust for a given operation.
- The Permissions API SHOULD
- be supported by UAs for implementing NFC related
- [[permissions]]. The required
+
+ The Permissions API is
+ suggested to be used by UAs for implementing NFC related
+ [[permissions]] in order to minimize the need for user prompting.
+ The suggested
- permission name is
@@ -1447,6 +1458,16 @@
Return a new promise promise, and then continue running this
algorithm in parallel.
+ Implementations are expected to clean up state on termination,
+ e.g. reset timer, clear output, etc.
+
- To map a URL to NDEF given a record, run these steps:
+ To map a URL to NDEF given a record, run these steps:
To create a Web NFC record, run these steps:
@@ -2228,7 +2235,8 @@
The NFCAdapter.pushMessage(message, options)
- method, when invoked, MUST run the push a message algorithm.
-
- To push a message given a message and options,
- run the following steps:
+ method, when invoked, MUST run the
+ push a message algorithm:
+ To obtain push permission, run these steps:
+
To map text to NDEF given a record, run these
steps:
@@ -2173,7 +2175,7 @@
- The ask for forgiveness interaction
- might show choices like "block now" or "block forever", etc. If the
- user has chosen to "block forever" the given origin, it
- is the responsibility of the UA to remember these user
- choices for each origin, regardless of which
- NFC adapter is used, and consult them on later invocations.
-
+ To obtain watch permission, run these steps:
+
+ The ask for forgiveness interaction
+ might show choices like "block now" or "block forever", etc.
+ If the user has chosen to "block forever" the given
+ origin, it is the responsibility of the UA to remember
+ these user choices for each origin, regardless of which
+ NFC adapter is used, and consult them on later invocations.
+
+ In this step UAs are advised to notify users about
+ that reading NFC content may indirectly reveal the physical
+ location of the user. In addition, if
- The concepts
-
- task source and
-
- queue a task are defined in [[!HTML5]].
-
The term
browsing context refers to the environment in which
@@ -612,7 +605,7 @@
This section shows how developers can make use of the various features of
@@ -1078,14 +1071,13 @@
The content of any Web NFC message is exposed by the following
sequence:
+ A Web NFC message is a valid Web NFC message if the
+ sequence of NFCRecord objects is not empty.
+
+ In other words, the current invocation of
- To map a URL to NDEF given a record, run these steps:
+ To map a URL to NDEF given a record, run these
+ steps:
This step also covers the case when the timer has already fired,
which also means that the message buffer is invalid, and is to be
@@ -2171,7 +2171,8 @@
NFCAdapter.watch() method is invoked, the UA MUST run
the following NFC watch algorithm:
- When the
The Web NFC Id is a URL according to
- [[RFC3986]], with
Web pages using the NFC API are not trusted.
This means that the user needs to be aware of exactly what a web page is
- intending to do with NFC at any given moment. Implementations SHOULD
- make sure that when the user authorizes an NFC operation, then only that
+ intending to do with NFC at any given moment. Implementations need to
+ make sure that when the user authorizes a method of this API, then only that
action is run, without side effects, and exactly in the context and the
- number of times the user allows the execution of NFC operations.
+ number of times the user allows the execution of NFC related operations,
+ according to the algorithmic steps detailed in this specification.
- The content of Web NFC messages is not trusted, unless the UA
- can safely assume that the content has not been change by third parties
- between writing and reading it, e.g. in the case of a
- prearranged trust relationship can be established.
+ The choice of trusting the integrity of NFC content when
+ used for implementing security policies, for instance the authenticity of
+ origins saved in the NDEF Id field, or that of the
+ URL path of the browsing context, and then used for
+ same-origin or allowed-origins policy by the UA, SHOULD be based on
+ prearranged trust relationship (such as encryption and other means),
+ otherwise the integrity of the content MUST NOT be trusted by UAs
+ and security policies MUST NOT be based on this.
- UAs MUST NOT provide Web NFC API access to browsing contexts
- without complying with the security policies described in this document.
-
This specification attempts to help minimizing the user prompts needed to
use the Web NFC API and tries to involve implicit policies which can
address the
@@ -944,23 +945,6 @@
This allows saving user permissions for a given origin in a
persistent database until revocation.
- UAs MUST acquire user consent, i.e. expressed permission for
- for using the methods of this API, unless a
- prearranged trust relationship applies, or unless an implicit policy
- specified in this document allows it, eventually with an
- ask for forgiveness indication.
-
- The choice of trusting the integrity of NFC content when
- used for implementing security policies, for instance the authenticity of
- origins saved in the NDEF Id field, or that of the
- URL path of the browsing context, and then used for
- same-origin or allowed-origins policy by the UA, SHOULD be based on
- prearranged trust relationship (such as encryption and other means),
- otherwise the integrity of the content MUST NOT be trusted by UAs
- and security policies MUST NOT be based on this.
-
All expressed permissions that are preserved beyond the current
browsing session MUST be revocable.
@@ -1074,10 +1058,6 @@
- A Web NFC message is a valid Web NFC message if the
- sequence of NFCRecord objects is not empty.
-
- The
+ This method enables listening to incoming NDEF messages.
The NFC content to which clients listen can be filtered based on
its data type, and based on the URL path of the
browsing context which has been saved to the Web NFC record
@@ -2156,10 +2131,11 @@
Watch filters are grouped by NFC adapter.
+
When the
When the
If there are any NFC watches set up for any NFC adapter, then
UAs MUST listen to NDEF messages, according to step 9
- of the NFC watch algorithm.
+ of the NFC watch algorithm.
When the UA is to receive an NDEF message it MUST run the
following algorithm:
The term
browsing context refers to the environment in which
@@ -184,6 +164,10 @@
web page, or an
iframe.
+ The term
+ top-level browsing context is defined in [[!HTML5]].
+
The term
@@ -284,6 +268,10 @@
IANA media types (formerly known as MIME types) are defined in
RFC2046.
+ A
+ valid MIME type is defined in [[!HTML5]].
+
The term queue
a task is defined in [[!HTML5]].
@@ -292,6 +280,7 @@
The term task
source is defined in [[!HTML5]].
The term expressed permission refers to an act by the user, e.g.
via user interface or setting or host device platform features, using which
@@ -318,6 +307,8 @@
asks for forgiveness, or ensured a
prearranged trust relationship exists.
NFC stands for Near Field Communications, short-range wireless
technology operating at 13.56 MHz which enables communication between
@@ -500,6 +491,7 @@
to the other device, printing to a Bluetooth printer or streaming video to
a television set.
- Web pages using the NFC API are not trusted.
+ Web pages using the Web NFC API are not trusted.
This means that the user needs to be aware of exactly what a web page is
intending to do with NFC at any given moment. Implementations need to
make sure that when the user authorizes a method of this API, then only that
@@ -890,14 +860,11 @@
according to the algorithmic steps detailed in this specification.
- The choice of trusting the integrity of NFC content when
+ The integrity of NFC content SHOULD NOT be trusted when
used for implementing security policies, for instance the authenticity of
- origins saved in the NDEF Id field, or that of the
- URL path of the browsing context, and then used for
- same-origin or allowed-origins policy by the UA, SHOULD be based on
- prearranged trust relationship (such as encryption and other means),
- otherwise the integrity of the content MUST NOT be trusted by UAs
- and security policies MUST NOT be based on this.
+ origins saved in the NDEF Id field, unless a
+ prearranged trust relationship (such as encryption and other means)
+ exists.
- UAs MUST implement the following policies:
-
+ This section summarizes the security policies which are specified as
+ normative requirements in the respective algorithms of this
+ specification:
+
As a consequence, since every access from a browsing context
needs the attention of the user, and since the user must do a physical
@@ -981,58 +950,53 @@
The NFCRecord.kind
- property MUST return the
The NFCRecord.type
- property MUST return the IANA media type of the NDEF record
+ property represents the IANA media type of the NDEF record
payload.
- The NFCRecord.data property MUST return the
+ The NFCRecord.data property represents the
payload data of the NDEF record with an appropriate ECMAScript
type, which depends on the IANA media type.
+ A valid NFCRecord record is an instance of
+
- When getting the nfc attribute, the
- UA MUST return the NFC object, which provides
- NFC related functionality.
+ On getting the nfc attribute, the UA MUST return the NFC
+ object, which provides NFC related functionality.
This is a placeholder for a possible future feature. In this step,
implementations MAY check if the origin of the
@@ -2311,6 +2297,7 @@
- Implementations are expected to clean up state on termination,
- e.g. reset timer, clear output, etc.
-
+ In other words, the current invocation of
+ Implementations are expected to clean up state on termination,
+ e.g. reset timer, clear output, etc.
+
- In other words, the current invocation of
@@ -1382,8 +1382,8 @@
The NFCPushOptions.timeout property
denotes the timeout for the pending The pushMessage() method
+
"SecurityError"
, and abort these steps.
"NotSupportedError"
, and abort these steps.
+ An implementation MAY reject promise with
+ "NotSupportedError"
, and abort these steps.
+ NFCRecord
objects, reject
- promise with "SyntaxError"
,
+ If the message parameter is not a valid Web NFC message,
+ reject promise with "SyntaxError"
,
and abort these steps.
NFCPushOptions
object with the default values.
"peer"
- and already there is a message set for sending by a previous
- invocation of pushMessage()
targeted for
- "any"
, reject promise with
- "SyntaxError"
, and abort these steps.
- "any"
- and already there is a message set for sending by a previous
- invocation of pushMessage()
targeted for
- "tag"
or "peer"
, then
- reject promise with "SyntaxError"
,
- and abort these steps.
- "tag"
- and already there is a message set for sending by a previous
- invocation of pushMessage()
targeted for
- "any"
, then reject promise with
- "SyntaxError"
, and abort these steps.
- pushMessage()
, then execute the following
- sub-steps:
-
-
- In other words, the current invocation of pushMessage()
.
- pushMessage()
with "AbortError"
.
- pushMessage()
- rejects and replaces eventual previous invocations if the
- options.target is the same as for the previous invocation.
+ If there are any existing instance of this algorithm running
+ whose target equal to options.target or
+ "any"
, reject the promise of these with
+ "AbortError"
.
+ pushMessage()
+ rejects and replaces existing running invocations handling the same
+ options.target. As "any"
handles both
+ "peer"
and "tag"
, existing running invocations for
+ "any"
always gets rejected.
+ pushMessage()
.
-
"empty"
, then
- execute the following steps:
- NFCMessage
output to
- contain only the current empty record record,
- and continue with step 11.
+ Skip the remaining substeps for the sequence message.
"text"
, then let
ndef be the result of passing record
to map text to NDEF. If this threw an exception, reject
promise with that exception and abort these steps.
"url"
, then let ndef
the be result of passing record to map a URL to NDEF.
If this threw an exception, reject promise with that exception
and abort these steps.
"json"
, then let ndef
the be result of passing record to map a JSON object to NDEF.
If this threw an exception, reject promise with that exception
and abort these steps.
"opaque"
, then
- execute the map binary to NDEF sub-steps, or ensure
- that the underlying platform provides equivalent values to
- ndef:
-
-
+ ArrayBuffer
, reject promise with
- "SyntaxError"
, and abort these steps.
- "SyntaxError"
, and
- terminate this algorithm.
- "opaque"
, then let ndef
+ the be result of passing record to map binary data to NDEF.
+ If this threw an exception, reject promise with that exception
+ and abort these steps.
undefined
,
@@ -1637,20 +1583,20 @@
If record.data is instance of
ArrayBuffer
, then set record.type to
"application/octet-stream"
and execute the
- map binary to NDEF
+ map binary data to NDEF
steps.
"object"
, then set record.type to
"application/json"
and execute the
- map JSON to NDEF steps.
+ map a JSON object to NDEF steps.
"number"
or "string"
, then
set record.type to "plain/text"
and
- execute the
+ execute the
map text to NDEF steps.
-
- "urn:nfc:ext:w3.org:webnfc"
.
- pushMessage()
.
+
+
+
"opaque"
with an explicit
IANA media type text type, which allows for better differentiation, e.g. when using "text/xml", or "text/vcard".
+
+
"SyntaxError"
exception, and abort these steps.
@@ -1804,6 +1757,10 @@
in order to maintain compatibility with NFC specifications.
+
+
"SyntaxError"
exception and abort these steps.
@@ -1879,15 +1836,15 @@
+
+
+
+
"TypeError"
exception
and abort these steps.
+
+
+ ArrayBuffer
, reject promise with
+ "SyntaxError"
, and abort these steps.
+
+ "SyntaxError"
exceeption and abort these steps.
+
+
"urn:nfc:ext:w3.org:webnfc"
.
+ The cancelPush() method
- cancelPush
+ NFCAcapter.cancelPush
method is used for resetting the NDEF message set to be pushed
next time an NFC device comes in range.
dictionary NFCWatchOptions {
- USVString url;
- USVString kind;
- USVString type;
- NFCWatchMode mode;
+ USVString url = null;
+ USVString kind = null;
+ USVString type = null;
+ NFCWatchMode mode = "web-nfc-only";
};
"web-only"
.
+ The default value is "web-nfc-only"
.
The watch() method
-
- watch(options, callback)
method enables listening to incoming
- NDEF messages.
+ NFCAdapter.watch(options, callback)
+ method enables listening to incoming NDEF messages.
-
- watch()
method is invoked, the UA MUST run
+ NFCAdapter.watch() method is invoked, the UA MUST run
the following NFC watch algorithm:
Promise
object.
From 20e8f4f19b60c2536a50b0dfdb055859e67e1778 Mon Sep 17 00:00:00 2001
From: Zoltan Kis "nfc"
.
+ permission name is
+ "nfc"
.
This allows saving user permissions for a given origin in a
persistent database until revocation.
getAdapter
+ When requesting an NFC adapter by the requestAdapter
method, or when setting up listeners for reading, or when sending
NFC content, the UA MAY warn the user that
physical location may be inferred from the act of using NFC by the
@@ -1278,9 +1287,11 @@
Navigator
interface [HTML] which this specification
extends.
-
-
+
+ partial interface Navigator {
+ readonly attribute NFC nfc;
+ };
+
The nfc attribute
"AbortError"
.
+
"NotSupportedError"
, and abort these steps.
pushMessage()
rejects and replaces existing running invocations handling the same
options.target. As "any"
handles both
- "peer"
and "tag"
, existing running invocations for
+ "peer" and "tag"
, existing running invocations for
"any"
always gets rejected.
"text"
, then let
+ If record.kind is "text"
, then let
ndef be the result of passing record
to map text to NDEF. If this threw an exception, reject
promise with that exception and abort these steps.
@@ -1621,20 +1642,6 @@
Let timer be a new timer associated with this invocation
of pushMessage()
.
pushMessage()
method replaces the previously set
- push message and resets the associated timer.
- "TimeoutError"
and abort these steps.
@@ -1734,7 +1741,7 @@
In addition, UAs MAY check that
record.type is an IANA registered media type
- for text.
+ for text.
If not, then the UA MAY throw a "SyntaxError"
exception,
and abort these steps.
+
Receiving and parsing content
MessageCallback
callback with record as its first argument,
- and messageId as its second argument. The task source
- for the tasks queued by algorithms in this section is the
- XXXXX task source.
+ and messageId as its second argument.
+ The task source for the tasks queued by algorithms in
+ this section is the Web NFC task source.
Receiving and parsing content
The editors would like to express their gratitude to the former editors
Luc Yriarte and Samuel Ortiz, and also to Don Coleman, Anne van Kesteren,
Domenic Denicola, Jonas Sickling, Jeffrey Yasskin, Alexander Shalamov,
- Salvatore Iovene, and Rijubrata Bhaumik for their technical guidance,
- implementation feedback and support.
+ Salvatore Iovene, Rijubrata Bhaumik and Anssi Kostiainen for their technical
+ guidance, implementation feedback and support.
From 622588061720d9155bac2694b6ed671bdc35a60d Mon Sep 17 00:00:00 2001
From: Zoltan Kis The pushMessage() method
+
-
+ If the obtain push permission steps return
+ "SecurityError"
, and abort these steps.
- false
, then reject promise with
+ "SecurityError"
, and abort these steps.
"SyntaxError"
,
and abort these steps.
+
+
true
.
+ true
.
+ true
.
+ false
.
+ false
, then reject promise with
"SecurityError"
, and abort these steps.
"all"
, then also include in this information that the
- origin is requesting to read all NFC content, not only
- those meant for web pages.
- "SecurityError"
, and abort these steps.
- "SyntaxError"
,
@@ -2258,6 +2234,44 @@
+
+
watch()
as well,
+ then return false
.
+ true
.
+ "any"
+ NfcWatchMode
is used, then also include in this
+ information that the origin is requesting to read not only
+ NFC content meant for web pages, but any NFC content.
+ true
.
+ Examples
typedef sequence<NFCRecord> NFCMessage;
- A Web NFC message is a valid Web NFC message if these steps
- return success:
-
-
+
+ typedef sequence<NFCRecord> NFCMessage;
+
+ The NFCRecord dictionary
@@ -1511,13 +1503,13 @@
whose target equal to options.target or
"any"
, reject the promise of these with
"AbortError"
.
- pushMessage()
- rejects and replaces existing running invocations handling the same
- options.target. As "any"
handles both
- "peer"
and "tag"
, existing running invocations for
- "any"
always gets rejected.
- pushMessage()
+ rejects and replaces existing running invocations handling the same
+ options.target. As "any"
handles both
+ "peer"
and "tag"
, existing running invocations
+ for "any"
always gets rejected.
+ "empty"
, then
"url"
, then let ndef
- the be result of passing record to map a URL to NDEF.
- If this threw an exception, reject promise with that exception
- and abort these steps.
+ If record.kind is "url"
, then let
+ ndef the be result of passing record to
+ map a URL to NDEF.
+ If this threw an exception, reject promise with that
+ exception and abort these steps.
"json"
, then let ndef
- the be result of passing record to map a JSON object to NDEF.
- If this threw an exception, reject promise with that exception
- and abort these steps.
+ If record.kind is "json"
, then let
+ ndef the be result of passing record to
+ map a JSON object to NDEF.
+ If this threw an exception, reject promise with that
+ exception and abort these steps.
"opaque"
, then let ndef
- the be result of passing record to map binary data to NDEF.
- If this threw an exception, reject promise with that exception
- and abort these steps.
+ If record.kind is "opaque"
, then let
+ ndef the be result of passing record to
+ map binary data to NDEF.
+ If this threw an exception, reject promise with that
+ exception and abort these steps.
undefined
,
@@ -1606,8 +1603,8 @@
"opaque"
with an explicit
- IANA media type text type, which allows for better differentiation, e.g. when using "text/xml", or "text/vcard".
+ IANA media type text type, which allows for better
+ differentiation, e.g. when using "text/xml", or "text/vcard".
"SyntaxError"
exception,
- and abort these steps.
+ If not, then the UA MAY throw a "SyntaxError"
+ exception, and abort these steps.
"en"
.
@@ -1817,7 +1815,8 @@
pushMessage()
algorithm,
- or no active timers associated with it, then terminate this algorithm.
+ or no active timers associated with it, then terminate this
+ algorithm.
-
Promise
object.
+ Promise
object.
"NotSupportedError"
, and abort these steps.
The unwatch() method
NFCAdapter.unwatch(id)
method is invoked,
- the UA MUST return a promise promise and run the following
- steps in parallel.
+ When the NFCAdapter.unwatch(id)
method is
+ invoked, the UA MUST return a promise promise and run the
+ following steps in parallel.
Receiving and parsing content
If there are any NFC watches set up for any NFC adapter, then
UAs MUST listen to NDEF messages, according to step 9
of the NFC watch algorithm.
- When the UA is to receive an NDEF message it MUST run the following
- algorithm:
+ When the UA is to receive an NDEF message it MUST run the
+ following algorithm:
Receiving and parsing content
Receiving and parsing content
ndef.PAYLOAD.
Receiving and parsing content
ArrayBuffer
- object constructed from the octets of ndef.PAYLOAD.
+ object constructed from the octets of
+ ndef.PAYLOAD.
Receiving and parsing content
watch()
method, execute the following sub-steps:
+ For matching message against the registered
+ NFC watches, for each NFC watch watch that has
+ been registered using the watch()
method, execute the
+ following sub-steps:
NFCWatchOptions
@@ -2511,10 +2515,10 @@ Receiving and parsing content
NFC watch.
"web-nfc-only"
, and
- messageId is not null
, or if
- options.mode is "all"
, then execute the
- following sub-steps:
+ Otherwise, if options.mode is
+ "web-nfc-only"
, and messageId is not
+ null
, or if options.mode is
+ "any"
, then execute the following sub-steps:
Receiving and parsing content
MessageCallback
- callback with record as its first argument,
- and messageId as its second argument.
+ callback with record as its first
+ argument, and messageId as its second argument.
The task source for the tasks queued by algorithms in
this section is the Web NFC task source.
true
.
true
.
true
.
- false
.
watch()
as well,
- then return false
.
+ If there is a prearranged trust relationship,
+ return true
.
true
.
+ Otherwise, if the user has earlier denied permission for the calling
+ origin for all future calls of watch()
as well,
+ then return false
.
"https"
scheme, and an
- ASCII serialized origin, optionally followed by a URL path.
+ [[RFC3986]], specifically an ASCII serialized origin with
+ "https"
scheme, and optionally followed by a URL path.
This allows matching Web NFC content with URL patterns
specified by NFC watches.
Permissions and user prompts
typedef sequence<NFCRecord> NFCMessage;
- The NFCRecord dictionary
@@ -1178,7 +1158,7 @@
"opaque"
IANA media type
-
+ ArrayBuffer
or typed arrayArrayBuffer
Media-type as defined in [[RFC2046]] (TNF=2)
@@ -1444,8 +1424,8 @@
push a message algorithm:
@@ -1464,6 +1447,8 @@
Promise
promise, and
+ then continue running this algorithm in parallel.
"SecurityError"
, and abort these steps.
"SyntaxError"
,
and abort these steps.
The watch() method
- NFCAdapter.watch(options, callback)
- method enables listening to incoming NDEF messages.
-
- NFCAdapter.watch()
method is invoked, the UA MUST run
- the following NFC watch algorithm:
+ NFCAdapter.watch(options, callback)
+ method is invoked, the UA MUST run the following
+ NFC watch algorithm:
Promise
object.
@@ -2269,8 +2245,8 @@
The unwatch() method
NFCAdapter.unwatch(id)
method is
- invoked, the UA MUST return a promise promise and run the
- following steps in parallel.
+ invoked, the UA MUST return a Promise
+ promise and run the following steps in parallel.
Receiving and parsing content
From 6b308d2ae029ff21be24cccea27fb2ffe1dc40aa Mon Sep 17 00:00:00 2001
From: Zoltan Kis
Terminology
-
Security
NFC specific
Chain of trust
@@ -1074,19 +1042,38 @@
Security policies
-
+
-
+
+ Security policies
+
"https"
SHOULD be able to access
+ is starting with "https"
must be able to access
NFC content.
- Browsers MAY ignore this rule for development purposes only.
+ Browsers may ignore this rule for development purposes only.
Window
object associated with the
- active Document
of the browsing context using
- the Web NFC API MUST be visible and
- in focus. This also means that UAs
- SHOULD make sure the display is on, and the device is unlocked.
+ In order to use NFC, the top-level browsing context of the
+ Window
object using the Web NFC API must be
+ visible and in focus. This also means
+ that UAs should make sure the display is on, and the device is unlocked.
For web pages in background, receiving and sending NFC content
- MUST be suspended.
+ must be suspended.
requestAdapter
method, or when setting up listeners for reading, or when sending
- NFC content, the UA MAY warn the user that
+ NFC content, the UA may warn the user that
physical location may be inferred from the act of using NFC by the
origin of the reading browsing context.
NFCRecordType
of the
+ property represents the NFCRecordType
of the
NDEF record.
NFCRecord
which matches the following criteria:
+
+
+
NFCRecordType
, or undefined
.
+ undefined
.
+ null
, or of type
+ "string"
, or "number"
, or instance of
+ Object
, or ArrayBuffer
.
+ The NFCRecordType enum
@@ -1267,9 +1254,8 @@
The nfc attribute
NFCRecord
element in
+ message is not a valid NFCRecord, then
reject promise with "SyntaxError"
,
and abort these steps.
cancelPush()
algorithm.
cancelPush()
method is called.
+ If the top-level browsing context loses focus (e.g. the user
+ navigated to another page), then pending push operations MUST be
+ canceled by executing the
+ cancelPush()
steps.
Receiving and parsing content
When the UA is to receive an NDEF message it MUST run the
following algorithm:
+
Receiving and parsing content
input is trusted integrity NFC content, then
allowed-origin policies MAY be applied.
+ NFCRecord
objects.
@@ -2501,11 +2488,10 @@ Receiving and parsing content
record.type, then skip to the next NFC watch.
MessageCallback
+ Queue a task using the Web NFC task source
+ to invoke the MessageCallback
callback with record as its first
argument, and messageId as its second argument.
- The task source for the tasks queued by algorithms in
- this section is the Web NFC task source.
- "SyntaxError"
exceeption and abort these steps.
+ "SyntaxError" exception and abort these steps.
The NFCPushOptions dictionary
dictionary NFCPushOptions {
- NCPushTarget target = "any";
+ NFCPushTarget target = "any";
unsigned long timeout = 10000;
};
From 462526c69be123e3f68dbc35b683a00956ae6dde Mon Sep 17 00:00:00 2001
From: Kenneth Rohde Christiansen "any"
, abort that instance of this algorithm,
by rejecting its promise with
"AbortError"
.
- pushMessage()
+ rejects and replaces existing running invocations handling the same
+ options.target. As "any"
handles both
+ "peer"
and "tag"
, existing running invocations
+ for "any"
always gets rejected.
+ "SyntaxError"
,
and abort these steps.
"any"
, reject the promise of these with
- "AbortError"
.
- pushMessage()
- rejects and replaces existing running invocations handling the same
- options.target. As "any"
handles both
- "peer"
and "tag"
, existing running invocations
- for "any"
always gets rejected.
- "SecurityError"
,
and abort these steps.
+ "SecurityError"
, and abort these steps.
+
@@ -1913,6 +1919,9 @@
If the incumbent settings object is not a
secure context, reject promise with
"SecurityError"
, and abort these steps.
+ "SecurityError"
, and abort these steps.
+ "SecurityError"
, and abort these steps.
+ undefined
, then
From 57d0487d0e93ad0df7d09588980ac9f940b412e3 Mon Sep 17 00:00:00 2001
From: Kenneth Rohde Christiansen
dictionary NFCPushOptions {
NFCPushTarget target = "any";
- unsigned long timeout = 10000;
+ unsigned long timeout;
};
pushMessage()
- operation expressed in milliseconds. The default, and maximal value is
- 10000, i.e. 10 seconds. After the timeout expires, the
+ operation expressed in milliseconds. The default value is
+ implementation-dependent. After the timeout expires, the
message set for sending is cleared, an error is returned, and a new
Web NFC message can be set for sending.
pushMessage()
operation expressed in milliseconds. The default value is
- implementation-dependent. After the timeout expires, the
+ implementation-dependent. The value Infinity
means there is
+ no timeout. After the timeout expires, the
message set for sending is cleared, an error is returned, and a new
Web NFC message can be set for sending.
@@ -1394,7 +1395,7 @@
This section describes how to write an NDEF message
to an NFC tag or how to push it to an NFC peer
device next time when they get into proximity range, or until
- a timeout expires. At any time for there is at maximum two
+ a timeout expires. At any time there is at maximum two
Web NFC messages that can be set for sending for an origin:
one targeted to NFC tags and one to NFC peers.
When there is a Web NFC message set for sending
@@ -1470,7 +1471,9 @@
NFCPushOptions
- object with the default values.
+ object with the default values. If any of the
+ NFCPushOptions
properties are undefined, use
+ the default values.
NFCPushOptions
, then
@@ -1480,7 +1483,8 @@
pushMessage()
.
+ If options.timeout value is not valid or not supported
+ in the underlying platform, reject promise with
+ "SyntaxError"
, and abort these steps.
+ Infinity
,
+ let timer be a new timer associated with this invocation
+ of pushMessage()
, set to options.timeout,
+ and start timer. On any termination of this algorithm,
+ timer MUST be cleared.
"TimeoutError"
and abort these steps.
+ If timer exists and expires, reject promise
+ with "TimeoutError"
and abort these steps.