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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
(...skipping 20 matching lines...) Expand all
31 31
32 #include "core/events/EventTarget.h" 32 #include "core/events/EventTarget.h"
33 33
34 #include "bindings/core/v8/ExceptionState.h" 34 #include "bindings/core/v8/ExceptionState.h"
35 #include "bindings/core/v8/V8DOMActivityLogger.h" 35 #include "bindings/core/v8/V8DOMActivityLogger.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 #include "core/editing/Editor.h" 37 #include "core/editing/Editor.h"
38 #include "core/events/Event.h" 38 #include "core/events/Event.h"
39 #include "core/inspector/InspectorInstrumentation.h" 39 #include "core/inspector/InspectorInstrumentation.h"
40 #include "core/frame/LocalDOMWindow.h" 40 #include "core/frame/LocalDOMWindow.h"
41 #include "core/frame/Settings.h"
41 #include "core/frame/UseCounter.h" 42 #include "core/frame/UseCounter.h"
42 #include "platform/EventDispatchForbiddenScope.h" 43 #include "platform/EventDispatchForbiddenScope.h"
43 #include "wtf/StdLibExtras.h" 44 #include "wtf/StdLibExtras.h"
44 #include "wtf/Threading.h" 45 #include "wtf/Threading.h"
45 #include "wtf/Vector.h" 46 #include "wtf/Vector.h"
46 47
47 using namespace WTF; 48 using namespace WTF;
48 49
49 namespace blink { 50 namespace blink {
50 namespace { 51 namespace {
51 52
52 void setDefaultEventListenerOptionsLegacy(EventListenerOptions& options, bool us eCapture) 53 Settings* windowSettings(LocalDOMWindow* executingWindow)
53 { 54 {
54 options.setCapture(useCapture); 55 if (executingWindow) {
55 } 56 if (LocalFrame* frame = executingWindow->frame()) {
56 57 return frame->settings();
57 void setDefaultAddEventListenerOptionsLegacy(AddEventListenerOptions& options, b ool useCapture) 58 }
58 { 59 }
59 setDefaultEventListenerOptionsLegacy(options, useCapture); 60 return nullptr;
60 options.setPassive(false);
61 }
62
63 void setDefaultAddEventListenerOptions(AddEventListenerOptions& options)
64 {
65 if (!options.hasPassive())
66 options.setPassive(false);
67 } 61 }
68 62
69 } // namespace 63 } // namespace
70 64
71 EventTargetData::EventTargetData() 65 EventTargetData::EventTargetData()
72 { 66 {
73 } 67 }
74 68
75 EventTargetData::~EventTargetData() 69 EventTargetData::~EventTargetData()
76 { 70 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return nullptr; 108 return nullptr;
115 } 109 }
116 110
117 inline LocalDOMWindow* EventTarget::executingWindow() 111 inline LocalDOMWindow* EventTarget::executingWindow()
118 { 112 {
119 if (ExecutionContext* context = getExecutionContext()) 113 if (ExecutionContext* context = getExecutionContext())
120 return context->executingWindow(); 114 return context->executingWindow();
121 return nullptr; 115 return nullptr;
122 } 116 }
123 117
118 void EventTarget::setDefaultAddEventListenerOptions(AddEventListenerOptions& opt ions)
119 {
120 if (Settings* settings = windowSettings(executingWindow())) {
121 switch (settings->passiveListenerDefault()) {
122 case PassiveListenerDefault::False:
123 if (!options.hasPassive())
124 options.setPassive(false);
125 break;
126 case PassiveListenerDefault::True:
127 if (!options.hasPassive())
128 options.setPassive(true);
129 break;
130 case PassiveListenerDefault::ForceAllTrue:
131 options.setPassive(true);
132 break;
133 case PassiveListenerDefault::DocumentTrue:
134 if (!options.hasPassive()) {
135 if (Node* node = toNode()) {
136 if (node->isDocumentNode() || static_cast<Node*>(node->docum ent().documentElement()) == node || static_cast<Node*>(node->document().body()) == node) {
Rick Byers 2016/05/09 21:48:48 the static_casts aren't actually necessary here, a
dtapuska 2016/05/11 20:01:10 I've tried it; I do recall one build bot complaini
137 options.setPassive(true);
138 }
139 } else if (toLocalDOMWindow()) {
140 options.setPassive(true);
141 }
142 }
143 break;
144 }
145 }
146 }
147
124 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture) 148 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
125 { 149 {
126 AddEventListenerOptions options; 150 AddEventListenerOptions options;
127 setDefaultAddEventListenerOptionsLegacy(options, useCapture); 151 options.setCapture(useCapture);
152 setDefaultAddEventListenerOptions(options);
128 return addEventListenerInternal(eventType, listener, options); 153 return addEventListenerInternal(eventType, listener, options);
129 } 154 }
130 155
131 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, const AddEventListenerOptionsOrBoolean& optionsUnion) 156 bool EventTarget::addEventListener(const AtomicString& eventType, EventListener* listener, const AddEventListenerOptionsOrBoolean& optionsUnion)
132 { 157 {
133 if (optionsUnion.isBoolean()) 158 if (optionsUnion.isBoolean())
134 return addEventListener(eventType, listener, optionsUnion.getAsBoolean() ); 159 return addEventListener(eventType, listener, optionsUnion.getAsBoolean() );
135 if (optionsUnion.isAddEventListenerOptions()) { 160 if (optionsUnion.isAddEventListenerOptions()) {
136 AddEventListenerOptions options = optionsUnion.getAsAddEventListenerOpti ons(); 161 AddEventListenerOptions options = optionsUnion.getAsAddEventListenerOpti ons();
137 return addEventListener(eventType, listener, options); 162 return addEventListener(eventType, listener, options);
(...skipping 27 matching lines...) Expand all
165 return added; 190 return added;
166 } 191 }
167 192
168 void EventTarget::addedEventListener(const AtomicString& eventType, RegisteredEv entListener& registeredListener) 193 void EventTarget::addedEventListener(const AtomicString& eventType, RegisteredEv entListener& registeredListener)
169 { 194 {
170 } 195 }
171 196
172 bool EventTarget::removeEventListener(const AtomicString& eventType, const Event Listener* listener, bool useCapture) 197 bool EventTarget::removeEventListener(const AtomicString& eventType, const Event Listener* listener, bool useCapture)
173 { 198 {
174 EventListenerOptions options; 199 EventListenerOptions options;
175 setDefaultEventListenerOptionsLegacy(options, useCapture); 200 options.setCapture(useCapture);
176 return removeEventListenerInternal(eventType, listener, options); 201 return removeEventListenerInternal(eventType, listener, options);
177 } 202 }
178 203
179 bool EventTarget::removeEventListener(const AtomicString& eventType, const Event Listener* listener, const EventListenerOptionsOrBoolean& optionsUnion) 204 bool EventTarget::removeEventListener(const AtomicString& eventType, const Event Listener* listener, const EventListenerOptionsOrBoolean& optionsUnion)
180 { 205 {
181 if (optionsUnion.isBoolean()) 206 if (optionsUnion.isBoolean())
182 return removeEventListener(eventType, listener, optionsUnion.getAsBoolea n()); 207 return removeEventListener(eventType, listener, optionsUnion.getAsBoolea n());
183 if (optionsUnion.isEventListenerOptions()) { 208 if (optionsUnion.isEventListenerOptions()) {
184 EventListenerOptions options = optionsUnion.getAsEventListenerOptions(); 209 EventListenerOptions options = optionsUnion.getAsEventListenerOptions();
185 return removeEventListener(eventType, listener, options); 210 return removeEventListener(eventType, listener, options);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // they have one less listener to invoke. 526 // they have one less listener to invoke.
502 if (d->firingEventIterators) { 527 if (d->firingEventIterators) {
503 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) { 528 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) {
504 d->firingEventIterators->at(i).iterator = 0; 529 d->firingEventIterators->at(i).iterator = 0;
505 d->firingEventIterators->at(i).end = 0; 530 d->firingEventIterators->at(i).end = 0;
506 } 531 }
507 } 532 }
508 } 533 }
509 534
510 } // namespace blink 535 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698