OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2014 Opera Software ASA. All rights reserved. |
3 * | 4 * |
4 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
6 * met: | 7 * met: |
7 * | 8 * |
8 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 11 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 12 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 13 * in the documentation and/or other materials provided with the |
(...skipping 10 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (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. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 30 */ |
30 | 31 |
31 #include "config.h" | 32 #include "config.h" |
32 | 33 |
| 34 #include "bindings/core/v8/NPV8Object.h" |
33 #include "bindings/core/v8/SharedPersistent.h" | 35 #include "bindings/core/v8/SharedPersistent.h" |
34 #include "bindings/core/v8/V8Binding.h" | 36 #include "bindings/core/v8/V8Binding.h" |
35 #include "bindings/core/v8/V8HTMLAppletElement.h" | 37 #include "bindings/core/v8/V8HTMLAppletElement.h" |
36 #include "bindings/core/v8/V8HTMLEmbedElement.h" | 38 #include "bindings/core/v8/V8HTMLEmbedElement.h" |
37 #include "bindings/core/v8/V8HTMLObjectElement.h" | 39 #include "bindings/core/v8/V8HTMLObjectElement.h" |
38 #include "bindings/core/v8/V8NPObject.h" | 40 #include "bindings/core/v8/V8NPObject.h" |
39 #include "core/frame/UseCounter.h" | 41 #include "core/frame/UseCounter.h" |
| 42 #include "wtf/OwnPtr.h" |
| 43 #include "wtf/PassOwnPtr.h" |
40 | 44 |
41 namespace blink { | 45 namespace blink { |
42 | 46 |
43 // FIXME: Consider moving getter/setter helpers to V8NPObject and renaming this
file to V8PluginElementFunctions | 47 namespace { |
44 // to match JSC bindings naming convention. | |
45 | 48 |
46 template <class C> | 49 template <typename ElementType, typename PropertyType> |
47 static void npObjectNamedGetter(v8::Local<v8::String> name, const v8::PropertyCa
llbackInfo<v8::Value>& info) | 50 void getScriptableObjectProperty(PropertyType property, const v8::PropertyCallba
ckInfo<v8::Value>& info) |
48 { | 51 { |
49 HTMLPlugInElement* impl = C::toNative(info.Holder()); | 52 HTMLPlugInElement* impl = ElementType::toNative(info.Holder()); |
50 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); | 53 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); |
51 if (!wrapper) | 54 if (!wrapper) |
52 return; | 55 return; |
53 | 56 |
54 v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate()
); | 57 v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate()); |
55 if (instanceTemplate.IsEmpty()) | 58 if (instance.IsEmpty()) |
56 return; | 59 return; |
57 | 60 |
58 npObjectGetNamedProperty(instanceTemplate, name, info); | 61 TONATIVE_VOID(v8::Local<v8::Value>, value, instance->Get(property)); |
| 62 |
| 63 // We quit here to allow the binding code to look up general HTMLObjectEleme
nt properties |
| 64 // if they are not overriden by plugin. |
| 65 if (value->IsUndefined()) |
| 66 return; |
| 67 |
| 68 v8SetReturnValue(info, value); |
59 } | 69 } |
60 | 70 |
61 template <class C> | 71 namespace { |
62 static void npObjectNamedSetter(v8::Local<v8::String> name, v8::Local<v8::Value>
value, const v8::PropertyCallbackInfo<v8::Value>& info) | 72 void callNpObjectSetter(v8::Local<v8::Object> self, v8::Local<v8::String> name,
v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
63 { | 73 { |
64 HTMLPlugInElement* impl = C::toNative(info.Holder()); | 74 npObjectSetNamedProperty(self, name, value, info); |
| 75 } |
| 76 |
| 77 void callNpObjectSetter(v8::Local<v8::Object> self, uint32_t index, v8::Local<v8
::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 78 { |
| 79 npObjectSetIndexedProperty(self, index, value, info); |
| 80 } |
| 81 } |
| 82 |
| 83 template <typename ElementType, typename PropertyType> |
| 84 void setScriptableObjectProperty(PropertyType property, v8::Local<v8::Value> val
ue, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 85 { |
| 86 HTMLPlugInElement* impl = ElementType::toNative(info.Holder()); |
65 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); | 87 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); |
66 if (!wrapper) | 88 if (!wrapper) |
67 return; | 89 return; |
68 | 90 |
69 v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate()
); | 91 v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate()); |
70 if (instanceTemplate.IsEmpty()) | 92 if (instance.IsEmpty()) |
71 return; | 93 return; |
72 | 94 |
73 npObjectSetNamedProperty(instanceTemplate, name, value, info); | 95 // We need to directly call setter on NPObject to be able to detect |
| 96 // situation where NPObject notifies it does not possess the property |
| 97 // to be able to lookup standard DOM property. |
| 98 // This information is lost when retrieving it through v8::Object. |
| 99 if (isWrappedNPObject(instance)) { |
| 100 callNpObjectSetter(instance, property, value, info); |
| 101 return; |
| 102 } |
| 103 |
| 104 if (instance->Set(property, value)) |
| 105 v8SetReturnValue(info, value); |
74 } | 106 } |
| 107 } // namespace |
75 | 108 |
76 void V8HTMLAppletElement::namedPropertyGetterCustom(v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) | 109 void V8HTMLAppletElement::namedPropertyGetterCustom(v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) |
77 { | 110 { |
78 npObjectNamedGetter<V8HTMLAppletElement>(name, info); | 111 getScriptableObjectProperty<V8HTMLAppletElement>(name, info); |
79 } | 112 } |
80 | 113 |
81 void V8HTMLEmbedElement::namedPropertyGetterCustom(v8::Local<v8::String> name, c
onst v8::PropertyCallbackInfo<v8::Value>& info) | 114 void V8HTMLEmbedElement::namedPropertyGetterCustom(v8::Local<v8::String> name, c
onst v8::PropertyCallbackInfo<v8::Value>& info) |
82 { | 115 { |
83 npObjectNamedGetter<V8HTMLEmbedElement>(name, info); | 116 getScriptableObjectProperty<V8HTMLEmbedElement>(name, info); |
84 } | 117 } |
85 | 118 |
86 void V8HTMLObjectElement::namedPropertyGetterCustom(v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) | 119 void V8HTMLObjectElement::namedPropertyGetterCustom(v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) |
87 { | 120 { |
88 npObjectNamedGetter<V8HTMLObjectElement>(name, info); | 121 getScriptableObjectProperty<V8HTMLObjectElement>(name, info); |
89 } | 122 } |
90 | 123 |
91 void V8HTMLAppletElement::namedPropertySetterCustom(v8::Local<v8::String> name,
v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 124 void V8HTMLAppletElement::namedPropertySetterCustom(v8::Local<v8::String> name,
v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
92 { | 125 { |
93 npObjectNamedSetter<V8HTMLAppletElement>(name, value, info); | 126 setScriptableObjectProperty<V8HTMLAppletElement>(name, value, info); |
94 } | 127 } |
95 | 128 |
96 void V8HTMLEmbedElement::namedPropertySetterCustom(v8::Local<v8::String> name, v
8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 129 void V8HTMLEmbedElement::namedPropertySetterCustom(v8::Local<v8::String> name, v
8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
97 { | 130 { |
98 npObjectNamedSetter<V8HTMLEmbedElement>(name, value, info); | 131 setScriptableObjectProperty<V8HTMLEmbedElement>(name, value, info); |
99 } | 132 } |
100 | 133 |
101 void V8HTMLObjectElement::namedPropertySetterCustom(v8::Local<v8::String> name,
v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 134 void V8HTMLObjectElement::namedPropertySetterCustom(v8::Local<v8::String> name,
v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
102 { | 135 { |
103 return npObjectNamedSetter<V8HTMLObjectElement>(name, value, info); | 136 setScriptableObjectProperty<V8HTMLObjectElement>(name, value, info); |
104 } | 137 } |
105 | 138 |
| 139 void V8HTMLAppletElement::indexedPropertyGetterCustom(uint32_t index, const v8::
PropertyCallbackInfo<v8::Value>& info) |
| 140 { |
| 141 getScriptableObjectProperty<V8HTMLAppletElement>(index, info); |
| 142 } |
| 143 |
| 144 void V8HTMLEmbedElement::indexedPropertyGetterCustom(uint32_t index, const v8::P
ropertyCallbackInfo<v8::Value>& info) |
| 145 { |
| 146 getScriptableObjectProperty<V8HTMLEmbedElement>(index, info); |
| 147 } |
| 148 |
| 149 void V8HTMLObjectElement::indexedPropertyGetterCustom(uint32_t index, const v8::
PropertyCallbackInfo<v8::Value>& info) |
| 150 { |
| 151 getScriptableObjectProperty<V8HTMLObjectElement>(index, info); |
| 152 } |
| 153 |
| 154 void V8HTMLAppletElement::indexedPropertySetterCustom(uint32_t index, v8::Local<
v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 155 { |
| 156 setScriptableObjectProperty<V8HTMLAppletElement>(index, value, info); |
| 157 } |
| 158 |
| 159 void V8HTMLEmbedElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v
8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 160 { |
| 161 setScriptableObjectProperty<V8HTMLEmbedElement>(index, value, info); |
| 162 } |
| 163 |
| 164 void V8HTMLObjectElement::indexedPropertySetterCustom(uint32_t index, v8::Local<
v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 165 { |
| 166 setScriptableObjectProperty<V8HTMLObjectElement>(index, value, info); |
| 167 } |
| 168 |
| 169 namespace { |
| 170 |
| 171 template <typename ElementType> |
| 172 void invokeOnScriptableObject(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 173 { |
| 174 HTMLPlugInElement* impl = ElementType::toNative(info.Holder()); |
| 175 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); |
| 176 if (!wrapper) |
| 177 return; |
| 178 |
| 179 v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate()); |
| 180 if (instance.IsEmpty()) |
| 181 return; |
| 182 |
| 183 WTF::OwnPtr<v8::Handle<v8::Value>[] > arguments = adoptArrayPtr(new v8::Hand
le<v8::Value>[info.Length()]); |
| 184 for (int i = 0; i < info.Length(); ++i) |
| 185 arguments[i] = info[i]; |
| 186 |
| 187 TONATIVE_VOID(v8::Local<v8::Value>, retVal, instance->CallAsFunction(info.Th
is(), info.Length(), arguments.get())); |
| 188 v8SetReturnValue(info, retVal); |
| 189 } |
| 190 |
| 191 } // namespace |
| 192 |
106 void V8HTMLAppletElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va
lue>& info) | 193 void V8HTMLAppletElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
107 { | 194 { |
108 HTMLPlugInElement* impl = V8HTMLAppletElement::toNative(info.Holder()); | 195 invokeOnScriptableObject<V8HTMLAppletElement>(info); |
109 UseCounter::count(impl->document(), UseCounter::HTMLAppletElementLegacyCall)
; | 196 UseCounter::count(V8HTMLAppletElement::toNative(info.Holder())->document(),
UseCounter::HTMLAppletElementLegacyCall); |
110 npObjectInvokeDefaultHandler(info); | |
111 } | 197 } |
112 | 198 |
113 void V8HTMLEmbedElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Val
ue>& info) | 199 void V8HTMLEmbedElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Val
ue>& info) |
114 { | 200 { |
115 HTMLPlugInElement* impl = V8HTMLEmbedElement::toNative(info.Holder()); | 201 invokeOnScriptableObject<V8HTMLEmbedElement>(info); |
116 UseCounter::count(impl->document(), UseCounter::HTMLEmbedElementLegacyCall); | 202 UseCounter::count(V8HTMLEmbedElement::toNative(info.Holder())->document(), U
seCounter::HTMLEmbedElementLegacyCall); |
117 npObjectInvokeDefaultHandler(info); | |
118 } | 203 } |
119 | 204 |
120 void V8HTMLObjectElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va
lue>& info) | 205 void V8HTMLObjectElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
121 { | 206 { |
122 HTMLPlugInElement* impl = V8HTMLObjectElement::toNative(info.Holder()); | 207 invokeOnScriptableObject<V8HTMLObjectElement>(info); |
123 UseCounter::count(impl->document(), UseCounter::HTMLObjectElementLegacyCall)
; | 208 UseCounter::count(V8HTMLObjectElement::toNative(info.Holder())->document(),
UseCounter::HTMLObjectElementLegacyCall); |
124 npObjectInvokeDefaultHandler(info); | |
125 } | |
126 | |
127 template <class C> | |
128 void npObjectIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Va
lue>& info) | |
129 { | |
130 HTMLPlugInElement* impl = C::toNative(info.Holder()); | |
131 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); | |
132 if (!wrapper) | |
133 return; | |
134 | |
135 v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate()
); | |
136 if (instanceTemplate.IsEmpty()) | |
137 return; | |
138 | |
139 npObjectGetIndexedProperty(instanceTemplate, index, info); | |
140 } | |
141 | |
142 template <class C> | |
143 void npObjectIndexedSetter(uint32_t index, v8::Local<v8::Value> value, const v8:
:PropertyCallbackInfo<v8::Value>& info) | |
144 { | |
145 HTMLPlugInElement* impl = C::toNative(info.Holder()); | |
146 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); | |
147 if (!wrapper) | |
148 return; | |
149 | |
150 v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate()
); | |
151 if (instanceTemplate.IsEmpty()) | |
152 return; | |
153 | |
154 npObjectSetIndexedProperty(instanceTemplate, index, value, info); | |
155 } | |
156 | |
157 void V8HTMLAppletElement::indexedPropertyGetterCustom(uint32_t index, const v8::
PropertyCallbackInfo<v8::Value>& info) | |
158 { | |
159 npObjectIndexedGetter<V8HTMLAppletElement>(index, info); | |
160 } | |
161 | |
162 void V8HTMLEmbedElement::indexedPropertyGetterCustom(uint32_t index, const v8::P
ropertyCallbackInfo<v8::Value>& info) | |
163 { | |
164 npObjectIndexedGetter<V8HTMLEmbedElement>(index, info); | |
165 } | |
166 | |
167 void V8HTMLObjectElement::indexedPropertyGetterCustom(uint32_t index, const v8::
PropertyCallbackInfo<v8::Value>& info) | |
168 { | |
169 npObjectIndexedGetter<V8HTMLObjectElement>(index, info); | |
170 } | |
171 | |
172 void V8HTMLAppletElement::indexedPropertySetterCustom(uint32_t index, v8::Local<
v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | |
173 { | |
174 npObjectIndexedSetter<V8HTMLAppletElement>(index, value, info); | |
175 } | |
176 | |
177 void V8HTMLEmbedElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v
8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | |
178 { | |
179 npObjectIndexedSetter<V8HTMLEmbedElement>(index, value, info); | |
180 } | |
181 | |
182 void V8HTMLObjectElement::indexedPropertySetterCustom(uint32_t index, v8::Local<
v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | |
183 { | |
184 npObjectIndexedSetter<V8HTMLObjectElement>(index, value, info); | |
185 } | 209 } |
186 | 210 |
187 } // namespace blink | 211 } // namespace blink |
OLD | NEW |