Home | History | Annotate | Download | only in results
      1 /*
      2     This file is part of the Blink open source project.
      3     This file has been auto-generated by CodeGeneratorV8.pm. 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 "RuntimeEnabledFeatures.h"
     25 #include "V8Node.h"
     26 #include "bindings/v8/BindingSecurity.h"
     27 #include "bindings/v8/ExceptionState.h"
     28 #include "bindings/v8/ScriptController.h"
     29 #include "bindings/v8/V8Binding.h"
     30 #include "bindings/v8/V8DOMConfiguration.h"
     31 #include "bindings/v8/V8DOMWrapper.h"
     32 #include "core/dom/ContextFeatures.h"
     33 #include "core/dom/Document.h"
     34 #include "core/page/Frame.h"
     35 #include "core/platform/chromium/TraceEvent.h"
     36 #include "wtf/UnusedParam.h"
     37 
     38 namespace WebCore {
     39 
     40 static void initializeScriptWrappableForInterface(TestActiveDOMObject* object)
     41 {
     42     if (ScriptWrappable::wrapperCanBeStoredInObject(object))
     43         ScriptWrappable::setTypeInfoInObject(object, &V8TestActiveDOMObject::info);
     44     else
     45         ASSERT_NOT_REACHED();
     46 }
     47 
     48 } // namespace WebCore
     49 
     50 // In ScriptWrappable::init, the use of a local function declaration has an issue on Windows:
     51 // the local declaration does not pick up the surrounding namespace. Therefore, we provide this function
     52 // in the global namespace.
     53 // (More info on the MSVC bug here: http://connect.microsoft.com/VisualStudio/feedback/details/664619/the-namespace-of-local-function-declarations-in-c)
     54 void webCoreInitializeScriptWrappableForInterface(WebCore::TestActiveDOMObject* object)
     55 {
     56     WebCore::initializeScriptWrappableForInterface(object);
     57 }
     58 
     59 namespace WebCore {
     60 WrapperTypeInfo V8TestActiveDOMObject::info = { V8TestActiveDOMObject::GetTemplate, V8TestActiveDOMObject::derefObject, 0, 0, 0, V8TestActiveDOMObject::installPerContextPrototypeProperties, 0, WrapperTypeObjectPrototype };
     61 
     62 namespace TestActiveDOMObjectV8Internal {
     63 
     64 template <typename T> void V8_USE(T) { }
     65 
     66 static void excitingAttrAttrGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     67 {
     68     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(info.Holder());
     69     v8SetReturnValueInt(info, imp->excitingAttr());
     70     return;
     71 }
     72 
     73 static void excitingAttrAttrGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
     74 {
     75     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
     76     TestActiveDOMObjectV8Internal::excitingAttrAttrGetter(name, info);
     77     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
     78 }
     79 
     80 bool indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>)
     81 {
     82     TestActiveDOMObject* imp =  V8TestActiveDOMObject::toNative(host);
     83     return BindingSecurity::shouldAllowAccessToFrame(imp->frame(), DoNotReportSecurityError);
     84 }
     85 
     86 bool namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
     87 {
     88     TestActiveDOMObject* imp =  V8TestActiveDOMObject::toNative(host);
     89     return BindingSecurity::shouldAllowAccessToFrame(imp->frame(), DoNotReportSecurityError);
     90 }
     91 
     92 static void excitingFunctionMethod(const v8::FunctionCallbackInfo<v8::Value>& args)
     93 {
     94     if (args.Length() < 1) {
     95         throwNotEnoughArgumentsError(args.GetIsolate());
     96         return;
     97     }
     98     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder());
     99     if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
    100         return;
    101     V8TRYCATCH_VOID(Node*, nextChild, V8Node::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0);
    102     imp->excitingFunction(nextChild);
    103 
    104     return;
    105 }
    106 
    107 static void excitingFunctionMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
    108 {
    109     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
    110     TestActiveDOMObjectV8Internal::excitingFunctionMethod(args);
    111     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
    112 }
    113 
    114 static void postMessageMethod(const v8::FunctionCallbackInfo<v8::Value>& args)
    115 {
    116     if (args.Length() < 1) {
    117         throwNotEnoughArgumentsError(args.GetIsolate());
    118         return;
    119     }
    120     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(args.Holder());
    121     V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, message, args[0]);
    122     imp->postMessage(message);
    123 
    124     return;
    125 }
    126 
    127 static void postMessageMethodCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
    128 {
    129     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMMethod");
    130     TestActiveDOMObjectV8Internal::postMessageMethod(args);
    131     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
    132 }
    133 
    134 static void postMessageAttrGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
    135 {
    136     // This is only for getting a unique pointer which we can pass to privateTemplate.
    137     static const char* privateTemplateUniqueKey = "postMessagePrivateTemplate";
    138     WrapperWorldType currentWorldType = worldType(info.GetIsolate());
    139     V8PerIsolateData* data = V8PerIsolateData::from(info.GetIsolate());
    140     v8::Handle<v8::FunctionTemplate> privateTemplate = data->privateTemplate(currentWorldType, &privateTemplateUniqueKey, TestActiveDOMObjectV8Internal::postMessageMethodCallback, v8Undefined(), v8::Signature::New(V8PerIsolateData::from(info.GetIsolate())->rawTemplate(&V8TestActiveDOMObject::info, currentWorldType)), 1);
    141 
    142     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8TestActiveDOMObject::GetTemplate(info.GetIsolate(), currentWorldType));
    143     if (holder.IsEmpty()) {
    144         // can only reach here by 'object.__proto__.func', and it should passed
    145         // domain security check already
    146         v8SetReturnValue(info, privateTemplate->GetFunction());
    147         return;
    148     }
    149     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder);
    150     if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), DoNotReportSecurityError)) {
    151         static const char* sharedTemplateUniqueKey = "postMessageSharedTemplate";
    152         v8::Handle<v8::FunctionTemplate> sharedTemplate = data->privateTemplate(currentWorldType, &sharedTemplateUniqueKey, TestActiveDOMObjectV8Internal::postMessageMethodCallback, v8Undefined(), v8::Signature::New(V8PerIsolateData::from(info.GetIsolate())->rawTemplate(&V8TestActiveDOMObject::info, currentWorldType)), 1);
    153         v8SetReturnValue(info, sharedTemplate->GetFunction());
    154         return;
    155     }
    156 
    157     v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(name);
    158     if (!hiddenValue.IsEmpty()) {
    159         v8SetReturnValue(info, hiddenValue);
    160         return;
    161     }
    162 
    163     v8SetReturnValue(info, privateTemplate->GetFunction());
    164 }
    165 
    166 static void postMessageAttrGetterCallback(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)
    167 {
    168     TRACE_EVENT_SET_SAMPLING_STATE("Blink", "DOMGetter");
    169     TestActiveDOMObjectV8Internal::postMessageAttrGetter(name, info);
    170     TRACE_EVENT_SET_SAMPLING_STATE("V8", "Execution");
    171 }
    172 
    173 static void TestActiveDOMObjectDomainSafeFunctionSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
    174 {
    175     v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8TestActiveDOMObject::GetTemplate(info.GetIsolate(), worldType(info.GetIsolate())));
    176     if (holder.IsEmpty())
    177         return;
    178     TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder);
    179     if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame()))
    180         return;
    181 
    182     info.This()->SetHiddenValue(name, value);
    183 }
    184 
    185 } // namespace TestActiveDOMObjectV8Internal
    186 
    187 static const V8DOMConfiguration::BatchedAttribute V8TestActiveDOMObjectAttrs[] = {
    188     // Attribute 'excitingAttr'
    189     {"excitingAttr", TestActiveDOMObjectV8Internal::excitingAttrAttrGetterCallback, 0, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
    190 };
    191 
    192 static v8::Handle<v8::FunctionTemplate> ConfigureV8TestActiveDOMObjectTemplate(v8::Handle<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorldType currentWorldType)
    193 {
    194     desc->ReadOnlyPrototype();
    195 
    196     v8::Local<v8::Signature> defaultSignature;
    197     defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestActiveDOMObject", v8::Local<v8::FunctionTemplate>(), V8TestActiveDOMObject::internalFieldCount,
    198         V8TestActiveDOMObjectAttrs, WTF_ARRAY_LENGTH(V8TestActiveDOMObjectAttrs),
    199         0, 0, isolate, currentWorldType);
    200     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
    201     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
    202     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
    203     UNUSED_PARAM(instance); // In some cases, it will not be used.
    204     UNUSED_PARAM(proto); // In some cases, it will not be used.
    205     instance->SetAccessCheckCallbacks(TestActiveDOMObjectV8Internal::namedSecurityCheck, TestActiveDOMObjectV8Internal::indexedSecurityCheck, v8::External::New(&V8TestActiveDOMObject::info));
    206 
    207     // Custom Signature 'excitingFunction'
    208     const int excitingFunctionArgc = 1;
    209     v8::Handle<v8::FunctionTemplate> excitingFunctionArgv[excitingFunctionArgc] = { V8PerIsolateData::from(isolate)->rawTemplate(&V8Node::info, currentWorldType) };
    210     v8::Handle<v8::Signature> excitingFunctionSignature = v8::Signature::New(desc, excitingFunctionArgc, excitingFunctionArgv);
    211     proto->Set(v8::String::NewSymbol("excitingFunction"), v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::excitingFunctionMethodCallback, v8Undefined(), excitingFunctionSignature, 1));
    212 
    213     // Function 'postMessage' (ExtAttr: 'DoNotCheckSecurity')
    214     proto->SetAccessor(v8::String::NewSymbol("postMessage"), TestActiveDOMObjectV8Internal::postMessageAttrGetterCallback, TestActiveDOMObjectV8Internal::TestActiveDOMObjectDomainSafeFunctionSetter, v8Undefined(), v8::ALL_CAN_READ, static_cast<v8::PropertyAttribute>(v8::DontDelete));
    215 
    216     // Custom toString template
    217     desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate());
    218     return desc;
    219 }
    220 
    221 v8::Handle<v8::FunctionTemplate> V8TestActiveDOMObject::GetTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
    222 {
    223     V8PerIsolateData* data = V8PerIsolateData::from(isolate);
    224     V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWorldType).find(&info);
    225     if (result != data->templateMap(currentWorldType).end())
    226         return result->value.newLocal(isolate);
    227 
    228     TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "BuildDOMTemplate");
    229     v8::HandleScope handleScope(isolate);
    230     v8::Handle<v8::FunctionTemplate> templ =
    231         ConfigureV8TestActiveDOMObjectTemplate(data->rawTemplate(&info, currentWorldType), isolate, currentWorldType);
    232     data->templateMap(currentWorldType).add(&info, UnsafePersistent<v8::FunctionTemplate>(isolate, templ));
    233     return handleScope.Close(templ);
    234 }
    235 
    236 bool V8TestActiveDOMObject::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* isolate, WrapperWorldType currentWorldType)
    237 {
    238     return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWorldType);
    239 }
    240 
    241 bool V8TestActiveDOMObject::HasInstanceInAnyWorld(v8::Handle<v8::Value> value, v8::Isolate* isolate)
    242 {
    243     return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld)
    244         || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWorld)
    245         || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorld);
    246 }
    247 
    248 
    249 v8::Handle<v8::Object> V8TestActiveDOMObject::createWrapper(PassRefPtr<TestActiveDOMObject> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
    250 {
    251     ASSERT(impl.get());
    252     ASSERT(DOMDataStore::getWrapper<V8TestActiveDOMObject>(impl.get(), isolate).IsEmpty());
    253     if (ScriptWrappable::wrapperCanBeStoredInObject(impl.get())) {
    254         const WrapperTypeInfo* actualInfo = ScriptWrappable::getTypeInfoFromObject(impl.get());
    255         // Might be a XXXConstructor::info instead of an XXX::info. These will both have
    256         // the same object de-ref functions, though, so use that as the basis of the check.
    257         RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(actualInfo->derefObjectFunction == info.derefObjectFunction);
    258     }
    259 
    260 
    261     v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, &info, toInternalPointer(impl.get()), isolate);
    262     if (UNLIKELY(wrapper.IsEmpty()))
    263         return wrapper;
    264     installPerContextProperties(wrapper, impl.get(), isolate);
    265     V8DOMWrapper::associateObjectWithWrapper<V8TestActiveDOMObject>(impl, &info, wrapper, isolate, WrapperConfiguration::Independent);
    266     return wrapper;
    267 }
    268 void V8TestActiveDOMObject::derefObject(void* object)
    269 {
    270     fromInternalPointer(object)->deref();
    271 }
    272 
    273 } // namespace WebCore
    274