<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[281520] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/281520">281520</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2021-08-24 15:03:34 -0700 (Tue, 24 Aug 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Geolocation API should callback with error if doc is not fully active
https://bugs.webkit.org/show_bug.cgi?id=228319
<rdar://problem/81450315>

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

* web-platform-tests/geolocation-API/PositionOptions.https-expected.txt:
Rebaseline WPT test now that more checks are passing.

* web-platform-tests/geolocation-API/non-fully-active.https-expected.txt: Added.
* web-platform-tests/geolocation-API/non-fully-active.https.html: Added.
* web-platform-tests/geolocation-API/resources/iframe.html: Added.
Import test coverage from WPT https://github.com/web-platform-tests/wpt/pull/29799.

* web-platform-tests/resources/testdriver-vendor.js:
(window.test_driver_internal.set_permission):
Add support for test_driver.set_permission("geolocation", "granted") so that Geolocation
WPT tests can run with our infrastructure.

Source/WebCore:

Test: imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https.html

* Modules/geolocation/Geolocation.cpp:
(WebCore::Geolocation::getCurrentPosition):
(WebCore::Geolocation::watchPosition):
Schedule a task to call the error callback if the document is not fully active, as
per the specification:
- https://github.com/w3c/geolocation-api/issues/96
- https://github.com/w3c/geolocation-api/pull/97

* bindings/js/JSDOMConvertCallbacks.h:
(WebCore::Converter<IDLCallbackFunction<T>>::convert):
(WebCore::Converter<IDLCallbackInterface<T>>::convert):
Make sure we use the incumbent global object when constructing callback functions /
interfaces, as per the Web IDL specification:
- https://heycam.github.io/webidl/#es-callback-interface
- https://heycam.github.io/webidl/#es-callback-function
Without this, the geolocation API would be unable to call its error callback when in
a detached frame because the callback's global object would be the geolocation object's
global object.

* dom/IdleCallbackController.cpp:
(WebCore::IdleCallbackController::invokeIdleCallbacks):
Make sure we don't fire requestIdleCallback callbacks in detached iframes, to maintain
pre-existing behavior and keep layout tests passing. I had to make this change because
callback interfaces / functions are now using a different global object and can now
get called in cases when they previously couldn't.

* dom/TaskSource.h:
As Geolocation task source for the HTML5 event loop, as per the Geolocation
specification.

LayoutTests:

Update / rebaseline existing layout tests to reflect behavior change.

* fast/dom/Geolocation/callback-to-deleted-context-expected.txt:
* fast/dom/Geolocation/callback-to-deleted-context.html:
* fast/dom/Geolocation/disconnected-frame-already-expected.txt:
* fast/dom/Geolocation/disconnected-frame-already.html:
* fast/dom/Geolocation/disconnected-frame-expected.txt:
* fast/dom/Geolocation/disconnected-frame-permission-denied-expected.txt:
* fast/dom/Geolocation/disconnected-frame-permission-denied.html:
* fast/dom/Geolocation/disconnected-frame.html:
* fast/dom/Geolocation/resources/callback-to-deleted-context-inner1.html:
* fast/events/detached-svg-parent-window-events-expected.txt:
* fast/events/detached-svg-parent-window-events.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationcallbacktodeletedcontextexpectedtxt">trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationcallbacktodeletedcontexthtml">trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context.html</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationdisconnectedframealreadyexpectedtxt">trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationdisconnectedframealreadyhtml">trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already.html</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationdisconnectedframeexpectedtxt">trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationdisconnectedframepermissiondeniedexpectedtxt">trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationdisconnectedframepermissiondeniedhtml">trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied.html</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationdisconnectedframehtml">trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame.html</a></li>
<li><a href="#trunkLayoutTestsfastdomGeolocationresourcescallbacktodeletedcontextinner1html">trunk/LayoutTests/fast/dom/Geolocation/resources/callback-to-deleted-context-inner1.html</a></li>
<li><a href="#trunkLayoutTestsfasteventsdetachedsvgparentwindoweventsexpectedtxt">trunk/LayoutTests/fast/events/detached-svg-parent-window-events-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasteventsdetachedsvgparentwindoweventshtml">trunk/LayoutTests/fast/events/detached-svg-parent-window-events.html</a></li>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsgeolocationAPIPositionOptionshttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/PositionOptions.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsresourcestestdrivervendorjs">trunk/LayoutTests/imported/w3c/web-platform-tests/resources/testdriver-vendor.js</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesgeolocationGeolocationcpp">trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSDOMConvertCallbacksh">trunk/Source/WebCore/bindings/js/JSDOMConvertCallbacks.h</a></li>
<li><a href="#trunkSourceWebCoredomIdleCallbackControllercpp">trunk/Source/WebCore/dom/IdleCallbackController.cpp</a></li>
<li><a href="#trunkSourceWebCoredomTaskSourceh">trunk/Source/WebCore/dom/TaskSource.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsgeolocationAPInonfullyactivehttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https-expected.txt</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsgeolocationAPInonfullyactivehttpshtml">trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https.html</a></li>
<li>trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/resources/</li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsgeolocationAPIresourcesiframehtml">trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/resources/iframe.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/ChangeLog 2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2021-08-24  Chris Dumez  <cdumez@apple.com>
+
+        Geolocation API should callback with error if doc is not fully active
+        https://bugs.webkit.org/show_bug.cgi?id=228319
+        <rdar://problem/81450315>
+
+        Reviewed by Ryosuke Niwa.
+
+        Update / rebaseline existing layout tests to reflect behavior change.
+
+        * fast/dom/Geolocation/callback-to-deleted-context-expected.txt:
+        * fast/dom/Geolocation/callback-to-deleted-context.html:
+        * fast/dom/Geolocation/disconnected-frame-already-expected.txt:
+        * fast/dom/Geolocation/disconnected-frame-already.html:
+        * fast/dom/Geolocation/disconnected-frame-expected.txt:
+        * fast/dom/Geolocation/disconnected-frame-permission-denied-expected.txt:
+        * fast/dom/Geolocation/disconnected-frame-permission-denied.html:
+        * fast/dom/Geolocation/disconnected-frame.html:
+        * fast/dom/Geolocation/resources/callback-to-deleted-context-inner1.html:
+        * fast/events/detached-svg-parent-window-events-expected.txt:
+        * fast/events/detached-svg-parent-window-events.html:
+
</ins><span class="cx"> 2021-08-24  Eric Hutchison  <ehutchison@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [BigSur wk2 Debug] webgl/1.0.3/conformance/glsl/constructors/glsl-construct-bvec2.html is a flaky timeout.
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationcallbacktodeletedcontextexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context-expected.txt (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context-expected.txt  2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context-expected.txt     2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -4,7 +4,7 @@
</span><span class="cx"> On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-PASS Success callback invoked
</del><ins>+PASS No callbacks invoked
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationcallbacktodeletedcontexthtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context.html (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context.html  2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context.html     2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -13,7 +13,7 @@
</span><span class="cx"> 
</span><span class="cx"> function onSecondIframeLoaded() {
</span><span class="cx">     window.setTimeout(function() {
</span><del>-        testFailed('No callbacks invoked');
</del><ins>+        testPassed('No callbacks invoked');
</ins><span class="cx">         finishJSTest();
</span><span class="cx">     }, 500);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationdisconnectedframealreadyexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already-expected.txt (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already-expected.txt   2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already-expected.txt      2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -3,7 +3,7 @@
</span><span class="cx"> On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-Method called on Geolocation object with disconnected Frame.
</del><ins>+PASS Error callback invoked
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationdisconnectedframealreadyhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already.html (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already.html   2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already.html      2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -23,7 +23,7 @@
</span><span class="cx">         testFailed('Success callback invoked unexpectedly');
</span><span class="cx">         finishJSTest();
</span><span class="cx">     }, function(e) {
</span><del>-        testFailed('Error callback invoked unexpectedly');
</del><ins>+        testPassed('Error callback invoked');
</ins><span class="cx">         finishJSTest();
</span><span class="cx">     });
</span><span class="cx">     setTimeout(finishTest, 1000);
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationdisconnectedframeexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-expected.txt (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-expected.txt   2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-expected.txt      2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -4,7 +4,7 @@
</span><span class="cx"> On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-PASS No callbacks invoked
</del><ins>+PASS Error callback invoked
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationdisconnectedframepermissiondeniedexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied-expected.txt (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied-expected.txt 2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied-expected.txt    2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -7,7 +7,7 @@
</span><span class="cx"> PASS error.code is error.PERMISSION_DENIED
</span><span class="cx"> PASS error.message is "User denied Geolocation"
</span><span class="cx"> 
</span><del>-PASS No callbacks invoked
</del><ins>+PASS Error callback invoked
</ins><span class="cx"> PASS successfullyParsed is true
</span><span class="cx"> 
</span><span class="cx"> TEST COMPLETE
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationdisconnectedframepermissiondeniedhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied.html (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied.html 2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied.html    2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -36,13 +36,13 @@
</span><span class="cx">         testFailed('Success callback invoked unexpectedly');
</span><span class="cx">         finishJSTest();
</span><span class="cx">     }, function(e) {
</span><del>-        testFailed('Error callback invoked unexpectedly');
</del><ins>+        testPassed('Error callback invoked');
</ins><span class="cx">         finishJSTest();
</span><span class="cx">     });
</span><span class="cx">     setTimeout(function() {
</span><del>-        testPassed('No callbacks invoked');
</del><ins>+        testFailed('No callbacks invoked');
</ins><span class="cx">         finishJSTest();
</span><del>-    }, 100);
</del><ins>+    }, 1000);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> var iframe = document.createElement('iframe');
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationdisconnectedframehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame.html (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame.html   2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame.html      2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -23,13 +23,13 @@
</span><span class="cx">         testFailed('Success callback invoked unexpectedly');
</span><span class="cx">         finishJSTest();
</span><span class="cx">     }, function(e) {
</span><del>-        testFailed('Error callback invoked unexpectedly');
</del><ins>+        testPassed('Error callback invoked');
</ins><span class="cx">         finishJSTest();
</span><span class="cx">     });
</span><span class="cx">     setTimeout(function() {
</span><del>-        testPassed('No callbacks invoked');
</del><ins>+        testFailed('No callbacks invoked');
</ins><span class="cx">         finishJSTest();
</span><del>-    }, 100);
</del><ins>+    }, 1000);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> var iframe = document.createElement('iframe');
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomGeolocationresourcescallbacktodeletedcontextinner1html"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/dom/Geolocation/resources/callback-to-deleted-context-inner1.html (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Geolocation/resources/callback-to-deleted-context-inner1.html 2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/dom/Geolocation/resources/callback-to-deleted-context-inner1.html    2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -13,7 +13,7 @@
</span><span class="cx">           // Make request from remote frame, this frame will be gone by the time the Geolocation
</span><span class="cx">           // object attempts to invoke the callback.
</span><span class="cx">           window.parent.navigator.geolocation.getCurrentPosition(function() {
</span><del>-              parent.testPassed('Success callback invoked');
</del><ins>+              parent.testFailed('Success callback invoked unexpectedly');
</ins><span class="cx">               parent.finishJSTest();
</span><span class="cx">           }, function() {
</span><span class="cx">               parent.testFailed('Error callback invoked unexpectedly');
</span></span></pre></div>
<a id="trunkLayoutTestsfasteventsdetachedsvgparentwindoweventsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/events/detached-svg-parent-window-events-expected.txt (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/events/detached-svg-parent-window-events-expected.txt     2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/events/detached-svg-parent-window-events-expected.txt        2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -1,9 +1,9 @@
</span><del>-CONSOLE MESSAGE: error
</del><span class="cx"> This tests creating a disconnected SVG element with resize event handler. The event handler should not get dispatched unless the element is connected
</span><span class="cx"> 
</span><span class="cx"> On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+PASS Exception thrown
</ins><span class="cx"> PASS didFireResize is false
</span><span class="cx"> PASS didFireOnError is false
</span><span class="cx"> PASS successfullyParsed is true
</span></span></pre></div>
<a id="trunkLayoutTestsfasteventsdetachedsvgparentwindoweventshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/events/detached-svg-parent-window-events.html (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/events/detached-svg-parent-window-events.html     2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/fast/events/detached-svg-parent-window-events.html        2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -21,7 +21,11 @@
</span><span class="cx">                         shouldBeFalse('didFireOnError');
</span><span class="cx">                         finishJSTest();
</span><span class="cx">                     });
</span><del>-                    iframe.contentWindow.eval('throw "error"');
</del><ins>+                    try {
+                        iframe.contentWindow.eval('throw "error"');
+                    } catch (e) {
+                        testPassed("Exception thrown");
+                    }
</ins><span class="cx">                 });
</span><span class="cx">             };
</span><span class="cx">             document.body.appendChild(iframe);
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -1,5 +1,26 @@
</span><span class="cx"> 2021-08-24  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><ins>+        Geolocation API should callback with error if doc is not fully active
+        https://bugs.webkit.org/show_bug.cgi?id=228319
+        <rdar://problem/81450315>
+
+        Reviewed by Ryosuke Niwa.
+
+        * web-platform-tests/geolocation-API/PositionOptions.https-expected.txt:
+        Rebaseline WPT test now that more checks are passing.
+
+        * web-platform-tests/geolocation-API/non-fully-active.https-expected.txt: Added.
+        * web-platform-tests/geolocation-API/non-fully-active.https.html: Added.
+        * web-platform-tests/geolocation-API/resources/iframe.html: Added.
+        Import test coverage from WPT https://github.com/web-platform-tests/wpt/pull/29799.
+
+        * web-platform-tests/resources/testdriver-vendor.js:
+        (window.test_driver_internal.set_permission):
+        Add support for test_driver.set_permission("geolocation", "granted") so that Geolocation
+        WPT tests can run with our infrastructure.
+
+2021-08-24  Chris Dumez  <cdumez@apple.com>
+
</ins><span class="cx">         [WK2] Implement process-swapping based on Cross-Origin-Opener-Policy HTTP header
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=229203
</span><span class="cx">         <rdar://problem/82047686>
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsgeolocationAPIPositionOptionshttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/PositionOptions.https-expected.txt (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/PositionOptions.https-expected.txt     2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/PositionOptions.https-expected.txt        2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -1,5 +1,9 @@
</span><span class="cx"> 
</span><span class="cx"> PASS Call getCurrentPosition with wrong type for enableHighAccuracy. No exception expected.
</span><span class="cx"> PASS Call watchPosition with wrong type for enableHighAccuracy. No exception expected.
</span><del>-FAIL PositionOptions tests promise_test: Unhandled rejection with value: object "Error: unimplemented"
</del><ins>+PASS PositionOptions tests
+PASS Set timeout and maximumAge to 0, check that timeout error raised (getCurrentPosition)
+PASS Set timeout and maximumAge to 0, check that timeout error raised (watchPosition)
+PASS Check that a negative timeout value is equivalent to a 0 timeout value (getCurrentLocation)
+PASS Check that a negative timeout value is equivalent to a 0 timeout value (watchPosition)
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsgeolocationAPInonfullyactivehttpsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https-expected.txt (0 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https-expected.txt                            (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https-expected.txt       2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+
+
+PASS non-fully active document behavior
+
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsgeolocationAPInonfullyactivehttpshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https.html (0 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https.html                            (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https.html       2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -0,0 +1,103 @@
</span><ins>+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: non-fully active document</title>
+<link rel="help" href="https://github.com/w3c/geolocation-api/pull/97" />
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="support.js"></script>
+<body></body>
+<script>
+  promise_test(async function () {
+    await test_driver.set_permission({ name: "geolocation" }, "granted");
+
+    // Create the iframe, wait for it to load...
+    const iframe = document.createElement("iframe");
+    iframe.src = "resources/iframe.html";
+    iframe.allow = "geolocation";
+    document.body.appendChild(iframe);
+
+    // ...wait for the iframe to load...
+    await new Promise((resolve) =>
+      iframe.addEventListener("load", resolve, { once: true })
+    );
+
+    // Steal geolocation.
+    const geo = iframe.contentWindow.navigator.geolocation;
+
+    // No longer fully active.
+    iframe.remove();
+
+    // Try to watch a position while not fully active...
+    const watchError = await new Promise((resolve, reject) => {
+      const watchId = geo.watchPosition(
+        reject, // We don't want a position
+        resolve // We want an error!
+      );
+      // Always return 0.
+      assert_equals(
+        watchId,
+        0,
+        "watchId is 0 when document is not fully-active"
+      );
+      // And again, to make sure it's not changing
+      const watchId2 = geo.watchPosition(
+        () => {},
+        () => {}
+      );
+      assert_equals(
+        watchId2,
+        0,
+        "watchId remains 0 when document is not fully-active"
+      );
+    });
+
+    assert_equals(
+      watchError.code,
+      GeolocationPositionError.POSITION_UNAVAILABLE,
+      "watchPosition() returns an error on non-fully-active document"
+    );
+
+    // Now try to get current position while not fully active...
+    const positionError = await new Promise((resolve, reject) => {
+      geo.getCurrentPosition(
+        reject, // We don't want a position
+        resolve // We want an error!
+      );
+    });
+    assert_equals(
+      positionError.code,
+      GeolocationPositionError.POSITION_UNAVAILABLE,
+      "getCurrentPosition() calls the errorCallback with POSITION_UNAVAILABLE"
+    );
+
+    // Re-attach, and go back to fully active.
+    document.body.appendChild(iframe);
+    iframe.contentWindow.opener = window;
+    await new Promise((resolve) =>
+      iframe.addEventListener("load", resolve, { once: true })
+    );
+
+    // And we are back to fully active.
+    let watchId;
+    let position = await new Promise((resolve, reject) => {
+      watchId = iframe.contentWindow.navigator.geolocation.watchPosition(
+        resolve,
+        reject
+      );
+    });
+    assert_true(Number.isInteger(watchId), "Expected some number for watchId");
+    assert_true(Boolean(position), "Expected a position");
+
+    // Finally, let's get the position from the reattached document.
+    position = await new Promise((resolve, reject) => {
+      iframe.contentWindow.navigator.geolocation.getCurrentPosition(
+        resolve,
+        reject
+      );
+    });
+    assert_true(Boolean(position), "Expected a position");
+    iframe.contentWindow.navigator.geolocation.clearWatch(watchId);
+  }, "non-fully active document behavior");
+</script>
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsgeolocationAPIresourcesiframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/resources/iframe.html (0 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/resources/iframe.html                          (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/resources/iframe.html     2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+<!DOCTYPE html>
+<meta charset="utf-8">
+<h1>Just a support file</h1>
</ins></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsresourcestestdrivervendorjs"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/resources/testdriver-vendor.js (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/resources/testdriver-vendor.js 2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/resources/testdriver-vendor.js    2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -293,3 +293,16 @@
</span><span class="cx">     if (pointerType === "mouse" || pointerType === "pen")
</span><span class="cx">         return dispatchMouseActions(pointerSource.actions, pointerType);
</span><span class="cx"> };
</span><ins>+
+window.test_driver_internal.set_permission = function(permission_params, context=null)
+{
+    if (window.testRunner && permission_params.descriptor.name == "geolocation") {
+        setInterval(() => {
+            window.testRunner.setMockGeolocationPosition(51.478, -0.166, 100);
+        }, 100);
+        testRunner.setGeolocationPermission(permission_params.state == "granted");
+        return Promise.resolve();
+    }
+    return Promise.reject(new Error("unimplemented"));
+};
+
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/Source/WebCore/ChangeLog      2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -1,5 +1,45 @@
</span><span class="cx"> 2021-08-24  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><ins>+        Geolocation API should callback with error if doc is not fully active
+        https://bugs.webkit.org/show_bug.cgi?id=228319
+        <rdar://problem/81450315>
+
+        Reviewed by Ryosuke Niwa.
+
+        Test: imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https.html
+
+        * Modules/geolocation/Geolocation.cpp:
+        (WebCore::Geolocation::getCurrentPosition):
+        (WebCore::Geolocation::watchPosition):
+        Schedule a task to call the error callback if the document is not fully active, as
+        per the specification:
+        - https://github.com/w3c/geolocation-api/issues/96
+        - https://github.com/w3c/geolocation-api/pull/97
+
+        * bindings/js/JSDOMConvertCallbacks.h:
+        (WebCore::Converter<IDLCallbackFunction<T>>::convert):
+        (WebCore::Converter<IDLCallbackInterface<T>>::convert):
+        Make sure we use the incumbent global object when constructing callback functions /
+        interfaces, as per the Web IDL specification:
+        - https://heycam.github.io/webidl/#es-callback-interface
+        - https://heycam.github.io/webidl/#es-callback-function
+        Without this, the geolocation API would be unable to call its error callback when in
+        a detached frame because the callback's global object would be the geolocation object's
+        global object.
+
+        * dom/IdleCallbackController.cpp:
+        (WebCore::IdleCallbackController::invokeIdleCallbacks):
+        Make sure we don't fire requestIdleCallback callbacks in detached iframes, to maintain
+        pre-existing behavior and keep layout tests passing. I had to make this change because
+        callback interfaces / functions are now using a different global object and can now
+        get called in cases when they previously couldn't.
+
+        * dom/TaskSource.h:
+        As Geolocation task source for the HTML5 event loop, as per the Geolocation
+        specification.
+
+2021-08-24  Chris Dumez  <cdumez@apple.com>
+
</ins><span class="cx">         [WK2] Implement process-swapping based on Cross-Origin-Opener-Policy HTTP header
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=229203
</span><span class="cx">         <rdar://problem/82047686>
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesgeolocationGeolocationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp 2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp    2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #if ENABLE(GEOLOCATION)
</span><span class="cx"> 
</span><span class="cx"> #include "Document.h"
</span><ins>+#include "EventLoop.h"
</ins><span class="cx"> #include "FeaturePolicy.h"
</span><span class="cx"> #include "Frame.h"
</span><span class="cx"> #include "GeoNotifier.h"
</span><span class="lines">@@ -299,8 +300,14 @@
</span><span class="cx"> 
</span><span class="cx"> void Geolocation::getCurrentPosition(Ref<PositionCallback>&& successCallback, RefPtr<PositionErrorCallback>&& errorCallback, PositionOptions&& options)
</span><span class="cx"> {
</span><del>-    if (!frame())
</del><ins>+    if (!document() || !document()->isFullyActive()) {
+        if (errorCallback && errorCallback->scriptExecutionContext()) {
+            errorCallback->scriptExecutionContext()->eventLoop().queueTask(TaskSource::Geolocation, [errorCallback] {
+                errorCallback->handleEvent(GeolocationPositionError::create(GeolocationPositionError::POSITION_UNAVAILABLE, "Document is not fully active"_s));
+            });
+        }
</ins><span class="cx">         return;
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     auto notifier = GeoNotifier::create(*this, WTFMove(successCallback), WTFMove(errorCallback), WTFMove(options));
</span><span class="cx">     startRequest(notifier.ptr());
</span><span class="lines">@@ -310,8 +317,14 @@
</span><span class="cx"> 
</span><span class="cx"> int Geolocation::watchPosition(Ref<PositionCallback>&& successCallback, RefPtr<PositionErrorCallback>&& errorCallback, PositionOptions&& options)
</span><span class="cx"> {
</span><del>-    if (!frame())
</del><ins>+    if (!document() || !document()->isFullyActive()) {
+        if (errorCallback && errorCallback->scriptExecutionContext()) {
+            errorCallback->scriptExecutionContext()->eventLoop().queueTask(TaskSource::Geolocation, [errorCallback] {
+                errorCallback->handleEvent(GeolocationPositionError::create(GeolocationPositionError::POSITION_UNAVAILABLE, "Document is not fully active"_s));
+            });
+        }
</ins><span class="cx">         return 0;
</span><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     auto notifier = GeoNotifier::create(*this, WTFMove(successCallback), WTFMove(errorCallback), WTFMove(options));
</span><span class="cx">     startRequest(notifier.ptr());
</span><span class="lines">@@ -693,10 +706,8 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    RefPtr<GeolocationPosition> position = lastPosition();
-    ASSERT(position);
-
-    makeSuccessCallbacks(*position);
</del><ins>+    if (RefPtr position = lastPosition())
+        makeSuccessCallbacks(*position);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Geolocation::setError(GeolocationError& error)
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSDOMConvertCallbacksh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertCallbacks.h (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSDOMConvertCallbacks.h 2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvertCallbacks.h    2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -44,8 +44,12 @@
</span><span class="cx">             exceptionThrower(lexicalGlobalObject, scope);
</span><span class="cx">             return nullptr;
</span><span class="cx">         }
</span><ins>+
+        JSDOMGlobalObject* incumbentGlobalObject = &globalObject;
+        if (auto* globalObject = JSC::CallFrame::globalObjectOfClosestCodeBlock(vm, vm.topCallFrame))
+            incumbentGlobalObject = JSC::jsCast<JSDOMGlobalObject*>(globalObject);
</ins><span class="cx">         
</span><del>-        return T::create(JSC::asObject(value), &globalObject);
</del><ins>+        return T::create(JSC::asObject(value), incumbentGlobalObject);
</ins><span class="cx">     }
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="lines">@@ -79,7 +83,11 @@
</span><span class="cx">             return nullptr;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        return T::create(JSC::asObject(value), &globalObject);
</del><ins>+        JSDOMGlobalObject* incumbentGlobalObject = &globalObject;
+        if (auto* globalObject = JSC::CallFrame::globalObjectOfClosestCodeBlock(vm, vm.topCallFrame))
+            incumbentGlobalObject = JSC::jsCast<JSDOMGlobalObject*>(globalObject);
+
+        return T::create(JSC::asObject(value), incumbentGlobalObject);
</ins><span class="cx">     }
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomIdleCallbackControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/IdleCallbackController.cpp (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/IdleCallbackController.cpp      2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/Source/WebCore/dom/IdleCallbackController.cpp 2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -109,7 +109,7 @@
</span><span class="cx"> // https://w3c.github.io/requestidlecallback/#invoke-idle-callbacks-algorithm
</span><span class="cx"> void IdleCallbackController::invokeIdleCallbacks(MonotonicTime deadline)
</span><span class="cx"> {
</span><del>-    if (!m_document)
</del><ins>+    if (!m_document || !m_document->frame())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     auto now = MonotonicTime::now();
</span></span></pre></div>
<a id="trunkSourceWebCoredomTaskSourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/TaskSource.h (281519 => 281520)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/TaskSource.h    2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/Source/WebCore/dom/TaskSource.h       2021-08-24 22:03:34 UTC (rev 281520)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx">     DatabaseAccess,
</span><span class="cx">     FileReading,
</span><span class="cx">     FontLoading,
</span><ins>+    Geolocation,
</ins><span class="cx">     IdleTask,
</span><span class="cx">     IndexedDB,
</span><span class="cx">     MediaElement,
</span></span></pre>
</div>
</div>

</body>
</html>