Index: Source/bindings/core/v8/custom/V8HTMLPlugInElementCustom.cpp |
diff --git a/Source/bindings/core/v8/custom/V8HTMLPlugInElementCustom.cpp b/Source/bindings/core/v8/custom/V8HTMLPlugInElementCustom.cpp |
index 6c3ef82b57bb13c25ff7b580074c39176a4d2ba4..f6b42d5d9a7ef3ee859466fbd4100c5cfee1353a 100644 |
--- a/Source/bindings/core/v8/custom/V8HTMLPlugInElementCustom.cpp |
+++ b/Source/bindings/core/v8/custom/V8HTMLPlugInElementCustom.cpp |
@@ -1,5 +1,6 @@ |
/* |
* Copyright (C) 2009 Google Inc. All rights reserved. |
+* Copyright (C) 2014 Opera Software ASA. All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions are |
@@ -37,151 +38,152 @@ |
#include "bindings/core/v8/V8HTMLObjectElement.h" |
#include "bindings/core/v8/V8NPObject.h" |
#include "core/frame/UseCounter.h" |
+#include "wtf/OwnPtr.h" |
+#include "wtf/PassOwnPtr.h" |
namespace blink { |
-// FIXME: Consider moving getter/setter helpers to V8NPObject and renaming this file to V8PluginElementFunctions |
-// to match JSC bindings naming convention. |
+namespace { |
-template <class C> |
-static void npObjectNamedGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) |
+template <typename TElement, typename TPropertyId> |
+void GetScriptableObjectProperty(TPropertyId propertyId, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- HTMLPlugInElement* impl = C::toNative(info.Holder()); |
+ HTMLPlugInElement* impl = TElement::toNative(info.Holder()); |
RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); |
if (!wrapper) |
return; |
- v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate()); |
- if (instanceTemplate.IsEmpty()) |
+ v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate()); |
+ if (instance.IsEmpty()) |
return; |
- npObjectGetNamedProperty(instanceTemplate, name, info); |
+ TONATIVE_VOID(v8::Local<v8::Value>, value, instance->Get(propertyId)); |
+ |
+ // We quit here to allow the binding code to look up general HTMLObjectElement properties |
+ // if they are not overriden by plugin. |
+ if (value->IsUndefined()) |
+ return; |
+ |
+ v8SetReturnValue(info, value); |
} |
-template <class C> |
-static void npObjectNamedSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
+template <typename TElement, typename TPropertyId> |
+void SetScriptableObjectProperty(TPropertyId propertyId, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- HTMLPlugInElement* impl = C::toNative(info.Holder()); |
+ HTMLPlugInElement* impl = TElement::toNative(info.Holder()); |
RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); |
if (!wrapper) |
return; |
- v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate()); |
- if (instanceTemplate.IsEmpty()) |
+ v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate()); |
+ if (instance.IsEmpty()) |
return; |
- npObjectSetNamedProperty(instanceTemplate, name, value, info); |
+ instance->Set(propertyId, value); |
+ v8SetReturnValueUndefined(info); |
} |
+} // namespace |
void V8HTMLAppletElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- npObjectNamedGetter<V8HTMLAppletElement>(name, info); |
+ GetScriptableObjectProperty<V8HTMLAppletElement>(name, info); |
} |
void V8HTMLEmbedElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- npObjectNamedGetter<V8HTMLEmbedElement>(name, info); |
+ GetScriptableObjectProperty<V8HTMLEmbedElement>(name, info); |
} |
void V8HTMLObjectElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- npObjectNamedGetter<V8HTMLObjectElement>(name, info); |
+ GetScriptableObjectProperty<V8HTMLObjectElement>(name, info); |
} |
void V8HTMLAppletElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- npObjectNamedSetter<V8HTMLAppletElement>(name, value, info); |
+ SetScriptableObjectProperty<V8HTMLAppletElement>(name, value, info); |
} |
void V8HTMLEmbedElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- npObjectNamedSetter<V8HTMLEmbedElement>(name, value, info); |
+ SetScriptableObjectProperty<V8HTMLEmbedElement>(name, value, info); |
} |
void V8HTMLObjectElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- return npObjectNamedSetter<V8HTMLObjectElement>(name, value, info); |
+ SetScriptableObjectProperty<V8HTMLObjectElement>(name, value, info); |
} |
-void V8HTMLAppletElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
+void V8HTMLAppletElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- HTMLPlugInElement* impl = V8HTMLAppletElement::toNative(info.Holder()); |
- UseCounter::count(impl->document(), UseCounter::HTMLAppletElementLegacyCall); |
- npObjectInvokeDefaultHandler(info); |
+ GetScriptableObjectProperty<V8HTMLAppletElement>(index, info); |
} |
-void V8HTMLEmbedElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
+void V8HTMLEmbedElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- HTMLPlugInElement* impl = V8HTMLEmbedElement::toNative(info.Holder()); |
- UseCounter::count(impl->document(), UseCounter::HTMLEmbedElementLegacyCall); |
- npObjectInvokeDefaultHandler(info); |
+ GetScriptableObjectProperty<V8HTMLEmbedElement>(index, info); |
} |
-void V8HTMLObjectElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
+void V8HTMLObjectElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- HTMLPlugInElement* impl = V8HTMLObjectElement::toNative(info.Holder()); |
- UseCounter::count(impl->document(), UseCounter::HTMLObjectElementLegacyCall); |
- npObjectInvokeDefaultHandler(info); |
+ GetScriptableObjectProperty<V8HTMLObjectElement>(index, info); |
} |
-template <class C> |
-void npObjectIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) |
+void V8HTMLAppletElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
{ |
- HTMLPlugInElement* impl = C::toNative(info.Holder()); |
- RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); |
- if (!wrapper) |
- return; |
+ SetScriptableObjectProperty<V8HTMLAppletElement>(index, value, info); |
+} |
- v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate()); |
- if (instanceTemplate.IsEmpty()) |
- return; |
+void V8HTMLEmbedElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
+{ |
+ SetScriptableObjectProperty<V8HTMLEmbedElement>(index, value, info); |
+} |
- npObjectGetIndexedProperty(instanceTemplate, index, info); |
+void V8HTMLObjectElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
+{ |
+ SetScriptableObjectProperty<V8HTMLObjectElement>(index, value, info); |
} |
-template <class C> |
-void npObjectIndexedSetter(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
+namespace { |
+ |
+template <typename TElement> |
+void InvokeOnScriptableObject(const v8::FunctionCallbackInfo<v8::Value>& info) |
{ |
- HTMLPlugInElement* impl = C::toNative(info.Holder()); |
+ HTMLPlugInElement* impl = TElement::toNative(info.Holder()); |
RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); |
if (!wrapper) |
return; |
- v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate()); |
- if (instanceTemplate.IsEmpty()) |
+ v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate()); |
+ if (instance.IsEmpty()) |
return; |
- npObjectSetIndexedProperty(instanceTemplate, index, value, info); |
-} |
+ WTF::OwnPtr<v8::Handle<v8::Value>[] > arguments = adoptArrayPtr(new v8::Handle<v8::Value>[info.Length()]); |
+ for (int i = 0; i < info.Length(); ++i) |
+ arguments[i] = info[i]; |
-void V8HTMLAppletElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) |
-{ |
- npObjectIndexedGetter<V8HTMLAppletElement>(index, info); |
-} |
- |
-void V8HTMLEmbedElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) |
-{ |
- npObjectIndexedGetter<V8HTMLEmbedElement>(index, info); |
+ TONATIVE_VOID(v8::Local<v8::Value>, retVal, instance->CallAsFunction(info.This(), info.Length(), arguments.get())); |
+ v8SetReturnValue(info, retVal); |
} |
-void V8HTMLObjectElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) |
-{ |
- npObjectIndexedGetter<V8HTMLObjectElement>(index, info); |
-} |
+} // namespace |
-void V8HTMLAppletElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
+void V8HTMLAppletElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
{ |
- npObjectIndexedSetter<V8HTMLAppletElement>(index, value, info); |
+ InvokeOnScriptableObject<V8HTMLAppletElement>(info); |
+ UseCounter::count(V8HTMLAppletElement::toNative(info.Holder())->document(), UseCounter::HTMLAppletElementLegacyCall); |
} |
-void V8HTMLEmbedElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
+void V8HTMLEmbedElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
{ |
- npObjectIndexedSetter<V8HTMLEmbedElement>(index, value, info); |
+ InvokeOnScriptableObject<V8HTMLEmbedElement>(info); |
+ UseCounter::count(V8HTMLEmbedElement::toNative(info.Holder())->document(), UseCounter::HTMLEmbedElementLegacyCall); |
} |
-void V8HTMLObjectElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
+void V8HTMLObjectElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
{ |
- npObjectIndexedSetter<V8HTMLObjectElement>(index, value, info); |
+ InvokeOnScriptableObject<V8HTMLObjectElement>(info); |
+ UseCounter::count(V8HTMLObjectElement::toNative(info.Holder())->document(), UseCounter::HTMLObjectElementLegacyCall); |
} |
} // namespace blink |