Home | History | Annotate | Download | only in custom
      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 
     33 #include "bindings/core/v8/V8HTMLAppletElement.h"
     34 #include "bindings/core/v8/V8HTMLEmbedElement.h"
     35 #include "bindings/core/v8/V8HTMLObjectElement.h"
     36 #include "bindings/v8/SharedPersistent.h"
     37 #include "bindings/v8/V8Binding.h"
     38 #include "bindings/v8/V8NPObject.h"
     39 #include "core/frame/UseCounter.h"
     40 
     41 namespace 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 
     46 template <class C>
     47 static void npObjectNamedGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     48 {
     49     HTMLPlugInElement* impl = C::toNative(info.Holder());
     50     RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper();
     51     if (!wrapper)
     52         return;
     53 
     54     v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate());
     55     if (instanceTemplate.IsEmpty())
     56         return;
     57 
     58     npObjectGetNamedProperty(instanceTemplate, name, info);
     59 }
     60 
     61 template <class C>
     62 static void npObjectNamedSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info)
     63 {
     64     HTMLPlugInElement* impl = C::toNative(info.Holder());
     65     RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper();
     66     if (!wrapper)
     67         return;
     68 
     69     v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate());
     70     if (instanceTemplate.IsEmpty())
     71         return;
     72 
     73     npObjectSetNamedProperty(instanceTemplate, name, value, info);
     74 }
     75 
     76 void V8HTMLAppletElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     77 {
     78     npObjectNamedGetter<V8HTMLAppletElement>(name, info);
     79 }
     80 
     81 void V8HTMLEmbedElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     82 {
     83     npObjectNamedGetter<V8HTMLEmbedElement>(name, info);
     84 }
     85 
     86 void V8HTMLObjectElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     87 {
     88     npObjectNamedGetter<V8HTMLObjectElement>(name, info);
     89 }
     90 
     91 void 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 
     96 void 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 
    101 void 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 
    106 void V8HTMLAppletElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
    107 {
    108     HTMLPlugInElement* impl = V8HTMLAppletElement::toNative(info.Holder());
    109     UseCounter::count(impl->document(), UseCounter::HTMLAppletElementLegacyCall);
    110     npObjectInvokeDefaultHandler(info);
    111 }
    112 
    113 void V8HTMLEmbedElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
    114 {
    115     HTMLPlugInElement* impl = V8HTMLEmbedElement::toNative(info.Holder());
    116     UseCounter::count(impl->document(), UseCounter::HTMLEmbedElementLegacyCall);
    117     npObjectInvokeDefaultHandler(info);
    118 }
    119 
    120 void V8HTMLObjectElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
    121 {
    122     HTMLPlugInElement* impl = V8HTMLObjectElement::toNative(info.Holder());
    123     UseCounter::count(impl->document(), UseCounter::HTMLObjectElementLegacyCall);
    124     npObjectInvokeDefaultHandler(info);
    125 }
    126 
    127 template <class C>
    128 void npObjectIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& 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::PropertyCallbackInfo<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<v8::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 }
    186 
    187 } // namespace WebCore
    188