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; |
47 class ScriptState; | 48 class ScriptState; |
49 class SVGElement; | |
haraken
2013/05/01 18:49:12
Nit: Alphabetical order please.
| |
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 |
63 // You can just use toV8(Node*) to get correct wrapper objects, | 65 // You can just use toV8(Node*) to get correct wrapper objects, |
64 // even for custom elements. Then generated | 66 // even for custom elements. Then generated |
65 // ElementWrapperFactories call V8CustomElement::wrap() with | 67 // ElementWrapperFactories call V8CustomElement::wrap() with |
66 // proper prototype instances accordingly. | 68 // proper prototype instances accordingly. |
67 static v8::Handle<v8::Object> wrap(Element*, v8::Handle<v8::Object> creation Context, v8::Isolate*); | |
68 | 69 |
69 static bool hasDefinition(Element*); | 70 typedef v8::Handle<v8::Object> (*CreateSVGWrapperFunction)(SVGElement*, v8:: Handle<v8::Object> creationContext, v8::Isolate*); |
71 typedef v8::Handle<v8::Object> (*CreateHTMLWrapperFunction)(HTMLElement*, v8 ::Handle<v8::Object> creationContext, v8::Isolate*); | |
72 class CreateWrapperFunction { | |
dglazkov
2013/05/01 16:51:22
Effectively, CreateWrapperFunction carries the kno
dominicc (has gone to gerrit)
2013/05/02 01:29:56
I added a brief comment. It's C++ man... in any re
| |
73 public: | |
74 explicit CreateWrapperFunction(CreateSVGWrapperFunction svg) | |
75 : m_svg(svg) { } | |
76 explicit CreateWrapperFunction(CreateHTMLWrapperFunction html) | |
77 : m_html(html) { } | |
78 v8::Handle<v8::Object> invoke(Element*, v8::Handle<v8::Object> creationC ontext, v8::Isolate*) const; | |
79 private: | |
80 CreateSVGWrapperFunction m_svg; | |
81 CreateHTMLWrapperFunction m_html; | |
82 }; | |
83 | |
84 static v8::Handle<v8::Object> wrap(Element*, v8::Handle<v8::Object> creation Context, v8::Isolate*, const CreateWrapperFunction& createTypeExtensionUpgradeCa ndidateWrapper); | |
85 | |
86 static bool isCustomElement(Element*); | |
70 | 87 |
71 private: | 88 private: |
72 static void invokeReadyCallbackIfNeeded(Element*, v8::Handle<v8::Context>); | 89 static void invokeReadyCallbackIfNeeded(Element*, v8::Handle<v8::Context>); |
73 static v8::Handle<v8::Object> createWrapper(PassRefPtr<Element>, v8::Handle< v8::Object>, v8::Isolate*); | 90 static v8::Handle<v8::Object> createWrapper(PassRefPtr<Element>, v8::Handle< v8::Object>, v8::Isolate*, const CreateWrapperFunction& createTypeExtensionUpgra deCandidateWrapper); |
91 static v8::Handle<v8::Object> createUpgradeCandidateWrapper(PassRefPtr<Eleme nt>, v8::Handle<v8::Object> creationContext, v8::Isolate*, const CreateWrapperFu nction& createTypeExtensionUpgradeCandidateWrapper); | |
dglazkov
2013/05/01 16:51:22
The new createUpgradeCandidateWrapper serves as th
| |
74 }; | 92 }; |
75 | 93 |
76 inline v8::Handle<v8::Object> CustomElementHelpers::wrap(Element* impl, v8::Hand le<v8::Object> creationContext, v8::Isolate* isolate) | 94 inline v8::Handle<v8::Object> CustomElementHelpers::wrap(Element* impl, v8::Hand le<v8::Object> creationContext, v8::Isolate* isolate, const CreateWrapperFunctio n& createWrapper) |
77 { | 95 { |
78 ASSERT(impl); | 96 ASSERT(impl); |
79 ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty()); | 97 ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty()); |
80 return CustomElementHelpers::createWrapper(impl, creationContext, isolate); | 98 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 } | 99 } |
90 | 100 |
91 inline bool CustomElementHelpers::isValidPrototypeParameter(const ScriptValue& v alue, ScriptState* state) | 101 inline bool CustomElementHelpers::isValidPrototypeParameter(const ScriptValue& v alue, ScriptState* state) |
92 { | 102 { |
93 AtomicString namespaceURI; | 103 AtomicString namespaceURI; |
94 return isValidPrototypeParameter(value, state, namespaceURI); | 104 return isValidPrototypeParameter(value, state, namespaceURI); |
95 } | 105 } |
96 | 106 |
97 } // namespace WebCore | 107 } // namespace WebCore |
98 | 108 |
99 #endif // CustomElementHelpers_h | 109 #endif // CustomElementHelpers_h |
OLD | NEW |