Skip to content
Permalink
Browse files
AudioContext::getOutputTimestamp() uses incorrect global object as a …
…high-res timestamp origin

https://bugs.webkit.org/show_bug.cgi?id=230138

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm-expected.txt: Added.
* web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm.html: Added.

Source/WebCore:

Although the spec [1] does not explicitly mention which global object to use, there is
a recommendation for web spec authors to use _relevant_ [2], unlike ECMA standards.

This patch fixes getOutputTimestamp() to use AudioContext's global object to compute
`performanceTime`. Aligns WebKit with Blink and Gecko in case of cross-realm method call.

[1] https://webaudio.github.io/web-audio-api/#dom-audiocontext-getoutputtimestamp
[2] https://html.spec.whatwg.org/multipage/webappapis.html#concept-current-everything

Test: imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm.html

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::getOutputTimestamp):
* Modules/webaudio/AudioContext.h:
* Modules/webaudio/AudioContext.idl:


Canonical link: https://commits.webkit.org/242990@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@284173 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
shvaikalesh committed Oct 14, 2021
1 parent 6006dae commit 3ef26caab68f782d0d8b0d0cf2b069dbed8477c6
Showing 7 changed files with 82 additions and 7 deletions.
@@ -1,3 +1,13 @@
2021-10-14 Alexey Shvayka <shvaikalesh@gmail.com>

AudioContext::getOutputTimestamp() uses incorrect global object as a high-res timestamp origin
https://bugs.webkit.org/show_bug.cgi?id=230138

Reviewed by Chris Dumez.

* web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm-expected.txt: Added.
* web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm.html: Added.

2021-10-14 Tim Nguyen <ntim@apple.com>

Import new <dialog> focus-related WPT
@@ -0,0 +1,11 @@


PASS # AUDIT TASK RUNNER STARTED.
PASS Executing "getoutputtimestamp-cross-realm"
PASS Audit report
PASS > [getoutputtimestamp-cross-realm]
PASS mainContext's performanceTime is greater than iframeContext's performanceTime.
PASS mainContext's performanceTime (via iframeContext's method) is mainContext's performanceTime within an error of 0.01.
PASS < [getoutputtimestamp-cross-realm] All assertions passed. (total 2 assertions)
PASS # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully.

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<title>
Testing AudioContext.getOutputTimestamp() method (cross-realm)
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webaudio/resources/audit.js"></script>
</head>
<body>
<script id="layout-test-code">
const audit = Audit.createTaskRunner();

audit.define("getoutputtimestamp-cross-realm", function(task, should) {
const mainContext = new AudioContext();
return task.timeout(() => {
const iframe = document.createElement("iframe");
document.body.append(iframe);
const iframeContext = new iframe.contentWindow.AudioContext();

should(mainContext.getOutputTimestamp().performanceTime, "mainContext's performanceTime")
.beGreaterThan(iframeContext.getOutputTimestamp().performanceTime, "iframeContext's performanceTime");
should(iframeContext.getOutputTimestamp.call(mainContext).performanceTime, "mainContext's performanceTime (via iframeContext's method)")
.beCloseTo(mainContext.getOutputTimestamp().performanceTime, "mainContext's performanceTime", { threshold: 0.01 });
}, 1000);
});

audit.run();
</script>
</body>
</html>
@@ -1,3 +1,26 @@
2021-10-14 Alexey Shvayka <shvaikalesh@gmail.com>

AudioContext::getOutputTimestamp() uses incorrect global object as a high-res timestamp origin
https://bugs.webkit.org/show_bug.cgi?id=230138

Reviewed by Chris Dumez.

Although the spec [1] does not explicitly mention which global object to use, there is
a recommendation for web spec authors to use _relevant_ [2], unlike ECMA standards.

This patch fixes getOutputTimestamp() to use AudioContext's global object to compute
`performanceTime`. Aligns WebKit with Blink and Gecko in case of cross-realm method call.

[1] https://webaudio.github.io/web-audio-api/#dom-audiocontext-getoutputtimestamp
[2] https://html.spec.whatwg.org/multipage/webappapis.html#concept-current-everything

Test: imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm.html

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::getOutputTimestamp):
* Modules/webaudio/AudioContext.h:
* Modules/webaudio/AudioContext.idl:

2021-10-14 Aditya Keerthi <akeerthi@apple.com>

REGRESSION (r283858): Intense white hover state appears on playback controls on Netflix/YouTube
@@ -176,18 +176,17 @@ double AudioContext::baseLatency()
return static_cast<double>(destination().framesPerBuffer()) / sampleRate();
}

AudioTimestamp AudioContext::getOutputTimestamp(DOMWindow& window)
AudioTimestamp AudioContext::getOutputTimestamp()
{
auto& performance = window.performance();

auto position = outputPosition();

// The timestamp of what is currently being played (contextTime) cannot be
// later than what is being rendered. (currentTime)
position.position = Seconds { std::min(position.position.seconds(), currentTime()) };

auto performanceTime = performance.relativeTimeFromTimeOriginInReducedResolution(position.timestamp);
performanceTime = std::max(performanceTime, 0.0);
DOMHighResTimeStamp performanceTime = 0.0;
if (document() && document()->domWindow())
performanceTime = std::max(document()->domWindow()->performance().relativeTimeFromTimeOriginInReducedResolution(position.timestamp), 0.0);

return { position.position.seconds(), performanceTime };
}
@@ -65,7 +65,7 @@ class AudioContext final

double baseLatency();

AudioTimestamp getOutputTimestamp(DOMWindow&);
AudioTimestamp getOutputTimestamp();

#if ENABLE(VIDEO)
ExceptionOr<Ref<MediaElementAudioSourceNode>> createMediaElementSource(HTMLMediaElement&);
@@ -38,7 +38,7 @@
// FIXME: Add support.
// readonly attribute double outputLatency;

[CallWith=ActiveWindow] AudioTimestamp getOutputTimestamp();
AudioTimestamp getOutputTimestamp();

[ImplementedAs=suspendRendering] Promise<undefined> suspend();
[ImplementedAs=resumeRendering] Promise<undefined> resume();

0 comments on commit 3ef26ca

Please sign in to comment.