| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 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 | |
| 13 * distribution. | |
| 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. | |
| 17 * | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "sky/engine/config.h" | |
| 32 #include "sky/engine/bindings/core/v8/CustomElementWrapper.h" | |
| 33 | |
| 34 #include "bindings/core/v8/V8HTMLElement.h" | |
| 35 #include "core/V8HTMLElementWrapperFactory.h" // FIXME: should be bindings/core/
v8 | |
| 36 #include "sky/engine/bindings/core/v8/DOMDataStore.h" | |
| 37 #include "sky/engine/bindings/core/v8/DOMWrapperWorld.h" | |
| 38 #include "sky/engine/bindings/core/v8/V8PerContextData.h" | |
| 39 #include "sky/engine/core/dom/custom/CustomElement.h" | |
| 40 #include "sky/engine/core/html/HTMLElement.h" | |
| 41 | |
| 42 namespace blink { | |
| 43 | |
| 44 template<typename ElementType> | |
| 45 v8::Handle<v8::Object> createDirectWrapper(ElementType*, v8::Handle<v8::Object>
creationContext, v8::Isolate*); | |
| 46 | |
| 47 template<> | |
| 48 v8::Handle<v8::Object> createDirectWrapper<HTMLElement>(HTMLElement* element, v8
::Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 49 { | |
| 50 return createV8HTMLDirectWrapper(element, creationContext, isolate); | |
| 51 } | |
| 52 | |
| 53 template<typename ElementType> | |
| 54 v8::Handle<v8::Object> createUpgradeCandidateWrapper(ElementType* element, v8::H
andle<v8::Object> creationContext, v8::Isolate* isolate, v8::Handle<v8::Object>
(*createSpecificWrapper)(ElementType* element, v8::Handle<v8::Object> creationCo
ntext, v8::Isolate*)) | |
| 55 { | |
| 56 if (CustomElement::isValidName(element->localName())) | |
| 57 return createDirectWrapper(element, creationContext, isolate); | |
| 58 if (createSpecificWrapper) | |
| 59 return createSpecificWrapper(element, creationContext, isolate); | |
| 60 return createDirectWrapper(element, creationContext, isolate); | |
| 61 } | |
| 62 | |
| 63 template<typename ElementType, typename WrapperType> | |
| 64 v8::Handle<v8::Object> CustomElementWrapper<ElementType, WrapperType>::wrap(Pass
RefPtr<ElementType> element, v8::Handle<v8::Object> creationContext, v8::Isolate
* isolate, v8::Handle<v8::Object> (*createSpecificWrapper)(ElementType* element,
v8::Handle<v8::Object> creationContext, v8::Isolate*)) | |
| 65 { | |
| 66 ASSERT(DOMDataStore::getWrapper<V8Element>(element.get(), isolate).IsEmpty()
); | |
| 67 | |
| 68 ASSERT(!creationContext.IsEmpty()); | |
| 69 v8::Handle<v8::Context> context = creationContext->CreationContext(); | |
| 70 | |
| 71 if (!element->isUpgradedCustomElement()) | |
| 72 return createUpgradeCandidateWrapper(element.get(), creationContext, iso
late, createSpecificWrapper); | |
| 73 | |
| 74 V8PerContextData* perContextData = V8PerContextData::from(context); | |
| 75 if (!perContextData) | |
| 76 return v8::Handle<v8::Object>(); | |
| 77 | |
| 78 CustomElementBinding* binding = perContextData->customElementBinding(element
->customElementDefinition()); | |
| 79 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext
, binding->wrapperType(), WrapperType::toScriptWrappableBase(element.get()), iso
late); | |
| 80 if (wrapper.IsEmpty()) | |
| 81 return v8::Handle<v8::Object>(); | |
| 82 | |
| 83 wrapper->SetPrototype(binding->prototype()); | |
| 84 | |
| 85 ASSERT(binding->wrapperType()->lifetime == WrapperTypeInfo::Dependent); | |
| 86 V8DOMWrapper::associateObjectWithWrapper<WrapperType>(element, binding->wrap
perType(), wrapper, isolate); | |
| 87 return wrapper; | |
| 88 } | |
| 89 | |
| 90 template | |
| 91 class CustomElementWrapper<HTMLElement, V8HTMLElement>; | |
| 92 | |
| 93 } // namespace blink | |
| OLD | NEW |