Title: [281520] trunk
Revision
281520
Author
[email protected]
Date
2021-08-24 15:03:34 -0700 (Tue, 24 Aug 2021)

Log Message

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:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (281519 => 281520)


--- trunk/LayoutTests/ChangeLog	2021-08-24 21:54:22 UTC (rev 281519)
+++ trunk/LayoutTests/ChangeLog	2021-08-24 22:03:34 UTC (rev 281520)
@@ -1,3 +1,25 @@
+2021-08-24  Chris Dumez  <[email protected]>
+
+        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:
+
 2021-08-24  Eric Hutchison  <[email protected]>
 
         [BigSur wk2 Debug] webgl/1.0.3/conformance/glsl/constructors/glsl-construct-bvec2.html is a flaky timeout.

Modified: trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context-expected.txt (281519 => 281520)


--- 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)
@@ -4,7 +4,7 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS Success callback invoked
+PASS No callbacks invoked
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/Geolocation/callback-to-deleted-context.html (281519 => 281520)


--- 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)
@@ -13,7 +13,7 @@
 
 function onSecondIframeLoaded() {
     window.setTimeout(function() {
-        testFailed('No callbacks invoked');
+        testPassed('No callbacks invoked');
         finishJSTest();
     }, 500);
 }

Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already-expected.txt (281519 => 281520)


--- 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)
@@ -3,7 +3,7 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-Method called on Geolocation object with disconnected Frame.
+PASS Error callback invoked
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-already.html (281519 => 281520)


--- 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)
@@ -23,7 +23,7 @@
         testFailed('Success callback invoked unexpectedly');
         finishJSTest();
     }, function(e) {
-        testFailed('Error callback invoked unexpectedly');
+        testPassed('Error callback invoked');
         finishJSTest();
     });
     setTimeout(finishTest, 1000);

Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-expected.txt (281519 => 281520)


--- 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)
@@ -4,7 +4,7 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS No callbacks invoked
+PASS Error callback invoked
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied-expected.txt (281519 => 281520)


--- 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)
@@ -7,7 +7,7 @@
 PASS error.code is error.PERMISSION_DENIED
 PASS error.message is "User denied Geolocation"
 
-PASS No callbacks invoked
+PASS Error callback invoked
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame-permission-denied.html (281519 => 281520)


--- 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)
@@ -36,13 +36,13 @@
         testFailed('Success callback invoked unexpectedly');
         finishJSTest();
     }, function(e) {
-        testFailed('Error callback invoked unexpectedly');
+        testPassed('Error callback invoked');
         finishJSTest();
     });
     setTimeout(function() {
-        testPassed('No callbacks invoked');
+        testFailed('No callbacks invoked');
         finishJSTest();
-    }, 100);
+    }, 1000);
 }
 
 var iframe = document.createElement('iframe');

Modified: trunk/LayoutTests/fast/dom/Geolocation/disconnected-frame.html (281519 => 281520)


--- 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)
@@ -23,13 +23,13 @@
         testFailed('Success callback invoked unexpectedly');
         finishJSTest();
     }, function(e) {
-        testFailed('Error callback invoked unexpectedly');
+        testPassed('Error callback invoked');
         finishJSTest();
     });
     setTimeout(function() {
-        testPassed('No callbacks invoked');
+        testFailed('No callbacks invoked');
         finishJSTest();
-    }, 100);
+    }, 1000);
 }
 
 var iframe = document.createElement('iframe');

Modified: trunk/LayoutTests/fast/dom/Geolocation/resources/callback-to-deleted-context-inner1.html (281519 => 281520)


--- 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)
@@ -13,7 +13,7 @@
           // Make request from remote frame, this frame will be gone by the time the Geolocation
           // object attempts to invoke the callback.
           window.parent.navigator.geolocation.getCurrentPosition(function() {
-              parent.testPassed('Success callback invoked');
+              parent.testFailed('Success callback invoked unexpectedly');
               parent.finishJSTest();
           }, function() {
               parent.testFailed('Error callback invoked unexpectedly');

Modified: trunk/LayoutTests/fast/events/detached-svg-parent-window-events-expected.txt (281519 => 281520)


--- 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)
@@ -1,9 +1,9 @@
-CONSOLE MESSAGE: error
 This tests creating a disconnected SVG element with resize event handler. The event handler should not get dispatched unless the element is connected
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
+PASS Exception thrown
 PASS didFireResize is false
 PASS didFireOnError is false
 PASS successfullyParsed is true

Modified: trunk/LayoutTests/fast/events/detached-svg-parent-window-events.html (281519 => 281520)


--- 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)
@@ -21,7 +21,11 @@
                         shouldBeFalse('didFireOnError');
                         finishJSTest();
                     });
-                    iframe.contentWindow.eval('throw "error"');
+                    try {
+                        iframe.contentWindow.eval('throw "error"');
+                    } catch (e) {
+                        testPassed("Exception thrown");
+                    }
                 });
             };
             document.body.appendChild(iframe);

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (281519 => 281520)


--- 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)
@@ -1,5 +1,26 @@
 2021-08-24  Chris Dumez  <[email protected]>
 
+        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  <[email protected]>
+
         [WK2] Implement process-swapping based on Cross-Origin-Opener-Policy HTTP header
         https://bugs.webkit.org/show_bug.cgi?id=229203
         <rdar://problem/82047686>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/PositionOptions.https-expected.txt (281519 => 281520)


--- 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)
@@ -1,5 +1,9 @@
 
 PASS Call getCurrentPosition with wrong type for enableHighAccuracy. No exception expected.
 PASS Call watchPosition with wrong type for enableHighAccuracy. No exception expected.
-FAIL PositionOptions tests promise_test: Unhandled rejection with value: object "Error: unimplemented"
+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)
 

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https-expected.txt (0 => 281520)


--- 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)
@@ -0,0 +1,4 @@
+
+
+PASS non-fully active document behavior
+

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/non-fully-active.https.html (0 => 281520)


--- 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)
@@ -0,0 +1,103 @@
+<!DOCTYPE html>
+<meta charset="utf-8" />
+<title>Geolocation Test: non-fully active document</title>
+<link rel="help" href="" />
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<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 = ""
+    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>

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/geolocation-API/resources/iframe.html (0 => 281520)


--- 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)
@@ -0,0 +1,3 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<h1>Just a support file</h1>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/resources/testdriver-vendor.js (281519 => 281520)


--- 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)
@@ -293,3 +293,16 @@
     if (pointerType === "mouse" || pointerType === "pen")
         return dispatchMouseActions(pointerSource.actions, pointerType);
 };
+
+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"));
+};
+

Modified: trunk/Source/WebCore/ChangeLog (281519 => 281520)


--- 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)
@@ -1,5 +1,45 @@
 2021-08-24  Chris Dumez  <[email protected]>
 
+        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  <[email protected]>
+
         [WK2] Implement process-swapping based on Cross-Origin-Opener-Policy HTTP header
         https://bugs.webkit.org/show_bug.cgi?id=229203
         <rdar://problem/82047686>

Modified: trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp (281519 => 281520)


--- 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)
@@ -31,6 +31,7 @@
 #if ENABLE(GEOLOCATION)
 
 #include "Document.h"
+#include "EventLoop.h"
 #include "FeaturePolicy.h"
 #include "Frame.h"
 #include "GeoNotifier.h"
@@ -299,8 +300,14 @@
 
 void Geolocation::getCurrentPosition(Ref<PositionCallback>&& successCallback, RefPtr<PositionErrorCallback>&& errorCallback, PositionOptions&& options)
 {
-    if (!frame())
+    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));
+            });
+        }
         return;
+    }
 
     auto notifier = GeoNotifier::create(*this, WTFMove(successCallback), WTFMove(errorCallback), WTFMove(options));
     startRequest(notifier.ptr());
@@ -310,8 +317,14 @@
 
 int Geolocation::watchPosition(Ref<PositionCallback>&& successCallback, RefPtr<PositionErrorCallback>&& errorCallback, PositionOptions&& options)
 {
-    if (!frame())
+    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));
+            });
+        }
         return 0;
+    }
 
     auto notifier = GeoNotifier::create(*this, WTFMove(successCallback), WTFMove(errorCallback), WTFMove(options));
     startRequest(notifier.ptr());
@@ -693,10 +706,8 @@
         return;
     }
 
-    RefPtr<GeolocationPosition> position = lastPosition();
-    ASSERT(position);
-
-    makeSuccessCallbacks(*position);
+    if (RefPtr position = lastPosition())
+        makeSuccessCallbacks(*position);
 }
 
 void Geolocation::setError(GeolocationError& error)

Modified: trunk/Source/WebCore/bindings/js/JSDOMConvertCallbacks.h (281519 => 281520)


--- 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)
@@ -44,8 +44,12 @@
             exceptionThrower(lexicalGlobalObject, scope);
             return nullptr;
         }
+
+        JSDOMGlobalObject* incumbentGlobalObject = &globalObject;
+        if (auto* globalObject = JSC::CallFrame::globalObjectOfClosestCodeBlock(vm, vm.topCallFrame))
+            incumbentGlobalObject = JSC::jsCast<JSDOMGlobalObject*>(globalObject);
         
-        return T::create(JSC::asObject(value), &globalObject);
+        return T::create(JSC::asObject(value), incumbentGlobalObject);
     }
 };
 
@@ -79,7 +83,11 @@
             return nullptr;
         }
 
-        return T::create(JSC::asObject(value), &globalObject);
+        JSDOMGlobalObject* incumbentGlobalObject = &globalObject;
+        if (auto* globalObject = JSC::CallFrame::globalObjectOfClosestCodeBlock(vm, vm.topCallFrame))
+            incumbentGlobalObject = JSC::jsCast<JSDOMGlobalObject*>(globalObject);
+
+        return T::create(JSC::asObject(value), incumbentGlobalObject);
     }
 };
 

Modified: trunk/Source/WebCore/dom/IdleCallbackController.cpp (281519 => 281520)


--- 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)
@@ -109,7 +109,7 @@
 // https://w3c.github.io/requestidlecallback/#invoke-idle-callbacks-algorithm
 void IdleCallbackController::invokeIdleCallbacks(MonotonicTime deadline)
 {
-    if (!m_document)
+    if (!m_document || !m_document->frame())
         return;
 
     auto now = MonotonicTime::now();

Modified: trunk/Source/WebCore/dom/TaskSource.h (281519 => 281520)


--- 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)
@@ -32,6 +32,7 @@
     DatabaseAccess,
     FileReading,
     FontLoading,
+    Geolocation,
     IdleTask,
     IndexedDB,
     MediaElement,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to