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 23 matching lines...) Expand all Loading... |
34 #include "bindings/core/v8/V8EventListenerList.h" | 34 #include "bindings/core/v8/V8EventListenerList.h" |
35 #include "bindings/core/v8/V8Window.h" | 35 #include "bindings/core/v8/V8Window.h" |
36 #include "core/frame/LocalDOMWindow.h" | 36 #include "core/frame/LocalDOMWindow.h" |
37 #include "core/frame/UseCounter.h" | 37 #include "core/frame/UseCounter.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 namespace { | 40 namespace { |
41 | 41 |
42 void addEventListenerMethodPrologueCustom(const v8::FunctionCallbackInfo<v8::Val
ue>& info, EventTarget*) | 42 void addEventListenerMethodPrologueCustom(const v8::FunctionCallbackInfo<v8::Val
ue>& info, EventTarget*) |
43 { | 43 { |
44 if (info.Length() < 2) { | |
45 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionC
ontext(info.GetIsolate()), | |
46 info.Length() == 0 ? UseCounter::AddEventListenerNoArguments : UseCo
unter::AddEventListenerOneArgument); | |
47 } | |
48 if (info.Length() >= 3 && info[2]->IsObject()) { | 44 if (info.Length() >= 3 && info[2]->IsObject()) { |
49 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionC
ontext(info.GetIsolate()), | 45 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionC
ontext(info.GetIsolate()), |
50 UseCounter::AddEventListenerThirdArgumentIsObject); | 46 UseCounter::AddEventListenerThirdArgumentIsObject); |
51 } | 47 } |
52 } | 48 } |
53 | 49 |
54 void addEventListenerMethodEpilogueCustom(const v8::FunctionCallbackInfo<v8::Val
ue>& info, EventTarget* impl) | 50 void addEventListenerMethodEpilogueCustom(const v8::FunctionCallbackInfo<v8::Val
ue>& info, EventTarget* impl) |
55 { | 51 { |
56 if (info.Length() >= 2 && info[1]->IsObject() && !impl->toNode()) | 52 if (info.Length() >= 2 && info[1]->IsObject() && !impl->toNode()) |
57 addHiddenValueToArray(info.GetIsolate(), info.Holder(), info[1], V8Event
Target::eventListenerCacheIndex); | 53 addHiddenValueToArray(info.GetIsolate(), info.Holder(), info[1], V8Event
Target::eventListenerCacheIndex); |
58 } | 54 } |
59 | 55 |
60 void removeEventListenerMethodPrologueCustom(const v8::FunctionCallbackInfo<v8::
Value>& info, EventTarget*) | 56 void removeEventListenerMethodPrologueCustom(const v8::FunctionCallbackInfo<v8::
Value>& info, EventTarget*) |
61 { | 57 { |
62 if (info.Length() < 2) { | |
63 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionC
ontext(info.GetIsolate()), | |
64 info.Length() == 0 ? UseCounter::RemoveEventListenerNoArguments : Us
eCounter::RemoveEventListenerOneArgument); | |
65 } | |
66 if (info.Length() >= 3 && info[2]->IsObject()) { | 58 if (info.Length() >= 3 && info[2]->IsObject()) { |
67 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionC
ontext(info.GetIsolate()), | 59 UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionC
ontext(info.GetIsolate()), |
68 UseCounter::RemoveEventListenerThirdArgumentIsObject); | 60 UseCounter::RemoveEventListenerThirdArgumentIsObject); |
69 } | 61 } |
70 } | 62 } |
71 | 63 |
72 void removeEventListenerMethodEpilogueCustom(const v8::FunctionCallbackInfo<v8::
Value>& info, EventTarget* impl) | 64 void removeEventListenerMethodEpilogueCustom(const v8::FunctionCallbackInfo<v8::
Value>& info, EventTarget* impl) |
73 { | 65 { |
74 if (info.Length() >= 2 && info[1]->IsObject() && !impl->toNode()) | 66 if (info.Length() >= 2 && info[1]->IsObject() && !impl->toNode()) |
75 removeHiddenValueFromArray(info.GetIsolate(), info.Holder(), info[1], V8
EventTarget::eventListenerCacheIndex); | 67 removeHiddenValueFromArray(info.GetIsolate(), info.Holder(), info[1], V8
EventTarget::eventListenerCacheIndex); |
76 } | 68 } |
77 | 69 |
78 } // namespace | 70 } // namespace |
79 | 71 |
80 void V8EventTarget::addEventListenerMethodCustom(const v8::FunctionCallbackInfo<
v8::Value>& info) | 72 void V8EventTarget::addEventListenerMethodCustom(const v8::FunctionCallbackInfo<
v8::Value>& info) |
81 { | 73 { |
82 ExceptionState exceptionState(ExceptionState::ExecutionContext, "addEventLis
tener", "EventTarget", info.Holder(), info.GetIsolate()); | 74 ExceptionState exceptionState(ExceptionState::ExecutionContext, "addEventLis
tener", "EventTarget", info.Holder(), info.GetIsolate()); |
| 75 if (UNLIKELY(info.Length() < 2)) { |
| 76 setMinimumArityTypeError(exceptionState, 2, info.Length()); |
| 77 exceptionState.throwIfNeeded(); |
| 78 return; |
| 79 } |
83 EventTarget* impl = V8EventTarget::toImpl(info.Holder()); | 80 EventTarget* impl = V8EventTarget::toImpl(info.Holder()); |
84 if (LocalDOMWindow* window = impl->toDOMWindow()) { | 81 if (LocalDOMWindow* window = impl->toDOMWindow()) { |
85 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), callin
gDOMWindow(info.GetIsolate()), window->frame(), exceptionState)) { | 82 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), callin
gDOMWindow(info.GetIsolate()), window->frame(), exceptionState)) { |
86 exceptionState.throwIfNeeded(); | 83 exceptionState.throwIfNeeded(); |
87 return; | 84 return; |
88 } | 85 } |
89 if (!window->document()) | 86 if (!window->document()) |
90 return; | 87 return; |
91 } | 88 } |
92 V8StringResource<TreatNullAsNullString> type; | 89 V8StringResource<> type; |
93 RefPtrWillBeRawPtr<EventListener> listener; | 90 RefPtrWillBeRawPtr<EventListener> listener; |
94 EventListenerOptionsOrBoolean options; | 91 EventListenerOptionsOrBoolean options; |
95 { | 92 { |
96 if (!info[0]->IsUndefined()) { | 93 type = info[0]; |
97 type = info[0]; | 94 if (!type.prepare()) |
98 if (!type.prepare()) | 95 return; |
99 return; | 96 listener = V8EventListenerList::getEventListener(ScriptState::current(in
fo.GetIsolate()), info[1], false, ListenerFindOrCreate); |
100 } else { | |
101 type = nullptr; | |
102 } | |
103 if (!info[1]->IsUndefined()) { | |
104 listener = V8EventListenerList::getEventListener(ScriptState::curren
t(info.GetIsolate()), info[1], false, ListenerFindOrCreate); | |
105 } else { | |
106 listener = nullptr; | |
107 } | |
108 // TODO(dtapuska): This custom binding code can be eliminated once | 97 // TODO(dtapuska): This custom binding code can be eliminated once |
109 // EventListenerOptions runtime enabled feature is removed. | 98 // EventListenerOptions runtime enabled feature is removed. |
110 // http://crbug.com/545163 | 99 // http://crbug.com/545163 |
111 if (UNLIKELY(info.Length() <= 2) || isUndefinedOrNull(info[2])) { | 100 if (UNLIKELY(info.Length() <= 2) || isUndefinedOrNull(info[2])) { |
112 addEventListenerMethodPrologueCustom(info, impl); | 101 addEventListenerMethodPrologueCustom(info, impl); |
113 impl->addEventListener(type, listener); | 102 impl->addEventListener(type, listener); |
114 addEventListenerMethodEpilogueCustom(info, impl); | 103 addEventListenerMethodEpilogueCustom(info, impl); |
115 return; | 104 return; |
116 } | 105 } |
117 V8EventListenerOptionsOrBoolean::toImpl(info.GetIsolate(), info[2], opti
ons, exceptionState); | 106 V8EventListenerOptionsOrBoolean::toImpl(info.GetIsolate(), info[2], opti
ons, exceptionState); |
118 if (exceptionState.throwIfNeeded()) | 107 if (exceptionState.throwIfNeeded()) |
119 return; | 108 return; |
120 } | 109 } |
121 addEventListenerMethodPrologueCustom(info, impl); | 110 addEventListenerMethodPrologueCustom(info, impl); |
122 impl->addEventListener(type, listener, options); | 111 impl->addEventListener(type, listener, options); |
123 addEventListenerMethodEpilogueCustom(info, impl); | 112 addEventListenerMethodEpilogueCustom(info, impl); |
124 } | 113 } |
125 | 114 |
126 void V8EventTarget::removeEventListenerMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) | 115 void V8EventTarget::removeEventListenerMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) |
127 { | 116 { |
128 ExceptionState exceptionState(ExceptionState::ExecutionContext, "removeEvent
Listener", "EventTarget", info.Holder(), info.GetIsolate()); | 117 ExceptionState exceptionState(ExceptionState::ExecutionContext, "removeEvent
Listener", "EventTarget", info.Holder(), info.GetIsolate()); |
| 118 if (UNLIKELY(info.Length() < 2)) { |
| 119 setMinimumArityTypeError(exceptionState, 2, info.Length()); |
| 120 exceptionState.throwIfNeeded(); |
| 121 return; |
| 122 } |
129 EventTarget* impl = V8EventTarget::toImpl(info.Holder()); | 123 EventTarget* impl = V8EventTarget::toImpl(info.Holder()); |
130 if (LocalDOMWindow* window = impl->toDOMWindow()) { | 124 if (LocalDOMWindow* window = impl->toDOMWindow()) { |
131 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), callin
gDOMWindow(info.GetIsolate()), window->frame(), exceptionState)) { | 125 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), callin
gDOMWindow(info.GetIsolate()), window->frame(), exceptionState)) { |
132 exceptionState.throwIfNeeded(); | 126 exceptionState.throwIfNeeded(); |
133 return; | 127 return; |
134 } | 128 } |
135 if (!window->document()) | 129 if (!window->document()) |
136 return; | 130 return; |
137 } | 131 } |
138 V8StringResource<TreatNullAsNullString> type; | 132 V8StringResource<> type; |
139 RefPtrWillBeRawPtr<EventListener> listener; | 133 RefPtrWillBeRawPtr<EventListener> listener; |
140 EventListenerOptionsOrBoolean options; | 134 EventListenerOptionsOrBoolean options; |
141 { | 135 { |
142 if (!info[0]->IsUndefined()) { | 136 type = info[0]; |
143 type = info[0]; | 137 if (!type.prepare()) |
144 if (!type.prepare()) | 138 return; |
145 return; | 139 listener = V8EventListenerList::getEventListener(ScriptState::current(in
fo.GetIsolate()), info[1], false, ListenerFindOnly); |
146 } else { | |
147 type = nullptr; | |
148 } | |
149 if (!info[1]->IsUndefined()) { | |
150 listener = V8EventListenerList::getEventListener(ScriptState::curren
t(info.GetIsolate()), info[1], false, ListenerFindOnly); | |
151 } else { | |
152 listener = nullptr; | |
153 } | |
154 // TODO(dtapuska): This custom binding code can be eliminated once | 140 // TODO(dtapuska): This custom binding code can be eliminated once |
155 // EventListenerOptions runtime enabled feature is removed. | 141 // EventListenerOptions runtime enabled feature is removed. |
156 // http://crbug.com/545163 | 142 // http://crbug.com/545163 |
157 if (UNLIKELY(info.Length() <= 2) || isUndefinedOrNull(info[2])) { | 143 if (UNLIKELY(info.Length() <= 2) || isUndefinedOrNull(info[2])) { |
158 removeEventListenerMethodPrologueCustom(info, impl); | 144 removeEventListenerMethodPrologueCustom(info, impl); |
159 impl->removeEventListener(type, listener); | 145 impl->removeEventListener(type, listener); |
160 removeEventListenerMethodEpilogueCustom(info, impl); | 146 removeEventListenerMethodEpilogueCustom(info, impl); |
161 return; | 147 return; |
162 } | 148 } |
163 V8EventListenerOptionsOrBoolean::toImpl(info.GetIsolate(), info[2], opti
ons, exceptionState); | 149 V8EventListenerOptionsOrBoolean::toImpl(info.GetIsolate(), info[2], opti
ons, exceptionState); |
164 if (exceptionState.throwIfNeeded()) | 150 if (exceptionState.throwIfNeeded()) |
165 return; | 151 return; |
166 } | 152 } |
167 removeEventListenerMethodPrologueCustom(info, impl); | 153 removeEventListenerMethodPrologueCustom(info, impl); |
168 impl->removeEventListener(type, listener, options); | 154 impl->removeEventListener(type, listener, options); |
169 removeEventListenerMethodEpilogueCustom(info, impl); | 155 removeEventListenerMethodEpilogueCustom(info, impl); |
170 } | 156 } |
171 | 157 |
172 } // namespace blink | 158 } // namespace blink |
OLD | NEW |