Skip to content

Commit 41d7945

Browse files
Add "geolocation task queue" (#87)
1 parent 71e4213 commit 41d7945

File tree

1 file changed

+154
-125
lines changed

1 file changed

+154
-125
lines changed

‎index.html

+154-125
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ <h2>
118118
has received the following changes:
119119
</p>
120120
<ul>
121+
<li>Added the [=geolocation task source=], which handles dispatching
122+
position updates and errors.
123+
</li>
121124
<li>[=Request position=] only proceeds when a document is visible, or
122125
the document becomes visible.
123126
</li>
@@ -585,173 +588,180 @@ <h2>
585588
|successCallback:PositionCallback|, a {{PositionErrorCallback}}`?`
586589
|errorCallback:PositionErrorCallback|, {{PositionOptions}}
587590
|options:PositionOptions|, a {{boolean}} |repeats:boolean|, and
588-
optionally (and only if |repeats| is true) a |previous id:long|.
591+
optionally (and only if |repeats| is true) a |previousId:long|.
589592
</p>
590593
<ol class="algorithm">
591594
<li>Let |watchTasks:Set| be [=this=]'s
592595
{{Geolocation/[[watchTasks]]}}.
593596
</li>
594-
<li>Acquire a watch id.
595-
<ol>
596-
<li>If |previous id| was provided, let |watchId:long| be
597-
|previous id|; Otherwise, let |watchId:long| be an
598-
[=implementation-defined=] {{long}} that is greater than or equal
599-
to zero.
600-
</li>
601-
<li>[=Set/Append=] |watchId| to |watchTasks|.
602-
</li>
603-
<li>Return |watchId| and continue [=in parallel=].
604-
</li>
605-
</ol>
597+
<li>If |previousId| was provided, let |watchId:long| be |previousId|;
598+
Otherwise, let |watchId:long| be an [=implementation-defined=]
599+
{{long}} that is greater than or equal to zero.
606600
</li>
607-
<li>Do security check.
608-
<ol>
609-
<li>If the <a>environment settings object</a> is a
610-
<a data-cite="secure-contexts">non-secure context</a>, then:
611-
<ol>
612-
<li>[=Call back with error=] |errorCallback| and
613-
{{GeolocationPositionError/PERMISSION_DENIED}}.
614-
</li>
615-
<li>[=List/Remove=] |watchId| from |watchTasks|.
616-
</li>
617-
<li>Terminate this algorithm.
618-
</li>
619-
</ol>
620-
</li>
621-
</ol>
601+
<li>[=Set/Append=] |watchId| to |watchTasks|.
622602
</li>
623-
<li data-cite="page-visibility-2">Wait for document to become
624-
visible.
625-
<ol>
626-
<li>Let |document:Document| be the [=current settings object=]'s
627-
[=associated Document=].
628-
</li>
629-
<li>If |document:Document| is [=Document/hidden=], wait for the
630-
|document| to become [=Document/visible=].
631-
</li>
632-
</ol>
603+
<li>Let |global| be [=this=]'s [=relevant global object=].
633604
</li>
634-
<li data-tests=
635-
"getCurrentPosition_permission_allow.https.html, getCurrentPosition_permission_deny.https.html">
636-
[=Check permission=] passing |errorCallback|. If the check return
637-
failure:
605+
<li>[=Queue a global task=] using the [=geolocation task source=]
606+
with |global| to run the following steps [=in parallel=]:
638607
<ol>
639-
<li>[=List/Remove=] |watchId| from |watchTasks|.
640-
</li>
641-
<li>Terminate this algorithm.
642-
</li>
643-
</ol>
644-
</li>
645-
<li>
646-
<dfn data-local-lt=
647-
"acquiring a position|acquire a position">Acquire position</dfn>.
648-
<ol>
649-
<li>Let |acquisitionTime:DOMTimeStamp| be a new {{DOMTimeStamp}}
650-
that represents now in milliseconds, using 01 January, 1970 UTC
651-
as the epoch.
652-
</li>
653-
<li>If |options|.{{PositionOptions/maximumAge}} is greater than
654-
0, and |cachedPosition| is not null:
608+
<li>Do security check.
655609
<ol>
656-
<li>Let |cachedPosition:GeolocationPosition| be [=this=]'s
657-
{{Geolocation/[[cachedPosition]]}}.
658-
</li>
659-
<li>Let |cacheTime:long| be |acquisitionTime| minus the value
660-
of |options|.{{PositionOptions/maximumAge}} member.
661-
</li>
662-
<li>If |cachedPosition|'s {{GeolocationPosition/timestamp}}'s
663-
value is greater than |cacheTime|, and
664-
|cachedPosition|.{{GeolocationPosition/[[isHighAccuracy]]}}
665-
equals |options|.{{PositionOptions/enableHighAccuracy}}:
610+
<li>If the <a>environment settings object</a> is a
611+
<a data-cite="secure-contexts">non-secure context</a>, then:
666612
<ol>
667-
<li>[=Queue a microtask=] to invoke |successCallback|
668-
with |cachedPosition|.
613+
<li>[=Call back with error=] |errorCallback| and
614+
{{GeolocationPositionError/PERMISSION_DENIED}}.
669615
</li>
670-
<li>Go to <a href="#check-repeats">determine
671-
repetition</a> steps below.
616+
<li>[=List/Remove=] |watchId| from |watchTasks|.
617+
</li>
618+
<li>Terminate this algorithm.
672619
</li>
673620
</ol>
674621
</li>
675622
</ol>
676623
</li>
677-
<li>Let |timeout:Task| be a new timed [=task=] that runs in
678-
|options|.{{PositionOptions/timeout}} milliseconds after
679-
|acquisitionTime|, which performs the following sub-steps:
680-
<aside class="note" title="Immediate cancellation">
681-
<p>
682-
An |options|.{{PositionOptions/timeout}} value 0
683-
effectively runs the |timeout| task immediately.
684-
</p>
685-
</aside>
624+
<li data-cite="page-visibility-2">Wait for document to become
625+
visible.
686626
<ol>
687-
<li>If the entry for |timerId| in the [=list of active
688-
timers=] has been cleared, then abort these steps.
627+
<li>Let |document:Document| be the [=current settings
628+
object=]'s [=associated Document=].
689629
</li>
690-
<li>[=Call back with error=] with |errorCallback| and
691-
{{GeolocationPositionError/TIMEOUT}}.
630+
<li>If |document:Document| is [=Document/hidden=], wait for
631+
the |document| to become [=Document/visible=].
692632
</li>
693633
</ol>
694634
</li>
695-
<li>Let |timerId:long| be an [=implementation-defined=]
696-
identifier that represents |timeout|.
697-
</li>
698-
<li>Add |timerId| to the [=list of active timers=].
635+
<li data-tests=
636+
"getCurrentPosition_permission_allow.https.html, getCurrentPosition_permission_deny.https.html">
637+
[=Check permission=] passing |errorCallback|. If the check
638+
returns failure:
639+
<ol>
640+
<li>[=List/Remove=] |watchId| from |watchTasks|.
641+
</li>
642+
<li>Terminate this algorithm.
643+
</li>
644+
</ol>
699645
</li>
700-
<li>Try to acquire the device's position, optionally taking into
701-
consideration the value of
702-
|options|.{{PositionOptions/enableHighAccuracy}}:
646+
<li>
647+
<dfn data-local-lt=
648+
"acquiring a position|acquire a position">Acquire
649+
position</dfn>.
703650
<ol>
704-
<li>If acquiring a position succeeds:
651+
<li>Let |acquisitionTime:DOMTimeStamp| be a new
652+
{{DOMTimeStamp}} that represents now in milliseconds, using
653+
01 January, 1970 UTC as the epoch.
654+
</li>
655+
<li>If |options|.{{PositionOptions/maximumAge}} is greater
656+
than 0, and |cachedPosition| is not null:
705657
<ol>
706-
<li>Let |position:GeolocationPosition| be [=a new
707-
`GeolocationPosition`=] passing |acquisitionTime| and
708-
|options|.{{PositionOptions/enableHighAccuracy}}.
658+
<li>Let |cachedPosition:GeolocationPosition| be
659+
[=this=]'s {{Geolocation/[[cachedPosition]]}}.
709660
</li>
710-
<li>Set [=this=]'s {{Geolocation/[[cachedPosition]]}} to
711-
|position|.
661+
<li>Let |cacheTime:long| be |acquisitionTime| minus the
662+
value of |options|.{{PositionOptions/maximumAge}} member.
712663
</li>
713-
<li>[=Queue a microtask=] to [=invoke=] |successCallback|
714-
with |position|.
664+
<li>If |cachedPosition|'s
665+
{{GeolocationPosition/timestamp}}'s value is greater than
666+
|cacheTime|, and
667+
|cachedPosition|.{{GeolocationPosition/[[isHighAccuracy]]}}
668+
equals |options|.{{PositionOptions/enableHighAccuracy}}:
669+
<ol>
670+
<li>[=Queue a task=] on the [=geolocation task
671+
source=] with a step that [=invokes=]
672+
|successCallback| with |cachedPosition|.
673+
</li>
674+
<li>Go to <a href="#check-repeats">determine
675+
repetition</a> steps below.
676+
</li>
677+
</ol>
715678
</li>
716679
</ol>
717680
</li>
718-
<li>If acquiring a position fails:
681+
<li>Let |timeout:Task| be a new timed [=task=] that runs in
682+
|options|.{{PositionOptions/timeout}} milliseconds after
683+
|acquisitionTime|, which performs the following sub-steps:
684+
<aside class="note" title="Immediate cancellation">
685+
<p>
686+
An |options|.{{PositionOptions/timeout}} value 0
687+
effectively runs the |timeout| task immediately.
688+
</p>
689+
</aside>
719690
<ol>
720-
<li>[=Call back with error=] passing |errorCallback| and
721-
{{GeolocationPositionError/POSITION_UNAVAILABLE}}.
691+
<li>If the entry for |timerId| in the [=list of active
692+
timers=] has been cleared, then abort these steps.
693+
</li>
694+
<li>[=Call back with error=] with |errorCallback| and
695+
{{GeolocationPositionError/TIMEOUT}}.
722696
</li>
723697
</ol>
724698
</li>
699+
<li>Let |timerId:long| be an [=implementation-defined=]
700+
identifier that represents |timeout|.
701+
</li>
702+
<li>Add |timerId| to the [=list of active timers=].
703+
</li>
704+
<li>Try to acquire the device's position, optionally taking
705+
into consideration the value of
706+
|options|.{{PositionOptions/enableHighAccuracy}}:
707+
<ol>
708+
<li>If acquiring a position succeeds:
709+
<ol>
710+
<li>Let |position:GeolocationPosition| be [=a new
711+
`GeolocationPosition`=] passing |acquisitionTime| and
712+
|options|.{{PositionOptions/enableHighAccuracy}}.
713+
</li>
714+
<li>Set [=this=]'s {{Geolocation/[[cachedPosition]]}}
715+
to |position|.
716+
</li>
717+
<li>[=Queue a task=] on the [=geolocation task
718+
source=] with a step that [=invokes=]
719+
|successCallback| with |position|.
720+
</li>
721+
</ol>
722+
</li>
723+
<li>If acquiring a position fails:
724+
<ol>
725+
<li>[=Call back with error=] passing |errorCallback|
726+
and
727+
{{GeolocationPositionError/POSITION_UNAVAILABLE}}.
728+
</li>
729+
</ol>
730+
</li>
731+
</ol>
732+
</li>
733+
<li>Clear |timerId| from the [=list of active timers=].
734+
</li>
725735
</ol>
726736
</li>
727-
<li>Clear |timerId| from the [=list of active timers=].
728-
</li>
729-
</ol>
730-
</li>
731-
<li>
732-
<span id="check-repeats">Determine repetition</span>.
733-
<ol>
734-
<li>If |repeats| is false:
737+
<li>
738+
<span id="check-repeats">Determine repetition</span>.
735739
<ol>
736-
<li>[=List/Remove=] |watchId| from |watchTasks|.
740+
<li>If |repeats| is false:
741+
<ol>
742+
<li>[=List/Remove=] |watchId| from |watchTasks|.
743+
</li>
744+
<li>Terminate this algorithm.
745+
</li>
746+
</ol>
737747
</li>
738-
<li>Terminate this algorithm.
748+
</ol>
749+
</li>
750+
<li>Wait for a significant change of geographic position. What
751+
constitutes a significant change of geographic position is left
752+
to the implementation. User agents MAY impose a rate limit on
753+
the frequency position changes.
754+
</li>
755+
<li>If |watchTasks| [=list/contain|contains=] |watchId|, then:
756+
<ol>
757+
<li>[=Request position=] passing |successCallback|,
758+
|errorCallback|, |options|, |repeats|, and |watchId|.
739759
</li>
740760
</ol>
741761
</li>
742762
</ol>
743763
</li>
744-
<li>Wait for a significant change of geographic position. What
745-
constitutes a significant change of geographic position is
746-
[=implementation-defined|left to the implementation=]. A user agent
747-
MAY impose a rate limit on the frequency of position changes.
748-
</li>
749-
<li>If |watchTasks| [=list/contain|contains=] |watchId|, then:
750-
<ol>
751-
<li>[=Request position=] passing |successCallback|,
752-
|errorCallback|, |options|, |repeats|, and |watchId|.
753-
</li>
754-
</ol>
764+
<li>Return |watchId|.
755765
</li>
756766
</ol>
757767
</section>
@@ -795,7 +805,8 @@ <h2>
795805
{{GeolocationPositionError}} instance whose
796806
{{GeolocationPositionError/code}} attribute is initialized to |code|.
797807
</li>
798-
<li>[=Invoke=] |callback| with |error|.
808+
<li>[=Queue a task=] on the [=geolocation task source=] with a step
809+
that [=invokes=] |callback| with |error|.
799810
</li>
800811
</ol>
801812
</section>
@@ -917,6 +928,24 @@ <h2>
917928
</tr>
918929
</table>
919930
</section>
931+
<section>
932+
<h2>
933+
Task sources
934+
</h2>
935+
<p>
936+
The following [=task source=] is defined by this specifications.
937+
</p>
938+
<dl>
939+
<dt>
940+
The <dfn>geolocation task source</dfn>
941+
</dt>
942+
<dd>
943+
Used by this specification to queue up non-blocking
944+
{{PositionCallback}} and {{PositionErrorCallback}} when performing
945+
[=request position|position requests=].
946+
</dd>
947+
</dl>
948+
</section>
920949
</section>
921950
<section id="coordinates_interface" data-dfn-for="GeolocationCoordinates">
922951
<h2>

0 commit comments

Comments
 (0)