@@ -466,14 +466,15 @@ etc.
466
466
467
467
<h4 id="limit-max-frequency" dfn>Limit maximum sampling frequency</h4>
468
468
469
- User agents may mitigate certain threats by
470
- limiting the maximum [=sampling frequency=] .
469
+ User agents and [=extension specifications=] may mitigate certain threats by defining a [=sensor
470
+ type=] 's [=sensor type/maximum sampling frequency=] .
471
+
471
472
What upper limit to choose depends on the [=sensor type=] ,
472
473
the kind of threats the user agent is trying to protect against,
473
474
the expected resources of the attacker, etc.
474
475
475
- Limiting the maximum [= sampling frequency=] prevents use cases
476
- which rely on low latency or high data density.
476
+ Limiting the [=sensor type/maximum sampling frequency=] prevents use cases which rely on low
477
+ latency or high data density.
477
478
478
479
479
480
<h4 id="stop-sensor" dfn>Stop the sensor altogether</h4>
@@ -489,9 +490,9 @@ or in a different application.
489
490
490
491
An alternative to [=limit maximum sampling frequency|limiting the maximum sampling frequency=] is to
491
492
limit the number of [=sensor readings=] delivered to Web application developer,
492
- regardless of what frequency the sensor is polled at .
493
+ regardless of the [=sampling frequency=] .
493
494
This allows use cases which have low latency requirement
494
- to increase [=sampling frequency=]
495
+ to increase the [=sampling frequency=]
495
496
without increasing the amount of data provided.
496
497
497
498
Discarding intermediary readings prevents certain use cases,
@@ -721,33 +722,57 @@ define ways to uniquely identify each one.
721
722
722
723
## Sampling Frequency and Reporting Frequency ## {#concepts-sampling-and-reporting-frequencies}
723
724
724
- For the purpose of this specification, <dfn>sampling frequency</dfn> for a [=platform sensor=] is
725
- defined as a frequency at which the user agent obtains [=sensor readings=] from the underlying
726
- platform.
725
+ For the purpose of this specification, a [=platform sensor=] 's <dfn>sampling frequency</dfn> is
726
+ defined as a frequency at which a [=platform sensor=] obtains [=sensor readings=] from the
727
+ underlying [=device sensor=] . The way such [=sensor readings=] are obtained is
728
+ [=implementation-defined=] .
729
+
730
+ The [=platform sensor=] 's [=sampling frequency=] may not correspond to the [=device sensor=]' s
731
+ actual sampling rate, which, for the purpose of this specification, is opaque.
732
+
733
+ Note: System-level APIs for [=sensor readings=] and the underlying hardware interface to the sensors
734
+ themselves may be built for polling or events. For a polling-based [=device sensor=] , the [=platform
735
+ sensor=] 's [=sampling frequency=] would be the rate at which a new reading is requested from the
736
+ system or hardware. For an event-based [=device sensor=] , a [=platform sensor=] provides a requested
737
+ sampling frequency to the system or hardware, and events are generated at that frequency or below.
738
+ Events may not be generated if the sensor reading has not changed.
739
+
740
+ A [=device sensor=] may provide bounds for the sampling frequency value it can accept from a
741
+ [=platform sensor=] in the form of a <dfn for="device sensor">minimum sampling frequency</dfn> and a
742
+ <dfn for= "device sensor">maximum sampling frequency</dfn> . A [=platform sensor=] 's [=sampling
743
+ frequency=] must not be less than the [=device sensor=] 's [=device sensor/minimum sampling
744
+ frequency=] or greater than its [=device sensor/maximum sampling frequency=] .
745
+
746
+ A [=platform sensor=] 's [=sampling frequency=] is determined based on the provided
747
+ {{Sensor/[[frequency]]}} of the [=set/items=] in its [=ordered set|set=] of [=activated sensor
748
+ objects=] . The calculation is [=implementation-defined=] , but the outcome value must lie within the
749
+ bounds set by the [=platform sensor=] 's [=sensor type=]' s [=sensor type/minimum sampling
750
+ frequency|minimum=] and [=sensor type/maximum sampling frequency|maximum=] sampling frequencies and
751
+ its [=device sensor=] 's [=device sensor/minimum sampling frequency|minimum=] and [=device
752
+ sensor/maximum sampling frequency|maximum=] sampling frequencies.
753
+
754
+ Note: For example, the user agent may estimate the [=sampling frequency=] as a Least Common
755
+ Denominator (LCD) for a set of provided {{Sensor/[[frequency]]}} capped by [=sampling frequency=]
756
+ bounds defined by the underlying platform.
727
757
728
- The user agent can request the underlying platform to deliver [=sensor readings|readings=] at a certain
729
- rate which is called <dfn>requested sampling frequency</dfn> .
758
+ The <dfn>reporting frequency</dfn> for a concrete {{Sensor}} object is defined as a frequency at which
759
+ the "reading" event is [=fire an event|fired=] at this object .
730
760
731
- The [=sampling frequency=] is equal to the [=requested sampling frequency=] if the underlying platform
732
- can support it.
761
+ A {{Sensor}} object cannot access new [=sensor readings|readings=] at a higher rate than the
762
+ user agent obtains them from the underlying platform, therefore the [=reporting frequency=] can
763
+ never exceed a [=platform sensor=] 's [=sampling frequency=] , which in turn can never exceed a
764
+ [=device sensor=] 's [=device sensor/maximum sampling frequency=] (when specified).
733
765
734
- The [=sampling frequency=] differs from the [=requested sampling frequency=] in the following cases :
735
- - the [= requested sampling frequency=] exceeds upper or lower [=sampling frequency=] bounds
736
- supported by the underlying platform.
766
+ The [=reporting frequency=] differs from the {{Sensor}} 's {{Sensor/[[ frequency]]}} in cases such as :
767
+ - the requested {{Sensor/[[ frequency]]}} lies outside the bounds returned by invoking [=get a
768
+ platform sensor's sampling bounds=] with {{Sensor}} 's associated [= platform sensor=] .
737
769
- the operating system and/or the [=device sensor=] automatically discard
738
770
readings that do not differ enough (in absolute or relative terms) from the
739
771
previously reported ones via a hardware or operating system filter.
740
- - the [=platform sensor=] 's associated [=sensor type=]' s [=threshold check
772
+ - the {{Sensor}} instance 's associated [=sensor type=] 's [=threshold check
741
773
algorithm=] fails and the [=platform sensor=] 's [=latest readings=] are not
742
774
updated.
743
775
744
- The <dfn>reporting frequency</dfn> for a concrete {{Sensor}} object is defined as a frequency at which
745
- the "reading" event is [=fire an event|fired=] at this object.
746
-
747
- A {{Sensor}} object cannot access new [=sensor readings|readings=] at a higher rate than the
748
- user agent obtains them from the underlying platform, therefore the [=reporting frequency=] can
749
- never exceed the [=sampling frequency=] for the given [=sensor type=] .
750
-
751
776
## Conditions to expose sensor readings ## {#concepts-can-expose-sensor-readings}
752
777
753
778
The user agent <dfn>can expose sensor readings</dfn> to a given |document| if and only if
@@ -781,6 +806,15 @@ A <dfn>sensor type</dfn> must have the following associated data:
781
806
- A [=set/is empty|non-empty=] [=ordered set=] of associated [=policy-controlled feature=] tokens
782
807
referred to as <dfn export>sensor feature names</dfn> .
783
808
- A [=permission revocation algorithm=] .
809
+ - A <dfn export for="sensor type">minimum sampling frequency</dfn> , a positive number. It is either
810
+ [=implementation-defined=] or defined by an [=extension specification=] . If both are set, the
811
+ largest value is used.
812
+ - A <dfn export for="sensor type">maximum sampling frequency</dfn> , a positive number. It is either
813
+ [=implementation-defined=] or defined by an [=extension specification=] . If both are set, the
814
+ smallest value is used.
815
+
816
+ The [=sensor type/minimum sampling frequency=] must not be greater than the [=sensor type/maximum
817
+ sampling frequency=] .
784
818
785
819
A [=sensor type=] may have the following associated data:
786
820
- A [=default sensor=] .
@@ -839,17 +873,19 @@ Note: There are additional privacy concerns when using cached [=sensor readings|
839
873
which predate either [=navigating=] to resources in the current [=origin=] ,
840
874
or being granted permission to access the [=platform sensor=] . -->
841
875
842
- A [=platform sensor=] has an associated [=requested sampling frequency=] which is initially null.
843
-
844
- For a non-[=set/is empty|empty=] [=ordered set|set=] of [=activated sensor objects=] the
845
- [=requested sampling frequency=] is equal to the <dfn>optimal sampling frequency</dfn> , which is estimated
846
- by the user agent by taking into account the {{[[frequency]]|provided frequencies}}
847
- of [=activated sensor objects|activated=] {{Sensor|Sensors}} and the [=sampling frequency=] bounds
848
- defined by the underlying platform.
849
-
850
- Note: For example, the user agent may estimate [=optimal sampling frequency=] as a Least Common
851
- Denominator (LCD) for a set of {{[[frequency]]|provided frequencies}} capped
852
- by [=sampling frequency=] bounds defined by the underlying platform.
876
+ <div algorithm>
877
+ To <dfn>get a platform sensor's sampling bounds</dfn> given a [=platform sensor=]
878
+ |platformSensor|:
879
+ 1. Let |minimumFrequency| be |platformSensor|'s [=sensor type=]' s [=sensor type/minimum sampling
880
+ frequency=] .
881
+ 1. If |platformSensor|'s connected [=device sensor=] has a [=device sensor/minimum sampling
882
+ frequency=] , set |minimumFrequency| to the maximum of |minimumFrequency| and this value.
883
+ 1. Let |maximumFrequency| be |platformSensor|'s [=sensor type=]' s [=sensor type/maximum sampling
884
+ frequency=] .
885
+ 1. If |platformSensor|'s connected [=device sensor=] has a [=device sensor/maximum sampling
886
+ frequency=] , set |maximumFrequency| to the minimum of |maximumFrequency| and this value.
887
+ 1. Return a [=tuple=] (|minimumFrequency|, |maximumFrequency|).
888
+ </div>
853
889
854
890
<div class=example>
855
891
@@ -866,7 +902,7 @@ The {{Sensor}} object in "idle" [[#sensor-lifecycle|state]] is not among the [=p
866
902
In this example there is a [=platform sensor=] instance per [=browsing context=] .
867
903
868
904
The [=latest reading=] [=ordered map|map=] is shared between {{Sensor}} objects from the
869
- same [=browsing context|context=] and is updated at a rate equal to the [= requested sampling frequency=]
905
+ same [=browsing context|context=] and is updated at a rate equal to the requested [= sampling frequency=]
870
906
of the corresponding [=platform sensor=] .
871
907
872
908
</div>
@@ -1063,12 +1099,10 @@ with the internal slots described in the following table:
1063
1099
<tr>
1064
1100
<td> <dfn attribute for=Sensor>\[[frequency]]</dfn> </td>
1065
1101
<td> A double representing frequency in Hz that is used to calculate
1066
- the [=requested sampling frequency=] for the associated [=platform sensor=]
1102
+ the [=sampling frequency=] for the associated [=platform sensor=]
1067
1103
and to define the upper bound of the [=reporting frequency=] for this
1068
- {{Sensor}} object.
1069
-
1070
- This slot holds the provided {{SensorOptions}} .{{frequency!!dict-member}} value.
1071
- It is initially unset.</td>
1104
+ {{Sensor}} object. It is initially null.
1105
+ </td>
1072
1106
</tr>
1073
1107
<tr>
1074
1108
<td> <dfn attribute for=Sensor>\[[lastEventFiredAt]]</dfn> </td>
@@ -1256,8 +1290,8 @@ to {{SensorErrorEventInit}}.
1256
1290
1. Set |sensor_instance|.{{[[frequency]]}} to |options|["{{frequency!!dict-member}}"] .
1257
1291
1258
1292
Note: There is no guarantee that the requested |options|["{{frequency!!dict-member}}"]
1259
- can be respected. The actual [= sampling frequency=] can be calculated using
1260
- {{Sensor}} {{Sensor/timestamp!!attribute}} attributes .
1293
+ can be respected. See [[#concepts- sampling-and-reporting-frequencies]] for constraints that
1294
+ may be applied .
1261
1295
</div>
1262
1296
1263
1297
<h3 dfn export>Check sensor policy-controlled features</h3>
@@ -1283,24 +1317,30 @@ to {{SensorErrorEventInit}}.
1283
1317
<div algorithm="connect to sensor">
1284
1318
1285
1319
: input
1286
- :: |sensor_instance |, a {{Sensor}} object.
1320
+ :: |sensor |, a {{Sensor}} object.
1287
1321
: output
1288
- :: True if sensor instance was associated with a [=platform sensor=] ,
1322
+ :: True if | sensor| was associated with a [=platform sensor=] ,
1289
1323
false otherwise.
1290
1324
1291
- 1. Let |type| be the [=sensor type=] of |sensor_instance|.
1325
+ 1. Let |platformSensor| be null.
1326
+ 1. Let |type| be |sensor|'s associated [=sensor type=] .
1292
1327
1. If the device has a single [=device sensor=] which can provide [=sensor readings|readings=]
1293
1328
for |type|, then
1294
- 1. Associate |sensor_instance| with a [=platform sensor=] corresponding
1329
+ 1. Set |platformSensor| to a [=platform sensor=] corresponding
1295
1330
to this [=device sensor=] .
1296
- 1. Return true.
1297
1331
1. If the device has multiple [=device sensors=] which can provide [=sensor readings|readings=]
1298
1332
for |type|, then
1299
1333
1. If |type| has an associated [=default sensor=] , then
1300
- 1. Associate |sensor_instance| with a [=platform sensor=] corresponding
1301
- to [=default sensor=] .
1302
- 1. Return true.
1303
- 1. Return false.
1334
+ 1. Set |platformSensor| to a [=platform sensor=] corresponding
1335
+ to this [=default sensor|default device sensor=] .
1336
+ 1. If |platformSensor| is null, return false.
1337
+ 1. Let |bounds| be the result of invoking [=get a platform sensor's sampling bounds=] with
1338
+ |platformSensor|.
1339
+ 1. If |sensor|.{{Sensor/[[frequency]]}} is null, set it to an [=implementation-defined=] value
1340
+ dependent on |type|.
1341
+ 1. If |sensor|.{{Sensor/[[frequency]]}} is less than |bounds|[0] , set it to |bounds|[0] .
1342
+ 1. If |sensor|.{{Sensor/[[frequency]]}} is greater than |bounds|[1] , set it to |bounds|[1] .
1343
+ 1. Return true.
1304
1344
</div>
1305
1345
1306
1346
<h3 dfn export>Activate a sensor object</h3>
@@ -1362,18 +1402,24 @@ to {{SensorErrorEventInit}}.
1362
1402
<div algorithm="set sensor settings">
1363
1403
1364
1404
: input
1365
- :: |sensor |, a [=platform sensor=] .
1405
+ :: |platformSensor |, a [=platform sensor=] .
1366
1406
: output
1367
1407
:: None
1368
1408
1369
- 1. If |sensor |'s set of [=activated sensor objects=] [=set/is empty=] ,
1370
- 1. Set [=requested sampling frequency=] to null.
1371
- 1. [=map/For each=] |key| → <var ignore> value</var> of [=latest reading=] .
1372
- 1. [=map/Set=] [=latest reading=] [|key|] to null.
1373
- 1. Update the user-agent-specific way in which [=sensor readings=] are obtained from |sensor|
1374
- to no longer provide [=sensor readings|readings=] .
1409
+ 1. If |platformSensor |'s set of [=activated sensor objects=] [=set/is empty=] ,
1410
+ 1. Set |platformSensor|'s [= sampling frequency=] to null.
1411
+ 1. [=map/For each=] |key| → <var ignore> value</var> of |platformSensor|'s [=latest reading=] .
1412
+ 1. [=map/Set=] |platformSensor|'s [=latest reading=] [|key|] to null.
1413
+ 1. Update the [=implementation-defined=] way in which [=sensor readings=] are obtained
1414
+ from |platformSensor| to no longer provide [=sensor readings|readings=] .
1375
1415
1. Return.
1376
- 1. Set [=requested sampling frequency=] to [=optimal sampling frequency=] .
1416
+ 1. Set |platformSensor|'s [=sampling frequency=] to an [=implementation-defined=] value based
1417
+ on the {{Sensor/[[frequency]]}} values of the items in its [=activated sensor objects=]
1418
+ [=ordered set|set=] .
1419
+ 1. Let |bounds| be the result of invoking [=get a platform sensor's sampling bounds=] with
1420
+ |platformSensor|.
1421
+ 1. [=Assert=] : |platformSensor|'s [=sampling frequency=] is greater than or equal to
1422
+ |bounds|[0] and less than or equal to |bounds|[1] .
1377
1423
</div>
1378
1424
1379
1425
<h3 dfn export>Update latest reading</h3>
@@ -1401,25 +1447,6 @@ to {{SensorErrorEventInit}}.
1401
1447
1. Invoke [=report latest reading updated=] with |s| as an argument.
1402
1448
</div>
1403
1449
1404
- <h3 dfn export>Find the reporting frequency of a sensor object</h3>
1405
-
1406
- <div algorithm="find the reporting frequency of a sensor object">
1407
-
1408
- : input
1409
- :: |sensor_instance|, a {{Sensor}} object.
1410
- : output
1411
- :: [=reporting frequency=] in Hz.
1412
-
1413
- 1. Let |frequency| be null.
1414
- 1. Let |f| be |sensor_instance|.{{[[frequency]]}} .
1415
- 1. if |f| is set,
1416
- 1. set |frequency| to |f| capped by the upper and lower [=sampling frequency=]
1417
- bounds for the associated [=platform sensor=] .
1418
- 1. Otherwise,
1419
- 1. user agent can assign |frequency| to an appropriate value.
1420
- 1. return |frequency|.
1421
- </div>
1422
-
1423
1450
<h3 dfn export>Report latest reading updated</h3>
1424
1451
1425
1452
<div algorithm="report latest reading updated">
@@ -1436,11 +1463,9 @@ to {{SensorErrorEventInit}}.
1436
1463
1. If |lastReportedTimestamp| is not set
1437
1464
1. Queue a task to run [=notify new reading=] with |sensor_instance| as an argument.
1438
1465
1. Return.
1439
- 1. Let |reportingFrequency| be result of invoking [=Find the reporting frequency of a sensor object=] .
1440
- 1. If |reportingFrequency| is null
1441
- 1. Queue a task to run [=notify new reading=] with |sensor_instance| as an argument.
1442
- 1. Return.
1443
- 1. Let |reportingInterval| be the result of 1 / |reportingFrequency|.
1466
+ 1. [=Assert=] : |sensor_instance|.{{Sensor/[[frequency]]}} is not null.
1467
+ 1. [=Assert=] : |sensor_instance|.{{Sensor/[[frequency]]}} is greater than 0.
1468
+ 1. Let |reportingInterval| be the result of 1 / |sensor_instance|.{{Sensor/[[frequency]]}} .
1444
1469
1. Let |timestampDelta| be the result of [=latest reading=] ["timestamp"] - |lastReportedTimestamp|.
1445
1470
1. If |timestampDelta| is greater than or equal to |reportingInterval|
1446
1471
1. Queue a task to run [=notify new reading=] with |sensor_instance| as an argument.
@@ -1567,13 +1592,10 @@ and whose initial [=map/values=] are implementation-dependent.
1567
1592
1568
1593
Note: The user agent must provide the [=mock sensor reading=] that are initially exposed to the {{Sensor}} objects.
1569
1594
1570
- A [=mock sensor=] has an associated [=requested sampling frequency=] . Its default value is implementation-dependent
1571
- but must be set within a [=mock sensor=] 's associated [=sampling frequency=] bounds.
1572
-
1573
1595
A [=mock sensor=] has an associated [=sampling frequency=] with supported bounds. The default values of
1574
1596
supported bounds are implementation-dependent.
1575
1597
1576
- A [=mock sensor=] must report the [=mock sensor reading=] at the rate of its [=requested sampling frequency=]
1598
+ A [=mock sensor=] must report the [=mock sensor reading=] at the rate of its [=sampling frequency=]
1577
1599
if the user agent [=can expose sensor readings=] to the [=current browsing context=] 's [=active document=] .
1578
1600
1579
1601
Note: The [=mock sensor=] defined in this specification is not intended be used by non-testing-related web content.
@@ -1625,7 +1647,7 @@ The {{MockSensor}} dictionary provides information about a [=mock sensor=].
1625
1647
:: A double representing frequency in Hz that indicates the minimum supported [=sampling frequency=] of the associated [=mock sensor=] .
1626
1648
1627
1649
: {{MockSensor/requestedSamplingFrequency}} member
1628
- :: A double representing frequency in Hz that indicates the [=requested sampling frequency=] of the associated [=mock sensor=] .
1650
+ :: A double representing frequency in Hz that indicates the [=sampling frequency=] of the associated [=mock sensor=] .
1629
1651
1630
1652
A <dfn>serialized mock sensor</dfn> is a JSON [=Object=] where a [=mock sensor=] 's fields listed in the {{MockSensor}} dictionary are mapped
1631
1653
using the <i> JSON Key</i> and the associated field's value from the available [=mock sensor=] in [=current browsing context=] .
@@ -2003,7 +2025,7 @@ creating multiple instances of the same [=sensor type=] and using simple {{Senso
2003
2025
handler.
2004
2026
2005
2027
Conversely, multiple {{Sensor|Sensors}} of the same [=sensor type=] can be created when they
2006
- are intended to be used with different settings, such as: [=requested sampling frequency=] ,
2028
+ are intended to be used with different settings, such as: {{SensorOptions/ frequency}} ,
2007
2029
accuracy or other settings defined in [=extension specifications=] .
2008
2030
2009
2031
<h3 id="definition-reqs">Definition Requirements</h3>
0 commit comments