2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "bindings/core/v8/CustomElementWrapper.h"
34 #include "bindings/core/v8/DOMDataStore.h"
35 #include "bindings/core/v8/DOMWrapperWorld.h"
36 #include "bindings/core/v8/V8HTMLElement.h"
37 #include "bindings/core/v8/V8PerContextData.h"
38 #include "bindings/core/v8/V8SVGElement.h"
39 #include "core/V8HTMLElementWrapperFactory.h" // FIXME: should be bindings/core/v8
40 #include "core/V8SVGElementWrapperFactory.h" // FIXME: should be bindings/core/v8
41 #include "core/dom/custom/CustomElement.h"
42 #include "core/html/HTMLElement.h"
43 #include "core/html/HTMLUnknownElement.h"
44 #include "core/svg/SVGElement.h"
48 template<typename ElementType>
49 v8::Handle<v8::Object> createDirectWrapper(ElementType*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
52 v8::Handle<v8::Object> createDirectWrapper<HTMLElement>(HTMLElement* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
54 return createV8HTMLDirectWrapper(element, creationContext, isolate);
58 v8::Handle<v8::Object> createDirectWrapper<SVGElement>(SVGElement* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
60 return createV8SVGDirectWrapper(element, creationContext, isolate);
63 template<typename ElementType>
64 v8::Handle<v8::Object> createFallbackWrapper(ElementType*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
67 v8::Handle<v8::Object> createFallbackWrapper<HTMLElement>(HTMLElement* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
69 return createV8HTMLFallbackWrapper(toHTMLUnknownElement(element), creationContext, isolate);
73 v8::Handle<v8::Object> createFallbackWrapper<SVGElement>(SVGElement* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
75 return createV8SVGFallbackWrapper(element, creationContext, isolate);
78 template<typename ElementType>
79 v8::Handle<v8::Object> createUpgradeCandidateWrapper(ElementType* element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate, v8::Handle<v8::Object> (*createSpecificWrapper)(ElementType* element, v8::Handle<v8::Object> creationContext, v8::Isolate*))
81 if (CustomElement::isValidName(element->localName()))
82 return createDirectWrapper(element, creationContext, isolate);
83 if (createSpecificWrapper)
84 return createSpecificWrapper(element, creationContext, isolate);
85 return createFallbackWrapper(element, creationContext, isolate);
88 template<typename ElementType, typename WrapperType>
89 v8::Handle<v8::Object> CustomElementWrapper<ElementType, WrapperType>::wrap(PassRefPtrWillBeRawPtr<ElementType> element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate, v8::Handle<v8::Object> (*createSpecificWrapper)(ElementType* element, v8::Handle<v8::Object> creationContext, v8::Isolate*))
91 ASSERT(DOMDataStore::getWrapper<V8Element>(element.get(), isolate).IsEmpty());
93 ASSERT(!creationContext.IsEmpty());
94 v8::Handle<v8::Context> context = creationContext->CreationContext();
96 if (!element->isUpgradedCustomElement() || DOMWrapperWorld::world(context).isIsolatedWorld())
97 return createUpgradeCandidateWrapper(element.get(), creationContext, isolate, createSpecificWrapper);
99 V8PerContextData* perContextData = V8PerContextData::from(context);
101 return v8::Handle<v8::Object>();
103 CustomElementBinding* binding = perContextData->customElementBinding(element->customElementDefinition());
104 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext, binding->wrapperType(), WrapperType::toInternalPointer(element.get()), isolate);
105 if (wrapper.IsEmpty())
106 return v8::Handle<v8::Object>();
108 wrapper->SetPrototype(binding->prototype());
110 V8DOMWrapper::associateObjectWithWrapper<WrapperType>(element, binding->wrapperType(), wrapper, isolate, WrapperConfiguration::Dependent);
115 class CustomElementWrapper<HTMLElement, V8HTMLElement>;
118 class CustomElementWrapper<SVGElement, V8SVGElement>;