XMLHttpRequest should propagate user gestures for media playback
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 May 2019 15:56:34 +0000 (15:56 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 May 2019 15:56:34 +0000 (15:56 +0000)
commita925cb2f90a7946c021ad8abd10f8f3431f0354f
tree090828ce46a314a17180d136457688b8ee00d5e6
parent6699c317e604ba356bd1cccfb62d4ab006fea8f9
XMLHttpRequest should propagate user gestures for media playback
https://bugs.webkit.org/show_bug.cgi?id=197428
<rdar://problem/46677392>

Reviewed by Jer Noble.

Source/WebCore:

A user gesture the would allow media state change in effect when XMLHttpRequest.send is
called should be active when the event handlers fire after the transaction completes successfully.

Test: http/tests/media/user-gesture-preserved-across-xmlhttprequest.html

* dom/UserGestureIndicator.cpp:
(WebCore::UserGestureIndicator::UserGestureIndicator): Add a 'scope' parameter to potentially
limit the scope of the gesture to just media.
(WebCore::UserGestureIndicator::~UserGestureIndicator): Clear the scope.
* dom/UserGestureIndicator.h:
(WebCore::UserGestureToken::processingUserGesture const):
(WebCore::UserGestureToken::setScope):
(WebCore::UserGestureToken::resetScope):
(WebCore::UserGestureToken::hasExpired const):

* page/DOMTimer.cpp:
(WebCore::DOMTimerFireState::DOMTimerFireState): Don't need to store the nested timer interval,
UserGestureIndicator knows when it started.
(WebCore::DOMTimer::DOMTimer): Ditto.
(WebCore::DOMTimer::fired): Ditto.
(WebCore::DOMTimerFireState::nestedTimerInterval const): Deleted.
(WebCore::shouldForwardUserGesture): Deleted.
(WebCore::userGestureTokenToForward): Deleted.
(WebCore::currentNestedTimerInterval): Deleted.
* page/DOMTimer.h:

* testing/Internals.cpp:
(WebCore::Internals::setXHRMaximumIntervalForUserGestureForwarding): Override the maximum
user gesture interval for testing.
* testing/Internals.h:
* testing/Internals.idl:

* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::XMLHttpRequest):
(WebCore::XMLHttpRequest::send): Stash the user gesture token.
(WebCore::XMLHttpRequest::dispatchEvent): Clear user gesture token if it has expired. If still
valid, activate it.
* xml/XMLHttpRequest.h:

LayoutTests:

* fast/events/popup-blocking-timers5-expected.txt:
* fast/events/popup-blocking-timers5.html: Decrease the timer interval from 1000 to 900
because the user gesture is invalidated based on wall clock time.
* fast/events/popup-blocking-timers6-expected.txt:
* fast/events/popup-blocking-timers6.html: Increase the timer interval from 1001 to 1100
because the user gesture is invalidated based on wall clock time.
* http/tests/media/user-gesture-preserved-across-xmlhttprequest-expected.txt: Added.
* http/tests/media/user-gesture-preserved-across-xmlhttprequest.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244823 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/events/popup-blocking-timers5-expected.txt
LayoutTests/fast/events/popup-blocking-timers5.html
LayoutTests/fast/events/popup-blocking-timers6-expected.txt
LayoutTests/fast/events/popup-blocking-timers6.html
LayoutTests/http/tests/media/user-gesture-preserved-across-xmlhttprequest-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/media/user-gesture-preserved-across-xmlhttprequest.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/UserGestureIndicator.cpp
Source/WebCore/dom/UserGestureIndicator.h
Source/WebCore/page/DOMTimer.cpp
Source/WebCore/page/DOMTimer.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebCore/xml/XMLHttpRequest.h