1/* 2* Copyright (C) 2009 Google Inc. All rights reserved. 3* 4* Redistribution and use in source and binary forms, with or without 5* modification, are permitted provided that the following conditions are 6* met: 7* 8* * Redistributions of source code must retain the above copyright 9* notice, this list of conditions and the following disclaimer. 10* * Redistributions in binary form must reproduce the above 11* copyright notice, this list of conditions and the following disclaimer 12* in the documentation and/or other materials provided with the 13* distribution. 14* * Neither the name of Google Inc. nor the names of its 15* contributors may be used to endorse or promote products derived from 16* this software without specific prior written permission. 17* 18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 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. 29*/ 30 31#include "config.h" 32#include "core/html/HTMLPlugInElement.h" 33 34#include "V8HTMLAppletElement.h" 35#include "V8HTMLEmbedElement.h" 36#include "V8HTMLObjectElement.h" 37#include "bindings/v8/ScriptInstance.h" 38#include "bindings/v8/V8Binding.h" 39#include "bindings/v8/V8NPObject.h" 40 41namespace WebCore { 42 43// FIXME: Consider moving getter/setter helpers to V8NPObject and renaming this file to V8PluginElementFunctions 44// to match JSC bindings naming convention. 45 46template <class C> 47static void npObjectNamedGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 48{ 49 HTMLPlugInElement* imp = C::toNative(info.Holder()); 50 ScriptInstance scriptInstance = imp->getInstance(); 51 if (!scriptInstance) 52 return; 53 54 v8::Local<v8::Object> instance = scriptInstance->newLocal(v8::Isolate::GetCurrent()); 55 if (instance.IsEmpty()) 56 return; 57 58 npObjectGetNamedProperty(instance, name, info); 59} 60 61template <class C> 62static void npObjectNamedSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 63{ 64 HTMLPlugInElement* imp = C::toNative(info.Holder()); 65 ScriptInstance scriptInstance = imp->getInstance(); 66 if (!scriptInstance) 67 return; 68 69 v8::Local<v8::Object> instance = scriptInstance->newLocal(v8::Isolate::GetCurrent()); 70 if (instance.IsEmpty()) 71 return; 72 73 npObjectSetNamedProperty(instance, name, value, info); 74} 75 76void V8HTMLAppletElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 77{ 78 npObjectNamedGetter<V8HTMLAppletElement>(name, info); 79} 80 81void V8HTMLEmbedElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 82{ 83 npObjectNamedGetter<V8HTMLEmbedElement>(name, info); 84} 85 86void V8HTMLObjectElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) 87{ 88 npObjectNamedGetter<V8HTMLObjectElement>(name, info); 89} 90 91void V8HTMLAppletElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 92{ 93 npObjectNamedSetter<V8HTMLAppletElement>(name, value, info); 94} 95 96void V8HTMLEmbedElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 97{ 98 npObjectNamedSetter<V8HTMLEmbedElement>(name, value, info); 99} 100 101void V8HTMLObjectElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 102{ 103 return npObjectNamedSetter<V8HTMLObjectElement>(name, value, info); 104} 105 106void V8HTMLAppletElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& args) 107{ 108 npObjectInvokeDefaultHandler(args); 109} 110 111void V8HTMLEmbedElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& args) 112{ 113 npObjectInvokeDefaultHandler(args); 114} 115 116void V8HTMLObjectElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& args) 117{ 118 npObjectInvokeDefaultHandler(args); 119} 120 121template <class C> 122void npObjectIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) 123{ 124 HTMLPlugInElement* imp = C::toNative(info.Holder()); 125 ScriptInstance scriptInstance = imp->getInstance(); 126 if (!scriptInstance) 127 return; 128 129 v8::Local<v8::Object> instance = scriptInstance->newLocal(v8::Isolate::GetCurrent()); 130 if (instance.IsEmpty()) 131 return; 132 133 npObjectGetIndexedProperty(instance, index, info); 134} 135 136template <class C> 137void npObjectIndexedSetter(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 138{ 139 HTMLPlugInElement* imp = C::toNative(info.Holder()); 140 ScriptInstance scriptInstance = imp->getInstance(); 141 if (!scriptInstance) 142 return; 143 144 v8::Local<v8::Object> instance = scriptInstance->newLocal(v8::Isolate::GetCurrent()); 145 if (instance.IsEmpty()) 146 return; 147 148 npObjectSetIndexedProperty(instance, index, value, info); 149} 150 151void V8HTMLAppletElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) 152{ 153 npObjectIndexedGetter<V8HTMLAppletElement>(index, info); 154} 155 156void V8HTMLEmbedElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) 157{ 158 npObjectIndexedGetter<V8HTMLEmbedElement>(index, info); 159} 160 161void V8HTMLObjectElement::indexedPropertyGetterCustom(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) 162{ 163 npObjectIndexedGetter<V8HTMLObjectElement>(index, info); 164} 165 166void V8HTMLAppletElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 167{ 168 npObjectIndexedSetter<V8HTMLAppletElement>(index, value, info); 169} 170 171void V8HTMLEmbedElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 172{ 173 npObjectIndexedSetter<V8HTMLEmbedElement>(index, value, info); 174} 175 176void V8HTMLObjectElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) 177{ 178 npObjectIndexedSetter<V8HTMLObjectElement>(index, value, info); 179} 180 181} // namespace WebCore 182