Title: [255499] trunk/Source/WebCore
Revision
255499
Author
an...@apple.com
Date
2020-01-31 09:07:15 -0800 (Fri, 31 Jan 2020)

Log Message

REGRESSION (r240250): Pages using smoothscroll.js can't be scrolled with trackpad
https://bugs.webkit.org/show_bug.cgi?id=207040
<rdar://problem/52712513>

Reviewed by Simon Fraser.

Add a quirk that makes the wheel event listener used by smoothscroll.js passive so it can't prevent scrolling.

This uses the same logic as the Chromium intervention in
https://chromium.googlesource.com/chromium/src/+/b6b13c9cfe64d52a4168d9d8d1ad9bb8f0b46a2a%5E%21/

* bindings/js/JSEventListener.cpp:
(WebCore::JSEventListener::functionName const):
* bindings/js/JSEventListener.h:
* dom/EventTarget.cpp:
(WebCore::EventTarget::addEventListener):
* page/Quirks.cpp:
(WebCore::Quirks::shouldMakeEventListenerPassive const):

Also factor the existing code for making some touch event listeners passive here.

* page/Quirks.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (255498 => 255499)


--- trunk/Source/WebCore/ChangeLog	2020-01-31 16:38:30 UTC (rev 255498)
+++ trunk/Source/WebCore/ChangeLog	2020-01-31 17:07:15 UTC (rev 255499)
@@ -1,3 +1,28 @@
+2020-01-31  Antti Koivisto  <an...@apple.com>
+
+        REGRESSION (r240250): Pages using smoothscroll.js can't be scrolled with trackpad
+        https://bugs.webkit.org/show_bug.cgi?id=207040
+        <rdar://problem/52712513>
+
+        Reviewed by Simon Fraser.
+
+        Add a quirk that makes the wheel event listener used by smoothscroll.js passive so it can't prevent scrolling.
+
+        This uses the same logic as the Chromium intervention in
+        https://chromium.googlesource.com/chromium/src/+/b6b13c9cfe64d52a4168d9d8d1ad9bb8f0b46a2a%5E%21/
+
+        * bindings/js/JSEventListener.cpp:
+        (WebCore::JSEventListener::functionName const):
+        * bindings/js/JSEventListener.h:
+        * dom/EventTarget.cpp:
+        (WebCore::EventTarget::addEventListener):
+        * page/Quirks.cpp:
+        (WebCore::Quirks::shouldMakeEventListenerPassive const):
+
+        Also factor the existing code for making some touch event listeners passive here.
+
+        * page/Quirks.h:
+
 2020-01-31  Peng Liu  <peng.l...@apple.com>
 
         Media controls of the video player on nfl.com are not visible in fullscreen mode (iPad only)

Modified: trunk/Source/WebCore/bindings/js/JSEventListener.cpp (255498 => 255499)


--- trunk/Source/WebCore/bindings/js/JSEventListener.cpp	2020-01-31 16:38:30 UTC (rev 255498)
+++ trunk/Source/WebCore/bindings/js/JSEventListener.cpp	2020-01-31 17:07:15 UTC (rev 255499)
@@ -222,6 +222,21 @@
     return m_jsFunction == other.m_jsFunction && m_isAttribute == other.m_isAttribute;
 }
 
+String JSEventListener::functionName() const
+{
+    if (!m_wrapper || !m_jsFunction)
+        return { };
+
+    auto& vm = isolatedWorld().vm();
+    JSC::JSLockHolder lock(vm);
+
+    auto* handlerFunction = JSC::jsDynamicCast<JSC::JSFunction*>(vm, m_jsFunction.get());
+    if (!handlerFunction)
+        return { };
+
+    return handlerFunction->name(vm);
+}
+
 static inline JSC::JSValue eventHandlerAttribute(EventListener* abstractListener, ScriptExecutionContext& context)
 {
     if (!is<JSEventListener>(abstractListener))

Modified: trunk/Source/WebCore/bindings/js/JSEventListener.h (255498 => 255499)


--- trunk/Source/WebCore/bindings/js/JSEventListener.h	2020-01-31 16:38:30 UTC (rev 255498)
+++ trunk/Source/WebCore/bindings/js/JSEventListener.h	2020-01-31 17:07:15 UTC (rev 255499)
@@ -57,6 +57,8 @@
     virtual String sourceURL() const { return String(); }
     virtual TextPosition sourcePosition() const { return TextPosition(); }
 
+    String functionName() const;
+
 private:
     virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext&) const;
     void visitJSFunction(JSC::SlotVisitor&) final;

Modified: trunk/Source/WebCore/dom/EventTarget.cpp (255498 => 255499)


--- trunk/Source/WebCore/dom/EventTarget.cpp	2020-01-31 16:38:30 UTC (rev 255498)
+++ trunk/Source/WebCore/dom/EventTarget.cpp	2020-01-31 17:07:15 UTC (rev 255499)
@@ -39,6 +39,7 @@
 #include "InspectorInstrumentation.h"
 #include "JSEventListener.h"
 #include "JSLazyEventListener.h"
+#include "Quirks.h"
 #include "ScriptController.h"
 #include "ScriptDisallowedScope.h"
 #include "Settings.h"
@@ -75,17 +76,8 @@
 
     auto passive = options.passive;
 
-    if (!passive.hasValue() && eventNames().isTouchScrollBlockingEventType(eventType)) {
-        if (is<DOMWindow>(*this)) {
-            auto& window = downcast<DOMWindow>(*this);
-            if (auto* document = window.document())
-                passive = document->settings().passiveTouchListenersAsDefaultOnDocument();
-        } else if (is<Node>(*this)) {
-            auto& node = downcast<Node>(*this);
-            if (is<Document>(node) || node.document().documentElement() == &node || node.document().body() == &node)
-                passive = node.document().settings().passiveTouchListenersAsDefaultOnDocument();
-        }
-    }
+    if (!passive.hasValue() && Quirks::shouldMakeEventListenerPassive(*this, eventType, listener.get()))
+        passive = true;
 
     bool listenerCreatedFromScript = listener->type() == EventListener::JSEventListenerType && !listener->wasCreatedFromMarkup();
     auto listenerRef = listener.copyRef();

Modified: trunk/Source/WebCore/page/Quirks.cpp (255498 => 255499)


--- trunk/Source/WebCore/page/Quirks.cpp	2020-01-31 16:38:30 UTC (rev 255498)
+++ trunk/Source/WebCore/page/Quirks.cpp	2020-01-31 17:07:15 UTC (rev 255499)
@@ -28,11 +28,15 @@
 
 #include "CustomHeaderFields.h"
 #include "DOMTokenList.h"
+#include "DOMWindow.h"
 #include "Document.h"
 #include "DocumentLoader.h"
+#include "EventNames.h"
 #include "FrameLoader.h"
+#include "HTMLBodyElement.h"
 #include "HTMLMetaElement.h"
 #include "HTMLObjectElement.h"
+#include "JSEventListener.h"
 #include "LayoutUnit.h"
 #include "RuntimeEnabledFeatures.h"
 #include "Settings.h"
@@ -617,6 +621,43 @@
     return false;
 }
 
+bool Quirks::shouldMakeEventListenerPassive(const EventTarget& eventTarget, const AtomString& eventType, const EventListener& eventListener)
+{
+    if (eventNames().isTouchScrollBlockingEventType(eventType)) {
+        if (is<DOMWindow>(eventTarget)) {
+            auto& window = downcast<DOMWindow>(eventTarget);
+            if (auto* document = window.document())
+                return document->settings().passiveTouchListenersAsDefaultOnDocument();
+        } else if (is<Node>(eventTarget)) {
+            auto& node = downcast<Node>(eventTarget);
+            if (is<Document>(node) || node.document().documentElement() == &node || node.document().body() == &node)
+                return node.document().settings().passiveTouchListenersAsDefaultOnDocument();
+        }
+        return false;
+    }
+
+    if (eventType == eventNames().mousewheelEvent) {
+        if (!is<JSEventListener>(eventListener))
+            return false;
+
+        // For SmoothScroll.js
+        // Matches Blink intervention in https://chromium.googlesource.com/chromium/src/+/b6b13c9cfe64d52a4168d9d8d1ad9bb8f0b46a2a%5E%21/
+        if (is<DOMWindow>(eventTarget)) {
+            auto* document = downcast<DOMWindow>(eventTarget).document();
+            if (!document || !document->quirks().needsQuirks())
+                return false;
+
+            auto& jsEventListener = downcast<JSEventListener>(eventListener);
+            if (jsEventListener.functionName() == "ssc_wheel")
+                return true;
+        }
+
+        return false;
+    }
+
+    return false;
+}
+
 #if ENABLE(MEDIA_STREAM)
 bool Quirks::shouldEnableLegacyGetUserMedia() const
 {

Modified: trunk/Source/WebCore/page/Quirks.h (255498 => 255499)


--- trunk/Source/WebCore/page/Quirks.h	2020-01-31 16:38:30 UTC (rev 255498)
+++ trunk/Source/WebCore/page/Quirks.h	2020-01-31 17:07:15 UTC (rev 255499)
@@ -32,6 +32,7 @@
 
 class Document;
 class Element;
+class EventListener;
 class EventTarget;
 class HTMLElement;
 class LayoutUnit;
@@ -83,6 +84,8 @@
 
     bool shouldBypassBackForwardCache() const;
 
+    static bool shouldMakeEventListenerPassive(const EventTarget&, const AtomString& eventType, const EventListener&);
+
 #if ENABLE(MEDIA_STREAM)
     bool shouldEnableLegacyGetUserMedia() const;
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to