Skip to content

Commit 29b3467

Browse files
committed
Restrict devicemotion and deviceorientation IDL to secure contexts
https://bugs.webkit.org/show_bug.cgi?id=304985 rdar://44804273 Reviewed by Ryosuke Niwa. As of 207177@main these events have been restricted to secure contexts, but the IDL has been available everywhere for no good reason. The ondevicemotion and ondeviceorientation properties were also not enumerable, but should be. As far as I can tell from blame nobody got around to making the change. There's no real reason not to do this. The SecureContext change is manually tested as this can only be tested through WPT and the tests for this feature don't work in WebKit due to missing WebDriver support. Since SecureContext is tested in general and we already have tests that the events don't dispatch in secure contexts this should be sufficient. This matches the specification for these events: https://w3c.github.io/deviceorientation/ Canonical link: https://commits.webkit.org/305266@main
1 parent 25fff15 commit 29b3467

8 files changed

Lines changed: 42 additions & 8 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Test that ondevicemotion and ondeviceorientation are enumerable.
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS Object.getOwnPropertyNames(window).includes('ondeviceorientation') is true
7+
PASS Object.getOwnPropertyNames(window).includes('ondevicemotion') is true
8+
PASS successfullyParsed is true
9+
10+
TEST COMPLETE
11+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<body>
3+
<script src="/js-test-resources/js-test.js"></script>
4+
<script>
5+
description("Test that ondevicemotion and ondeviceorientation are enumerable.");
6+
7+
shouldBeTrue("Object.getOwnPropertyNames(window).includes('ondeviceorientation')");
8+
shouldBeTrue("Object.getOwnPropertyNames(window).includes('ondevicemotion')");
9+
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Test that ondevicemotion and ondeviceorientation are enumerable.
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
FAIL Object.getOwnPropertyNames(window).includes('ondeviceorientation') should be true. Was false.
7+
FAIL Object.getOwnPropertyNames(window).includes('ondevicemotion') should be true. Was false.
8+
PASS successfullyParsed is true
9+
Some tests failed.
10+
11+
TEST COMPLETE
12+

Source/WebCore/bindings/js/WebCoreBuiltinNames.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ namespace WebCore {
191191
macro(DecompressionStreamTransform) \
192192
macro(DelayNode) \
193193
macro(DeprecationReportBody) \
194+
macro(DeviceMotionEvent) \
195+
macro(DeviceOrientationEvent) \
194196
macro(DigitalCredential) \
195197
macro(DocumentTimeline) \
196198
macro(DynamicsCompressorNode) \
@@ -671,6 +673,8 @@ namespace WebCore {
671673
macro(onbeforematch) \
672674
macro(oncommand) \
673675
macro(oncookiechange) \
676+
macro(ondevicemotion) \
677+
macro(ondeviceorientation) \
674678
macro(onnotificationclick) \
675679
macro(onnotificationclose) \
676680
macro(onpush) \

Source/WebCore/dom/DeviceMotionEvent.idl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
[
2727
Conditional=DEVICE_ORIENTATION,
28-
Exposed=Window
28+
Exposed=Window,
29+
SecureContext
2930
] interface DeviceMotionEvent : Event {
3031
readonly attribute Acceleration? acceleration;
3132
readonly attribute Acceleration? accelerationIncludingGravity;

Source/WebCore/dom/DeviceOrientationEvent.idl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
[
2727
Conditional=DEVICE_ORIENTATION,
28-
Exposed=Window
28+
Exposed=Window,
29+
SecureContext
2930
] interface DeviceOrientationEvent : Event {
3031
readonly attribute unrestricted double? alpha;
3132
readonly attribute unrestricted double? beta;

Source/WebCore/page/DOMWindow+DeviceMotion.idl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,5 @@
2727
[
2828
Conditional=DEVICE_ORIENTATION
2929
] partial interface DOMWindow {
30-
// FIXME: 'ondevicemotion' should be enumerable.
31-
// FIXME: 'ondevicemotion' should be [SecureContext].
32-
[NotEnumerable] attribute EventHandler ondevicemotion;
30+
[SecureContext] attribute EventHandler ondevicemotion;
3331
};

Source/WebCore/page/DOMWindow+DeviceOrientation.idl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,5 @@
2727
[
2828
Conditional=DEVICE_ORIENTATION
2929
] partial interface DOMWindow {
30-
// FIXME: 'ondeviceorientation' should be enumerable.
31-
// FIXME: 'ondeviceorientation' should be [SecureContext].
32-
[NotEnumerable] attribute EventHandler ondeviceorientation;
30+
[SecureContext] attribute EventHandler ondeviceorientation;
3331
};

0 commit comments

Comments
 (0)