OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2014 Opera Software ASA. All rights reserved. | |
3 * | 4 * |
4 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
6 * met: | 7 * met: |
7 * | 8 * |
8 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 11 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 12 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 13 * in the documentation and/or other materials provided with the |
(...skipping 17 matching lines...) Expand all Loading... | |
30 | 31 |
31 #include "config.h" | 32 #include "config.h" |
32 | 33 |
33 #include "bindings/core/v8/SharedPersistent.h" | 34 #include "bindings/core/v8/SharedPersistent.h" |
34 #include "bindings/core/v8/V8Binding.h" | 35 #include "bindings/core/v8/V8Binding.h" |
35 #include "bindings/core/v8/V8HTMLAppletElement.h" | 36 #include "bindings/core/v8/V8HTMLAppletElement.h" |
36 #include "bindings/core/v8/V8HTMLEmbedElement.h" | 37 #include "bindings/core/v8/V8HTMLEmbedElement.h" |
37 #include "bindings/core/v8/V8HTMLObjectElement.h" | 38 #include "bindings/core/v8/V8HTMLObjectElement.h" |
38 #include "bindings/core/v8/V8NPObject.h" | 39 #include "bindings/core/v8/V8NPObject.h" |
39 #include "core/frame/UseCounter.h" | 40 #include "core/frame/UseCounter.h" |
41 #include "wtf/OwnPtr.h" | |
42 #include "wtf/PassOwnPtr.h" | |
40 | 43 |
41 namespace blink { | 44 namespace blink { |
42 | 45 |
43 // FIXME: Consider moving getter/setter helpers to V8NPObject and renaming this file to V8PluginElementFunctions | 46 namespace { |
44 // to match JSC bindings naming convention. | |
45 | 47 |
46 template <class C> | 48 template <typename TElement, typename TPropertyId> |
abarth-chromium
2014/07/29 17:34:21
TElement -> ElementType
TPropertyId -> PropertyTyp
Krzysztof Olczyk
2014/07/30 08:40:30
Done.
| |
47 static void npObjectNamedGetter(v8::Local<v8::String> name, const v8::PropertyCa llbackInfo<v8::Value>& info) | 49 void GetScriptableObjectProperty(TPropertyId propertyId, const v8::PropertyCallb ackInfo<v8::Value>& info) |
abarth-chromium
2014/07/29 17:34:21
GetScriptableObjectProperty -> getScriptableObject
Krzysztof Olczyk
2014/07/30 08:40:30
Done.
| |
48 { | 50 { |
49 HTMLPlugInElement* impl = C::toNative(info.Holder()); | 51 HTMLPlugInElement* impl = TElement::toNative(info.Holder()); |
50 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); | 52 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); |
51 if (!wrapper) | 53 if (!wrapper) |
52 return; | 54 return; |
53 | 55 |
54 v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate() ); | 56 v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate()); |
55 if (instanceTemplate.IsEmpty()) | 57 if (instance.IsEmpty()) |
56 return; | 58 return; |
57 | 59 |
58 npObjectGetNamedProperty(instanceTemplate, name, info); | 60 TONATIVE_VOID(v8::Local<v8::Value>, value, instance->Get(propertyId)); |
61 | |
62 // We quit here to allow the binding code to look up general HTMLObjectEleme nt properties | |
63 // if they are not overriden by plugin. | |
64 if (value->IsUndefined()) | |
65 return; | |
66 | |
67 v8SetReturnValue(info, value); | |
59 } | 68 } |
60 | 69 |
61 template <class C> | 70 template <typename TElement, typename TPropertyId> |
abarth-chromium
2014/07/29 17:34:21
ditto
Krzysztof Olczyk
2014/07/30 08:40:30
Done.
| |
62 static void npObjectNamedSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 71 void SetScriptableObjectProperty(TPropertyId propertyId, v8::Local<v8::Value> va lue, const v8::PropertyCallbackInfo<v8::Value>& info) |
abarth-chromium
2014/07/29 17:34:21
SetScriptableObjectProperty -> setScriptableObject
Krzysztof Olczyk
2014/07/30 08:40:30
Done.
| |
63 { | 72 { |
64 HTMLPlugInElement* impl = C::toNative(info.Holder()); | 73 HTMLPlugInElement* impl = TElement::toNative(info.Holder()); |
65 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); | 74 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); |
66 if (!wrapper) | 75 if (!wrapper) |
67 return; | 76 return; |
68 | 77 |
69 v8::Local<v8::Object> instanceTemplate = wrapper->newLocal(info.GetIsolate() ); | 78 v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate()); |
70 if (instanceTemplate.IsEmpty()) | 79 if (instance.IsEmpty()) |
71 return; | 80 return; |
72 | 81 |
73 npObjectSetNamedProperty(instanceTemplate, name, value, info); | 82 instance->Set(propertyId, value); |
83 v8SetReturnValueUndefined(info); | |
74 } | 84 } |
85 } // namespace | |
75 | 86 |
76 void V8HTMLAppletElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) | 87 void V8HTMLAppletElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) |
77 { | 88 { |
78 npObjectNamedGetter<V8HTMLAppletElement>(name, info); | 89 GetScriptableObjectProperty<V8HTMLAppletElement>(name, info); |
79 } | 90 } |
80 | 91 |
81 void V8HTMLEmbedElement::namedPropertyGetterCustom(v8::Local<v8::String> name, c onst v8::PropertyCallbackInfo<v8::Value>& info) | 92 void V8HTMLEmbedElement::namedPropertyGetterCustom(v8::Local<v8::String> name, c onst v8::PropertyCallbackInfo<v8::Value>& info) |
82 { | 93 { |
83 npObjectNamedGetter<V8HTMLEmbedElement>(name, info); | 94 GetScriptableObjectProperty<V8HTMLEmbedElement>(name, info); |
84 } | 95 } |
85 | 96 |
86 void V8HTMLObjectElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) | 97 void V8HTMLObjectElement::namedPropertyGetterCustom(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info) |
87 { | 98 { |
88 npObjectNamedGetter<V8HTMLObjectElement>(name, info); | 99 GetScriptableObjectProperty<V8HTMLObjectElement>(name, info); |
89 } | 100 } |
90 | 101 |
91 void V8HTMLAppletElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 102 void V8HTMLAppletElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
92 { | 103 { |
93 npObjectNamedSetter<V8HTMLAppletElement>(name, value, info); | 104 SetScriptableObjectProperty<V8HTMLAppletElement>(name, value, info); |
94 } | 105 } |
95 | 106 |
96 void V8HTMLEmbedElement::namedPropertySetterCustom(v8::Local<v8::String> name, v 8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 107 void V8HTMLEmbedElement::namedPropertySetterCustom(v8::Local<v8::String> name, v 8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
97 { | 108 { |
98 npObjectNamedSetter<V8HTMLEmbedElement>(name, value, info); | 109 SetScriptableObjectProperty<V8HTMLEmbedElement>(name, value, info); |
99 } | 110 } |
100 | 111 |
101 void V8HTMLObjectElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 112 void V8HTMLObjectElement::namedPropertySetterCustom(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
102 { | 113 { |
103 return npObjectNamedSetter<V8HTMLObjectElement>(name, value, info); | 114 SetScriptableObjectProperty<V8HTMLObjectElement>(name, value, info); |
104 } | 115 } |
105 | 116 |
117 void V8HTMLAppletElement::indexedPropertyGetterCustom(uint32_t index, const v8:: PropertyCallbackInfo<v8::Value>& info) | |
118 { | |
119 GetScriptableObjectProperty<V8HTMLAppletElement>(index, info); | |
120 } | |
121 | |
122 void V8HTMLEmbedElement::indexedPropertyGetterCustom(uint32_t index, const v8::P ropertyCallbackInfo<v8::Value>& info) | |
123 { | |
124 GetScriptableObjectProperty<V8HTMLEmbedElement>(index, info); | |
125 } | |
126 | |
127 void V8HTMLObjectElement::indexedPropertyGetterCustom(uint32_t index, const v8:: PropertyCallbackInfo<v8::Value>& info) | |
128 { | |
129 GetScriptableObjectProperty<V8HTMLObjectElement>(index, info); | |
130 } | |
131 | |
132 void V8HTMLAppletElement::indexedPropertySetterCustom(uint32_t index, v8::Local< v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | |
133 { | |
134 SetScriptableObjectProperty<V8HTMLAppletElement>(index, value, info); | |
135 } | |
136 | |
137 void V8HTMLEmbedElement::indexedPropertySetterCustom(uint32_t index, v8::Local<v 8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | |
138 { | |
139 SetScriptableObjectProperty<V8HTMLEmbedElement>(index, value, info); | |
140 } | |
141 | |
142 void V8HTMLObjectElement::indexedPropertySetterCustom(uint32_t index, v8::Local< v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | |
143 { | |
144 SetScriptableObjectProperty<V8HTMLObjectElement>(index, value, info); | |
145 } | |
146 | |
147 namespace { | |
148 | |
149 template <typename TElement> | |
150 void InvokeOnScriptableObject(const v8::FunctionCallbackInfo<v8::Value>& info) | |
abarth-chromium
2014/07/29 17:34:21
InvokeOnScriptableObject -> invokeOnScriptableObje
Krzysztof Olczyk
2014/07/30 08:40:30
Done.
| |
151 { | |
152 HTMLPlugInElement* impl = TElement::toNative(info.Holder()); | |
153 RefPtr<SharedPersistent<v8::Object> > wrapper = impl->pluginWrapper(); | |
154 if (!wrapper) | |
155 return; | |
156 | |
157 v8::Local<v8::Object> instance = wrapper->newLocal(info.GetIsolate()); | |
158 if (instance.IsEmpty()) | |
159 return; | |
160 | |
161 WTF::OwnPtr<v8::Handle<v8::Value>[] > arguments = adoptArrayPtr(new v8::Hand le<v8::Value>[info.Length()]); | |
162 for (int i = 0; i < info.Length(); ++i) | |
163 arguments[i] = info[i]; | |
164 | |
165 TONATIVE_VOID(v8::Local<v8::Value>, retVal, instance->CallAsFunction(info.Th is(), info.Length(), arguments.get())); | |
166 v8SetReturnValue(info, retVal); | |
167 } | |
168 | |
169 } // namespace | |
170 | |
106 void V8HTMLAppletElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va lue>& info) | 171 void V8HTMLAppletElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va lue>& info) |
107 { | 172 { |
108 HTMLPlugInElement* impl = V8HTMLAppletElement::toNative(info.Holder()); | 173 InvokeOnScriptableObject<V8HTMLAppletElement>(info); |
109 UseCounter::count(impl->document(), UseCounter::HTMLAppletElementLegacyCall) ; | 174 UseCounter::count(V8HTMLAppletElement::toNative(info.Holder())->document(), UseCounter::HTMLAppletElementLegacyCall); |
110 npObjectInvokeDefaultHandler(info); | |
111 } | 175 } |
112 | 176 |
113 void V8HTMLEmbedElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Val ue>& info) | 177 void V8HTMLEmbedElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Val ue>& info) |
114 { | 178 { |
115 HTMLPlugInElement* impl = V8HTMLEmbedElement::toNative(info.Holder()); | 179 InvokeOnScriptableObject<V8HTMLEmbedElement>(info); |
116 UseCounter::count(impl->document(), UseCounter::HTMLEmbedElementLegacyCall); | 180 UseCounter::count(V8HTMLEmbedElement::toNative(info.Holder())->document(), U seCounter::HTMLEmbedElementLegacyCall); |
117 npObjectInvokeDefaultHandler(info); | |
118 } | 181 } |
119 | 182 |
120 void V8HTMLObjectElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va lue>& info) | 183 void V8HTMLObjectElement::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Va lue>& info) |
121 { | 184 { |
122 HTMLPlugInElement* impl = V8HTMLObjectElement::toNative(info.Holder()); | 185 InvokeOnScriptableObject<V8HTMLObjectElement>(info); |
123 UseCounter::count(impl->document(), UseCounter::HTMLObjectElementLegacyCall) ; | 186 UseCounter::count(V8HTMLObjectElement::toNative(info.Holder())->document(), UseCounter::HTMLObjectElementLegacyCall); |
124 npObjectInvokeDefaultHandler(info); | |
125 } | |
126 | |
127 template <class C> | |
128 void npObjectIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Va lue>& 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::P ropertyCallbackInfo<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<v 8::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 } | 187 } |
186 | 188 |
187 } // namespace blink | 189 } // namespace blink |
OLD | NEW |