| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "core/dom/CustomElementDefinition.h" | 36 #include "core/dom/CustomElementDefinition.h" |
| 37 #include "core/dom/CustomElementRegistry.h" | 37 #include "core/dom/CustomElementRegistry.h" |
| 38 #include "core/dom/Element.h" | 38 #include "core/dom/Element.h" |
| 39 #include <wtf/Forward.h> | 39 #include <wtf/Forward.h> |
| 40 #include <wtf/PassRefPtr.h> | 40 #include <wtf/PassRefPtr.h> |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace WebCore { |
| 43 | 43 |
| 44 class CustomElementConstructor; | 44 class CustomElementConstructor; |
| 45 class CustomElementInvocation; | 45 class CustomElementInvocation; |
| 46 class HTMLElement; |
| 46 class QualifiedName; | 47 class QualifiedName; |
| 48 class SVGElement; |
| 47 class ScriptState; | 49 class ScriptState; |
| 48 | 50 |
| 49 class CustomElementHelpers { | 51 class CustomElementHelpers { |
| 50 public: | 52 public: |
| 51 static bool initializeConstructorWrapper(CustomElementConstructor*, const Sc
riptValue& prototype, ScriptState*); | 53 static bool initializeConstructorWrapper(CustomElementConstructor*, const Sc
riptValue& prototype, ScriptState*); |
| 52 static bool isValidPrototypeParameter(const ScriptValue&, ScriptState*, Atom
icString& namespaceURI); | 54 static bool isValidPrototypeParameter(const ScriptValue&, ScriptState*, Atom
icString& namespaceURI); |
| 53 static bool isValidPrototypeParameter(const ScriptValue&, ScriptState*); | 55 static bool isValidPrototypeParameter(const ScriptValue&, ScriptState*); |
| 54 static bool isFeatureAllowed(ScriptState*); | 56 static bool isFeatureAllowed(ScriptState*); |
| 55 static const QualifiedName* findLocalName(const ScriptValue& prototype); | 57 static const QualifiedName* findLocalName(const ScriptValue& prototype); |
| 56 | 58 |
| 57 static bool isFeatureAllowed(v8::Handle<v8::Context>); | 59 static bool isFeatureAllowed(v8::Handle<v8::Context>); |
| 58 static WrapperTypeInfo* findWrapperType(v8::Handle<v8::Value> chain); | 60 static WrapperTypeInfo* findWrapperType(v8::Handle<v8::Value> chain); |
| 59 static const QualifiedName* findLocalName(v8::Handle<v8::Object> chain); | 61 static const QualifiedName* findLocalName(v8::Handle<v8::Object> chain); |
| 60 | 62 |
| 61 static void invokeReadyCallbacksIfNeeded(ScriptExecutionContext*, const Vect
or<CustomElementInvocation>&); | 63 static void invokeReadyCallbacksIfNeeded(ScriptExecutionContext*, const Vect
or<CustomElementInvocation>&); |
| 62 | 64 |
| 65 typedef v8::Handle<v8::Object> (*CreateSVGWrapperFunction)(SVGElement*, v8::
Handle<v8::Object> creationContext, v8::Isolate*); |
| 66 typedef v8::Handle<v8::Object> (*CreateHTMLWrapperFunction)(HTMLElement*, v8
::Handle<v8::Object> creationContext, v8::Isolate*); |
| 67 |
| 68 // CustomElementHelpers::wrap is a factory for both HTMLElement |
| 69 // and SVGElement wrappers. CreateWrapperFunction is a type safe |
| 70 // way of passing a wrapping function for specific elements of |
| 71 // either type; it's used as a fallback when creating wrappers for |
| 72 // type extensions. |
| 73 class CreateWrapperFunction { |
| 74 public: |
| 75 explicit CreateWrapperFunction(CreateSVGWrapperFunction svg) |
| 76 : m_svg(svg) { } |
| 77 explicit CreateWrapperFunction(CreateHTMLWrapperFunction html) |
| 78 : m_html(html) { } |
| 79 v8::Handle<v8::Object> invoke(Element*, v8::Handle<v8::Object> creationC
ontext, v8::Isolate*) const; |
| 80 private: |
| 81 CreateSVGWrapperFunction m_svg; |
| 82 CreateHTMLWrapperFunction m_html; |
| 83 }; |
| 84 |
| 63 // You can just use toV8(Node*) to get correct wrapper objects, | 85 // You can just use toV8(Node*) to get correct wrapper objects, |
| 64 // even for custom elements. Then generated | 86 // even for custom elements. Then generated |
| 65 // ElementWrapperFactories call V8CustomElement::wrap() with | 87 // ElementWrapperFactories call V8CustomElement::wrap() with |
| 66 // proper prototype instances accordingly. | 88 // proper prototype instances accordingly. |
| 67 static v8::Handle<v8::Object> wrap(Element*, v8::Handle<v8::Object> creation
Context, v8::Isolate*); | 89 static v8::Handle<v8::Object> wrap(Element*, v8::Handle<v8::Object> creation
Context, v8::Isolate*, const CreateWrapperFunction& createTypeExtensionUpgradeCa
ndidateWrapper); |
| 68 | 90 |
| 69 static bool hasDefinition(Element*); | 91 static bool isCustomElement(Element*); |
| 70 | 92 |
| 71 private: | 93 private: |
| 72 static void invokeReadyCallbackIfNeeded(Element*, v8::Handle<v8::Context>); | 94 static void invokeReadyCallbackIfNeeded(Element*, v8::Handle<v8::Context>); |
| 73 static v8::Handle<v8::Object> createWrapper(PassRefPtr<Element>, v8::Handle<
v8::Object>, v8::Isolate*); | 95 static v8::Handle<v8::Object> createWrapper(PassRefPtr<Element>, v8::Handle<
v8::Object>, v8::Isolate*, const CreateWrapperFunction& createTypeExtensionUpgra
deCandidateWrapper); |
| 96 static v8::Handle<v8::Object> createUpgradeCandidateWrapper(PassRefPtr<Eleme
nt>, v8::Handle<v8::Object> creationContext, v8::Isolate*, const CreateWrapperFu
nction& createTypeExtensionUpgradeCandidateWrapper); |
| 74 }; | 97 }; |
| 75 | 98 |
| 76 inline v8::Handle<v8::Object> CustomElementHelpers::wrap(Element* impl, v8::Hand
le<v8::Object> creationContext, v8::Isolate* isolate) | 99 inline v8::Handle<v8::Object> CustomElementHelpers::wrap(Element* impl, v8::Hand
le<v8::Object> creationContext, v8::Isolate* isolate, const CreateWrapperFunctio
n& createWrapper) |
| 77 { | 100 { |
| 78 ASSERT(impl); | 101 ASSERT(impl); |
| 79 ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty()); | 102 ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty()); |
| 80 return CustomElementHelpers::createWrapper(impl, creationContext, isolate); | 103 return CustomElementHelpers::createWrapper(impl, creationContext, isolate, c
reateWrapper); |
| 81 } | |
| 82 | |
| 83 inline bool CustomElementHelpers::hasDefinition(Element* element) | |
| 84 { | |
| 85 CustomElementRegistry* registry = element->document()->registry(); | |
| 86 if (registry && registry->findFor(element)) | |
| 87 return 1; | |
| 88 return 0; | |
| 89 } | 104 } |
| 90 | 105 |
| 91 inline bool CustomElementHelpers::isValidPrototypeParameter(const ScriptValue& v
alue, ScriptState* state) | 106 inline bool CustomElementHelpers::isValidPrototypeParameter(const ScriptValue& v
alue, ScriptState* state) |
| 92 { | 107 { |
| 93 AtomicString namespaceURI; | 108 AtomicString namespaceURI; |
| 94 return isValidPrototypeParameter(value, state, namespaceURI); | 109 return isValidPrototypeParameter(value, state, namespaceURI); |
| 95 } | 110 } |
| 96 | 111 |
| 97 } // namespace WebCore | 112 } // namespace WebCore |
| 98 | 113 |
| 99 #endif // CustomElementHelpers_h | 114 #endif // CustomElementHelpers_h |
| OLD | NEW |