- Revision
- 284173
- Author
- [email protected]
- Date
- 2021-10-14 10:49:57 -0700 (Thu, 14 Oct 2021)
Log Message
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:
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (284172 => 284173)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-10-14 17:32:02 UTC (rev 284172)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-10-14 17:49:57 UTC (rev 284173)
@@ -1,3 +1,13 @@
+2021-10-14 Alexey Shvayka <[email protected]>
+
+ 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 <[email protected]>
Import new <dialog> focus-related WPT
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm-expected.txt (0 => 284173)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm-expected.txt 2021-10-14 17:49:57 UTC (rev 284173)
@@ -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.
+
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm.html (0 => 284173)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-getoutputtimestamp-cross-realm.html 2021-10-14 17:49:57 UTC (rev 284173)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>
+ Testing AudioContext.getOutputTimestamp() method (cross-realm)
+ </title>
+ <script src=""
+ <script src=""
+ <script src=""
+ </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>
Modified: trunk/Source/WebCore/ChangeLog (284172 => 284173)
--- trunk/Source/WebCore/ChangeLog 2021-10-14 17:32:02 UTC (rev 284172)
+++ trunk/Source/WebCore/ChangeLog 2021-10-14 17:49:57 UTC (rev 284173)
@@ -1,3 +1,26 @@
+2021-10-14 Alexey Shvayka <[email protected]>
+
+ 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 <[email protected]>
REGRESSION (r283858): Intense white hover state appears on playback controls on Netflix/YouTube
Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp (284172 => 284173)
--- trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp 2021-10-14 17:32:02 UTC (rev 284172)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.cpp 2021-10-14 17:49:57 UTC (rev 284173)
@@ -176,10 +176,8 @@
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
@@ -186,8 +184,9 @@
// 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 };
}
Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.h (284172 => 284173)
--- trunk/Source/WebCore/Modules/webaudio/AudioContext.h 2021-10-14 17:32:02 UTC (rev 284172)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.h 2021-10-14 17:49:57 UTC (rev 284173)
@@ -65,7 +65,7 @@
double baseLatency();
- AudioTimestamp getOutputTimestamp(DOMWindow&);
+ AudioTimestamp getOutputTimestamp();
#if ENABLE(VIDEO)
ExceptionOr<Ref<MediaElementAudioSourceNode>> createMediaElementSource(HTMLMediaElement&);
Modified: trunk/Source/WebCore/Modules/webaudio/AudioContext.idl (284172 => 284173)
--- trunk/Source/WebCore/Modules/webaudio/AudioContext.idl 2021-10-14 17:32:02 UTC (rev 284172)
+++ trunk/Source/WebCore/Modules/webaudio/AudioContext.idl 2021-10-14 17:49:57 UTC (rev 284173)
@@ -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();