| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 This file is part of the WebKit open source project. | |
| 3 This file has been generated by generate-bindings.pl. DO NOT MODIFY! | |
| 4 | |
| 5 This library is free software; you can redistribute it and/or | |
| 6 modify it under the terms of the GNU Library General Public | |
| 7 License as published by the Free Software Foundation; either | |
| 8 version 2 of the License, or (at your option) any later version. | |
| 9 | |
| 10 This library is distributed in the hope that it will be useful, | |
| 11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 Library General Public License for more details. | |
| 14 | |
| 15 You should have received a copy of the GNU Library General Public License | |
| 16 along with this library; see the file COPYING.LIB. If not, write to | |
| 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 18 Boston, MA 02111-1307, USA. | |
| 19 */ | |
| 20 | |
| 21 #include "config.h" | |
| 22 #include "V8TestActiveDOMObject.h" | |
| 23 | |
| 24 #include "BindingState.h" | |
| 25 #include "ContextFeatures.h" | |
| 26 #include "ExceptionCode.h" | |
| 27 #include "Frame.h" | |
| 28 #include "RuntimeEnabledFeatures.h" | |
| 29 #include "V8Binding.h" | |
| 30 #include "V8DOMWrapper.h" | |
| 31 #include "V8Node.h" | |
| 32 #include <wtf/UnusedParam.h> | |
| 33 | |
| 34 #if ENABLE(BINDING_INTEGRITY) | |
| 35 #if defined(OS_WIN) | |
| 36 #pragma warning(disable: 4483) | |
| 37 extern "C" { extern void (*const __identifier("??_7TestActiveDOMObject@WebCore@@
6B@")[])(); } | |
| 38 #else | |
| 39 extern "C" { extern void* _ZTVN7WebCore19TestActiveDOMObjectE[]; } | |
| 40 #endif | |
| 41 #endif // ENABLE(BINDING_INTEGRITY) | |
| 42 | |
| 43 namespace WebCore { | |
| 44 | |
| 45 #if ENABLE(BINDING_INTEGRITY) | |
| 46 // This checks if a DOM object that is about to be wrapped is valid. | |
| 47 // Specifically, it checks that a vtable of the DOM object is equal to | |
| 48 // a vtable of an expected class. | |
| 49 // Due to a dangling pointer, the DOM object you are wrapping might be | |
| 50 // already freed or realloced. If freed, the check will fail because | |
| 51 // a free list pointer should be stored at the head of the DOM object. | |
| 52 // If realloced, the check will fail because the vtable of the DOM object | |
| 53 // differs from the expected vtable (unless the same class of DOM object | |
| 54 // is realloced on the slot). | |
| 55 inline void checkTypeOrDieTrying(TestActiveDOMObject* object) | |
| 56 { | |
| 57 void* actualVTablePointer = *(reinterpret_cast<void**>(object)); | |
| 58 #if defined(OS_WIN) | |
| 59 void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7Test
ActiveDOMObject@WebCore@@6B@")); | |
| 60 #else | |
| 61 void* expectedVTablePointer = &_ZTVN7WebCore19TestActiveDOMObjectE[2]; | |
| 62 #endif | |
| 63 if (actualVTablePointer != expectedVTablePointer) | |
| 64 CRASH(); | |
| 65 } | |
| 66 #endif // ENABLE(BINDING_INTEGRITY) | |
| 67 | |
| 68 WrapperTypeInfo V8TestActiveDOMObject::info = { V8TestActiveDOMObject::GetTempla
te, V8TestActiveDOMObject::derefObject, 0, 0, 0, V8TestActiveDOMObject::installP
erContextPrototypeProperties, 0, WrapperTypeObjectPrototype }; | |
| 69 | |
| 70 namespace TestActiveDOMObjectV8Internal { | |
| 71 | |
| 72 template <typename T> void V8_USE(T) { } | |
| 73 | |
| 74 static v8::Handle<v8::Value> excitingAttrAttrGetter(v8::Local<v8::String> name,
const v8::AccessorInfo& info) | |
| 75 { | |
| 76 TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(info.Holder()); | |
| 77 return v8Integer(imp->excitingAttr(), info.GetIsolate()); | |
| 78 } | |
| 79 | |
| 80 static v8::Handle<v8::Value> excitingAttrAttrGetterCallback(v8::Local<v8::String
> name, const v8::AccessorInfo& info) | |
| 81 { | |
| 82 return TestActiveDOMObjectV8Internal::excitingAttrAttrGetter(name, info); | |
| 83 } | |
| 84 | |
| 85 bool indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::Access
Type type, v8::Local<v8::Value>) | |
| 86 { | |
| 87 TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(host); | |
| 88 return BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), i
mp->frame(), DoNotReportSecurityError); | |
| 89 } | |
| 90 | |
| 91 bool namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8
::AccessType type, v8::Local<v8::Value>) | |
| 92 { | |
| 93 TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(host); | |
| 94 return BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), i
mp->frame(), DoNotReportSecurityError); | |
| 95 } | |
| 96 | |
| 97 static v8::Handle<v8::Value> excitingFunctionMethod(const v8::Arguments& args) | |
| 98 { | |
| 99 if (args.Length() < 1) | |
| 100 return throwNotEnoughArgumentsError(args.GetIsolate()); | |
| 101 TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder()); | |
| 102 if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp
->frame())) | |
| 103 return v8Undefined(); | |
| 104 V8TRYCATCH(Node*, nextChild, V8Node::HasInstance(args[0], args.GetIsolate(),
worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(a
rgs[0])) : 0); | |
| 105 imp->excitingFunction(nextChild); | |
| 106 return v8Undefined(); | |
| 107 } | |
| 108 | |
| 109 static v8::Handle<v8::Value> excitingFunctionMethodCallback(const v8::Arguments&
args) | |
| 110 { | |
| 111 return TestActiveDOMObjectV8Internal::excitingFunctionMethod(args); | |
| 112 } | |
| 113 | |
| 114 static v8::Handle<v8::Value> postMessageMethod(const v8::Arguments& args) | |
| 115 { | |
| 116 if (args.Length() < 1) | |
| 117 return throwNotEnoughArgumentsError(args.GetIsolate()); | |
| 118 TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder()); | |
| 119 V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, message, args[0]); | |
| 120 imp->postMessage(message); | |
| 121 return v8Undefined(); | |
| 122 } | |
| 123 | |
| 124 static v8::Handle<v8::Value> postMessageMethodCallback(const v8::Arguments& args
) | |
| 125 { | |
| 126 return TestActiveDOMObjectV8Internal::postMessageMethod(args); | |
| 127 } | |
| 128 | |
| 129 static v8::Handle<v8::Value> postMessageAttrGetter(v8::Local<v8::String> name, c
onst v8::AccessorInfo& info) | |
| 130 { | |
| 131 // This is only for getting a unique pointer which we can pass to privateTem
plate. | |
| 132 static const char* privateTemplateUniqueKey = "postMessagePrivateTemplate"; | |
| 133 WrapperWorldType currentWorldType = worldType(info.GetIsolate()); | |
| 134 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); | |
| 135 v8::Persistent<v8::FunctionTemplate> privateTemplate = data->privateTemplate
(currentWorldType, &privateTemplateUniqueKey, TestActiveDOMObjectV8Internal::pos
tMessageMethodCallback, v8Undefined(), v8::Signature::New(V8PerIsolateData::from
(info.GetIsolate())->rawTemplate(&V8TestActiveDOMObject::info, currentWorldType)
)); | |
| 136 | |
| 137 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8
TestActiveDOMObject::GetTemplate(info.GetIsolate(), currentWorldType)); | |
| 138 if (holder.IsEmpty()) { | |
| 139 // can only reach here by 'object.__proto__.func', and it should passed | |
| 140 // domain security check already | |
| 141 return privateTemplate->GetFunction(); | |
| 142 } | |
| 143 TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder); | |
| 144 if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp
->frame(), DoNotReportSecurityError)) { | |
| 145 static const char* sharedTemplateUniqueKey = "postMessageSharedTemplate"
; | |
| 146 v8::Persistent<v8::FunctionTemplate> sharedTemplate = data->privateTempl
ate(currentWorldType, &sharedTemplateUniqueKey, TestActiveDOMObjectV8Internal::p
ostMessageMethodCallback, v8Undefined(), v8::Signature::New(V8PerIsolateData::fr
om(info.GetIsolate())->rawTemplate(&V8TestActiveDOMObject::info, currentWorldTyp
e))); | |
| 147 return sharedTemplate->GetFunction(); | |
| 148 } | |
| 149 | |
| 150 v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(name); | |
| 151 if (!hiddenValue.IsEmpty()) | |
| 152 return hiddenValue; | |
| 153 | |
| 154 return privateTemplate->GetFunction(); | |
| 155 } | |
| 156 | |
| 157 static v8::Handle<v8::Value> postMessageAttrGetterCallback(v8::Local<v8::String>
name, const v8::AccessorInfo& info) | |
| 158 { | |
| 159 return TestActiveDOMObjectV8Internal::postMessageAttrGetter(name, info); | |
| 160 } | |
| 161 | |
| 162 static void TestActiveDOMObjectDomainSafeFunctionSetter(v8::Local<v8::String> na
me, v8::Local<v8::Value> value, const v8::AccessorInfo& info) | |
| 163 { | |
| 164 v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8
TestActiveDOMObject::GetTemplate(info.GetIsolate(), worldType(info.GetIsolate())
)); | |
| 165 if (holder.IsEmpty()) | |
| 166 return; | |
| 167 TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder); | |
| 168 if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp
->frame())) | |
| 169 return; | |
| 170 | |
| 171 info.This()->SetHiddenValue(name, value); | |
| 172 } | |
| 173 | |
| 174 } // namespace TestActiveDOMObjectV8Internal | |
| 175 | |
| 176 static const V8DOMConfiguration::BatchedAttribute V8TestActiveDOMObjectAttrs[] =
{ | |
| 177 // Attribute 'excitingAttr' (Type: 'readonly attribute' ExtAttr: '') | |
| 178 {"excitingAttr", TestActiveDOMObjectV8Internal::excitingAttrAttrGetterCallba
ck, 0, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), stati
c_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, | |
| 179 }; | |
| 180 | |
| 181 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestActiveDOMObjectTempla
te(v8::Persistent<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorld
Type currentWorldType) | |
| 182 { | |
| 183 desc->ReadOnlyPrototype(); | |
| 184 | |
| 185 v8::Local<v8::Signature> defaultSignature; | |
| 186 defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestActiveDO
MObject", v8::Persistent<v8::FunctionTemplate>(), V8TestActiveDOMObject::interna
lFieldCount, | |
| 187 V8TestActiveDOMObjectAttrs, WTF_ARRAY_LENGTH(V8TestActiveDOMObjectAttrs)
, | |
| 188 0, 0, isolate, currentWorldType); | |
| 189 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. | |
| 190 v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate(); | |
| 191 v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate(); | |
| 192 UNUSED_PARAM(instance); // In some cases, it will not be used. | |
| 193 UNUSED_PARAM(proto); // In some cases, it will not be used. | |
| 194 instance->SetAccessCheckCallbacks(TestActiveDOMObjectV8Internal::namedSecuri
tyCheck, TestActiveDOMObjectV8Internal::indexedSecurityCheck, v8::External::New(
&V8TestActiveDOMObject::info)); | |
| 195 | |
| 196 // Custom Signature 'excitingFunction' | |
| 197 const int excitingFunctionArgc = 1; | |
| 198 v8::Handle<v8::FunctionTemplate> excitingFunctionArgv[excitingFunctionArgc]
= { V8PerIsolateData::from(isolate)->rawTemplate(&V8Node::info, currentWorldType
) }; | |
| 199 v8::Handle<v8::Signature> excitingFunctionSignature = v8::Signature::New(des
c, excitingFunctionArgc, excitingFunctionArgv); | |
| 200 proto->Set(v8::String::NewSymbol("excitingFunction"), v8::FunctionTemplate::
New(TestActiveDOMObjectV8Internal::excitingFunctionMethodCallback, v8Undefined()
, excitingFunctionSignature)); | |
| 201 | |
| 202 // Function 'postMessage' (ExtAttr: 'DoNotCheckSecurity') | |
| 203 proto->SetAccessor(v8::String::NewSymbol("postMessage"), TestActiveDOMObject
V8Internal::postMessageAttrGetterCallback, TestActiveDOMObjectV8Internal::TestAc
tiveDOMObjectDomainSafeFunctionSetter, v8Undefined(), v8::ALL_CAN_READ, static_c
ast<v8::PropertyAttribute>(v8::DontDelete)); | |
| 204 | |
| 205 // Custom toString template | |
| 206 desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->to
StringTemplate()); | |
| 207 return desc; | |
| 208 } | |
| 209 | |
| 210 v8::Persistent<v8::FunctionTemplate> V8TestActiveDOMObject::GetTemplate(v8::Isol
ate* isolate, WrapperWorldType currentWorldType) | |
| 211 { | |
| 212 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | |
| 213 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWo
rldType).find(&info); | |
| 214 if (result != data->templateMap(currentWorldType).end()) | |
| 215 return result->value; | |
| 216 | |
| 217 v8::HandleScope handleScope; | |
| 218 v8::Persistent<v8::FunctionTemplate> templ = | |
| 219 ConfigureV8TestActiveDOMObjectTemplate(data->rawTemplate(&info, currentW
orldType), isolate, currentWorldType); | |
| 220 data->templateMap(currentWorldType).add(&info, templ); | |
| 221 return templ; | |
| 222 } | |
| 223 | |
| 224 bool V8TestActiveDOMObject::HasInstance(v8::Handle<v8::Value> value, v8::Isolate
* isolate, WrapperWorldType currentWorldType) | |
| 225 { | |
| 226 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWor
ldType); | |
| 227 } | |
| 228 | |
| 229 bool V8TestActiveDOMObject::HasInstanceInAnyWorld(v8::Handle<v8::Value> value, v
8::Isolate* isolate) | |
| 230 { | |
| 231 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld) | |
| 232 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWo
rld) | |
| 233 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorl
d); | |
| 234 } | |
| 235 | |
| 236 | |
| 237 v8::Handle<v8::Object> V8TestActiveDOMObject::createWrapper(PassRefPtr<TestActiv
eDOMObject> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 238 { | |
| 239 ASSERT(impl.get()); | |
| 240 ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty()); | |
| 241 | |
| 242 #if ENABLE(BINDING_INTEGRITY) | |
| 243 checkTypeOrDieTrying(impl.get()); | |
| 244 #endif | |
| 245 | |
| 246 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext
, &info, impl.get(), isolate); | |
| 247 if (UNLIKELY(wrapper.IsEmpty())) | |
| 248 return wrapper; | |
| 249 | |
| 250 installPerContextProperties(wrapper, impl.get(), isolate); | |
| 251 V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasD
ependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Indep
endent); | |
| 252 return wrapper; | |
| 253 } | |
| 254 void V8TestActiveDOMObject::derefObject(void* object) | |
| 255 { | |
| 256 static_cast<TestActiveDOMObject*>(object)->deref(); | |
| 257 } | |
| 258 | |
| 259 } // namespace WebCore | |
| OLD | NEW |