| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 16 matching lines...) Expand all Loading... |
| 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 #include "config.h" | 31 #include "config.h" |
| 32 #include "bindings/core/v8/V8EventTarget.h" | 32 #include "bindings/core/v8/V8EventTarget.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/BindingSecurity.h" | 34 #include "bindings/core/v8/BindingSecurity.h" |
| 35 #include "bindings/core/v8/V8EventListenerList.h" | 35 #include "bindings/core/v8/V8EventListenerList.h" |
| 36 #include "core/frame/LocalDOMWindow.h" | 36 #include "core/frame/LocalDOMWindow.h" |
| 37 #include "core/frame/UseCounter.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 static void addEventListenerMethodEpilogue(const v8::FunctionCallbackInfo<v8::Va
lue>& info, EventTarget* impl) | 41 static void addEventListenerMethodEpilogue(const v8::FunctionCallbackInfo<v8::Va
lue>& info, EventTarget* impl) |
| 41 { | 42 { |
| 42 if (info.Length() >= 2 && info[1]->IsObject() && !impl->toNode()) | 43 if (info.Length() >= 2 && info[1]->IsObject() && !impl->toNode()) |
| 43 addHiddenValueToArray(info.GetIsolate(), info.Holder(), info[1], V8Event
Target::eventListenerCacheIndex); | 44 addHiddenValueToArray(info.GetIsolate(), info.Holder(), info[1], V8Event
Target::eventListenerCacheIndex); |
| 44 } | 45 } |
| 45 | 46 |
| 46 void V8EventTarget::addEventListenerMethodCustom(const v8::FunctionCallbackInfo<
v8::Value>& info) | 47 void V8EventTarget::addEventListenerMethodCustom(const v8::FunctionCallbackInfo<
v8::Value>& info) |
| 47 { | 48 { |
| 48 ExceptionState exceptionState(ExceptionState::ExecutionContext, "addEventLis
tener", "EventTarget", info.Holder(), info.GetIsolate()); | 49 ExceptionState exceptionState(ExceptionState::ExecutionContext, "addEventLis
tener", "EventTarget", info.Holder(), info.GetIsolate()); |
| 50 if (UNLIKELY(info.Length() < 2)) { |
| 51 // TODO(philipj): Remove the custom bindings when usage allows. The |
| 52 // generated bindings would thrown here instead. crbug.com/353484 |
| 53 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionC
ontext(info.GetIsolate()), |
| 54 info.Length() == 0 ? UseCounter::AddEventListenerNoArguments : UseCo
unter::AddEventListenerOneArgument); |
| 55 return; |
| 56 } |
| 49 EventTarget* impl = V8EventTarget::toImpl(info.Holder()); | 57 EventTarget* impl = V8EventTarget::toImpl(info.Holder()); |
| 50 if (LocalDOMWindow* window = impl->toDOMWindow()) { | 58 if (LocalDOMWindow* window = impl->toDOMWindow()) { |
| 51 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window
->frame(), exceptionState)) { | 59 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window
->frame(), exceptionState)) { |
| 52 exceptionState.throwIfNeeded(); | 60 exceptionState.throwIfNeeded(); |
| 53 return; | 61 return; |
| 54 } | 62 } |
| 55 if (!window->document()) | 63 if (!window->document()) |
| 56 return; | 64 return; |
| 57 } | 65 } |
| 58 V8StringResource<TreatNullAsNullString> type; | 66 V8StringResource<TreatNullAsNullString> type; |
| 59 RefPtr<EventListener> listener; | 67 RefPtr<EventListener> listener; |
| 60 bool capture; | 68 bool capture; |
| 61 { | 69 { |
| 62 if (UNLIKELY(info.Length() <= 0)) { | |
| 63 impl->addEventListener(); | |
| 64 addEventListenerMethodEpilogue(info, impl); | |
| 65 return; | |
| 66 } | |
| 67 type = info[0]; | 70 type = info[0]; |
| 68 if (!type.prepare()) | 71 if (!type.prepare()) |
| 69 return; | 72 return; |
| 70 listener = V8EventListenerList::getEventListener(ScriptState::current(in
fo.GetIsolate()), info[1], false, ListenerFindOrCreate); | 73 listener = V8EventListenerList::getEventListener(ScriptState::current(in
fo.GetIsolate()), info[1], false, ListenerFindOrCreate); |
| 71 if (UNLIKELY(info.Length() <= 2)) { | |
| 72 impl->addEventListener(type, listener); | |
| 73 addEventListenerMethodEpilogue(info, impl); | |
| 74 return; | |
| 75 } | |
| 76 capture = toBoolean(info.GetIsolate(), info[2], exceptionState); | 74 capture = toBoolean(info.GetIsolate(), info[2], exceptionState); |
| 77 if (exceptionState.throwIfNeeded()) | 75 if (exceptionState.throwIfNeeded()) |
| 78 return; | 76 return; |
| 79 } | 77 } |
| 80 impl->addEventListener(type, listener, capture); | 78 impl->addEventListener(type, listener, capture); |
| 81 addEventListenerMethodEpilogue(info, impl); | 79 addEventListenerMethodEpilogue(info, impl); |
| 82 } | 80 } |
| 83 | 81 |
| 84 static void removeEventListenerMethodEpilogue(const v8::FunctionCallbackInfo<v8:
:Value>& info, EventTarget* impl) | 82 static void removeEventListenerMethodEpilogue(const v8::FunctionCallbackInfo<v8:
:Value>& info, EventTarget* impl) |
| 85 { | 83 { |
| 86 if (info.Length() >= 2 && info[1]->IsObject() && !impl->toNode()) | 84 if (info.Length() >= 2 && info[1]->IsObject() && !impl->toNode()) |
| 87 removeHiddenValueFromArray(info.GetIsolate(), info.Holder(), info[1], V8
EventTarget::eventListenerCacheIndex); | 85 removeHiddenValueFromArray(info.GetIsolate(), info.Holder(), info[1], V8
EventTarget::eventListenerCacheIndex); |
| 88 } | 86 } |
| 89 | 87 |
| 90 void V8EventTarget::removeEventListenerMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) | 88 void V8EventTarget::removeEventListenerMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) |
| 91 { | 89 { |
| 92 ExceptionState exceptionState(ExceptionState::ExecutionContext, "removeEvent
Listener", "EventTarget", info.Holder(), info.GetIsolate()); | 90 ExceptionState exceptionState(ExceptionState::ExecutionContext, "removeEvent
Listener", "EventTarget", info.Holder(), info.GetIsolate()); |
| 91 if (UNLIKELY(info.Length() < 2)) { |
| 92 // TODO(philipj): Remove the custom bindings when usage allows. The |
| 93 // generated bindings would thrown here instead. crbug.com/353484 |
| 94 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionC
ontext(info.GetIsolate()), |
| 95 info.Length() == 0 ? UseCounter::RemoveEventListenerNoArguments : Us
eCounter::RemoveEventListenerOneArgument); |
| 96 return; |
| 97 } |
| 93 EventTarget* impl = V8EventTarget::toImpl(info.Holder()); | 98 EventTarget* impl = V8EventTarget::toImpl(info.Holder()); |
| 94 if (LocalDOMWindow* window = impl->toDOMWindow()) { | 99 if (LocalDOMWindow* window = impl->toDOMWindow()) { |
| 95 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window
->frame(), exceptionState)) { | 100 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window
->frame(), exceptionState)) { |
| 96 exceptionState.throwIfNeeded(); | 101 exceptionState.throwIfNeeded(); |
| 97 return; | 102 return; |
| 98 } | 103 } |
| 99 if (!window->document()) | 104 if (!window->document()) |
| 100 return; | 105 return; |
| 101 } | 106 } |
| 102 V8StringResource<TreatNullAsNullString> type; | 107 V8StringResource<TreatNullAsNullString> type; |
| 103 RefPtr<EventListener> listener; | 108 RefPtr<EventListener> listener; |
| 104 bool capture; | 109 bool capture; |
| 105 { | 110 { |
| 106 if (UNLIKELY(info.Length() <= 0)) { | |
| 107 impl->removeEventListener(); | |
| 108 removeEventListenerMethodEpilogue(info, impl); | |
| 109 return; | |
| 110 } | |
| 111 type = info[0]; | 111 type = info[0]; |
| 112 if (!type.prepare()) | 112 if (!type.prepare()) |
| 113 return; | 113 return; |
| 114 listener = V8EventListenerList::getEventListener(ScriptState::current(in
fo.GetIsolate()), info[1], false, ListenerFindOnly); | 114 listener = V8EventListenerList::getEventListener(ScriptState::current(in
fo.GetIsolate()), info[1], false, ListenerFindOnly); |
| 115 if (UNLIKELY(info.Length() <= 2)) { | |
| 116 impl->removeEventListener(type, listener); | |
| 117 removeEventListenerMethodEpilogue(info, impl); | |
| 118 return; | |
| 119 } | |
| 120 capture = toBoolean(info.GetIsolate(), info[2], exceptionState); | 115 capture = toBoolean(info.GetIsolate(), info[2], exceptionState); |
| 121 if (exceptionState.throwIfNeeded()) | 116 if (exceptionState.throwIfNeeded()) |
| 122 return; | 117 return; |
| 123 } | 118 } |
| 124 impl->removeEventListener(type, listener, capture); | 119 impl->removeEventListener(type, listener, capture); |
| 125 removeEventListenerMethodEpilogue(info, impl); | 120 removeEventListenerMethodEpilogue(info, impl); |
| 126 } | 121 } |
| 127 | 122 |
| 128 } // namespace blink | 123 } // namespace blink |
| OLD | NEW |