OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "core/events/Event.h" | 39 #include "core/events/Event.h" |
40 #include "core/inspector/InstanceCounters.h" | 40 #include "core/inspector/InstanceCounters.h" |
41 #include "core/workers/WorkerGlobalScope.h" | 41 #include "core/workers/WorkerGlobalScope.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 V8AbstractEventListener::V8AbstractEventListener(bool isAttribute, DOMWrapperWor
ld& world, v8::Isolate* isolate) | 45 V8AbstractEventListener::V8AbstractEventListener(bool isAttribute, DOMWrapperWor
ld& world, v8::Isolate* isolate) |
46 : EventListener(JSEventListenerType) | 46 : EventListener(JSEventListenerType) |
47 , m_isAttribute(isAttribute) | 47 , m_isAttribute(isAttribute) |
48 , m_world(world) | 48 , m_world(world) |
| 49 , m_originWorld(PassRefPtr<DOMWrapperWorld>(world.originWorld())) |
49 , m_isolate(isolate) | 50 , m_isolate(isolate) |
50 , m_workerGlobalScope(nullptr) | 51 , m_workerGlobalScope(nullptr) |
51 { | 52 { |
52 if (isMainThread()) | 53 if (isMainThread()) |
53 InstanceCounters::incrementCounter(InstanceCounters::JSEventListenerCoun
ter); | 54 InstanceCounters::incrementCounter(InstanceCounters::JSEventListenerCoun
ter); |
54 else | 55 else |
55 m_workerGlobalScope = toWorkerGlobalScope(currentExecutionContext(isolat
e)); | 56 m_workerGlobalScope = toWorkerGlobalScope(currentExecutionContext(isolat
e)); |
56 } | 57 } |
57 | 58 |
58 V8AbstractEventListener::~V8AbstractEventListener() | 59 V8AbstractEventListener::~V8AbstractEventListener() |
(...skipping 25 matching lines...) Expand all Loading... |
84 handleEvent(scriptState, event); | 85 handleEvent(scriptState, event); |
85 } | 86 } |
86 | 87 |
87 void V8AbstractEventListener::handleEvent(ScriptState* scriptState, Event* event
) | 88 void V8AbstractEventListener::handleEvent(ScriptState* scriptState, Event* event
) |
88 { | 89 { |
89 // The callback function on XMLHttpRequest can clear the event listener and
destroys 'this' object. Keep a local reference to it. | 90 // The callback function on XMLHttpRequest can clear the event listener and
destroys 'this' object. Keep a local reference to it. |
90 // See issue 889829. | 91 // See issue 889829. |
91 RefPtrWillBeRawPtr<V8AbstractEventListener> protect(this); | 92 RefPtrWillBeRawPtr<V8AbstractEventListener> protect(this); |
92 | 93 |
93 ScriptState::Scope scope(scriptState); | 94 ScriptState::Scope scope(scriptState); |
| 95 // Ensure the origin world gets propagated to the event and is reset afterwa
rds. |
| 96 DOMWrapperWorld::OriginWorldScope worldScope(m_originWorld); |
94 | 97 |
95 // Get the V8 wrapper for the event object. | 98 // Get the V8 wrapper for the event object. |
96 v8::Local<v8::Value> jsEvent = toV8(event, scriptState->context()->Global(),
isolate()); | 99 v8::Local<v8::Value> jsEvent = toV8(event, scriptState->context()->Global(),
isolate()); |
97 if (jsEvent.IsEmpty()) | 100 if (jsEvent.IsEmpty()) |
98 return; | 101 return; |
| 102 |
99 invokeEventHandler(scriptState, event, v8::Local<v8::Value>::New(isolate(),
jsEvent)); | 103 invokeEventHandler(scriptState, event, v8::Local<v8::Value>::New(isolate(),
jsEvent)); |
100 } | 104 } |
101 | 105 |
102 void V8AbstractEventListener::setListenerObject(v8::Local<v8::Object> listener) | 106 void V8AbstractEventListener::setListenerObject(v8::Local<v8::Object> listener) |
103 { | 107 { |
104 ASSERT(m_listener.isEmpty()); | 108 ASSERT(m_listener.isEmpty()); |
105 // Balanced in secondWeakCallback xor clearListenerObject. | 109 // Balanced in secondWeakCallback xor clearListenerObject. |
106 if (m_workerGlobalScope) { | 110 if (m_workerGlobalScope) { |
107 m_workerGlobalScope->registerEventListener(this); | 111 m_workerGlobalScope->registerEventListener(this); |
108 } else { | 112 } else { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 232 |
229 DEFINE_TRACE(V8AbstractEventListener) | 233 DEFINE_TRACE(V8AbstractEventListener) |
230 { | 234 { |
231 #if ENABLE(OILPAN) | 235 #if ENABLE(OILPAN) |
232 visitor->trace(m_workerGlobalScope); | 236 visitor->trace(m_workerGlobalScope); |
233 #endif | 237 #endif |
234 EventListener::trace(visitor); | 238 EventListener::trace(visitor); |
235 } | 239 } |
236 | 240 |
237 } // namespace blink | 241 } // namespace blink |
OLD | NEW |