Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / tests / results / V8TestInterfaceCheckSecurity.cpp
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 "RuntimeEnabledFeatures.h"
11 #include "bindings/v8/BindingSecurity.h"
12 #include "bindings/v8/ExceptionState.h"
13 #include "bindings/v8/V8DOMConfiguration.h"
14 #include "bindings/v8/V8HiddenValue.h"
15 #include "bindings/v8/V8ObjectConstructor.h"
16 #include "core/dom/ContextFeatures.h"
17 #include "core/dom/Document.h"
18 #include "platform/TraceEvent.h"
19 #include "wtf/GetPtr.h"
20 #include "wtf/RefPtr.h"
21
22 namespace WebCore {
23
24 static void initializeScriptWrappableForInterface(TestInterfaceCheckSecurity* object)
25 {
26     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
27         ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfaceCheckSecurity::wrapperTypeInfo);
28     else
29         ASSERT_NOT_REACHED();
30 }
31
32 } // namespace WebCore
33
34 void webCoreInitializeScriptWrappableForInterface(WebCore::TestInterfaceCheckSecurity* object)
35 {
36     WebCore::initializeScriptWrappableForInterface(object);
37 }
38
39 namespace WebCore {
40 const WrapperTypeInfo V8TestInterfaceCheckSecurity::wrapperTypeInfo = { gin::kEmbedderBlink, V8TestInterfaceCheckSecurity::domTemplate, V8TestInterfaceCheckSecurity::derefObject, 0, 0, 0, V8TestInterfaceCheckSecurity::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
41
42 namespace TestInterfaceCheckSecurityV8Internal {
43
44 template <typename T> void V8_USE(T) { }
45
46 static void longAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
47 {
48     v8::Handle<v8::Object> holder = info.Holder();
49     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
50     v8SetReturnValueInt(info, impl->longAttribute());
51 }
52
53 static void longAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
54 {
55     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
56     TestInterfaceCheckSecurityV8Internal::longAttributeAttributeGetter(info);
57     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
58 }
59
60 static void doNotCheckSecurityLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
61 {
62     v8::Handle<v8::Object> holder = info.Holder();
63     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
64     v8SetReturnValueInt(info, impl->doNotCheckSecurityLongAttribute());
65 }
66
67 static void doNotCheckSecurityLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
68 {
69     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
70     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityLongAttributeAttributeGetter(info);
71     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
72 }
73
74 static void doNotCheckSecurityLongAttributeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
75 {
76     v8::Handle<v8::Object> holder = info.Holder();
77     ExceptionState exceptionState(ExceptionState::SetterContext, "doNotCheckSecurityLongAttribute", "TestInterfaceCheckSecurity", holder, info.GetIsolate());
78     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
79     V8TRYCATCH_EXCEPTION_VOID(int, cppValue, toInt32(v8Value, exceptionState), exceptionState);
80     impl->setDoNotCheckSecurityLongAttribute(cppValue);
81 }
82
83 static void doNotCheckSecurityLongAttributeAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
84 {
85     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
86     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityLongAttributeAttributeSetter(v8Value, info);
87     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
88 }
89
90 static void doNotCheckSecurityReadonlyLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
91 {
92     v8::Handle<v8::Object> holder = info.Holder();
93     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
94     v8SetReturnValueInt(info, impl->doNotCheckSecurityReadonlyLongAttribute());
95 }
96
97 static void doNotCheckSecurityReadonlyLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
98 {
99     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
100     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReadonlyLongAttributeAttributeGetter(info);
101     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
102 }
103
104 static void doNotCheckSecurityOnSetterLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
105 {
106     v8::Handle<v8::Object> holder = info.Holder();
107     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
108     v8SetReturnValueInt(info, impl->doNotCheckSecurityOnSetterLongAttribute());
109 }
110
111 static void doNotCheckSecurityOnSetterLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
112 {
113     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
114     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityOnSetterLongAttributeAttributeGetter(info);
115     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
116 }
117
118 static void doNotCheckSecurityOnSetterLongAttributeAttributeSetter(v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
119 {
120     v8::Handle<v8::Object> holder = info.Holder();
121     ExceptionState exceptionState(ExceptionState::SetterContext, "doNotCheckSecurityOnSetterLongAttribute", "TestInterfaceCheckSecurity", holder, info.GetIsolate());
122     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
123     V8TRYCATCH_EXCEPTION_VOID(int, cppValue, toInt32(v8Value, exceptionState), exceptionState);
124     impl->setDoNotCheckSecurityOnSetterLongAttribute(cppValue);
125 }
126
127 static void doNotCheckSecurityOnSetterLongAttributeAttributeSetterCallback(v8::Local<v8::String>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
128 {
129     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
130     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityOnSetterLongAttributeAttributeSetter(v8Value, info);
131     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
132 }
133
134 static void doNotCheckSecurityReplaceableReadonlyLongAttributeAttributeGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
135 {
136     v8::Handle<v8::Object> holder = info.Holder();
137     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
138     v8SetReturnValueInt(info, impl->doNotCheckSecurityReplaceableReadonlyLongAttribute());
139 }
140
141 static void doNotCheckSecurityReplaceableReadonlyLongAttributeAttributeGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
142 {
143     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
144     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReplaceableReadonlyLongAttributeAttributeGetter(info);
145     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
146 }
147
148 static void TestInterfaceCheckSecurityReplaceableAttributeSetter(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
149 {
150     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(info.Holder());
151     v8::Isolate* isolate = info.GetIsolate();
152     v8::String::Utf8Value attributeName(name);
153     ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "TestInterfaceCheckSecurity", info.Holder(), isolate);
154     if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), exceptionState)) {
155         exceptionState.throwIfNeeded();
156         return;
157     }
158     info.This()->ForceSet(name, v8Value);
159 }
160
161 static void TestInterfaceCheckSecurityReplaceableAttributeSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
162 {
163     TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityReplaceableAttributeSetter(name, v8Value, info);
164 }
165
166 bool indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>)
167 {
168     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(host);
169     return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), impl->frame(), DoNotReportSecurityError);
170 }
171
172 bool namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
173 {
174     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(host);
175     return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), impl->frame(), DoNotReportSecurityError);
176 }
177
178 static void voidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
179 {
180     ExceptionState exceptionState(ExceptionState::ExecutionContext, "voidMethod", "TestInterfaceCheckSecurity", info.Holder(), info.GetIsolate());
181     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(info.Holder());
182     if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), impl->frame(), exceptionState)) {
183         exceptionState.throwIfNeeded();
184         return;
185     }
186     impl->voidMethod();
187 }
188
189 static void voidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
190 {
191     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
192     TestInterfaceCheckSecurityV8Internal::voidMethodMethod(info);
193     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
194 }
195
196 static void doNotCheckSecurityVoidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
197 {
198     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(info.Holder());
199     impl->doNotCheckSecurityVoidMethod();
200 }
201
202 static void doNotCheckSecurityVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
203 {
204     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
205     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodMethod(info);
206     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
207 }
208
209 static void doNotCheckSecurityVoidMethodOriginSafeMethodGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
210 {
211     v8::Isolate* isolate = info.GetIsolate();
212     static int domTemplateKey; // This address is used for a key to look up the dom template.
213     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
214     v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
215
216     v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), isolate);
217     if (holder.IsEmpty()) {
218         // This is only reachable via |object.__proto__.func|, in which case it
219         // has already passed the same origin security check
220         v8SetReturnValue(info, privateTemplate->GetFunction());
221         return;
222     }
223     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
224     if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), DoNotReportSecurityError)) {
225         static int sharedTemplateKey; // This address is used for a key to look up the dom template.
226         v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
227         v8SetReturnValue(info, sharedTemplate->GetFunction());
228         return;
229     }
230
231     v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(v8AtomicString(isolate, "doNotCheckSecurityVoidMethod"));
232     if (!hiddenValue.IsEmpty()) {
233         v8SetReturnValue(info, hiddenValue);
234         return;
235     }
236
237     v8SetReturnValue(info, privateTemplate->GetFunction());
238 }
239
240 static void doNotCheckSecurityVoidMethodOriginSafeMethodGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
241 {
242     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
243     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodOriginSafeMethodGetter(info);
244     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
245 }
246
247 static void doNotCheckSecurityDoNotCheckSignatureVoidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
248 {
249     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(info.Holder());
250     impl->doNotCheckSecurityDoNotCheckSignatureVoidMethod();
251 }
252
253 static void doNotCheckSecurityDoNotCheckSignatureVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
254 {
255     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
256     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodMethod(info);
257     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
258 }
259
260 static void doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeMethodGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
261 {
262     v8::Isolate* isolate = info.GetIsolate();
263     static int domTemplateKey; // This address is used for a key to look up the dom template.
264     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
265     v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodMethodCallback, v8Undefined(), v8::Local<v8::Signature>(), 0);
266
267     v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), isolate);
268     if (holder.IsEmpty()) {
269         // This is only reachable via |object.__proto__.func|, in which case it
270         // has already passed the same origin security check
271         v8SetReturnValue(info, privateTemplate->GetFunction());
272         return;
273     }
274     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
275     if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), DoNotReportSecurityError)) {
276         static int sharedTemplateKey; // This address is used for a key to look up the dom template.
277         v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodMethodCallback, v8Undefined(), v8::Local<v8::Signature>(), 0);
278         v8SetReturnValue(info, sharedTemplate->GetFunction());
279         return;
280     }
281
282     v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(v8AtomicString(isolate, "doNotCheckSecurityDoNotCheckSignatureVoidMethod"));
283     if (!hiddenValue.IsEmpty()) {
284         v8SetReturnValue(info, hiddenValue);
285         return;
286     }
287
288     v8SetReturnValue(info, privateTemplate->GetFunction());
289 }
290
291 static void doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeMethodGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
292 {
293     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
294     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeMethodGetter(info);
295     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
296 }
297
298 static void doNotCheckSecurityPerWorldBindingsVoidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
299 {
300     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(info.Holder());
301     impl->doNotCheckSecurityPerWorldBindingsVoidMethod();
302 }
303
304 static void doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
305 {
306     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
307     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethod(info);
308     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
309 }
310
311 static void doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
312 {
313     v8::Isolate* isolate = info.GetIsolate();
314     static int domTemplateKey; // This address is used for a key to look up the dom template.
315     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
316     v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
317
318     v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), isolate);
319     if (holder.IsEmpty()) {
320         // This is only reachable via |object.__proto__.func|, in which case it
321         // has already passed the same origin security check
322         v8SetReturnValue(info, privateTemplate->GetFunction());
323         return;
324     }
325     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
326     if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), DoNotReportSecurityError)) {
327         static int sharedTemplateKey; // This address is used for a key to look up the dom template.
328         v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
329         v8SetReturnValue(info, sharedTemplate->GetFunction());
330         return;
331     }
332
333     v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(v8AtomicString(isolate, "doNotCheckSecurityPerWorldBindingsVoidMethod"));
334     if (!hiddenValue.IsEmpty()) {
335         v8SetReturnValue(info, hiddenValue);
336         return;
337     }
338
339     v8SetReturnValue(info, privateTemplate->GetFunction());
340 }
341
342 static void doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
343 {
344     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
345     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetter(info);
346     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
347 }
348
349 static void doNotCheckSecurityPerWorldBindingsVoidMethodMethodForMainWorld(const v8::FunctionCallbackInfo<v8::Value>& info)
350 {
351     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(info.Holder());
352     impl->doNotCheckSecurityPerWorldBindingsVoidMethod();
353 }
354
355 static void doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallbackForMainWorld(const v8::FunctionCallbackInfo<v8::Value>& info)
356 {
357     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
358     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodForMainWorld(info);
359     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
360 }
361
362 static void doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterForMainWorld(const v8::PropertyCallbackInfo<v8::Value>& info)
363 {
364     v8::Isolate* isolate = info.GetIsolate();
365     static int domTemplateKey; // This address is used for a key to look up the dom template.
366     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
367     v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallbackForMainWorld, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
368
369     v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), isolate);
370     if (holder.IsEmpty()) {
371         // This is only reachable via |object.__proto__.func|, in which case it
372         // has already passed the same origin security check
373         v8SetReturnValue(info, privateTemplate->GetFunction());
374         return;
375     }
376     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
377     if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), DoNotReportSecurityError)) {
378         static int sharedTemplateKey; // This address is used for a key to look up the dom template.
379         v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodMethodCallbackForMainWorld, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
380         v8SetReturnValue(info, sharedTemplate->GetFunction());
381         return;
382     }
383
384     v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(v8AtomicString(isolate, "doNotCheckSecurityPerWorldBindingsVoidMethod"));
385     if (!hiddenValue.IsEmpty()) {
386         v8SetReturnValue(info, hiddenValue);
387         return;
388     }
389
390     v8SetReturnValue(info, privateTemplate->GetFunction());
391 }
392
393 static void doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterCallbackForMainWorld(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
394 {
395     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
396     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterForMainWorld(info);
397     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
398 }
399
400 static void doNotCheckSecurityReadOnlyVoidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
401 {
402     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(info.Holder());
403     impl->doNotCheckSecurityReadOnlyVoidMethod();
404 }
405
406 static void doNotCheckSecurityReadOnlyVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
407 {
408     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
409     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReadOnlyVoidMethodMethod(info);
410     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
411 }
412
413 static void doNotCheckSecurityReadOnlyVoidMethodOriginSafeMethodGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
414 {
415     v8::Isolate* isolate = info.GetIsolate();
416     static int domTemplateKey; // This address is used for a key to look up the dom template.
417     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
418     v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReadOnlyVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
419
420     v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), isolate);
421     if (holder.IsEmpty()) {
422         // This is only reachable via |object.__proto__.func|, in which case it
423         // has already passed the same origin security check
424         v8SetReturnValue(info, privateTemplate->GetFunction());
425         return;
426     }
427     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
428     if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), DoNotReportSecurityError)) {
429         static int sharedTemplateKey; // This address is used for a key to look up the dom template.
430         v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReadOnlyVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
431         v8SetReturnValue(info, sharedTemplate->GetFunction());
432         return;
433     }
434
435     v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(v8AtomicString(isolate, "doNotCheckSecurityReadOnlyVoidMethod"));
436     if (!hiddenValue.IsEmpty()) {
437         v8SetReturnValue(info, hiddenValue);
438         return;
439     }
440
441     v8SetReturnValue(info, privateTemplate->GetFunction());
442 }
443
444 static void doNotCheckSecurityReadOnlyVoidMethodOriginSafeMethodGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
445 {
446     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
447     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReadOnlyVoidMethodOriginSafeMethodGetter(info);
448     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
449 }
450
451 static void doNotCheckSecurityUnforgeableVoidMethodMethod(const v8::FunctionCallbackInfo<v8::Value>& info)
452 {
453     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(info.Holder());
454     impl->doNotCheckSecurityUnforgeableVoidMethod();
455 }
456
457 static void doNotCheckSecurityUnforgeableVoidMethodMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
458 {
459     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
460     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodMethod(info);
461     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
462 }
463
464 static void doNotCheckSecurityUnforgeableVoidMethodOriginSafeMethodGetter(const v8::PropertyCallbackInfo<v8::Value>& info)
465 {
466     v8::Isolate* isolate = info.GetIsolate();
467     static int domTemplateKey; // This address is used for a key to look up the dom template.
468     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
469     v8::Handle<v8::FunctionTemplate> privateTemplate = data->domTemplate(&domTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
470
471     v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), isolate);
472     if (holder.IsEmpty()) {
473         // This is only reachable via |object.__proto__.func|, in which case it
474         // has already passed the same origin security check
475         v8SetReturnValue(info, privateTemplate->GetFunction());
476         return;
477     }
478     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
479     if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), DoNotReportSecurityError)) {
480         static int sharedTemplateKey; // This address is used for a key to look up the dom template.
481         v8::Handle<v8::FunctionTemplate> sharedTemplate = data->domTemplate(&sharedTemplateKey, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodMethodCallback, v8Undefined(), v8::Signature::New(info.GetIsolate(), V8TestInterfaceCheckSecurity::domTemplate(info.GetIsolate())), 0);
482         v8SetReturnValue(info, sharedTemplate->GetFunction());
483         return;
484     }
485
486     v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(v8AtomicString(isolate, "doNotCheckSecurityUnforgeableVoidMethod"));
487     if (!hiddenValue.IsEmpty()) {
488         v8SetReturnValue(info, hiddenValue);
489         return;
490     }
491
492     v8SetReturnValue(info, privateTemplate->GetFunction());
493 }
494
495 static void doNotCheckSecurityUnforgeableVoidMethodOriginSafeMethodGetterCallback(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>& info)
496 {
497     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
498     TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodOriginSafeMethodGetter(info);
499     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
500 }
501
502 static void TestInterfaceCheckSecurityOriginSafeMethodSetter(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
503 {
504     v8::Isolate* isolate = info.GetIsolate();
505     v8::Handle<v8::Object> holder = V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(info.This(), isolate);
506     if (holder.IsEmpty())
507         return;
508     TestInterfaceCheckSecurity* impl = V8TestInterfaceCheckSecurity::toNative(holder);
509     v8::String::Utf8Value attributeName(name);
510     ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "TestInterfaceCheckSecurity", info.Holder(), isolate);
511     if (!BindingSecurity::shouldAllowAccessToFrame(isolate, impl->frame(), exceptionState)) {
512         exceptionState.throwIfNeeded();
513         return;
514     }
515
516     V8HiddenValue::setHiddenValue(isolate, info.This(), name, v8Value);
517 }
518
519 static void TestInterfaceCheckSecurityOriginSafeMethodSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info)
520 {
521     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMSetter");
522     TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetter(name, v8Value, info);
523     TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution");
524 }
525
526 } // namespace TestInterfaceCheckSecurityV8Internal
527
528 static const V8DOMConfiguration::AttributeConfiguration V8TestInterfaceCheckSecurityAttributes[] = {
529     {"longAttribute", TestInterfaceCheckSecurityV8Internal::longAttributeAttributeGetterCallback, 0, 0, 0, 0, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
530     {"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), 0 /* on instance */},
531     {"doNotCheckSecurityReadonlyLongAttribute", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReadonlyLongAttributeAttributeGetterCallback, 0, 0, 0, 0, static_cast<v8::AccessControl>(v8::ALL_CAN_READ), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
532     {"doNotCheckSecurityOnSetterLongAttribute", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityOnSetterLongAttributeAttributeGetterCallback, TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityOnSetterLongAttributeAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::ALL_CAN_WRITE), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
533     {"doNotCheckSecurityReplaceableReadonlyLongAttribute", TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReplaceableReadonlyLongAttributeAttributeGetterCallback, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityReplaceableAttributeSetterCallback, 0, 0, 0, static_cast<v8::AccessControl>(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
534 };
535
536 static const V8DOMConfiguration::MethodConfiguration V8TestInterfaceCheckSecurityMethods[] = {
537     {"voidMethod", TestInterfaceCheckSecurityV8Internal::voidMethodMethodCallback, 0, 0},
538 };
539
540 static void configureV8TestInterfaceCheckSecurityTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
541 {
542     functionTemplate->ReadOnlyPrototype();
543
544     v8::Local<v8::Signature> defaultSignature;
545     defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceCheckSecurity", v8::Local<v8::FunctionTemplate>(), V8TestInterfaceCheckSecurity::internalFieldCount,
546         V8TestInterfaceCheckSecurityAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceCheckSecurityAttributes),
547         0, 0,
548         V8TestInterfaceCheckSecurityMethods, WTF_ARRAY_LENGTH(V8TestInterfaceCheckSecurityMethods),
549         isolate);
550     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED instanceTemplate = functionTemplate->InstanceTemplate();
551     v8::Local<v8::ObjectTemplate> ALLOW_UNUSED prototypeTemplate = functionTemplate->PrototypeTemplate();
552     instanceTemplate->SetAccessCheckCallbacks(TestInterfaceCheckSecurityV8Internal::namedSecurityCheck, TestInterfaceCheckSecurityV8Internal::indexedSecurityCheck, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&V8TestInterfaceCheckSecurity::wrapperTypeInfo)));
553     prototypeTemplate->SetAccessor(v8AtomicString(isolate, "doNotCheckSecurityVoidMethod"), TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityVoidMethodOriginSafeMethodGetterCallback, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetterCallback, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete));
554     prototypeTemplate->SetAccessor(v8AtomicString(isolate, "doNotCheckSecurityDoNotCheckSignatureVoidMethod"), TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityDoNotCheckSignatureVoidMethodOriginSafeMethodGetterCallback, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetterCallback, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete));
555     if (DOMWrapperWorld::current(isolate)->isMainWorld()) {
556         prototypeTemplate->SetAccessor(v8AtomicString(isolate, "doNotCheckSecurityPerWorldBindingsVoidMethod"), TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterCallbackForMainWorld, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetterCallback, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete));
557     } else {
558         prototypeTemplate->SetAccessor(v8AtomicString(isolate, "doNotCheckSecurityPerWorldBindingsVoidMethod"), TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityPerWorldBindingsVoidMethodOriginSafeMethodGetterCallback, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetterCallback, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete));
559     }
560     prototypeTemplate->SetAccessor(v8AtomicString(isolate, "doNotCheckSecurityReadOnlyVoidMethod"), TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityReadOnlyVoidMethodOriginSafeMethodGetterCallback, 0, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly));
561     instanceTemplate->SetAccessor(v8AtomicString(isolate, "doNotCheckSecurityUnforgeableVoidMethod"), TestInterfaceCheckSecurityV8Internal::doNotCheckSecurityUnforgeableVoidMethodOriginSafeMethodGetterCallback, TestInterfaceCheckSecurityV8Internal::TestInterfaceCheckSecurityOriginSafeMethodSetterCallback, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete));
562
563     // Custom toString template
564     functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::current()->toStringTemplate());
565 }
566
567 v8::Handle<v8::FunctionTemplate> V8TestInterfaceCheckSecurity::domTemplate(v8::Isolate* isolate)
568 {
569     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
570     v8::Local<v8::FunctionTemplate> result = data->existingDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo));
571     if (!result.IsEmpty())
572         return result;
573
574     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
575     result = v8::FunctionTemplate::New(isolate, V8ObjectConstructor::isValidConstructorMode);
576     configureV8TestInterfaceCheckSecurityTemplate(result, isolate);
577     data->setDOMTemplate(const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), result);
578     return result;
579 }
580
581 bool V8TestInterfaceCheckSecurity::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
582 {
583     return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value);
584 }
585
586 v8::Handle<v8::Object> V8TestInterfaceCheckSecurity::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate)
587 {
588     return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value);
589 }
590
591 TestInterfaceCheckSecurity* V8TestInterfaceCheckSecurity::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
592 {
593     return hasInstance(value, isolate) ? fromInternalPointer(v8::Handle<v8::Object>::Cast(value)->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)) : 0;
594 }
595
596 v8::Handle<v8::Object> V8TestInterfaceCheckSecurity::createWrapper(PassRefPtr<TestInterfaceCheckSecurity> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
597 {
598     ASSERT(impl);
599     ASSERT(!DOMDataStore::containsWrapper<V8TestInterfaceCheckSecurity>(impl.get(), isolate));
600     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
601         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
602         // Might be a XXXConstructor::wrapperTypeInfo instead of an XXX::wrapperTypeInfo. These will both have
603         // the same object de-ref functions, though, so use that as the basis of the check.
604         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == wrapperTypeInfo.derefObjectFunction);
605     }
606
607     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &wrapperTypeInfo, toInternalPointer(impl.get()), isolate);
608     if (UNLIKELY(wrapper.IsEmpty()))
609         return wrapper;
610
611     installPerContextEnabledProperties(wrapper, impl.get(), isolate);
612     V8DOMWrapper::associateObjectWithWrapper<V8TestInterfaceCheckSecurity>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
613     return wrapper;
614 }
615
616 void V8TestInterfaceCheckSecurity::derefObject(void* object)
617 {
618     fromInternalPointer(object)->deref();
619 }
620
621 template<>
622 v8::Handle<v8::Value> toV8NoInline(TestInterfaceCheckSecurity* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
623 {
624     return toV8(impl, creationContext, isolate);
625 }
626
627 } // namespace WebCore