2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2014 Opera Software ASA. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "bindings/core/v8/NPV8Object.h"
35 #include "bindings/core/v8/SharedPersistent.h"
36 #include "bindings/core/v8/V8Binding.h"
37 #include "bindings/core/v8/V8HTMLAppletElement.h"
38 #include "bindings/core/v8/V8HTMLEmbedElement.h"
39 #include "bindings/core/v8/V8HTMLObjectElement.h"
40 #include "bindings/core/v8/V8NPObject.h"
41 #include "core/frame/UseCounter.h"
42 #include "wtf/OwnPtr.h"
43 #include "wtf/PassOwnPtr.h"
49 template <typename ElementType, typename PropertyType>
50 void getScriptableObjectProperty(PropertyType property, const v8::PropertyCallbackInfo<v8::Value>& info)
52 HTMLPlugInElement* impl = ElementType::toNative(info.Holder());
53 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper();
57 v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate());
58 if (instance.IsEmpty())
61 TONATIVE_VOID(v8::Local<v8::Value>, value, instance->Get(property));
63 // We quit here to allow the binding code to look up general HTMLObjectElement properties
64 // if they are not overriden by plugin.
65 if (value->IsUndefined())
68 v8SetReturnValue(info, value);
72 void callNpObjectSetter(v8::Local<v8::Object> self, v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
74 npObjectSetNamedProperty(self, name, value, info);
77 void callNpObjectSetter(v8::Local<v8::Object> self, uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
79 npObjectSetIndexedProperty(self, index, value, info);
83 template <typename ElementType, typename PropertyType>
84 void setScriptableObjectProperty(PropertyType property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
86 HTMLPlugInElement* impl = ElementType::toNative(info.Holder());
87 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper();
91 v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate());
92 if (instance.IsEmpty())
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);
104 if (instance->Set(property, value))
105 v8SetReturnValue(info, value);
109 void V8HTMLAppletElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
111 getScriptableObjectProperty<V8HTMLAppletElement>(name, info);
114 void V8HTMLEmbedElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
116 getScriptableObjectProperty<V8HTMLEmbedElement>(name, info);
119 void V8HTMLObjectElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
121 getScriptableObjectProperty<V8HTMLObjectElement>(name, info);
124 void V8HTMLAppletElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
126 setScriptableObjectProperty<V8HTMLAppletElement>(name, value, info);
129 void V8HTMLEmbedElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
131 setScriptableObjectProperty<V8HTMLEmbedElement>(name, value, info);
134 void V8HTMLObjectElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
136 setScriptableObjectProperty<V8HTMLObjectElement>(name, value, info);
139 void V8HTMLAppletElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
141 getScriptableObjectProperty<V8HTMLAppletElement>(index, info);
144 void V8HTMLEmbedElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
146 getScriptableObjectProperty<V8HTMLEmbedElement>(index, info);
149 void V8HTMLObjectElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)
151 getScriptableObjectProperty<V8HTMLObjectElement>(index, info);
154 void V8HTMLAppletElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
156 setScriptableObjectProperty<V8HTMLAppletElement>(index, value, info);
159 void V8HTMLEmbedElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
161 setScriptableObjectProperty<V8HTMLEmbedElement>(index, value, info);
164 void V8HTMLObjectElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
166 setScriptableObjectProperty<V8HTMLObjectElement>(index, value, info);
171 template <typename ElementType>
172 void invokeOnScriptableObject(const v8::FunctionCallbackInfo<v8::Value>& info)
174 HTMLPlugInElement* impl = ElementType::toNative(info.Holder());
175 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper();
179 v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate());
180 if (instance.IsEmpty())
183 WTF::OwnPtr<v8::Handle<v8::Value>[] > arguments = adoptArrayPtr(new v8::Handle<v8::Value>[info.Length()]);
184 for (int i = 0; i < info.Length(); ++i)
185 arguments[i] = info[i];
187 TONATIVE_VOID(v8::Local<v8::Value>, retVal, instance->CallAsFunction(info.This(), info.Length(), arguments.get()));
188 v8SetReturnValue(info, retVal);
193 void V8HTMLAppletElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
195 invokeOnScriptableObject<V8HTMLAppletElement>(info);
196 UseCounter::count(V8HTMLAppletElement::toNative(info.Holder())->document(), UseCounter::HTMLAppletElementLegacyCall);
199 void V8HTMLEmbedElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
201 invokeOnScriptableObject<V8HTMLEmbedElement>(info);
202 UseCounter::count(V8HTMLEmbedElement::toNative(info.Holder())->document(), UseCounter::HTMLEmbedElementLegacyCall);
205 void V8HTMLObjectElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
207 invokeOnScriptableObject<V8HTMLObjectElement>(info);
208 UseCounter::count(V8HTMLObjectElement::toNative(info.Holder())->document(), UseCounter::HTMLObjectElementLegacyCall);