Exemplo n.º 1
0
GEN_DOMCSSValue* GEN_DOMCSSValue::createInstance(WebCore::CSSValue* value)
{
    if (!value)
        return 0;

    if (GEN_DOMObject* cachedInstance = getDOMWrapper(value)) {
        cachedInstance->AddRef();
        return static_cast<GEN_DOMCSSValue*>(cachedInstance);
    }

    COMPtr<GEN_DOMCSSValue> domValue;
    switch (value->cssValueType()) {
        case WebCore::CSSValue::CSS_PRIMITIVE_VALUE:
            domValue = new GEN_DOMCSSPrimitiveValue(static_cast<WebCore::CSSPrimitiveValue*>(value));
            break;
        case WebCore::CSSValue::CSS_VALUE_LIST:
            domValue = new GEN_DOMCSSValueList(static_cast<WebCore::CSSValueList*>(value));
            break;
        case WebCore::CSSValue::CSS_INHERIT:
            domValue = new GEN_DOMCSSValue(value);
            break;
        case WebCore::CSSValue::CSS_CUSTOM:
            // FIXME: add support for SVGPaint and SVGColor
            domValue = new GEN_DOMCSSValue(value);
            break;
    }

    setDOMWrapper(value, domValue.get());
    return domValue.releaseRef();
}
Exemplo n.º 2
0
v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(Document* deprecatedDocument, WrapperTypeInfo* type, void* impl)
{
    V8PerContextData* perContextData = 0;

    // Please don't add any more uses of deprecatedDocument. We want to remove it.

    // If we have a pointer to the frame, we cna get the V8PerContextData
    // directly, which is faster than going through V8.
    if (deprecatedDocument && deprecatedDocument->frame())
        perContextData = perContextDataForCurrentWorld(deprecatedDocument->frame());
    else
        perContextData = V8PerContextData::from(v8::Context::GetCurrent());

    v8::Local<v8::Object> instance = perContextData ? perContextData->createWrapperFromCache(type) : V8ObjectConstructor::newInstance(type->getTemplate()->GetFunction());

    // Avoid setting the DOM wrapper for failed allocations.
    if (instance.IsEmpty())
        return instance;

    setDOMWrapper(instance, type, impl);
    if (type == &V8HTMLDocument::info)
        instance = V8HTMLDocument::wrapInShadowObject(instance, static_cast<Node*>(impl));

    return instance;
}
Exemplo n.º 3
0
v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(V8Proxy* proxy, WrapperTypeInfo* type, void* impl)
{
#if ENABLE(WORKERS)
    WorkerContext* workerContext = 0;
#endif
    V8BindingPerContextData* contextData = 0;
    V8IsolatedContext* isolatedContext;
    if (UNLIKELY(!!(isolatedContext = V8IsolatedContext::getEntered()))) {
        contextData = isolatedContext->perContextData();
    } else if (!proxy) {
        v8::Handle<v8::Context> context = v8::Context::GetCurrent();
        if (!context.IsEmpty()) {
            v8::Handle<v8::Object> globalPrototype = v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype());
            if (isWrapperOfType(globalPrototype, &V8DOMWindow::info)) {
                Frame* frame = V8DOMWindow::toNative(globalPrototype)->frame();
                if (frame && frame->script()->canExecuteScripts(NotAboutToExecuteScript))
                    proxy = V8Proxy::retrieve(frame);
            }
#if ENABLE(WORKERS)
            else if (isWrapperOfType(globalPrototype, &V8WorkerContext::info))
                workerContext = V8WorkerContext::toNative(lookupDOMWrapper(V8WorkerContext::GetTemplate(), context->Global()));
#endif
        }
    }

    v8::Local<v8::Object> instance;
    if (!contextData) {
        if (proxy)
            contextData = perContextData(proxy);
#if ENABLE(WORKERS)
        else if (workerContext)
            contextData = perContextData(workerContext);
#endif
    }

    if (contextData)
        instance = contextData->createWrapperFromCache(type);
    else {
        v8::Local<v8::Function> function = type->getTemplate()->GetFunction();
        instance = SafeAllocation::newInstance(function);
    }

    if (!instance.IsEmpty()) {
        // Avoid setting the DOM wrapper for failed allocations.
        setDOMWrapper(instance, type, impl);
        if (type == &V8HTMLDocument::info)
            instance = V8HTMLDocument::WrapInShadowObject(instance, static_cast<Node*>(impl));
    }
    return instance;
}
Exemplo n.º 4
0
GEN_DOMImplementation* GEN_DOMImplementation::createInstance(WebCore::DOMImplementation* impl)
{
    if (!impl)
        return 0;

    if (GEN_DOMObject* cachedInstance = getDOMWrapper(impl)) {
        cachedInstance->AddRef();
        return static_cast<GEN_DOMImplementation*>(cachedInstance);
    }

    COMPtr<GEN_DOMImplementation> comDOMObject = new GEN_DOMImplementation(impl);
    setDOMWrapper(impl, comDOMObject.get());
    return comDOMObject.releaseRef();
}
Exemplo n.º 5
0
v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(V8Proxy* proxy, WrapperTypeInfo* type, void* impl)
{
#if ENABLE(WORKERS)
    WorkerContext* workerContext = 0;
#endif
    if (V8IsolatedContext::getEntered()) {
        // This effectively disables the wrapper cache for isolated worlds.
        proxy = 0;
        // FIXME: Do we need a wrapper cache for the isolated world?  We should
        //        see if the performance gains are worth while.
        // We'll get one once we give the isolated context a proper window shell.
    } else if (!proxy) {
        v8::Handle<v8::Context> context = v8::Context::GetCurrent();
        if (!context.IsEmpty()) {
            v8::Handle<v8::Object> globalPrototype = v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype());
            if (isWrapperOfType(globalPrototype, &V8DOMWindow::info)) {
                Frame* frame = V8DOMWindow::toNative(globalPrototype)->frame();
                if (frame && frame->script()->canExecuteScripts(NotAboutToExecuteScript))
                    proxy = V8Proxy::retrieve(frame);
            }
#if ENABLE(WORKERS)
            else
                workerContext = V8WorkerContext::toNative(lookupDOMWrapper(V8WorkerContext::GetTemplate(), context->Global()));
#endif
        }
    }

    v8::Local<v8::Object> instance;
    if (proxy)
        // FIXME: Fix this to work properly with isolated worlds (see above).
        instance = proxy->windowShell()->createWrapperFromCache(type);
    else {
        v8::Local<v8::Function> function;
#if ENABLE(WORKERS)
        if (workerContext)
            function = getConstructor(type, workerContext);
        else
#endif
            function = type->getTemplate()->GetFunction();
        instance = SafeAllocation::newInstance(function);
    }
    if (!instance.IsEmpty()) {
        // Avoid setting the DOM wrapper for failed allocations.
        setDOMWrapper(instance, type, impl);
        if (type == &V8HTMLDocument::info)
            instance = V8HTMLDocument::WrapInShadowObject(instance, static_cast<Node*>(impl));
    }
    return instance;
}
Exemplo n.º 6
0
GEN_DOMStyleSheet* GEN_DOMStyleSheet::createInstance(WebCore::StyleSheet* styleSheet)
{
    if (!styleSheet)
        return 0;

    if (GEN_DOMObject* cachedInstance = getDOMWrapper(styleSheet)) {
        cachedInstance->AddRef();
        return static_cast<GEN_DOMStyleSheet*>(cachedInstance);
    }

    COMPtr<GEN_DOMStyleSheet> domStyleSheet;
    if (styleSheet->isCSSStyleSheet())
        domStyleSheet = new GEN_DOMCSSStyleSheet(static_cast<WebCore::CSSStyleSheet*>(styleSheet));
    else
        domStyleSheet = new GEN_DOMStyleSheet(styleSheet);

    setDOMWrapper(styleSheet, domStyleSheet.get());
    return domStyleSheet.releaseRef();
}
Exemplo n.º 7
0
GEN_DOMCSSRule* GEN_DOMCSSRule::createInstance(WebCore::CSSRule* rule)
{
    if (!rule)
        return 0;

    if (GEN_DOMObject* cachedInstance = getDOMWrapper(rule)) {
        cachedInstance->AddRef();
        return static_cast<GEN_DOMCSSRule*>(cachedInstance);
    }

    COMPtr<GEN_DOMCSSRule> domRule;
    switch (rule->type()) {
        case WebCore::CSSRule::STYLE_RULE:
            domRule = new GEN_DOMCSSStyleRule(static_cast<WebCore::CSSStyleRule*>(rule));
            break;
        case WebCore::CSSRule::CHARSET_RULE:
            domRule = new GEN_DOMCSSCharsetRule(static_cast<WebCore::CSSCharsetRule*>(rule));
            break;
        case WebCore::CSSRule::IMPORT_RULE:
            domRule = new GEN_DOMCSSImportRule(static_cast<WebCore::CSSImportRule*>(rule));
            break;
        case WebCore::CSSRule::MEDIA_RULE:
            domRule = new GEN_DOMCSSMediaRule(static_cast<WebCore::CSSMediaRule*>(rule));
            break;
        case WebCore::CSSRule::FONT_FACE_RULE:
            domRule = new GEN_DOMCSSFontFaceRule(static_cast<WebCore::CSSFontFaceRule*>(rule));
            break;
        case WebCore::CSSRule::PAGE_RULE:
            domRule = new GEN_DOMCSSPageRule(static_cast<WebCore::CSSPageRule*>(rule));
            break;
        case WebCore::CSSRule::UNKNOWN_RULE:
        default:
            domRule = new GEN_DOMCSSRule(rule);
            break;
    }

    setDOMWrapper(rule, domRule.get());
    return domRule.releaseRef();
}
Exemplo n.º 8
0
v8::Local<v8::Object> V8DOMWrapper::instantiateV8Object(V8Proxy* proxy, V8ClassIndex::V8WrapperType type, void* impl)
{
    WorkerContext* workerContext = 0;
    if (V8IsolatedContext::getEntered()) {
        // This effectively disables the wrapper cache for isolated worlds.
        proxy = 0;
        // FIXME: Do we need a wrapper cache for the isolated world?  We should
        //        see if the performance gains are worth while.
        // We'll get one once we give the isolated context a proper window shell.
    } else if (!proxy) {
        v8::Handle<v8::Context> context = v8::Context::GetCurrent();
        if (!context.IsEmpty()) {
            v8::Handle<v8::Object> globalPrototype = v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype());
            if (globalObjectPrototypeIsDOMWindow(globalPrototype))
                proxy = V8Proxy::retrieve(V8DOMWindow::toNative(globalPrototype)->frame());
            else
                workerContext = V8WorkerContext::toNative(lookupDOMWrapper(V8WorkerContext::GetTemplate(), context->Global()));
        }
    }

    v8::Local<v8::Object> instance;
    if (proxy)
        // FIXME: Fix this to work properly with isolated worlds (see above).
        instance = proxy->windowShell()->createWrapperFromCache(type);
    else {
        v8::Local<v8::Function> function;
        if (workerContext)
            function = getConstructor(type, workerContext);
        else
            function = V8ClassIndex::getTemplate(type)->GetFunction();
        instance = SafeAllocation::newInstance(function);
    }
    if (!instance.IsEmpty()) {
        // Avoid setting the DOM wrapper for failed allocations.
        setDOMWrapper(instance, V8ClassIndex::ToInt(type), impl);
    }
    return instance;
}
Exemplo n.º 9
0
GEN_DOMNode* GEN_DOMNode::createInstance(WebCore::Node* node)
{
    if (!node)
        return 0;

    if (GEN_DOMObject* cachedInstance = getDOMWrapper(node)) {
        cachedInstance->AddRef();
        return static_cast<GEN_DOMNode*>(cachedInstance);
    }

    COMPtr<GEN_DOMNode> domNode;
    switch (node->nodeType()) {
        case WebCore::Node::ELEMENT_NODE:
            // FIXME: add support for creating subclasses of HTMLElement.
            // FIXME: add support for creating SVGElements and its subclasses.
            if (node->isHTMLElement())
                domNode = new GEN_DOMHTMLElement(static_cast<WebCore::HTMLElement*>(node));
            else
                domNode = new GEN_DOMElement(static_cast<WebCore::Element*>(node));
            break;
        case WebCore::Node::ATTRIBUTE_NODE:
            domNode = new GEN_DOMAttr(static_cast<WebCore::Attr*>(node));
            break;
        case WebCore::Node::TEXT_NODE:
            domNode = new GEN_DOMText(static_cast<WebCore::Text*>(node));
            break;
        case WebCore::Node::CDATA_SECTION_NODE:
            domNode = new GEN_DOMCDATASection(static_cast<WebCore::CDATASection*>(node));
            break;
        case WebCore::Node::ENTITY_REFERENCE_NODE:
            domNode = new GEN_DOMEntityReference(static_cast<WebCore::EntityReference*>(node));
            break;
        case WebCore::Node::ENTITY_NODE:
            domNode = new GEN_DOMEntity(static_cast<WebCore::Entity*>(node));
            break;
        case WebCore::Node::PROCESSING_INSTRUCTION_NODE:
            domNode = new GEN_DOMProcessingInstruction(static_cast<WebCore::ProcessingInstruction*>(node));
            break;
        case WebCore::Node::COMMENT_NODE:
            domNode = new GEN_DOMComment(static_cast<WebCore::Comment*>(node));
            break;
        case WebCore::Node::DOCUMENT_NODE:
            // FIXME: add support for SVGDocument.
            if (static_cast<WebCore::Document*>(node)->isHTMLDocument())
                domNode = new GEN_DOMHTMLDocument(static_cast<WebCore::HTMLDocument*>(node));
            else
                domNode = new GEN_DOMDocument(static_cast<WebCore::Document*>(node));
            break;
        case WebCore::Node::DOCUMENT_TYPE_NODE:
            domNode = new GEN_DOMDocumentType(static_cast<WebCore::DocumentType*>(node));
            break;
        case WebCore::Node::DOCUMENT_FRAGMENT_NODE:
            domNode = new GEN_DOMDocumentFragment(static_cast<WebCore::DocumentFragment*>(node));
            break;
        case WebCore::Node::NOTATION_NODE:
            domNode = new GEN_DOMNotation(static_cast<WebCore::Notation*>(node));
            break;
        default:
            domNode = new GEN_DOMNode(node);
            break;
    }

    setDOMWrapper(node, domNode.get());
    return domNode.releaseRef();
}