Set lastHandledUserGestureTimestamp on all ancestor documents, not just the top document
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Apr 2017 00:55:14 +0000 (00:55 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Apr 2017 00:55:14 +0000 (00:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=170479

Reviewed by Sam Weinig.

Source/WebCore:

When interacting with a subframe document, set lastHandledUserGestureTimestamp on all ancestor
documents up to the root.

This will be used in future for requestAnimationFrame throttling.

Test: fast/frames/user-gesture-timestamp-propagation.html

* dom/Document.cpp:
(WebCore::Document::updateLastHandledUserGestureTimestamp):
* dom/Document.h:
* dom/UserGestureIndicator.cpp:
(WebCore::UserGestureIndicator::UserGestureIndicator):
* testing/Internals.cpp:
(WebCore::Internals::lastHandledUserGestureTimestamp):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* fast/frames/user-gesture-timestamp-propagation-expected.txt: Added.
* fast/frames/user-gesture-timestamp-propagation.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@214982 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/frames/user-gesture-timestamp-propagation-expected.txt [new file with mode: 0644]
LayoutTests/fast/frames/user-gesture-timestamp-propagation.html [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/UserGestureIndicator.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index a8c4611..9698e20 100644 (file)
@@ -1,3 +1,14 @@
+2017-04-05  Simon Fraser  <simon.fraser@apple.com>
+
+        Set lastHandledUserGestureTimestamp on all ancestor documents, not just the top document
+        https://bugs.webkit.org/show_bug.cgi?id=170479
+
+        Reviewed by Sam Weinig.
+
+        * fast/frames/user-gesture-timestamp-propagation-expected.txt: Added.
+        * fast/frames/user-gesture-timestamp-propagation.html: Added.
+        * platform/ios/TestExpectations:
+
 2017-04-05  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream] Host application should be able to mute and unmute media streams
diff --git a/LayoutTests/fast/frames/user-gesture-timestamp-propagation-expected.txt b/LayoutTests/fast/frames/user-gesture-timestamp-propagation-expected.txt
new file mode 100644 (file)
index 0000000..08863d0
--- /dev/null
@@ -0,0 +1,18 @@
+Tests that the EventTarget API is no longer working on detached frames.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS internals.lastHandledUserGestureTimestamp() is 0
+PASS frame.contentWindow.internals.lastHandledUserGestureTimestamp() is 0
+PASS innerFrame.contentWindow.internals.lastHandledUserGestureTimestamp() is 0
+PASS innerFrame2.contentWindow.internals.lastHandledUserGestureTimestamp() is 0
+Dispatching click
+PASS internals.lastHandledUserGestureTimestamp() is not 0
+PASS frame.contentWindow.internals.lastHandledUserGestureTimestamp() is not 0
+PASS innerFrame.contentWindow.internals.lastHandledUserGestureTimestamp() is not 0
+PASS innerFrame2.contentWindow.internals.lastHandledUserGestureTimestamp() is 0
+
diff --git a/LayoutTests/fast/frames/user-gesture-timestamp-propagation.html b/LayoutTests/fast/frames/user-gesture-timestamp-propagation.html
new file mode 100644 (file)
index 0000000..6f3ed6c
--- /dev/null
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+    <script src="../../resources/js-test-pre.js"></script>
+    <script>
+        description("Tests that the EventTarget API is no longer working on detached frames.");
+
+        var frame;
+        var innerFrame;
+        var innerFrame2;
+
+        function dispatchClick()
+        {
+            var x = frame.offsetLeft + frame.offsetWidth / 2;
+            var y = frame.offsetTop + frame.offsetHeight / 2;
+
+            eventSender.mouseMoveTo(x, y);
+            eventSender.mouseDown();
+            eventSender.mouseUp();
+        }
+
+        function doTest()
+        {
+            frame = document.getElementById('frame');
+            innerFrame = frame.contentWindow.document.getElementById('frame');
+            innerFrame2 = frame.contentWindow.document.getElementById('frame2');
+
+            shouldBe('internals.lastHandledUserGestureTimestamp()', '0');
+            shouldBe('frame.contentWindow.internals.lastHandledUserGestureTimestamp()', '0');
+            shouldBe('innerFrame.contentWindow.internals.lastHandledUserGestureTimestamp()', '0');
+            shouldBe('innerFrame2.contentWindow.internals.lastHandledUserGestureTimestamp()', '0');
+
+            debug('Dispatching click');
+            dispatchClick();
+
+            shouldNotBe('internals.lastHandledUserGestureTimestamp()', '0');
+            shouldNotBe('frame.contentWindow.internals.lastHandledUserGestureTimestamp()', '0');
+            shouldNotBe('innerFrame.contentWindow.internals.lastHandledUserGestureTimestamp()', '0');
+            // Should have not hit frame2
+            shouldBe('innerFrame2.contentWindow.internals.lastHandledUserGestureTimestamp()', '0');
+        }
+
+        window.addEventListener('load', doTest, false);
+    </script>
+</head>
+<body>
+    <iframe id="frame" srcdoc="
+        <body>
+            <iframe id='frame' srcdoc='
+                Inner frame
+                    '>
+            </iframe>
+            <iframe id='frame2' srcdoc='
+                Inner frame
+                    '>
+            </iframe>
+        </body>">
+    </iframe>
+    <script src="../../resources/js-test-post.js"></script>
+
+</body>
+</html>
index ebd39b6..f137c20 100644 (file)
@@ -379,10 +379,10 @@ fast/events/keyboardevent-code.html [ Skip ]
 http/tests/navigation/keyboard-events-during-provisional-navigation.html [ Skip ]
 media/audio-dealloc-crash.html [ Skip ]
 
-# This test uses EventSender's mouseMoveTo, mouseUp and mouseDown
+# Tests that use EventSender's mouseMoveTo, mouseUp and mouseDown
 fast/forms/range/disabled-while-dragging.html [ Skip ]
 fast/forms/range/range-drag-when-toggled-disabled.html [ Skip ]
-fast/media/video-element-in-details-collapse.html [ Skip ]
+fast/frames/user-gesture-timestamp-propagation.html [ Failure ]
 
 # The file-wrapper part of <attachment> is not yet working on iOS
 fast/attachment/attachment-type-attribute.html [ Skip ]
index d785e8e..8625841 100644 (file)
@@ -1,3 +1,27 @@
+2017-04-05  Simon Fraser  <simon.fraser@apple.com>
+
+        Set lastHandledUserGestureTimestamp on all ancestor documents, not just the top document
+        https://bugs.webkit.org/show_bug.cgi?id=170479
+
+        Reviewed by Sam Weinig.
+
+        When interacting with a subframe document, set lastHandledUserGestureTimestamp on all ancestor
+        documents up to the root.
+
+        This will be used in future for requestAnimationFrame throttling.
+
+        Test: fast/frames/user-gesture-timestamp-propagation.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::updateLastHandledUserGestureTimestamp):
+        * dom/Document.h:
+        * dom/UserGestureIndicator.cpp:
+        (WebCore::UserGestureIndicator::UserGestureIndicator):
+        * testing/Internals.cpp:
+        (WebCore::Internals::lastHandledUserGestureTimestamp):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2017-04-05  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream] Host application should be able to mute and unmute media streams
index feca013..2965abe 100644 (file)
 #include "RenderView.h"
 #include "RenderWidget.h"
 #include "RequestAnimationFrameCallback.h"
-#include "ResourceLoadObserver.h"
 #include "RuntimeEnabledFeatures.h"
 #include "SVGDocumentExtensions.h"
 #include "SVGElement.h"
@@ -6313,10 +6312,12 @@ Document::RegionFixedPair Document::absoluteRegionForEventTargets(const EventTar
     return RegionFixedPair(targetRegion, insideFixedPosition);
 }
 
-void Document::updateLastHandledUserGestureTimestamp()
+void Document::updateLastHandledUserGestureTimestamp(MonotonicTime time)
 {
-    m_lastHandledUserGestureTimestamp = MonotonicTime::now();
-    ResourceLoadObserver::sharedObserver().logUserInteractionWithReducedTimeResolution(*this);
+    m_lastHandledUserGestureTimestamp = time;
+    
+    if (HTMLFrameOwnerElement* element = ownerElement())
+        element->document().updateLastHandledUserGestureTimestamp(time);
 }
 
 void Document::startTrackingStyleRecalcs()
index 0b19f3c..0465bcc 100644 (file)
@@ -1144,7 +1144,7 @@ public:
     void didRemoveWheelEventHandler(Node&, EventHandlerRemoval = EventHandlerRemoval::One);
 
     MonotonicTime lastHandledUserGestureTimestamp() const { return m_lastHandledUserGestureTimestamp; }
-    void updateLastHandledUserGestureTimestamp();
+    void updateLastHandledUserGestureTimestamp(MonotonicTime);
 
     // Used for testing. Count handlers in the main document, and one per frame which contains handlers.
     WEBCORE_EXPORT unsigned wheelEventHandlerCount() const;
index ece68f1..0ac50fc 100644 (file)
@@ -27,6 +27,7 @@
 #include "UserGestureIndicator.h"
 
 #include "Document.h"
+#include "ResourceLoadObserver.h"
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
 
@@ -54,8 +55,10 @@ UserGestureIndicator::UserGestureIndicator(std::optional<ProcessingUserGestureSt
     if (state)
         currentToken() = UserGestureToken::create(state.value());
 
-    if (document && currentToken()->processingUserGesture())
-        document->topDocument().updateLastHandledUserGestureTimestamp();
+    if (document && currentToken()->processingUserGesture()) {
+        document->updateLastHandledUserGestureTimestamp(MonotonicTime::now());
+        ResourceLoadObserver::sharedObserver().logUserInteractionWithReducedTimeResolution(*document);
+    }
 }
 
 UserGestureIndicator::UserGestureIndicator(RefPtr<UserGestureToken> token)
index afa368c..b8c2878 100644 (file)
@@ -3773,6 +3773,15 @@ bool Internals::isProcessingUserGesture()
     return UserGestureIndicator::processingUserGesture();
 }
 
+double Internals::lastHandledUserGestureTimestamp()
+{
+    Document* document = contextDocument();
+    if (!document)
+        return 0;
+
+    return document->lastHandledUserGestureTimestamp().secondsSinceEpoch().value();
+}
+
 RefPtr<GCObservation> Internals::observeGC(JSC::JSValue value)
 {
     if (!value.isObject())
index 199b03e..4bc38d8 100644 (file)
@@ -532,6 +532,7 @@ public:
     String composedTreeAsText(Node&);
     
     bool isProcessingUserGesture();
+    double lastHandledUserGestureTimestamp();
 
     RefPtr<GCObservation> observeGC(JSC::JSValue);
 
index 108a01a..b85a049 100644 (file)
@@ -501,6 +501,7 @@ enum EventThrottlingBehavior {
     DOMString composedTreeAsText(Node parent);
 
     boolean isProcessingUserGesture();
+    double lastHandledUserGestureTimestamp();
 
     GCObservation? observeGC(any observed);