@@ -470,14 +470,15 @@ etc.
470
470
471
471
<h4 id="limit-max-frequency" dfn>Limit maximum sampling frequency</h4>
472
472
473
- User agents may mitigate certain threats by
474
- limiting the maximum [=sampling frequency=] .
473
+ User agents and [=extension specifications=] may mitigate certain threats by defining a [=sensor
474
+ type=] 's [=sensor type/maximum sampling frequency=] .
475
+
475
476
What upper limit to choose depends on the [=sensor type=] ,
476
477
the kind of threats the user agent is trying to protect against,
477
478
the expected resources of the attacker, etc.
478
479
479
- Limiting the maximum [= sampling frequency=] prevents use cases
480
- which rely on low latency or high data density.
480
+ Limiting the [=sensor type/maximum sampling frequency=] prevents use cases which rely on low
481
+ latency or high data density.
481
482
482
483
483
484
<h4 id="stop-sensor" dfn>Stop the sensor altogether</h4>
@@ -493,9 +494,9 @@ or in a different application.
493
494
494
495
An alternative to [=limit maximum sampling frequency|limiting the maximum sampling frequency=] is to
495
496
limit the number of [=sensor readings=] delivered to Web application developer,
496
- regardless of what frequency the sensor is polled at .
497
+ regardless of the [=sampling frequency=] .
497
498
This allows use cases which have low latency requirement
498
- to increase [=sampling frequency=]
499
+ to increase the [=sampling frequency=]
499
500
without increasing the amount of data provided.
500
501
501
502
Discarding intermediary readings prevents certain use cases,
@@ -725,32 +726,52 @@ define ways to uniquely identify each one.
725
726
726
727
## Sampling Frequency and Reporting Frequency ## {#concepts-sampling-and-reporting-frequencies}
727
728
728
- For the purpose of this specification, <dfn>sampling frequency</dfn> for a [=platform sensor=] is
729
- defined as a frequency at which the user agent obtains [=sensor readings=] from the underlying
730
- platform.
729
+ For the purpose of this specification, a [=platform sensor=] 's <dfn>sampling frequency</dfn> is
730
+ defined as a frequency at which a [=platform sensor=] obtains [=sensor readings=] from the
731
+ underlying [=device sensor=] . The way such [=sensor readings=] are obtained is
732
+ [=implementation-defined=] .
731
733
732
- The user agent can request the underlying platform to deliver [=sensor readings|readings=] at a certain
733
- rate which is called <dfn>requested sampling frequency</dfn> .
734
+ Note: The user agent can, for example, poll the operating system/ [=device sensor=] , or register for
735
+ operating system notifications .
734
736
735
- The [=sampling frequency=] is equal to the [=requested sampling frequency=] if the underlying platform
736
- can support it .
737
+ The [=platform sensor=] 's [= sampling frequency=] may not correspond to the [=device sensor=]' s
738
+ actual sampling rate, which, for the purpose of this specification, is opaque .
737
739
738
- The [=sampling frequency=] differs from the [=requested sampling frequency=] in the following cases:
739
- - the [=requested sampling frequency=] exceeds upper or lower [=sampling frequency=] bounds
740
- supported by the underlying platform.
741
- - the operating system and/or the [=device sensor=] automatically discard
742
- readings that do not differ enough (in absolute or relative terms) from the
743
- previously reported ones via a hardware or operating system filter.
744
- - the [=platform sensor=] 's associated [=sensor type=]' s [=threshold check
745
- algorithm=] fails and the [=platform sensor=] 's [=latest readings=] are not
746
- updated.
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.
747
757
748
758
The <dfn>reporting frequency</dfn> for a concrete {{Sensor}} object is defined as a frequency at which
749
759
the "reading" event is [=fire an event|fired=] at this object.
750
760
751
761
A {{Sensor}} object cannot access new [=sensor readings|readings=] at a higher rate than the
752
762
user agent obtains them from the underlying platform, therefore the [=reporting frequency=] can
753
- never exceed the [=sampling frequency=] for the given [=sensor type=] .
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).
765
+
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=] .
769
+ - the operating system and/or the [=device sensor=] automatically discard
770
+ readings that do not differ enough (in absolute or relative terms) from the
771
+ previously reported ones via a hardware or operating system filter.
772
+ - the {{Sensor}} instance's associated [=sensor type=] 's [=threshold check
773
+ algorithm=] fails and the [=platform sensor=] 's [=latest readings=] are not
774
+ updated.
754
775
755
776
## Conditions to expose sensor readings ## {#concepts-can-expose-sensor-readings}
756
777
@@ -785,6 +806,15 @@ A <dfn>sensor type</dfn> must have the following associated data:
785
806
- An [=set/is empty|nonempty=] [=ordered set=] of associated [=policy-controlled feature=] tokens
786
807
referred to as <dfn export>sensor feature names</dfn> .
787
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=] .
788
818
789
819
A [=sensor type=] may have the following associated data:
790
820
- A [=default sensor=] .
@@ -843,17 +873,21 @@ Note: There are additional privacy concerns when using cached [=sensor readings|
843
873
which predate either [=navigating=] to resources in the current [=origin=] ,
844
874
or being granted permission to access the [=platform sensor=] . -->
845
875
846
- A [=platform sensor=] has an associated [=requested sampling frequency=] which is initially null.
847
-
848
- For a non-[=set/is empty|empty=] [=ordered set|set=] of [=activated sensor objects=] the
849
- [=requested sampling frequency=] is equal to the <dfn>optimal sampling frequency</dfn> , which is estimated
850
- by the user agent by taking into account the {{[[frequency]]|provided frequencies}}
851
- of [=activated sensor objects|activated=] {{Sensor|Sensors}} and the [=sampling frequency=] bounds
852
- defined by the underlying platform.
853
-
854
- Note: For example, the user agent may estimate [=optimal sampling frequency=] as a Least Common
855
- Denominator (LCD) for a set of {{[[frequency]]|provided frequencies}} capped
856
- 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 the [=device
883
+ sensor/minimum sampling frequency=] .
884
+ 1. Let |maximumFrequency| be |platformSensor|'s [=sensor type=]' s [=sensor type/maximum sampling
885
+ frequency=] .
886
+ 1. If |platformSensor|'s connected [=device sensor=] has a [=device sensor/maximum sampling
887
+ frequency=] , set |maximumFrequency| to the minimum of |maximumFrequency| and the [=device
888
+ sensor/maximum sampling frequency=] .
889
+ 1. Return a [=tuple=] (|minimumFrequency|, |maximumFrequency|).
890
+ </div>
857
891
858
892
<div class=example>
859
893
@@ -870,7 +904,7 @@ The {{Sensor}} object in "idle" [[#sensor-lifecycle|state]] is not among the [=p
870
904
In this example there is a [=platform sensor=] instance per [=browsing context=] .
871
905
872
906
The [=latest reading=] [=ordered map|map=] is shared between {{Sensor}} objects from the
873
- same [=browsing context|context=] and is updated at a rate equal to the [= requested sampling frequency=]
907
+ same [=browsing context|context=] and is updated at a rate equal to the requested [= sampling frequency=]
874
908
of the corresponding [=platform sensor=] .
875
909
876
910
</div>
@@ -1067,12 +1101,10 @@ with the internal slots described in the following table:
1067
1101
<tr>
1068
1102
<td> <dfn attribute for=Sensor>\[[frequency]]</dfn> </td>
1069
1103
<td> A double representing frequency in Hz that is used to calculate
1070
- the [=requested sampling frequency=] for the associated [=platform sensor=]
1104
+ the [=sampling frequency=] for the associated [=platform sensor=]
1071
1105
and to define the upper bound of the [=reporting frequency=] for this
1072
- {{Sensor}} object.
1073
-
1074
- This slot holds the provided {{SensorOptions}} .{{frequency!!dict-member}} value.
1075
- It is initially unset.</td>
1106
+ {{Sensor}} object. It is initially null.
1107
+ </td>
1076
1108
</tr>
1077
1109
<tr>
1078
1110
<td> <dfn attribute for=Sensor>\[[lastEventFiredAt]]</dfn> </td>
@@ -1260,8 +1292,8 @@ to {{SensorErrorEventInit}}.
1260
1292
1. Set |sensor_instance|.{{[[frequency]]}} to |options|["{{frequency!!dict-member}}"] .
1261
1293
1262
1294
Note: There is no guarantee that the requested |options|["{{frequency!!dict-member}}"]
1263
- can be respected. The actual [= sampling frequency=] can be calculated using
1264
- {{Sensor}} {{Sensor/timestamp!!attribute}} attributes .
1295
+ can be respected. See [[#concepts- sampling-and-reporting-frequencies]] for constraints that
1296
+ may be applied .
1265
1297
</div>
1266
1298
1267
1299
<h3 dfn export>Check sensor policy-controlled features</h3>
@@ -1287,24 +1319,30 @@ to {{SensorErrorEventInit}}.
1287
1319
<div algorithm="connect to sensor">
1288
1320
1289
1321
: input
1290
- :: |sensor_instance |, a {{Sensor}} object.
1322
+ :: |sensor |, a {{Sensor}} object.
1291
1323
: output
1292
- :: True if sensor instance was associated with a [=platform sensor=] ,
1324
+ :: True if | sensor| was associated with a [=platform sensor=] ,
1293
1325
false otherwise.
1294
1326
1295
- 1. Let |type| be the [=sensor type=] of |sensor_instance|.
1327
+ 1. Let |platformSensor| be null.
1328
+ 1. Let |type| be |sensor|'s associated [=sensor type=] .
1296
1329
1. If the device has a single [=device sensor=] which can provide [=sensor readings|readings=]
1297
1330
for |type|, then
1298
- 1. Associate |sensor_instance| with a [=platform sensor=] corresponding
1331
+ 1. Set |platformSensor| to a [=platform sensor=] corresponding
1299
1332
to this [=device sensor=] .
1300
- 1. Return true.
1301
1333
1. If the device has multiple [=device sensors=] which can provide [=sensor readings|readings=]
1302
1334
for |type|, then
1303
1335
1. If |type| has an associated [=default sensor=] , then
1304
- 1. Associate |sensor_instance| with a [=platform sensor=] corresponding
1305
- to [=default sensor=] .
1306
- 1. Return true.
1307
- 1. Return false.
1336
+ 1. Set |platformSensor| to a [=platform sensor=] corresponding
1337
+ to this [=default sensor|default device sensor=] .
1338
+ 1. If |platformSensor| is null, return false.
1339
+ 1. Let |bounds| be the result of invoking [=get a platform sensor's sampling bounds=] with
1340
+ |platformSensor|.
1341
+ 1. If |sensor|.{{Sensor/[[frequency]]}} is null, set it to an [=implementation-defined=] value
1342
+ dependent on |type|.
1343
+ 1. If |sensor|.{{Sensor/[[frequency]]}} is less than |bounds|[0] , set it to |bounds|[0] .
1344
+ 1. If |sensor|.{{Sensor/[[frequency]]}} is greater than |bounds|[1] , set it to |bounds|[1] .
1345
+ 1. Return true.
1308
1346
</div>
1309
1347
1310
1348
<h3 dfn export>Activate a sensor object</h3>
@@ -1365,18 +1403,24 @@ to {{SensorErrorEventInit}}.
1365
1403
<div algorithm="set sensor settings">
1366
1404
1367
1405
: input
1368
- :: |sensor |, a [=platform sensor=] .
1406
+ :: |platformSensor |, a [=platform sensor=] .
1369
1407
: output
1370
1408
:: None
1371
1409
1372
- 1. If |sensor |'s set of [=activated sensor objects=] [=set/is empty=] ,
1373
- 1. Set [=requested sampling frequency=] to null.
1374
- 1. [=map/For each=] |key| → <var ignore> value</var> of [=latest reading=] .
1375
- 1. [=map/Set=] [=latest reading=] [|key|] to null.
1376
- 1. Update the user-agent-specific way in which [=sensor readings=] are obtained from |sensor|
1377
- to no longer provide [=sensor readings|readings=] .
1410
+ 1. If |platformSensor |'s set of [=activated sensor objects=] [=set/is empty=] ,
1411
+ 1. Set |platformSensor|'s [= sampling frequency=] to null.
1412
+ 1. [=map/For each=] |key| → <var ignore> value</var> of |platformSensor|'s [=latest reading=] .
1413
+ 1. [=map/Set=] |platformSensor|'s [=latest reading=] [|key|] to null.
1414
+ 1. Update the [=implementation-defined=] way in which [=sensor readings=] are obtained
1415
+ from |platformSensor| to no longer provide [=sensor readings|readings=] .
1378
1416
1. Return.
1379
- 1. Set [=requested sampling frequency=] to [=optimal sampling frequency=] .
1417
+ 1. Set |platformSensor|'s [=sampling frequency=] to an [=implementation-defined=] value based
1418
+ on the {{Sensor/[[frequency]]}} values of the items in its [=activated sensor objects=]
1419
+ [=ordered set|set=] .
1420
+ 1. Let |bounds| be the result of invoking [=get a platform sensor's sampling bounds=] with
1421
+ |platformSensor|.
1422
+ 1. [=Assert=] : |platformSensor|'s [=sampling frequency=] is greater than or equal to
1423
+ |bounds|[0] and less than or equal to |bounds|[1] .
1380
1424
</div>
1381
1425
1382
1426
<h3 dfn export>Update latest reading</h3>
@@ -1404,25 +1448,6 @@ to {{SensorErrorEventInit}}.
1404
1448
1. Invoke [=report latest reading updated=] with |s| as an argument.
1405
1449
</div>
1406
1450
1407
- <h3 dfn export>Find the reporting frequency of a sensor object</h3>
1408
-
1409
- <div algorithm="find the reporting frequency of a sensor object">
1410
-
1411
- : input
1412
- :: |sensor_instance|, a {{Sensor}} object.
1413
- : output
1414
- :: [=reporting frequency=] in Hz.
1415
-
1416
- 1. Let |frequency| be null.
1417
- 1. Let |f| be |sensor_instance|.{{[[frequency]]}} .
1418
- 1. if |f| is set,
1419
- 1. set |frequency| to |f| capped by the upper and lower [=sampling frequency=]
1420
- bounds for the associated [=platform sensor=] .
1421
- 1. Otherwise,
1422
- 1. user agent can assign |frequency| to an appropriate value.
1423
- 1. return |frequency|.
1424
- </div>
1425
-
1426
1451
<h3 dfn export>Report latest reading updated</h3>
1427
1452
1428
1453
<div algorithm="report latest reading updated">
@@ -1439,11 +1464,9 @@ to {{SensorErrorEventInit}}.
1439
1464
1. If |lastReportedTimestamp| is not set
1440
1465
1. Queue a task to run [=notify new reading=] with |sensor_instance| as an argument.
1441
1466
1. Return.
1442
- 1. Let |reportingFrequency| be result of invoking [=Find the reporting frequency of a sensor object=] .
1443
- 1. If |reportingFrequency| is null
1444
- 1. Queue a task to run [=notify new reading=] with |sensor_instance| as an argument.
1445
- 1. Return.
1446
- 1. Let |reportingInterval| be the result of 1 / |reportingFrequency|.
1467
+ 1. [=Assert=] : |sensor_instance|.{{Sensor/[[frequency]]}} is not null.
1468
+ 1. [=Assert=] : |sensor_instance|.{{Sensor/[[frequency]]}} is greater than 0.
1469
+ 1. Let |reportingInterval| be the result of 1 / |sensor_instance|.{{Sensor/[[frequency]]}} .
1447
1470
1. Let |timestampDelta| be the result of [=latest reading=] ["timestamp"] - |lastReportedTimestamp|.
1448
1471
1. If |timestampDelta| is greater than or equal to |reportingInterval|
1449
1472
1. Queue a task to run [=notify new reading=] with |sensor_instance| as an argument.
@@ -1570,13 +1593,10 @@ and whose initial [=map/values=] are implementation-dependent.
1570
1593
1571
1594
Note: The user agent must provide the [=mock sensor reading=] that are initially exposed to the {{Sensor}} objects.
1572
1595
1573
- A [=mock sensor=] has an associated [=requested sampling frequency=] . Its default value is implementation-dependent
1574
- but must be set within a [=mock sensor=] 's associated [=sampling frequency=] bounds.
1575
-
1576
1596
A [=mock sensor=] has an associated [=sampling frequency=] with supported bounds. The default values of
1577
1597
supported bounds are implementation-dependent.
1578
1598
1579
- A [=mock sensor=] must report the [=mock sensor reading=] at the rate of its [=requested sampling frequency=]
1599
+ A [=mock sensor=] must report the [=mock sensor reading=] at the rate of its [=sampling frequency=]
1580
1600
if the user agent [=can expose sensor readings=] to the [=current browsing context=] 's [=active document=] .
1581
1601
1582
1602
Note: The [=mock sensor=] defined in this specification is not intended be used by non-testing-related web content.
@@ -1628,7 +1648,7 @@ The {{MockSensor}} dictionary provides information about a [=mock sensor=].
1628
1648
:: A double representing frequency in Hz that indicates the minimum supported [=sampling frequency=] of the associated [=mock sensor=] .
1629
1649
1630
1650
: {{MockSensor/requestedSamplingFrequency}} member
1631
- :: A double representing frequency in Hz that indicates the [=requested sampling frequency=] of the associated [=mock sensor=] .
1651
+ :: A double representing frequency in Hz that indicates the [=sampling frequency=] of the associated [=mock sensor=] .
1632
1652
1633
1653
A <dfn>serialized mock sensor</dfn> is a JSON [=Object=] where a [=mock sensor=] 's fields listed in the {{MockSensor}} dictionary are mapped
1634
1654
using the <i> JSON Key</i> and the associated field's value from the available [=mock sensor=] in [=current browsing context=] .
@@ -2006,7 +2026,7 @@ creating multiple instances of the same [=sensor type=] and using simple {{Senso
2006
2026
handler.
2007
2027
2008
2028
Conversely, multiple {{Sensor|Sensors}} of the same [=sensor type=] can be created when they
2009
- are intended to be used with different settings, such as: [=requested sampling frequency=] ,
2029
+ are intended to be used with different settings, such as: {{SensorOptions/ frequency}} ,
2010
2030
accuracy or other settings defined in [=extension specifications=] .
2011
2031
2012
2032
<h3 id="definition-reqs">Definition Requirements</h3>
0 commit comments