Title: [242628] trunk
Revision
242628
Author
[email protected]
Date
2019-03-07 19:21:14 -0800 (Thu, 07 Mar 2019)

Log Message

[ContentChangeObserver] Introduce fixed duration content observation
https://bugs.webkit.org/show_bug.cgi?id=195295
<rdar://problem/48579913>

Reviewed by Simon Fraser.

Source/WebCore:

Some pages have a runloop-like scheduling setup where the content triggering change happens at a nested timer firing.
This patch helps finding cases like that using a 32ms long fixed window. Currently nested timers get dropped on the floor and
we stop observing for content changes before they even get fired.

Test: fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops.html

* page/ios/ContentChangeObserver.cpp:
(WebCore::ContentChangeObserver::ContentChangeObserver):
(WebCore::ContentChangeObserver::startContentObservationForDuration):
(WebCore::ContentChangeObserver::completeDurationBasedContentObservation):
(WebCore::ContentChangeObserver::didInstallDOMTimer):
(WebCore::ContentChangeObserver::didRemoveDOMTimer):
(WebCore::ContentChangeObserver::domTimerExecuteDidStart):
(WebCore::ContentChangeObserver::domTimerExecuteDidFinish):
(WebCore::ContentChangeObserver::styleRecalcDidStart):
(WebCore::ContentChangeObserver::styleRecalcDidFinish):
(WebCore::ContentChangeObserver::cancelPendingActivities):
(WebCore::ContentChangeObserver::didSuspendActiveDOMObjects):
(WebCore::ContentChangeObserver::willDetachPage):
(WebCore::ContentChangeObserver::contentVisibilityDidChange):
(WebCore::ContentChangeObserver::setShouldObserveNextStyleRecalc):
(WebCore::ContentChangeObserver::adjustObservedState):
(WebCore::ContentChangeObserver::StyleChangeScope::StyleChangeScope):
(WebCore::ContentChangeObserver::StyleChangeScope::~StyleChangeScope):
(WebCore::ContentChangeObserver::clearTimersAndReportContentChange): Deleted.
* page/ios/ContentChangeObserver.h:
(WebCore::ContentChangeObserver::clearObservedDOMTimers):
(WebCore::ContentChangeObserver::isObservingContentChanges const):
(WebCore::ContentChangeObserver::hasPendingActivity const):

Source/WebKit:

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::handleSyntheticClick):
(WebKit::WebPage::completePendingSyntheticClickForContentChangeObserver):

LayoutTests:

* fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops-expected.txt: Added.
* fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (242627 => 242628)


--- trunk/LayoutTests/ChangeLog	2019-03-08 02:54:17 UTC (rev 242627)
+++ trunk/LayoutTests/ChangeLog	2019-03-08 03:21:14 UTC (rev 242628)
@@ -1,3 +1,14 @@
+2019-03-07  Zalan Bujtas  <[email protected]>
+
+        [ContentChangeObserver] Introduce fixed duration content observation
+        https://bugs.webkit.org/show_bug.cgi?id=195295
+        <rdar://problem/48579913>
+
+        Reviewed by Simon Fraser.
+
+        * fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops-expected.txt: Added.
+        * fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops.html: Added.
+
 2019-03-07  Said Abou-Hallawa  <[email protected]>
 
         requestAnimationFrame should execute before the next frame

Added: trunk/LayoutTests/fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops-expected.txt (0 => 242628)


--- trunk/LayoutTests/fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops-expected.txt	2019-03-08 03:21:14 UTC (rev 242628)
@@ -0,0 +1,2 @@
+PASS if 'clicked' text is not shown below.
+

Added: trunk/LayoutTests/fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops.html (0 => 242628)


--- trunk/LayoutTests/fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops.html	2019-03-08 03:21:14 UTC (rev 242628)
@@ -0,0 +1,68 @@
+<html>
+<head>
+<title>This tests the case when nested timers trigger visible content change</title>
+<script src=""
+<style>
+#tapthis {
+    width: 400px;
+    height: 400px;
+    border: 1px solid green;
+}
+
+#becomesVisible {
+    visibility: hidden;
+    width: 100px;
+    height: 100px;
+    background-color: green;
+}
+</style>
+<script>
+async function test() {
+    if (!window.testRunner || !testRunner.runUIScript)
+        return;
+    if (window.internals)
+        internals.settings.setContentChangeObserverEnabled(true);
+
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+
+    let rect = tapthis.getBoundingClientRect();
+    let x = rect.left + rect.width / 2;
+    let y = rect.top + rect.height / 2;
+
+    await tapAtPoint(x, y);
+}
+</script>
+</head>
+<body _onload_="test()">
+<div id=tapthis>PASS if 'clicked' text is not shown below.</div>
+<div id=becomesVisible></div>
+<pre id=result></pre>
+<script>
+tapthis.addEventListener("mouseover", function( event ) {
+    // 1. Install a short timer on hover
+    setTimeout(function() {
+        // 2. Trigger some non-visibility style change with forcing offsetHeight.
+        becomesVisible.style.marginLeft = "5px";
+        document.body.offsetHeight;
+
+        // 3. Install a nested timer with visibility change.
+        setTimeout(function() {
+            becomesVisible.style.visibility = "visible";
+            document.body.offsetHeight;
+            if (window.testRunner)
+                setTimeout(testRunner.notifyDone(), 0);
+        }, 10);
+    }, 0);
+}, false);
+
+becomesVisible.addEventListener("click", function( event ) {   
+    result.innerHTML = "clicked hidden";
+}, false);
+
+tapthis.addEventListener("click", function( event ) {   
+    result.innerHTML = "clicked";
+}, false);
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (242627 => 242628)


--- trunk/Source/WebCore/ChangeLog	2019-03-08 02:54:17 UTC (rev 242627)
+++ trunk/Source/WebCore/ChangeLog	2019-03-08 03:21:14 UTC (rev 242628)
@@ -1,3 +1,41 @@
+2019-03-07  Zalan Bujtas  <[email protected]>
+
+        [ContentChangeObserver] Introduce fixed duration content observation
+        https://bugs.webkit.org/show_bug.cgi?id=195295
+        <rdar://problem/48579913>
+
+        Reviewed by Simon Fraser.
+
+        Some pages have a runloop-like scheduling setup where the content triggering change happens at a nested timer firing.
+        This patch helps finding cases like that using a 32ms long fixed window. Currently nested timers get dropped on the floor and
+        we stop observing for content changes before they even get fired.
+
+        Test: fast/events/touch/ios/content-observation/visibility-change-happens-on-timer-hops.html
+
+        * page/ios/ContentChangeObserver.cpp:
+        (WebCore::ContentChangeObserver::ContentChangeObserver):
+        (WebCore::ContentChangeObserver::startContentObservationForDuration):
+        (WebCore::ContentChangeObserver::completeDurationBasedContentObservation):
+        (WebCore::ContentChangeObserver::didInstallDOMTimer):
+        (WebCore::ContentChangeObserver::didRemoveDOMTimer):
+        (WebCore::ContentChangeObserver::domTimerExecuteDidStart):
+        (WebCore::ContentChangeObserver::domTimerExecuteDidFinish):
+        (WebCore::ContentChangeObserver::styleRecalcDidStart):
+        (WebCore::ContentChangeObserver::styleRecalcDidFinish):
+        (WebCore::ContentChangeObserver::cancelPendingActivities):
+        (WebCore::ContentChangeObserver::didSuspendActiveDOMObjects):
+        (WebCore::ContentChangeObserver::willDetachPage):
+        (WebCore::ContentChangeObserver::contentVisibilityDidChange):
+        (WebCore::ContentChangeObserver::setShouldObserveNextStyleRecalc):
+        (WebCore::ContentChangeObserver::adjustObservedState):
+        (WebCore::ContentChangeObserver::StyleChangeScope::StyleChangeScope):
+        (WebCore::ContentChangeObserver::StyleChangeScope::~StyleChangeScope):
+        (WebCore::ContentChangeObserver::clearTimersAndReportContentChange): Deleted.
+        * page/ios/ContentChangeObserver.h:
+        (WebCore::ContentChangeObserver::clearObservedDOMTimers):
+        (WebCore::ContentChangeObserver::isObservingContentChanges const):
+        (WebCore::ContentChangeObserver::hasPendingActivity const):
+
 2019-03-07  Said Abou-Hallawa  <[email protected]>
 
         requestAnimationFrame should execute before the next frame

Modified: trunk/Source/WebCore/page/ios/ContentChangeObserver.cpp (242627 => 242628)


--- trunk/Source/WebCore/page/ios/ContentChangeObserver.cpp	2019-03-08 02:54:17 UTC (rev 242627)
+++ trunk/Source/WebCore/page/ios/ContentChangeObserver.cpp	2019-03-08 03:21:14 UTC (rev 242628)
@@ -39,9 +39,26 @@
 
 ContentChangeObserver::ContentChangeObserver(Document& document)
     : m_document(document)
+    , m_contentObservationTimer([this] { completeDurationBasedContentObservation(); })
 {
 }
 
+void ContentChangeObserver::startContentObservationForDuration(Seconds duration)
+{
+    if (!m_document.settings().contentChangeObserverEnabled())
+        return;
+    ASSERT(!hasVisibleChangeState());
+    LOG_WITH_STREAM(ContentObservation, stream << "startContentObservationForDuration: start observing the content for " << duration.milliseconds() << "ms");
+    adjustObservedState(Event::StartedFixedObservationTimeWindow);
+    m_contentObservationTimer.startOneShot(duration);
+}
+
+void ContentChangeObserver::completeDurationBasedContentObservation()
+{
+    LOG_WITH_STREAM(ContentObservation, stream << "completeDurationBasedContentObservation: complete duration based content observing ");
+    adjustObservedState(Event::EndedFixedObservationTimeWindow);
+}
+
 void ContentChangeObserver::didInstallDOMTimer(const DOMTimer& timer, Seconds timeout, bool singleShot)
 {
     if (!m_document.settings().contentChangeObserverEnabled())
@@ -113,26 +130,22 @@
     adjustObservedState(Event::StyleRecalcFinished);
 }
 
-void ContentChangeObserver::clearTimersAndReportContentChange()
+void ContentChangeObserver::cancelPendingActivities()
 {
-    if (!hasObservedDOMTimer())
-        return;
-    LOG_WITH_STREAM(ContentObservation, stream << "clearTimersAndReportContentChange: remove registered timers and report content change." << observedContentChange());
-
     clearObservedDOMTimers();
-    ASSERT(m_document.page());
-    ASSERT(m_document.frame());
-    m_document.page()->chrome().client().observedContentChange(*m_document.frame());
+    m_contentObservationTimer.stop();
 }
 
 void ContentChangeObserver::didSuspendActiveDOMObjects()
 {
-    clearTimersAndReportContentChange();
+    LOG(ContentObservation, "didSuspendActiveDOMObjects");
+    cancelPendingActivities();
 }
 
 void ContentChangeObserver::willDetachPage()
 {
-    clearTimersAndReportContentChange();
+    LOG(ContentObservation, "willDetachPage");
+    cancelPendingActivities();
 }
 
 void ContentChangeObserver::contentVisibilityDidChange()
@@ -205,6 +218,7 @@
         setHasNoChangeState();
         break;
     case Event::InstalledDOMTimer:
+    case Event::StartedFixedObservationTimeWindow:
         // Expecting a timer fire. Promote to an indeterminate state.
         ASSERT(!hasVisibleChangeState());
         setHasIndeterminateState();
@@ -212,6 +226,7 @@
     case Event::RemovedDOMTimer:
     case Event::StyleRecalcFinished:
     case Event::EndedDOMTimerExecution:
+    case Event::EndedFixedObservationTimeWindow:
         // Demote to "no change" when there's no pending activity anymore.
         if (observedContentChange() == WKContentIndeterminateChange && !hasPendingActivity())
             setHasNoChangeState();

Modified: trunk/Source/WebCore/page/ios/ContentChangeObserver.h (242627 => 242628)


--- trunk/Source/WebCore/page/ios/ContentChangeObserver.h	2019-03-08 02:54:17 UTC (rev 242627)
+++ trunk/Source/WebCore/page/ios/ContentChangeObserver.h	2019-03-08 03:21:14 UTC (rev 242628)
@@ -29,6 +29,7 @@
 
 #include "Document.h"
 #include "RenderStyleConstants.h"
+#include "Timer.h"
 #include "WKContentObservation.h"
 #include <wtf/HashSet.h>
 #include <wtf/Seconds.h>
@@ -42,11 +43,11 @@
 public:
     ContentChangeObserver(Document&);
 
+    WEBCORE_EXPORT void startContentObservationForDuration(Seconds duration);
     WEBCORE_EXPORT WKContentChange observedContentChange() const;
 
     void didInstallDOMTimer(const DOMTimer&, Seconds timeout, bool singleShot);
     void didRemoveDOMTimer(const DOMTimer&);
-    void contentVisibilityDidChange();
     void didSuspendActiveDOMObjects();
     void willDetachPage();
 
@@ -93,6 +94,8 @@
     void mouseMovedDidStart();
     void mouseMovedDidFinish();
 
+    void contentVisibilityDidChange();
+
     void setShouldObserveDOMTimerScheduling(bool observe) { m_isObservingDOMTimerScheduling = observe; }
     bool isObservingDOMTimerScheduling() const { return m_isObservingDOMTimerScheduling; }
     void domTimerExecuteDidStart(const DOMTimer&);
@@ -99,6 +102,7 @@
     void domTimerExecuteDidFinish(const DOMTimer&);
     void registerDOMTimer(const DOMTimer& timer) { m_DOMTimerList.add(&timer); }
     void unregisterDOMTimer(const DOMTimer& timer) { m_DOMTimerList.remove(&timer); }
+    void clearObservedDOMTimers() { m_DOMTimerList.clear(); }
     bool containsObservedDOMTimer(const DOMTimer& timer) const { return m_DOMTimerList.contains(&timer); }
 
     void styleRecalcDidStart();
@@ -106,10 +110,9 @@
     void setShouldObserveNextStyleRecalc(bool);
     bool isObservingStyleRecalc() const { return m_isObservingStyleRecalc; }
 
-    bool isObservingContentChanges() const { return m_domTimerIsBeingExecuted || m_styleRecalcIsBeingExecuted; }
+    bool isObservingContentChanges() const { return m_domTimerIsBeingExecuted || m_styleRecalcIsBeingExecuted || m_contentObservationTimer.isActive(); }
 
-    void clearObservedDOMTimers() { m_DOMTimerList.clear(); }
-    void clearTimersAndReportContentChange();
+    void cancelPendingActivities();
 
     void setHasIndeterminateState();
     void setHasVisibleChangeState();
@@ -119,11 +122,13 @@
     bool hasObservedDOMTimer() const { return !m_DOMTimerList.isEmpty(); }
     bool hasDeterminateState() const;
 
-    bool hasPendingActivity() const { return hasObservedDOMTimer() || m_document.hasPendingStyleRecalc(); }
+    bool hasPendingActivity() const { return hasObservedDOMTimer() || m_document.hasPendingStyleRecalc() || m_contentObservationTimer.isActive(); }
 #if !ASSERT_DISABLED
     bool isNotifyContentChangeAllowed() const;
 #endif
 
+    void completeDurationBasedContentObservation();
+
     enum class Event {
         StartedMouseMovedEventDispatching,
         InstalledDOMTimer,
@@ -130,11 +135,14 @@
         RemovedDOMTimer,
         EndedDOMTimerExecution,
         StyleRecalcFinished,
-        ContentVisibilityChanged
+        ContentVisibilityChanged,
+        StartedFixedObservationTimeWindow,
+        EndedFixedObservationTimeWindow
     };
     void adjustObservedState(Event);
 
     Document& m_document;
+    Timer m_contentObservationTimer;
     HashSet<const DOMTimer*> m_DOMTimerList;
     bool m_isObservingStyleRecalc { false };
     bool m_styleRecalcIsBeingExecuted { false };

Modified: trunk/Source/WebKit/ChangeLog (242627 => 242628)


--- trunk/Source/WebKit/ChangeLog	2019-03-08 02:54:17 UTC (rev 242627)
+++ trunk/Source/WebKit/ChangeLog	2019-03-08 03:21:14 UTC (rev 242628)
@@ -1,3 +1,15 @@
+2019-03-07  Zalan Bujtas  <[email protected]>
+
+        [ContentChangeObserver] Introduce fixed duration content observation
+        https://bugs.webkit.org/show_bug.cgi?id=195295
+        <rdar://problem/48579913>
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::handleSyntheticClick):
+        (WebKit::WebPage::completePendingSyntheticClickForContentChangeObserver):
+
 2019-03-07  Fujii Hironori  <[email protected]>
 
         [WinCairo][WebKit] Nothing is drawn after Web process crashed

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (242627 => 242628)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-03-08 02:54:17 UTC (rev 242627)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-03-08 03:21:14 UTC (rev 242628)
@@ -559,32 +559,29 @@
         mainframe.document()->updateStyleIfNeeded();
     }
 
-    m_pendingSyntheticClickNode = nullptr;
-    m_pendingSyntheticClickLocation = FloatPoint();
-    m_pendingSyntheticClickModifiers = { };
-
     if (m_isClosed)
         return;
 
-    switch (respondingDocument.contentChangeObserver().observedContentChange()) {
-    case WKContentVisibilityChange:
+    auto& contentChangeObserver = respondingDocument.contentChangeObserver();
+    auto observedContentChange = contentChangeObserver.observedContentChange();
+    if (observedContentChange == WKContentVisibilityChange) {
         // The move event caused new contents to appear. Don't send the click event.
         LOG(ContentObservation, "handleSyntheticClick: Observed meaningful visible change -> hover.");
         return;
-    case WKContentIndeterminateChange: {
-        // Wait for callback to completePendingSyntheticClickForContentChangeObserver() to decide whether to send the click event.
-        ASSERT(respondingDocument.settings().contentChangeObserverEnabled());
-        m_pendingSyntheticClickNode = &nodeRespondingToClick;
-        m_pendingSyntheticClickLocation = location;
-        m_pendingSyntheticClickModifiers = modifiers;
-        LOG(ContentObservation, "handleSyntheticClick: Observed some change, but can't decide it yet -> wait.");
-        return;
-    } case WKContentNoChange:
-        LOG(ContentObservation, "handleSyntheticClick: No change was observed -> click.");
+    }
+    const Seconds observationDuration = 32_ms;
+    contentChangeObserver.startContentObservationForDuration(observationDuration);
+    if (contentChangeObserver.observedContentChange() == WKContentNoChange) {
+        ASSERT(!respondingDocument.settings().contentChangeObserverEnabled());
         completeSyntheticClick(nodeRespondingToClick, location, modifiers, WebCore::OneFingerTap);
         return;
     }
-    ASSERT_NOT_REACHED();
+
+    LOG(ContentObservation, "handleSyntheticClick: Can't decide it yet -> wait.");
+    // Wait for callback to completePendingSyntheticClickForContentChangeObserver() to decide whether to send the click event.
+    m_pendingSyntheticClickNode = &nodeRespondingToClick;
+    m_pendingSyntheticClickLocation = location;
+    m_pendingSyntheticClickModifiers = modifiers;
 }
 
 void WebPage::completePendingSyntheticClickForContentChangeObserver()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to