Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1382)

Unified Diff: third_party/WebKit/Source/core/events/EventTarget.cpp

Issue 1965493002: Add runtime setting to force passive event listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/events/EventTarget.cpp
diff --git a/third_party/WebKit/Source/core/events/EventTarget.cpp b/third_party/WebKit/Source/core/events/EventTarget.cpp
index c8caf6c1c80cc24dfb511c85d736e0cbdf81e0ff..7781288b249f8885ed54b6ba726baf63644f95d4 100644
--- a/third_party/WebKit/Source/core/events/EventTarget.cpp
+++ b/third_party/WebKit/Source/core/events/EventTarget.cpp
@@ -54,21 +54,14 @@ using namespace WTF;
namespace blink {
namespace {
-void setDefaultEventListenerOptionsLegacy(EventListenerOptions& options, bool useCapture)
+Settings* windowSettings(LocalDOMWindow* executingWindow)
{
- options.setCapture(useCapture);
-}
-
-void setDefaultAddEventListenerOptionsLegacy(AddEventListenerOptions& options, bool useCapture)
-{
- setDefaultEventListenerOptionsLegacy(options, useCapture);
- options.setPassive(false);
-}
-
-void setDefaultAddEventListenerOptions(AddEventListenerOptions& options)
-{
- if (!options.hasPassive())
- options.setPassive(false);
+ if (executingWindow) {
+ if (LocalFrame* frame = executingWindow->frame()) {
+ return frame->settings();
+ }
+ }
+ return nullptr;
}
double blockedEventsWarningThreshold(const ExecutionContext* context, const Event* event)
@@ -189,10 +182,44 @@ inline LocalDOMWindow* EventTarget::executingWindow()
return nullptr;
}
+void EventTarget::setDefaultAddEventListenerOptions(AddEventListenerOptions& options)
+{
+ if (Settings* settings = windowSettings(executingWindow())) {
+ switch (settings->passiveListenerDefault()) {
+ case PassiveListenerDefault::False:
+ if (!options.hasPassive())
+ options.setPassive(false);
+ break;
+ case PassiveListenerDefault::True:
+ if (!options.hasPassive())
+ options.setPassive(true);
+ break;
+ case PassiveListenerDefault::ForceAllTrue:
+ options.setPassive(true);
+ break;
+ case PassiveListenerDefault::DocumentTrue:
+ if (!options.hasPassive()) {
+ if (Node* node = toNode()) {
+ if (node->isDocumentNode() || node->document().documentElement() == node || node->document().body() == node) {
+ options.setPassive(true);
+ }
+ } else if (toLocalDOMWindow()) {
+ options.setPassive(true);
+ }
+ }
+ break;
+ }
+ } else {
+ if (!options.hasPassive())
+ options.setPassive(false);
+ }
+}
+
bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
{
AddEventListenerOptions options;
- setDefaultAddEventListenerOptionsLegacy(options, useCapture);
+ options.setCapture(useCapture);
+ setDefaultAddEventListenerOptions(options);
return addEventListenerInternal(eventType, listener, options);
}
@@ -245,7 +272,7 @@ void EventTarget::addedEventListener(const AtomicString& eventType, RegisteredEv
bool EventTarget::removeEventListener(const AtomicString& eventType, const EventListener* listener, bool useCapture)
{
EventListenerOptions options;
- setDefaultEventListenerOptionsLegacy(options, useCapture);
+ options.setCapture(useCapture);
return removeEventListenerInternal(eventType, listener, options);
}
« no previous file with comments | « third_party/WebKit/Source/core/events/EventTarget.h ('k') | third_party/WebKit/Source/core/frame/Settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698