• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "HTMLPlugInElement.h"
33 
34 #include "ScriptInstance.h"
35 #include "V8Binding.h"
36 #include "V8HTMLAppletElement.h"
37 #include "V8HTMLEmbedElement.h"
38 #include "V8HTMLObjectElement.h"
39 #include "V8NPObject.h"
40 #include "V8Proxy.h"
41 
42 namespace WebCore {
43 
44 // FIXME: Consider moving getter/setter helpers to V8NPObject and renaming this file to V8PluginElementFunctions
45 // to match JSC bindings naming convention.
46 
47 template <class C>
npObjectNamedGetter(v8::Local<v8::String> name,const v8::AccessorInfo & info)48 static v8::Handle<v8::Value> npObjectNamedGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
49 {
50     HTMLPlugInElement* imp = C::toNative(info.Holder());
51     ScriptInstance scriptInstance = imp->getInstance();
52     if (!scriptInstance)
53         return notHandledByInterceptor();
54 
55     v8::Local<v8::Object> instance = v8::Local<v8::Object>::New(scriptInstance->instance());
56     if (instance.IsEmpty())
57         return notHandledByInterceptor();
58 
59     return npObjectGetNamedProperty(instance, name);
60 }
61 
62 template <class C>
npObjectNamedSetter(v8::Local<v8::String> name,v8::Local<v8::Value> value,const v8::AccessorInfo & info)63 static v8::Handle<v8::Value> npObjectNamedSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
64 {
65     HTMLPlugInElement* imp = C::toNative(info.Holder());
66     ScriptInstance scriptInstance = imp->getInstance();
67     if (!scriptInstance)
68         return notHandledByInterceptor();
69 
70     v8::Local<v8::Object> instance = v8::Local<v8::Object>::New(scriptInstance->instance());
71     if (instance.IsEmpty())
72         return notHandledByInterceptor();
73 
74     return npObjectSetNamedProperty(instance, name, value);
75 }
76 
namedPropertyGetter(v8::Local<v8::String> name,const v8::AccessorInfo & info)77 v8::Handle<v8::Value> V8HTMLAppletElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
78 {
79     INC_STATS("DOM.HTMLAppletElement.NamedPropertyGetter");
80     return npObjectNamedGetter<V8HTMLAppletElement>(name, info);
81 }
82 
namedPropertyGetter(v8::Local<v8::String> name,const v8::AccessorInfo & info)83 v8::Handle<v8::Value> V8HTMLEmbedElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
84 {
85     INC_STATS("DOM.HTMLEmbedElement.NamedPropertyGetter");
86     return npObjectNamedGetter<V8HTMLEmbedElement>(name, info);
87 }
88 
namedPropertyGetter(v8::Local<v8::String> name,const v8::AccessorInfo & info)89 v8::Handle<v8::Value> V8HTMLObjectElement::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
90 {
91     INC_STATS("DOM.HTMLObjectElement.NamedPropertyGetter");
92     return npObjectNamedGetter<V8HTMLObjectElement>(name, info);
93 }
94 
namedPropertySetter(v8::Local<v8::String> name,v8::Local<v8::Value> value,const v8::AccessorInfo & info)95 v8::Handle<v8::Value> V8HTMLAppletElement::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
96 {
97     INC_STATS("DOM.HTMLAppletElement.NamedPropertySetter");
98     return npObjectNamedSetter<V8HTMLAppletElement>(name, value, info);
99 }
100 
namedPropertySetter(v8::Local<v8::String> name,v8::Local<v8::Value> value,const v8::AccessorInfo & info)101 v8::Handle<v8::Value> V8HTMLEmbedElement::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
102 {
103     INC_STATS("DOM.HTMLEmbedElement.NamedPropertySetter");
104     return npObjectNamedSetter<V8HTMLEmbedElement>(name, value, info);
105 }
106 
namedPropertySetter(v8::Local<v8::String> name,v8::Local<v8::Value> value,const v8::AccessorInfo & info)107 v8::Handle<v8::Value> V8HTMLObjectElement::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
108 {
109     INC_STATS("DOM.HTMLObjectElement.NamedPropertySetter");
110     return npObjectNamedSetter<V8HTMLObjectElement>(name, value, info);
111 }
112 
callAsFunctionCallback(const v8::Arguments & args)113 v8::Handle<v8::Value> V8HTMLAppletElement::callAsFunctionCallback(const v8::Arguments& args)
114 {
115     INC_STATS("DOM.HTMLAppletElement()");
116     return npObjectInvokeDefaultHandler(args);
117 }
118 
callAsFunctionCallback(const v8::Arguments & args)119 v8::Handle<v8::Value> V8HTMLEmbedElement::callAsFunctionCallback(const v8::Arguments& args)
120 {
121     INC_STATS("DOM.HTMLEmbedElement()");
122     return npObjectInvokeDefaultHandler(args);
123 }
124 
callAsFunctionCallback(const v8::Arguments & args)125 v8::Handle<v8::Value> V8HTMLObjectElement::callAsFunctionCallback(const v8::Arguments& args)
126 {
127     INC_STATS("DOM.HTMLObjectElement()");
128     return npObjectInvokeDefaultHandler(args);
129 }
130 
131 template <class C>
npObjectIndexedGetter(uint32_t index,const v8::AccessorInfo & info)132 v8::Handle<v8::Value> npObjectIndexedGetter(uint32_t index, const v8::AccessorInfo& info)
133 {
134     INC_STATS("DOM.HTMLPlugInElement.IndexedPropertyGetter");
135     HTMLPlugInElement* imp = C::toNative(info.Holder());
136     ScriptInstance scriptInstance = imp->getInstance();
137     if (!scriptInstance)
138         return notHandledByInterceptor();
139 
140     v8::Local<v8::Object> instance = v8::Local<v8::Object>::New(scriptInstance->instance());
141     if (instance.IsEmpty())
142         return notHandledByInterceptor();
143 
144     return npObjectGetIndexedProperty(instance, index);
145 }
146 
147 template <class C>
npObjectIndexedSetter(uint32_t index,v8::Local<v8::Value> value,const v8::AccessorInfo & info)148 v8::Handle<v8::Value> npObjectIndexedSetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
149 {
150     INC_STATS("DOM.HTMLPlugInElement.IndexedPropertySetter");
151     HTMLPlugInElement* imp = C::toNative(info.Holder());
152     ScriptInstance scriptInstance = imp->getInstance();
153     if (!scriptInstance)
154         return notHandledByInterceptor();
155 
156     v8::Local<v8::Object> instance = v8::Local<v8::Object>::New(scriptInstance->instance());
157     if (instance.IsEmpty())
158         return notHandledByInterceptor();
159 
160     return npObjectSetIndexedProperty(instance, index, value);
161 }
162 
indexedPropertyGetter(uint32_t index,const v8::AccessorInfo & info)163 v8::Handle<v8::Value> V8HTMLAppletElement::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)
164 {
165     INC_STATS("DOM.HTMLAppletElement.IndexedPropertyGetter");
166     return npObjectIndexedGetter<V8HTMLAppletElement>(index, info);
167 }
168 
indexedPropertyGetter(uint32_t index,const v8::AccessorInfo & info)169 v8::Handle<v8::Value> V8HTMLEmbedElement::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)
170 {
171     INC_STATS("DOM.HTMLEmbedElement.IndexedPropertyGetter");
172     return npObjectIndexedGetter<V8HTMLEmbedElement>(index, info);
173 }
174 
indexedPropertyGetter(uint32_t index,const v8::AccessorInfo & info)175 v8::Handle<v8::Value> V8HTMLObjectElement::indexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info)
176 {
177     INC_STATS("DOM.HTMLObjectElement.IndexedPropertyGetter");
178     return npObjectIndexedGetter<V8HTMLObjectElement>(index, info);
179 }
180 
indexedPropertySetter(uint32_t index,v8::Local<v8::Value> value,const v8::AccessorInfo & info)181 v8::Handle<v8::Value> V8HTMLAppletElement::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
182 {
183     INC_STATS("DOM.HTMLAppletElement.IndexedPropertySetter");
184     return npObjectIndexedSetter<V8HTMLAppletElement>(index, value, info);
185 }
186 
indexedPropertySetter(uint32_t index,v8::Local<v8::Value> value,const v8::AccessorInfo & info)187 v8::Handle<v8::Value> V8HTMLEmbedElement::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
188 {
189     INC_STATS("DOM.HTMLEmbedElement.IndexedPropertySetter");
190     return npObjectIndexedSetter<V8HTMLEmbedElement>(index, value, info);
191 }
192 
indexedPropertySetter(uint32_t index,v8::Local<v8::Value> value,const v8::AccessorInfo & info)193 v8::Handle<v8::Value> V8HTMLObjectElement::indexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
194 {
195     INC_STATS("DOM.HTMLObjectElement.IndexedPropertySetter");
196     return npObjectIndexedSetter<V8HTMLObjectElement>(index, value, info);
197 }
198 
199 } // namespace WebCore
200