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

Side by Side Diff: Source/core/dom/EventTarget.cpp

Issue 16904002: Avoid leaking objects between isolated worlds via attribute event listeners (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Patch for landing Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/EventTarget.h ('k') | Source/core/dom/MessagePort.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 14 matching lines...) Expand all
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * 29 *
30 */ 30 */
31 31
32 #include "config.h" 32 #include "config.h"
33 #include "core/dom/EventTarget.h" 33 #include "core/dom/EventTarget.h"
34 34
35 #include "bindings/v8/DOMWrapperWorld.h"
35 #include "bindings/v8/ScriptController.h" 36 #include "bindings/v8/ScriptController.h"
36 #include "core/dom/Event.h" 37 #include "core/dom/Event.h"
37 #include "core/dom/ExceptionCode.h" 38 #include "core/dom/ExceptionCode.h"
38 #include "core/inspector/InspectorInstrumentation.h" 39 #include "core/inspector/InspectorInstrumentation.h"
39 #include <wtf/MainThread.h> 40 #include <wtf/MainThread.h>
40 #include <wtf/StdLibExtras.h> 41 #include <wtf/StdLibExtras.h>
41 #include <wtf/Vector.h> 42 #include <wtf/Vector.h>
42 43
43 using namespace WTF; 44 using namespace WTF;
44 45
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 continue; 97 continue;
97 98
98 --firingIterator.end; 99 --firingIterator.end;
99 if (indexOfRemovedListener <= firingIterator.iterator) 100 if (indexOfRemovedListener <= firingIterator.iterator)
100 --firingIterator.iterator; 101 --firingIterator.iterator;
101 } 102 }
102 103
103 return true; 104 return true;
104 } 105 }
105 106
106 bool EventTarget::setAttributeEventListener(const AtomicString& eventType, PassR efPtr<EventListener> listener) 107 bool EventTarget::setAttributeEventListener(const AtomicString& eventType, PassR efPtr<EventListener> listener, DOMWrapperWorld* isolatedWorld)
107 { 108 {
108 clearAttributeEventListener(eventType); 109 clearAttributeEventListener(eventType, isolatedWorld);
109 if (!listener) 110 if (!listener)
110 return false; 111 return false;
111 return addEventListener(eventType, listener, false); 112 return addEventListener(eventType, listener, false);
112 } 113 }
113 114
114 EventListener* EventTarget::getAttributeEventListener(const AtomicString& eventT ype) 115 EventListener* EventTarget::getAttributeEventListener(const AtomicString& eventT ype, DOMWrapperWorld* isolatedWorld)
115 { 116 {
116 const EventListenerVector& entry = getEventListeners(eventType); 117 const EventListenerVector& entry = getEventListeners(eventType);
117 for (size_t i = 0; i < entry.size(); ++i) { 118 for (size_t i = 0; i < entry.size(); ++i) {
118 if (entry[i].listener->isAttribute()) 119 EventListener* listener = entry[i].listener.get();
119 return entry[i].listener.get(); 120 if (listener->isAttribute()) {
121 DOMWrapperWorld* listenerWorld = listener->world();
122 // Worker listener
123 if (!listenerWorld) {
124 ASSERT(!isolatedWorld);
125 return listener;
126 }
127 if (listenerWorld->isMainWorld() && !isolatedWorld)
128 return listener;
129 if (listenerWorld == isolatedWorld)
130 return listener;
131 }
120 } 132 }
121 return 0; 133 return 0;
122 } 134 }
123 135
124 bool EventTarget::clearAttributeEventListener(const AtomicString& eventType) 136 bool EventTarget::clearAttributeEventListener(const AtomicString& eventType, DOM WrapperWorld* isolatedWorld)
125 { 137 {
126 EventListener* listener = getAttributeEventListener(eventType); 138 EventListener* listener = getAttributeEventListener(eventType, isolatedWorld );
127 if (!listener) 139 if (!listener)
128 return false; 140 return false;
129 return removeEventListener(eventType, listener, false); 141 return removeEventListener(eventType, listener, false);
130 } 142 }
131 143
132 bool EventTarget::dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec) 144 bool EventTarget::dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec)
133 { 145 {
134 if (!event || event->type().isEmpty() || event->isBeingDispatched()) { 146 if (!event || event->type().isEmpty() || event->isBeingDispatched()) {
135 ec = INVALID_STATE_ERR; 147 ec = INVALID_STATE_ERR;
136 return false; 148 return false;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // they have one less listener to invoke. 292 // they have one less listener to invoke.
281 if (d->firingEventIterators) { 293 if (d->firingEventIterators) {
282 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) { 294 for (size_t i = 0; i < d->firingEventIterators->size(); ++i) {
283 d->firingEventIterators->at(i).iterator = 0; 295 d->firingEventIterators->at(i).iterator = 0;
284 d->firingEventIterators->at(i).end = 0; 296 d->firingEventIterators->at(i).end = 0;
285 } 297 }
286 } 298 }
287 } 299 }
288 300
289 } // namespace WebCore 301 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/EventTarget.h ('k') | Source/core/dom/MessagePort.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698