1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // This file has been auto-generated by code_generator_v8.py. DO NOT MODIFY! 6 7 #include "config.h" 8 #include "V8TestInterfaceCheckSecurity.h" 9 10 #include "bindings/core/v8/BindingSecurity.h" 11 #include "bindings/core/v8/ExceptionState.h" 12 #include "bindings/core/v8/V8DOMConfiguration.h" 13 #include "bindings/core/v8/V8HiddenValue.h" 14 #include "bindings/core/v8/V8ObjectConstructor.h" 15 #include "core/dom/ContextFeatures.h" 16 #include "core/dom/Document.h" 17 #include "platform/RuntimeEnabledFeatures.h" 18 #include "platform/TraceEvent.h" 19 #include "wtf/GetPtr.h" 20 #include "wtf/RefPtr.h" 21 22 namespace blink { 23 24 const WrapperTypeInfo V8TestInterfaceCheckSecurity::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceCheckSecurity::domTemplate, V8TestInterfaceCheckSecurity::refObject, V8TestInterfaceCheckSecurity::derefObject, V8TestInterfaceCheckSecurity::createPersistentHandle, 0, 0, 0, V8TestInterfaceCheckSecurity::installConditionallyEnabledMethods, V8TestInterfaceCheckSecurity::installConditionallyEnabledProperties, 0, WrapperTypeInfo::WrapperTypeObjectPrototype, WrapperTypeInfo::ObjectClassId, WrapperTypeInfo::Independent, WrapperTypeInfo::RefCountedObject }; 25 26 // This static member must be declared by DEFINE_WRAPPERTYPEINFO in TestInterfaceCheckSecurity.h. 27 // For details, see the comment of DEFINE_WRAPPERTYPEINFO in 28 // bindings/core/v8/ScriptWrappable.h. 29 const WrapperTypeInfo& TestInterfaceCheckSecurity::s_wrapperTypeInfo = V8TestInterfaceCheckSecurity::wrapperTypeInfo; 30 31 namespace TestInterfaceCheckSecurityV8Internal { 32 33 template <typename T> void V8_USE(T) { } 34 35 static void longAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 36 { 37 v8::Handle<v8::Object> holder = info.Holder(); 38 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 39 v8SetReturnValueInt(info, impl->longAttribute()); 40 } 41 42 static void longAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 43 { 44 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 45 TestInterfaceCheckSecurityV8Internal::longAttributeAttributeGetter(info); 46 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 47 } 48 49 static void doNotCheckSecurityLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 50 { 51 v8::Handle<v8::Object> holder = info.Holder(); 52 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 53 v8SetReturnValueInt(info, impl->doNotCheckSecurityLongAttribute()); 54 } 55 56 static void doNotCheckSecurityLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 57 { 58 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 59 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityLongAttributeAttributeGetter(info); 60 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 61 } 62 63 static void doNotCheckSecurityLongAttributeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 64 { 65 v8::Handle<v8::Object> holder = info.Holder(); 66 ExceptionState exceptionState(ExceptionState::SetterContext, "doNotCheckSecurityLongAttribute", "TestInterfaceCheckSecurity", holder, info.GetIsolate()); 67 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 68 TONATIVE_VOID_EXCEPTIONSTATE(int, cppValue, toInt32(v8Value, exceptionState), exceptionState); 69 impl->setDoNotCheckSecurityLongAttribute(cppValue); 70 } 71 72 static void doNotCheckSecurityLongAttributeAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 73 { 74 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter"); 75 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityLongAttributeAttributeSetter(v8Value, info); 76 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 77 } 78 79 static void doNotCheckSecurityReadonlyLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 80 { 81 v8::Handle<v8::Object> holder = info.Holder(); 82 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 83 v8SetReturnValueInt(info, impl->doNotCheckSecurityReadonlyLongAttribute()); 84 } 85 86 static void doNotCheckSecurityReadonlyLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 87 { 88 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 89 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReadonlyLongAttributeAttributeGetter(info); 90 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 91 } 92 93 static void doNotCheckSecurityOnSetterLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 94 { 95 v8::Handle<v8::Object> holder = info.Holder(); 96 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 97 v8SetReturnValueInt(info, impl->doNotCheckSecurityOnSetterLongAttribute()); 98 } 99 100 static void doNotCheckSecurityOnSetterLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 101 { 102 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 103 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityOnSetterLongAttributeAttributeGetter(info); 104 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 105 } 106 107 static void doNotCheckSecurityOnSetterLongAttributeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 108 { 109 v8::Handle<v8::Object> holder = info.Holder(); 110 ExceptionState exceptionState(ExceptionState::SetterContext, "doNotCheckSecurityOnSetterLongAttribute", "TestInterfaceCheckSecurity", holder, info.GetIsolate()); 111 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 112 TONATIVE_VOID_EXCEPTIONSTATE(int, cppValue, toInt32(v8Value, exceptionState), exceptionState); 113 impl->setDoNotCheckSecurityOnSetterLongAttribute(cppValue); 114 } 115 116 static void doNotCheckSecurityOnSetterLongAttributeAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 117 { 118 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter"); 119 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityOnSetterLongAttributeAttributeSetter(v8Value, info); 120 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 121 } 122 123 static void doNotCheckSecurityReplaceableReadonlyLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 124 { 125 v8::Handle<v8::Object> holder = info.Holder(); 126 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 127 v8SetReturnValueInt(info, impl->doNotCheckSecurityReplaceableReadonlyLongAttribute()); 128 } 129 130 static void doNotCheckSecurityReplaceableReadonlyLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 131 { 132 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 133 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReplaceableReadonlyLongAttributeAttributeGetter(info); 134 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 135 } 136 137 static void TestInterfaceCheckSecurityForceSetAttributeOnThis(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 138 { 139 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(info.Holder()); 140 v8::String::Utf8Value attributeName(name); 141 ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "TestInterfaceCheckSecurity", info.Holder(), info.GetIsolate()); 142 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), exceptionState)) { 143 exceptionState.throwIfNeeded(); 144 return; 145 } 146 if (info.This()->IsObject()) 147 v8::Handle<v8::Object>::Cast(info.This())->ForceSet(name, v8Value); 148 } 149 150 static void TestInterfaceCheckSecurityForceSetAttributeOnThisCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 151 { 152 TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityForceSetAttributeOnThis(name, v8Value, info); 153 } 154 155 bool indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>) 156 { 157 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(host); 158 return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), impl->frame(), DoNotReportSecurityError); 159 } 160 161 bool namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>) 162 { 163 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(host); 164 return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), impl->frame(), DoNotReportSecurityError); 165 } 166 167 static void voidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 168 { 169 ExceptionState exceptionState(ExceptionState::ExecutionContext, "voidMethod", "TestInterfaceCheckSecurity", info.Holder(), info.GetIsolate()); 170 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(info.Holder()); 171 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), exceptionState)) { 172 exceptionState.throwIfNeeded(); 173 return; 174 } 175 impl->voidMethod(); 176 } 177 178 static void voidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 179 { 180 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 181 TestInterfaceCheckSecurityV8Internal::voidMethodMethod(info); 182 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 183 } 184 185 static void doNotCheckSecurityVoidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 186 { 187 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(info.Holder()); 188 impl->doNotCheckSecurityVoidMethod(); 189 } 190 191 static void doNotCheckSecurityVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 192 { 193 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 194 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodMethod(info); 195 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 196 } 197 198 static void doNotCheckSecurityVoidMethodOriginSafeMethodGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 199 { 200 static int domTemplateKey; // This address is used for a key to look up the dom template. 201 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); 202 v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0); 203 204 v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), info.GetIsolate()); 205 if (holder.IsEmpty()) { 206 // This is only reachable via |object.__proto__.func|, in which case it 207 // has already passed the same origin security check 208 v8SetReturnValue(info, privateTemplate->GetFunction()); 209 return; 210 } 211 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 212 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), DoNotReportSecurityError)) { 213 static int sharedTemplateKey; // This address is used for a key to look up the dom template. 214 v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0); 215 v8SetReturnValue(info, sharedTemplate->GetFunction()); 216 return; 217 } 218 219 v8::Local<v8::Value> hiddenValue = v8::Handle<v8::Object>::Cast(info.This())->GetHiddenValue(v8AtomicString(info.GetIsolate(), "doNotCheckSecurityVoidMethod")); 220 if (!hiddenValue.IsEmpty()) { 221 v8SetReturnValue(info, hiddenValue); 222 return; 223 } 224 225 v8SetReturnValue(info, privateTemplate->GetFunction()); 226 } 227 228 static void doNotCheckSecurityVoidMethodOriginSafeMethodGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 229 { 230 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 231 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodOriginSafeMethodGetter(info); 232 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 233 } 234 235 static void doNotCheckSecurityDoNotCheckSignatureVoidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 236 { 237 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(info.Holder()); 238 impl->doNotCheckSecurityDoNotCheckSignatureVoidMethod(); 239 } 240 241 static void doNotCheckSecurityDoNotCheckSignatureVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 242 { 243 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 244 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodMethod(info); 245 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 246 } 247 248 static void doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeMethodGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 249 { 250 static int domTemplateKey; // This address is used for a key to look up the dom template. 251 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); 252 v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodMethodCallback, v8Undefined(), v8::Local<v8::Signature>(), 0); 253 254 v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), info.GetIsolate()); 255 if (holder.IsEmpty()) { 256 // This is only reachable via |object.__proto__.func|, in which case it 257 // has already passed the same origin security check 258 v8SetReturnValue(info, privateTemplate->GetFunction()); 259 return; 260 } 261 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 262 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), DoNotReportSecurityError)) { 263 static int sharedTemplateKey; // This address is used for a key to look up the dom template. 264 v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodMethodCallback, v8Undefined(), v8::Local<v8::Signature>(), 0); 265 v8SetReturnValue(info, sharedTemplate->GetFunction()); 266 return; 267 } 268 269 v8::Local<v8::Value> hiddenValue = v8::Handle<v8::Object>::Cast(info.This())->GetHiddenValue(v8AtomicString(info.GetIsolate(), "doNotCheckSecurityDoNotCheckSignatureVoidMethod")); 270 if (!hiddenValue.IsEmpty()) { 271 v8SetReturnValue(info, hiddenValue); 272 return; 273 } 274 275 v8SetReturnValue(info, privateTemplate->GetFunction()); 276 } 277 278 static void doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeMethodGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 279 { 280 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 281 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeMethodGetter(info); 282 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 283 } 284 285 static void doNotCheckSecurityPerWorldBindingsVoidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 286 { 287 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(info.Holder()); 288 impl->doNotCheckSecurityPerWorldBindingsVoidMethod(); 289 } 290 291 static void doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 292 { 293 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 294 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethod(info); 295 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 296 } 297 298 static void doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 299 { 300 static int domTemplateKey; // This address is used for a key to look up the dom template. 301 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); 302 v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0); 303 304 v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), info.GetIsolate()); 305 if (holder.IsEmpty()) { 306 // This is only reachable via |object.__proto__.func|, in which case it 307 // has already passed the same origin security check 308 v8SetReturnValue(info, privateTemplate->GetFunction()); 309 return; 310 } 311 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 312 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), DoNotReportSecurityError)) { 313 static int sharedTemplateKey; // This address is used for a key to look up the dom template. 314 v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0); 315 v8SetReturnValue(info, sharedTemplate->GetFunction()); 316 return; 317 } 318 319 v8::Local<v8::Value> hiddenValue = v8::Handle<v8::Object>::Cast(info.This())->GetHiddenValue(v8AtomicString(info.GetIsolate(), "doNotCheckSecurityPerWorldBindingsVoidMethod")); 320 if (!hiddenValue.IsEmpty()) { 321 v8SetReturnValue(info, hiddenValue); 322 return; 323 } 324 325 v8SetReturnValue(info, privateTemplate->GetFunction()); 326 } 327 328 static void doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 329 { 330 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 331 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetter(info); 332 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 333 } 334 335 static void doNotCheckSecurityPerWorldBindingsVoidMethodMethodForMainWorld(const v8::FunctionCallbackInfo<v8::Value>& info) 336 { 337 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(info.Holder()); 338 impl->doNotCheckSecurityPerWorldBindingsVoidMethod(); 339 } 340 341 static void doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallbackForMainWorld(const v8::FunctionCallbackInfo<v8::Value>& info) 342 { 343 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 344 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodForMainWorld(info); 345 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 346 } 347 348 static void doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterForMainWorld(const v8::PropertyCallbackInfo<v8::Value>& info) 349 { 350 static int domTemplateKey; // This address is used for a key to look up the dom template. 351 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); 352 v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallbackForMainWorld, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0); 353 354 v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), info.GetIsolate()); 355 if (holder.IsEmpty()) { 356 // This is only reachable via |object.__proto__.func|, in which case it 357 // has already passed the same origin security check 358 v8SetReturnValue(info, privateTemplate->GetFunction()); 359 return; 360 } 361 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 362 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), DoNotReportSecurityError)) { 363 static int sharedTemplateKey; // This address is used for a key to look up the dom template. 364 v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallbackForMainWorld, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0); 365 v8SetReturnValue(info, sharedTemplate->GetFunction()); 366 return; 367 } 368 369 v8::Local<v8::Value> hiddenValue = v8::Handle<v8::Object>::Cast(info.This())->GetHiddenValue(v8AtomicString(info.GetIsolate(), "doNotCheckSecurityPerWorldBindingsVoidMethod")); 370 if (!hiddenValue.IsEmpty()) { 371 v8SetReturnValue(info, hiddenValue); 372 return; 373 } 374 375 v8SetReturnValue(info, privateTemplate->GetFunction()); 376 } 377 378 static void doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterCallbackForMainWorld(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 379 { 380 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 381 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterForMainWorld(info); 382 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 383 } 384 385 static void doNotCheckSecurityUnforgeableVoidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info) 386 { 387 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(info.Holder()); 388 impl->doNotCheckSecurityUnforgeableVoidMethod(); 389 } 390 391 static void doNotCheckSecurityUnforgeableVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 392 { 393 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMMethod"); 394 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodMethod(info); 395 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 396 } 397 398 static void doNotCheckSecurityUnforgeableVoidMethodOriginSafeMethodGetter(const v8::PropertyCallbackInfo<v8::Value>& info) 399 { 400 static int domTemplateKey; // This address is used for a key to look up the dom template. 401 V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate()); 402 v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0); 403 404 v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), info.GetIsolate()); 405 if (holder.IsEmpty()) { 406 // This is only reachable via |object.__proto__.func|, in which case it 407 // has already passed the same origin security check 408 v8SetReturnValue(info, privateTemplate->GetFunction()); 409 return; 410 } 411 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 412 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), DoNotReportSecurityError)) { 413 static int sharedTemplateKey; // This address is used for a key to look up the dom template. 414 v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0); 415 v8SetReturnValue(info, sharedTemplate->GetFunction()); 416 return; 417 } 418 419 v8::Local<v8::Value> hiddenValue = v8::Handle<v8::Object>::Cast(info.This())->GetHiddenValue(v8AtomicString(info.GetIsolate(), "doNotCheckSecurityUnforgeableVoidMethod")); 420 if (!hiddenValue.IsEmpty()) { 421 v8SetReturnValue(info, hiddenValue); 422 return; 423 } 424 425 v8SetReturnValue(info, privateTemplate->GetFunction()); 426 } 427 428 static void doNotCheckSecurityUnforgeableVoidMethodOriginSafeMethodGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info) 429 { 430 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter"); 431 TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodOriginSafeMethodGetter(info); 432 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 433 } 434 435 static void TestInterfaceCheckSecurityOriginSafeMethodSetter(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 436 { 437 v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), info.GetIsolate()); 438 if (holder.IsEmpty()) 439 return; 440 TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toImpl(holder); 441 v8::String::Utf8Value attributeName(name); 442 ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "TestInterfaceCheckSecurity", info.Holder(), info.GetIsolate()); 443 if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), exceptionState)) { 444 exceptionState.throwIfNeeded(); 445 return; 446 } 447 448 V8HiddenValue::setHiddenValue(info.GetIsolate(), v8::Handle<v8::Object>::Cast(info.This()), name, v8Value); 449 } 450 451 static void TestInterfaceCheckSecurityOriginSafeMethodSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info) 452 { 453 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMSetter"); 454 TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetter(name, v8Value, info); 455 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution"); 456 } 457 458 } // namespace TestInterfaceCheckSecurityV8Internal 459 460 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceCheckSecurityAttributes[] = { 461 {"longAttribute", TestInterfaceCheckSecurityV8Internal::longAttributeAttributeGetterCallback, 0, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance}, 462 {"doNotCheckSecurityLongAttribute", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityLongAttributeAttributeGetterCallback, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityLongAttributeAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance}, 463 {"doNotCheckSecurityReadonlyLongAttribute", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReadonlyLongAttributeAttributeGetterCallback, 0, 0, 0, 0, static_cast<v8::AccessControl>(v8::ALL_CAN_READ), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance}, 464 {"doNotCheckSecurityOnSetterLongAttribute", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityOnSetterLongAttributeAttributeGetterCallback, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityOnSetterLongAttributeAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::ALL_CAN_WRITE), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance}, 465 {"doNotCheckSecurityReplaceableReadonlyLongAttribute", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReplaceableReadonlyLongAttributeAttributeGetterCallback, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityForceSetAttributeOnThisCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE), static_cast<v8::PropertyAttribute>(v8::None), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance}, 466 }; 467 468 static const V8DOMConfiguration::MethodConfiguration V8TestInterfaceCheckSecurityMethods[] = { 469 {"voidMethod", TestInterfaceCheckSecurityV8Internal::voidMethodMethodCallback, 0, 0, V8DOMConfiguration::ExposedToAllScripts}, 470 }; 471 472 static void installV8TestInterfaceCheckSecurityTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate) 473 { 474 functionTemplate->ReadOnlyPrototype(); 475 476 v8::Local<v8::Signature> defaultSignature; 477 defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceCheckSecurity", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceCheckSecurity::internalFieldCount, 478 V8TestInterfaceCheckSecurityAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceCheckSecurityAttributes), 479 0, 0, 480 V8TestInterfaceCheckSecurityMethods, WTF_ARRAY_LENGTH(V8TestInterfaceCheckSecurityMethods), 481 isolate); 482 v8::Local<v8::ObjectTemplate> instanceTemplate ALLOW_UNUSED = functionTemplate->InstanceTemplate(); 483 v8::Local<v8::ObjectTemplate> prototypeTemplate ALLOW_UNUSED = functionTemplate->PrototypeTemplate(); 484 instanceTemplate->SetAccessCheckCallbacks(TestInterfaceCheckSecurityV8Internal::namedSecurityCheck, TestInterfaceCheckSecurityV8Internal::indexedSecurityCheck, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&V8TestInterfaceCheckSecurity::wrapperTypeInfo))); 485 static const V8DOMConfiguration::AttributeConfiguration doNotCheckSecurityVoidMethodOriginSafeAttributeConfiguration = { 486 "doNotCheckSecurityVoidMethod", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodOriginSafeMethodGetterCallback, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetterCallback, 0, 0, &V8TestInterfaceCheckSecurity::wrapperTypeInfo, v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance, 487 }; 488 V8DOMConfiguration::installAttribute(prototypeTemplate, v8::Handle<v8::ObjectTemplate>(), doNotCheckSecurityVoidMethodOriginSafeAttributeConfiguration, isolate); 489 static const V8DOMConfiguration::AttributeConfiguration doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeAttributeConfiguration = { 490 "doNotCheckSecurityDoNotCheckSignatureVoidMethod", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeMethodGetterCallback, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetterCallback, 0, 0, &V8TestInterfaceCheckSecurity::wrapperTypeInfo, v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance, 491 }; 492 V8DOMConfiguration::installAttribute(prototypeTemplate, v8::Handle<v8::ObjectTemplate>(), doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeAttributeConfiguration, isolate); 493 static const V8DOMConfiguration::AttributeConfiguration doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeAttributeConfiguration = { 494 "doNotCheckSecurityPerWorldBindingsVoidMethod", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterCallback, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetterCallback, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterCallbackForMainWorld, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetterCallbackForMainWorld, &V8TestInterfaceCheckSecurity::wrapperTypeInfo, v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance, 495 }; 496 V8DOMConfiguration::installAttribute(prototypeTemplate, v8::Handle<v8::ObjectTemplate>(), doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeAttributeConfiguration, isolate); 497 static const V8DOMConfiguration::AttributeConfiguration doNotCheckSecurityUnforgeableVoidMethodOriginSafeAttributeConfiguration = { 498 "doNotCheckSecurityUnforgeableVoidMethod", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodOriginSafeMethodGetterCallback, 0, 0, 0, &V8TestInterfaceCheckSecurity::wrapperTypeInfo, v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly), V8DOMConfiguration::ExposedToAllScripts, V8DOMConfiguration::OnInstance, 499 }; 500 V8DOMConfiguration::installAttribute(instanceTemplate, v8::Handle<v8::ObjectTemplate>(), doNotCheckSecurityUnforgeableVoidMethodOriginSafeAttributeConfiguration, isolate); 501 502 // Custom toString template 503 functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate()); 504 } 505 506 v8::Handle<v8::FunctionTemplate> V8TestInterfaceCheckSecurity::domTemplate(v8::Isolate* isolate) 507 { 508 return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), installV8TestInterfaceCheckSecurityTemplate); 509 } 510 511 bool V8TestInterfaceCheckSecurity::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 512 { 513 return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); 514 } 515 516 v8::Handle<v8::Object> V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) 517 { 518 return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); 519 } 520 521 TestInterfaceCheckSecurity* V8TestInterfaceCheckSecurity::toImplWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value) 522 { 523 return hasInstance(value, isolate) ? blink::toScriptWrappableBase(v8::Handle<v8::Object>::Cast(value))->toImpl<TestInterfaceCheckSecurity>() : 0; 524 } 525 526 527 void V8TestInterfaceCheckSecurity::refObject(ScriptWrappableBase* internalPointer) 528 { 529 internalPointer->toImpl<TestInterfaceCheckSecurity>()->ref(); 530 } 531 532 void V8TestInterfaceCheckSecurity::derefObject(ScriptWrappableBase* internalPointer) 533 { 534 internalPointer->toImpl<TestInterfaceCheckSecurity>()->deref(); 535 } 536 537 WrapperPersistentNode* V8TestInterfaceCheckSecurity::createPersistentHandle(ScriptWrappableBase* internalPointer) 538 { 539 ASSERT_NOT_REACHED(); 540 return 0; 541 } 542 543 template<> 544 v8::Handle<v8::Value> toV8NoInline(TestInterfaceCheckSecurity* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 545 { 546 return toV8(impl, creationContext, isolate); 547 } 548 549 } // namespace blink 550